public static byte[] convert(String srcPath, double a, double b) throws IOException {
NetcdfFile ncfile = NetcdfFile.open(srcPath);
try {
Variable v = ncfile.findVariable("image1/image_data");
Array array = v.read();
int[] cmap = new int[256]; // palette
cmap[0] = 0x00FFFFFF; // transparent and white
for (int i = 1; i != 256; i++) {
// 1 to 255 renders as (almost) white to black
cmap[i] = 0xFF000000 | ((0xFF - i) * 0x010101);
}
IndexColorModel colorModel = new IndexColorModel(8,
cmap.length, cmap, 0, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
int[] shape = array.getShape();
BufferedImage bi = new BufferedImage(shape[1], shape[0],BufferedImage.TYPE_BYTE_INDEXED, colorModel);
Index index = array.getIndex();
for (int y = 0; y < shape[0]; y++) {
for (int x = 0; x < shape[1]; x++) {
index.set(y, x);
byte bval = array.getByte(index);
double dval = v.isUnsigned() ? (double) DataType.unsignedByteToShort(bval) : (double) bval;
//double dval = array.getDouble(index);
// Fix for NetCDF returning all values larger than 127 as (value - 256):
//if (dval < -1) {