Greetings all,
I am trying to create a script that will mimic the output of NCDump. I
have successfully done this for NetCDF files, and now I am trying to apply
it to grib2 files. I am using the NetCDF-java library in conjunction with
Apache Tika to do this. Other posts have indicated I should be able to
open my grib2 files, just as if they were .nc files. However, I continue
to get the following error:
"Caused by: java.io.IOException: Cant read gdas1.forecmwf.2014062612.grib2:
not a valid CDM file."
To open the .nc files, this is the bit of code I use (with the exception of
changing the .nc file to a .grib2 file):
String name = "gdas1.forecmwf.2014062612.grib2";
if (name == null) {
name = "";
}
try NetcdfFile ncFile = NetcdfFile.openInMemory(name,
os.toByteArray());
// first parse out the set of global attributes
for (Attribute attr : ncFile.getGlobalAttributes()) {
Property property = resolveMetadataKey(attr.getName());
if (attr.getDataType().isString()) {
metadata.add(property, attr.getStringValue());
} else if (attr.getDataType().isNumeric()) {
int value = attr.getNumericValue().intValue();
metadata.add(property, String.valueOf(value));
}
}
Also, I am using the netcdfAll-4.3.jar at the command line. Does anyone
have any insight as to *why *I'd be getting the 'not a valid CDM' error. I
have checked the file using the NetCDF (4.3) GUI and the file looks good.
Thank you for any insight you can give.
Annie