[netcdf-java] Reading sequences from BUFR with NetcdfDataset


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

I opened my BUFR-File with ToolsUI to examine the content. Here was the first 
surprise: The icon 
shows "add Coordinates..." as tooltip. But it is actually the enable/disable of 
the enhance-mode, as stated here
The tooltip should be changed.

Reading variables was easy thanks to the enhance-mode:
try (NetcdfDataset ncFile = NetcdfDataset.openDataset(filename);) {
  VariableDS variable = (VariableDS) 
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 
 (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) 
  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:
"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.


Kind regards


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: