[netcdf-java] Reading sequences from BUFR with NetcdfDataset

Hi,

I have to read the attached BUFR-File with netcdf-java and it works a little 
bit.

I opened my BUFR-File with ToolsUI to examine the content. Here was the first 
surprise: The icon 
https://docs.unidata.ucar.edu/netcdf-java/5.0/userguide/images/netcdf-java/tutorial/cdmdatasets/enhanceButton.jpg
shows "add Coordinates..." as tooltip. But it is actually the enable/disable of 
the enhance-mode, as stated here
https://docs.unidata.ucar.edu/netcdf-java/5.0/userguide/netcdf_dataset.html
The tooltip should be changed.

Reading variables was easy thanks to the enhance-mode:
try (NetcdfDataset ncFile = NetcdfDataset.openDataset(filename);) {
  VariableDS variable = (VariableDS) 
ncFile.findVariable("obs.Software_identification_and_version_number");
  System.out.println(variable.readScalarString());
  }
Float and all other types are correctly enhanced.

Naively I thought reading sequences is easy too. I have to read the sequence 
"obs.Long_time_period_or_displacement" (as an example). Aunt Google showed me 
the function "showNestedSequence" from 
https://www.unidata.ucar.edu/software/netcdf-java/current/reference/Cookbook.html
 (can't find it in the current documentation). This function shows me all 
values, but not enhanced. Furthermore 2 nested loops were used. I would prefer 
ONE loop (if possible).

After (I think) thousands of failed attempts, I came to this
try (NetcdfDataset ncFile = NetcdfDataset.openDataset(filename);) {
  VariableDS variable = (VariableDS) 
ncFile.findVariable("obs.Long_time_period_or_displacement");
  System.out.println("Type: " + variable.getDataType());
  Array value = variable.read();
  System.out.println("THIS LINE IS NOT PRINTED");
  }
The following exception is thrown:
java.lang.ClassCastException: class ucar.ma2.ArrayObject$D1 cannot be cast to 
class ucar.ma2.ArrayStructure (ucar.ma2.ArrayObject$D1 and 
ucar.ma2.ArrayStructure are in unnamed module of loader 
org.apache.catalina.loader.ParallelWebappClassLoader @ebbfb89)
        at ucar.nc2.dataset.StructureDS.convert(StructureDS.java:268)
        at ucar.nc2.dataset.SequenceDS.read(SequenceDS.java:84)
        at de.sample.BUFRTest.showNestedSequenceNew(BUFRTest.java:88)
Line 88 is the "variable.read();".
I called your netcdf-lib from a servlet, therefore the "org.apache.catalina", 
but this should not be the problem.

So it seems this sentence is not correct:
https://docs.unidata.ucar.edu/netcdf-java/5.0/userguide/netcdf_dataset.html
"Note that NetcdfDataset is a subclass of NetcdfFile, and so can be used 
wherever a NetcdfFile is used."

Someone suggested to have a look at NCdumpW, which I also did, but this program 
does not enhance any values.

Since I don't want to open my file as NetcdfDataset and again as NetcdfFile, I 
would try to open it as NetcdfFile and manually enhance the values. But no idea 
how to do this. Any good solution for my problem is also appreciated.

Thanks

Kind regards

Netty

Attachment: 3_Z__C_EDZW_aero1,IUKD07_DWSU_0600____ATSO.bin
Description: Binary data

  • 2019 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: