[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java netCDF 2.2.14 Structures API Example Code?



Hi Mark,

The problem is that the netCDF-3 file format does not support structures (more on this in a moment). So, until netCDF-4 support comes out, you can't really write structures. On the other hand, when you are reading a dataset through netCDF-java, you very well might get structures. It depends on the type of dataset you are reading. OPeNDAP datasets, NIDS, and NEXRAD level II files all may return structures or sequences.

Back to netCDF-3 file format and structure support. As I said, the file format does not explicitly support structures. However, if a nc-3 dataset has an unlimited dimension, the variables on that dimension can be viewed as a structure. You can use the ucar.nc2.NetcdfFile.addRecordStructure() method to add a structure variable to the NetcdfFile that provides this view. Similarly, you can view any set of variables with the same outer dimension as a structure. Take a look at ucar.nc2.StructurePseudo to try this out.

But unless you are reading files that might contain structures or writing a ucar.nc2.IOServiceProvider to read a type of file where structures make sense, it is probably best to stick with the standard netCDF-3 objects.

Hope this helps,

Ethan

Mark Ohrenschall wrote:
Has anyone used the Java NetCDF library to define and write structures (e.g., point observation data)? Is there a tutorial or cookbook example documented anywhere?

I naively tried the following (code snippet):
        Structure struct = new Structure(ncFile, null, null, "obs");
        ncFile.addVariable("obs", DataType.STRUCTURE, new Dimension[] {iDim});

        // more stuff happens

        ncFile.create();
But received the following disconcerting run-time error:
Exception in thread "main" java.lang.IllegalStateException: unknown DataType == 
Structure
        at ucar.nc2.N3header.getType(N3header.java:434)
        at ucar.nc2.N3header.writeVars(N3header.java:627)
        at ucar.nc2.N3header.create(N3header.java:487)
        at ucar.nc2.N3iosp.create(N3iosp.java:299)
        at ucar.nc2.NetcdfFileWriteable.create(NetcdfFileWriteable.java:320)
So I'm not at all clear whether structures are fully implemented in version 2.2.14 or what the proper sequence of netCDF API calls are that I need to be making. Can anyone offer me guidance?

Thanks in advance! Cheers *--* Mark

--
Ethan R. Davis                                Telephone: (303) 497-8155
Software Engineer                             Fax:       (303) 497-8690
UCAR Unidata Program Center                   E-mail:    address@hidden
P.O. Box 3000
Boulder, CO  80307-3000                       http://www.unidata.ucar.edu/
---------------------------------------------------------------------------


===============================================================================
To unsubscribe netcdf-java, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
===============================================================================