//System.out.println(now.toString() + " ... Start of TestGrib2GetData");
// Reading of grib data must be inside a try-catch block
try {
// Create RandomAccessFile instance
RandomAccessFile raf = null;
PrintStream ps = System.out;
long GdsOffset = 0;
long PdsOffset = 0;
// input file and Gds/Pds Offsets given
if (args.length == 1) {
// Create RandomAccessFile
raf = new RandomAccessFile(args[0], "r");
raf.order(RandomAccessFile.BIG_ENDIAN);
//GdsOffset = Long.parseLong(args[1]);
//PdsOffset = Long.parseLong(args[2]);
} else {
System.exit(0);
}
if (args.length == 4) {
ps = new PrintStream(
new BufferedOutputStream(
new FileOutputStream(args[3], false)));
}
Grib2Data g2d = new Grib2Data(raf);
// open index file
InputStream ios = open( GribIndexName.getCurrentSuffix(args[ 0 ] ) );
long start = System.currentTimeMillis();
BufferedReader dataIS =
new BufferedReader(new InputStreamReader(ios));
// section 1 - global attributes
while (true) {
String line = dataIS.readLine();
if (line == null || line.length() == 0) { // 0 length/corrupted index
break;
}
if (line.startsWith("--")) {
break;
}
}
// section 2 -- grib records
while (true) {
String line = dataIS.readLine();
if (line == null || line.length() == 0) { // 0 length/corrupted index
break;
}
if (line.startsWith("--")) {
break;
}
StringTokenizer stoke = new StringTokenizer(line);
String productType = stoke.nextToken();
String discipline = stoke.nextToken();
String category = stoke.nextToken();
String param = stoke.nextToken();
String typeGenProcess = stoke.nextToken();
String levelType1 = stoke.nextToken();
String levelValue1 = stoke.nextToken();
String levelType2 = stoke.nextToken();
String levelValue2 = stoke.nextToken();
String refTime = stoke.nextToken();
String foreTime = stoke.nextToken();
String gdsKey = stoke.nextToken();
GdsOffset = Long.parseLong( stoke.nextToken() );
PdsOffset = Long.parseLong( stoke.nextToken() );
float data[] = g2d.getData(GdsOffset, PdsOffset, 0);
if (data != null) {
System.err.println("OK "+ line );
/*
int row = 0;
for (int j = 0; j < data.length; j++) {
//if( j % 800 == 0 ) // used to test quasi data
//ps.println( "row ="+ row++ );
ps.println("data[ " + j + " ]=" + data[j]);
}
*/
} else {
System.err.println("No data returned "+ line );
}
}
raf.close();
ps.close();
// Catch thrown errors from Grib2GetData
} catch (FileNotFoundException noFileError) {
System.err.println("FileNotFoundException : " + noFileError);