Re: Questions

Hi Michael:

Michael Tiller wrote:
I'm evaluating a couple of different data storage schemes but I'm having
some difficulty with netCDF.  First, let me say that I am much happier
with the netCDF Java interface than with the way it is handled in HDF5. The fact that the netCDF stuff is not just 100% Java but also done the
way a Java interface would normally done has made getting started very easy.

However, I do have some problems.  I looked in the User's guide and
tried putting together some example code based on what is found in
Appendix A and I've run into several problems.  First let me list my
questions and comments and I'll include my sample code (written as a
JUnit TestCase) at the end:

   1. FYI, I'm using netCDF 2.2.12.
   2. The example code in the user's guide seems "out of date".  Some of
      the constructs (use of default constructor for
      NetcdfFileWriteable, use of Class object arguments in addVariable)
      are now deprecated in the library.

yeah, its way out of date, sorry.

   3. Is there a "bug tracker" for netCDF?  Just sending stuff to a
      mailing list seems like a recipe for falling through the cracks.

not yet, but we're working on one.

   4. I get an error when trying to use the NetcdFileWriteable(String
      file) constructor (it says "Not a netCDF file" or something like
      that).  I added the fill argument and now things work?!?

 new NetcdFileWriteable(String file) is for opening existing files for writing.
 new NetcdFileWriteable(String file, boolean fill) is for creating new files.

In the latest version (2.2.13) these are deprecated in favor of static methods

 NetcdFileWriteable.openExisting(..)
 NetcdFileWriteable.createNew(..)
   5. I'm trying to simple record some time series data.  So I created a
      dimension for "time" (i.e. a 1D dataset).  The idea (in the code
      below) is that "h" should be a function of "time".  Am I doing
      that write?  It doesn't seem like anything in that code
      distinguishes "time" as the independent variable!?!

what you're doing is correct, as far as it goes, the coordinate variable time(time) 
indicates that time is the "independent variable". if you want to go another 
step, use a convention such as CF 
(http://www.unidata.ucar.edu/software/netcdf/docs/conventions.html) or _Coordinate 
(http://www.unidata.ucar.edu/software/netcdf-java/CoordinateAttributes3.html)

   6. The ArrayDouble.D1 "helper" class seems like it could do much
      more.  It has special scalar get and set methods, but what about
      having "public double[] get()" and "public void set(double [] v)"
      methods!?!  It would make it much easier to initialize the data.

good idea, ill think about adding

   7. I get messages about not being able to load Nexrad and Grib
      service providers.  What are those about?  Do I need those?  If
      not, can I shut those warnings off?

no, you dont need; ill turn off those warnings.


   8. The example code mentions a class called "ArrayAbstract" which
      would appear to be handy but I couldn't find it in the jar file.

now called Array

   9. The *main problem* I'm having right now is that I get an error
      during "file.create()".  I get an "IllegalStateException" with the
      message "unknown Dimension ==  time = 4; // (has coord.var)".  Any
      ideas?

you need the dimension time to be shared, so change to
     Dimension time = file.addDimension("time", 4, true, false, false);



Overall, I'm pretty happy with the design of the system, what can be
expressed and the tie in with NcML (which I assume is still ongoing).  I
just wish I could get my sample code to work. :-)

thanks for the feedback


Any help would be very much appreciated. Here is the sample code....

import java.io.IOException;

import junit.framework.TestCase;
import ucar.ma2.ArrayDouble;
import ucar.ma2.DataType;
import ucar.ma2.InvalidRangeException;
import ucar.nc2.Dimension;
import ucar.nc2.NetcdfFileWriteable;

public class TestNetCDF extends TestCase {
    public void testCreateData() {
        NetcdfFileWriteable file = null;
        file = new NetcdfFileWriteable("./example.nc", true);
Dimension time = file.addDimension("time", 4, false, false, false);
        Dimension dims[] = {time};
/* Add time */
        file.addVariable("time", DataType.DOUBLE, dims);
        file.addVariableAttribute("time", "quantity", "time");
        file.addVariableAttribute("time", "units", "s");
/* Add a dependent variable */
        file.addVariable("h", DataType.DOUBLE, dims);
        file.addVariableAttribute("h", "quantity", "Height");
        file.addVariableAttribute("h", "units", "m");
        try {
            file.create();
        } catch (IOException e) {
            e.printStackTrace(System.err);
            fail("IOException on creation");
        }
double td[] = {1.0, 2.0, 3.0, 4.0};
        double hd[] = {0.0, 0.1, 0.3, 0.9};
        ArrayDouble.D1 ta = new ArrayDouble.D1(4);
        ArrayDouble.D1 ha = new ArrayDouble.D1(4);
        for(int i=0;i<4;i++) {
            ta.set(i, td[i]);
            ha.set(i, hd[i]);
        }
try {
            file.write("time", ta);
        } catch (IOException e) {
            e.printStackTrace(System.err);
            fail("IOException thrown while writing time");
        } catch (InvalidRangeException e) {
            e.printStackTrace(System.err);
            fail("InvalidRangeException thrown while writing time");
        }
try {
            file.write("h", ha);
        } catch (IOException e) {
            e.printStackTrace(System.err);
            fail("IOException thrown while writing h");
        } catch (InvalidRangeException e) {
            e.printStackTrace(System.err);
            fail("InvalidRangeException thrown while writing h");
        }
    }
}


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