//System.out.println(now.toString() + " ... Start of Grib1Dump");
// Reading of Grib files must be inside a try-catch block
calendar = Calendar.getInstance();
calendar.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
PrintStream ps = System.out;
try {
RandomAccessFile raf = null;
if (args.length == 3) { // input file, output file, get data for dump
raf = new RandomAccessFile(args[0], "r");
ps = new PrintStream(
new BufferedOutputStream(
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 BufferedOutputStream(
new FileOutputStream(args[1], false)));
}
} else if (args.length == 1) {
raf = new RandomAccessFile(args[0], "r");
} else {
System.exit(0);
}
// test for a user defined parameter table read
//GribPDSParamTable.addParameterUserLookup( "/local/robb/trunk20081229/grib/resources/resources/grib/tables/userlookup.lst");
raf.order(RandomAccessFile.BIG_ENDIAN);
// Create Grib1Input instance
Grib1Input g1i = new Grib1Input(raf);
// boolean params getProducts, oneRecord
g1i.scan(false, false);
// record contains objects for all 5 Grib1 sections
ArrayList records = g1i.getRecords();
for (int i = 0; i < records.size(); i++) {
Grib1Record record = (Grib1Record) records.get(i);
Grib1IndicatorSection is = record.getIs();
Grib1ProductDefinitionSection pds = record.getPDS();
Grib1GridDefinitionSection gds = record.getGDS();
// create dump output here
ps.println(
"--------------------------------------------------------------------");
ps.println(" Header : "
+ record.getHeader());
printIS(is, ps);
printPDS(pds, ps);
printGDS(gds, pds, ps);
ps.println();
if (displayData) {
float[] data = null;
ps.println(
"--------------------------------------------------------------------");
Grib1Data gd = new Grib1Data(raf);
// TODO: pds vars needed
data = gd.getData(record.getDataOffset(),
pds.getDecimalScale(), pds.bmsExists());
if (data != null) {
for (int j = 0; j < data.length; j++) {
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) {
System.err.println("IOException : " + ioError);
} catch (NoValidGribException noGrib) {
System.err.println("NoValidGribException : " + noGrib);
} finally {
ps.close(); // done writing
}
// Goodbye message
now = Calendar.getInstance().getTime();
//System.out.println(now.toString() + " ... End of Grib1Dump!");