//System.out.println(now.toString() + " ... Start of Grib1GetData");
// Reading of grib data must be inside a try-catch block
try {
// Create RandomAccessFile instance
RandomAccessFile raf = null;
PrintStream ps = System.out;
long offset1 = 0;
long offset2 = 0;
boolean bmsExists = true;
int decimalScale = 1;
// input file, offset, decimalScale given
// Create RandomAccessFile
raf = new RandomAccessFile(args[0], "r");
raf.order(RandomAccessFile.BIG_ENDIAN);
offset1 = Long.decode(args[1]).longValue();
//if ((args.length == 4) || (args.length == 5)) {
if ((args.length == 4)) {
decimalScale = Integer.parseInt(args[2]);
Boolean B = Boolean.valueOf(args[3]);
bmsExists = B.booleanValue();
} else if ((args.length == 5)) {
offset2 = Long.decode(args[2]).longValue();
decimalScale = Integer.parseInt(args[3]);
Boolean B = Boolean.valueOf(args[4]);
bmsExists = B.booleanValue();
} else if ((args.length == 6)) {
offset2 = Long.decode(args[2]).longValue();
decimalScale = Integer.parseInt(args[3]);
Boolean B = Boolean.valueOf(args[4]);
bmsExists = B.booleanValue();
ps = new PrintStream(
new BufferedOutputStream(
new FileOutputStream(args[5], false)));
} else {
System.exit(0);
}
long start = System.currentTimeMillis();
Grib1Data g1d = new Grib1Data(raf);
float[] data;
if ((args.length == 4)) {
data = g1d.getData(offset1, decimalScale, bmsExists);
} else {
data = g1d.getData(offset1, offset2, decimalScale, bmsExists);
}
System.out.println("getting data size " + data.length + " took "
+ (System.currentTimeMillis() - start) + " msec");
if (data != null) {
//ps.println("length ="+ data.length );
for (int j = 0; j < data.length; j++) {
ps.println("data[ " + j + " ]=" + data[j]);
}
}
raf.close();
ps.close();
// Catch thrown errors from Grib1GetData
} catch (FileNotFoundException noFileError) {
System.err.println("FileNotFoundException : " + noFileError);