Page NetCDF

How can we make use of the properties of NetCDF in our project?

How to define a new trajectory class

i. The steps to using your TrajectoryBuilderIF class (=Factory class) in the NetCDF-Java library:

  • 1. Write a class that implements the interface ucar.nc2.dt.TrajectoryBuilderIF, such as by subclassing ucar.nc2.dt.TypedDataset.
  • 2. Add the class to your classpath.
  • 3. From your application, call ucar.nc2.dt.TrajectoryBuilder.registerConvention( String conventionName, Class c). This is called "plugging in" your code at runtime.
  • 4. When you open the dataset in enhanced mode, eg by calling NetcdfDataset.openDataset(String location, boolean enhance, ucar.nc2.util.CancelTask cancelTask);
  • an instance of your class will be called to add trajectory objects to the NetcdfDataset.

ii. Adding attributes to a dataset:

  • 1. Use a NcML-file:
  •  <variable name="latitude" shape="row" type="double">
     </variable> 

  • 2. Call wrapNcMl:
  •  protected void augmentDataset( NetcdfDataset ncDataset, CancelTask cancelTask) throws IOException {
       this.conventionName = "ATDRadar";
       NcMLReader.wrapNcML( ncDataset, "file:/MyResource/ATDRadar.ncml", cancelTask);
     }   

How to define a new data type with a certain precision

Avaiable data types:
  • ° NetCDF supported six data types through version 3.6.0 (char, byte, short, int, float, and double)
  • ° Starting with version 4.0, many new data types are supported (unsigned int types, strings, compound types, variable length arrays, enums, opaque)
  • ° In addition to the new atomic types, with netCDF-4/HDF5 files, the user may define types

How to access a NetCDF file via Java

i.a) The preferred way to open a NetcdfFile is through the NetcdfDataset.openFile factory method:
  •   String filename = "/home/cocktail/noe/moldata/MR121-GSGSW/sim293K/TRAJ2_400ns+TRAJ1_604880ps.cdf";
      NetcdfFile ncfile = null;
      try {
        ncfile = NetcdfDataset.openFile(filename, null);
        ...
        file_id = ncfile.getId();    //see ii. for details
      } catch (IOException ioe) { ... } 

i.b) Example: Accessing a file of type TrajectoryObsDataset via public methods

  • The TrajectoryObsDataset interface provides access to a collection of trajectories. Each trajectory in the collection is then accessed through an instance of the TrajectoryObsDatatype interface. As with TypedDataset, some basic dataset discovery metadata is available for each trajectory:

  •   public String getId();
      public String getDescription();
      public Date getStartDate();
      public Date getEndDate();
      public ucar.unidata.geoloc.LatLonRect getBoundingBox(); 

ii. Writing in a NetCDF file via NetcdfFileWriteable

  •   String filename = "testWrite.nc";
      NetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew(filename, false);
      // add dimensions
      Dimension latDim = ncfile.addDimension("lat", 64);
      Dimension lonDim = ncfile.addDimension("lon", 128);
    
      try {
        ncfile.create();
      } catch (IOException e) {}  

How to access a NetCDF file via network

i. NetcdfDataset.openFile does the following:

  • ° Opens a OPeNDAP remote dataset, if the location is a URL that starts with "http:"
  • ° OPeNDAP (Open-source Project for a Network Data Access Protocol): provides software which makes local data accessible to remote locations regardless of local storage format.
  • ° The protocol is based on HTTP and an OPeNDAP server can serve an arbitrarily large collection of data.
  • ° The OPeNDAP software is composed of a core library, and a variety of libraries that each support a different data access API. The OPeNDAP core is a set of C++ classes for building OPeNDAP servers and OPeNDAP clients.


Comments

 
Topic revision: r2 - 19 Sep 2007, ChristopherHase
 
  • Printable version of this topic (p) Printable version of this topic (p)