NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

[netcdf-java] grib2

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
  • 2014 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: