Re: Questions

  • Subject: Re: Questions
  • From: Michael Tiller <mtiller@xxxxxxxxxxxx>
  • Date: Tue, 17 Jan 2006 13:12:25 -0500
OK, next question.  Exactly what are the semantics of "Unlimited"
dimensions?  I assume this means that I can add data bit by bit (or
perhaps it doesn't).  I'm thinking of applications where a simulation
does not know, a priori, how long it will run but I'd like to write the
data out as I go.  I assume this is possible, but how would I do it. 
For example, could I just list the dimension as Unlimited and then just
keep setting the data for ever increasing indices?!?

Also, I can I have more than 1 unlimited dimension?  I don't need that
but I'm just curious if it is possible (neat trick if you can).

--
Mike

Roland Schweitzer wrote:
> Michael,
>
> Change
> Dimension time = file.addDimension("time", 4, false, false, false);
> to
> Dimension time = file.addDimension("time", 4, true, false, false);
> and your example work (at least it did for me with a slightly older jar).
>
> as will
> Dimension time = file.addDimension("time", 4);
>
> AND !!!!!!
>
> add a file.close() at the bottom to write the new values to disk! 
> create() makes the empty shell close() commits the writes to disk.
>
> Can't fathom why the API allows a dimension to be created that cannot
> be shared, but it does.
> Nor can I exactly fathom what it means for a dimension to be shared or
> not shared, but there it is.
>
> The Unidata gang will set me straight I'm sure.
>
> Roland
>
>
>
>
> 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.
>>   3. Is there a "bug tracker" for netCDF?  Just sending stuff to a
>>      mailing list seems like a recipe for falling through the cracks.
>>   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?!?
>>   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!?!
>>   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.
>>   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?
>>   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.
>>   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?
>>
>> 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. :-)
>>
>> 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");
>>        }
>>    }
>> }
>>  
>>
>

begin:vcard
fn:Michael Tiller
n:Tiller;Michael
org:Emmeskay, Inc.
adr;dom:;;47119 Five Mile Road;Plymouth;MI;48170
email;internet:mtiller@xxxxxxxxxxxx
title:Vice-President Modeling Research and Development
tel;work:(734) 635-3450
x-mozilla-html:TRUE
url:http://www.emmeskay.com
version:2.1
end:vcard

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