//System.out.println(now.toString() + " ... Start of Grib2Dump");
// Reading of Grib files must be inside a try-catch block
try {
//ParameterTable.addParametersUser("/home/rkambic/code/grib/resources/resources/grib/tables/grib2userparameters" );
RandomAccessFile raf = null;
PrintStream ps = System.out;
if (args.length == 3) { // input file, output file, get data for dump
raf = new RandomAccessFile(args[0], "r");
ps = new PrintStream(
new FilterOutputStream(
new FileOutputStream(args[1], false)));
displayData = args[2].equalsIgnoreCase("true");
} else if (args.length == 2) { // input file and output file for dump
raf = new RandomAccessFile(args[0], "r");
if (args[1].equalsIgnoreCase("true")
|| args[1].equalsIgnoreCase("false")) {
displayData = args[1].equalsIgnoreCase("true");
} else {
ps = new PrintStream(
new FilterOutputStream(
new FileOutputStream(args[1], false)));
}
} else if (args.length == 1) {
raf = new RandomAccessFile(args[0], "r");
} else {
System.exit(0);
}
raf.order(RandomAccessFile.BIG_ENDIAN);
// Create Grib2Input instance
Grib2Input g2i = new Grib2Input(raf);
// boolean params getProductsOnly, oneRecord
g2i.scan(false, false);
// record contains objects for all 8 Grib2 sections
List records = g2i.getRecords();
for (int i = 0; i < records.size(); i++) {
Grib2Record record = (Grib2Record) records.get(i);
Grib2IndicatorSection is = record.getIs();
Grib2IdentificationSection id = record.getId();
Grib2GridDefinitionSection gds = record.getGDS();
Grib2ProductDefinitionSection pds = record.getPDS();
// create dump output here
ps.println(
"--------------------------------------------------------------------");
ps.println(" Header : "
+ record.getHeader());
printIS(is, ps);
printID(id, dateFormat, ps);
printGDS(gds, ps);
printPDS(is, pds, ps);
if (displayData) {
float[] data = null;
ps.println(
"--------------------------------------------------------------------");
Grib2Data gd = new Grib2Data(raf);
data = gd.getData(record.getGdsOffset(), record.getPdsOffset(), id.getRefTime());
if (data != null) {
//float missingValue =
// record.getDRS().getPrimaryMissingValue();
for (int j = 0; j < data.length; j++) {
//if( data[ j ] != missingValue )
ps.println("data[ " + j + " ]=" + data[j]);
}
}
break; // only display data for 1st record
}
}
raf.close(); // done reading
// Catch thrown errors from GribFile
} catch (FileNotFoundException noFileError) {
System.err.println("FileNotFoundException : " + noFileError);
} catch (IOException ioError) {