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

Re: 20010709: time as unlimited variable



Reggie,

> I do have another question related to time as
> unlimited variable.  In your email, you said
> "it uses the current size of the unlimited dimension
> in the file to determine how many records to write"
> How does one increase the size of the unlimited
> dimension, then?  If I have an 1-D array and want
> to save the array by unknown times (say in an outer
> loop ending with a condition satisfied), can I 'put'
> the array into the *.nc file each time without allocating
> a big 2-D array that has a huge 2nd dimension to
> cover the unknown unlimited dimension?
>
> I can give you more specific description with a
> pseudo code if you wish.  I will also try to find some
> clues in the archive tomorrow.

Yes, you can write any portion of an array, including single values.
There is no need to write all the values at once.  The typical use of
the unlimited dimension is to have several variables that use it and
to write all their values for the next value of the unlimited
dimension, appending a "record" at a time to the netCDF file, where
each record contains all the values of record variables (variables
that use the unlimited dimension) for a specific value of the
unlimited dimension.  You would typically use the nf_put_vara_...(
..., start, count, vals) interfaces for this, specifying which record
by the last value of the "start" array.

But it's not necessary to do it that way.  For example, if a netCDF
file open for writing currently contains 2 records (the unlimited
dimension "time" has size 2), and the shape of the variable rh is

 int rh(time, lat, lon) ;

which means there may be a corresponding Fortran array for one
record's worth of data dimensioned as something like

 integer rhrec(lon, lat);

you can write the 100th record of rh values, making the number of
records in the file jump from 2 to 100:

 start(1) = 1   ! lon
 start(2) = 1   ! lat
 start(3) = 100 ! time
 count(1) = lons
 count(2) = lats
 count(3) = 1   ! write only one record
 status = nf_put_vara_int(ncid, rhid, start, count, rhrec)

This writes a lon-lat slice of the variable.  As a side effect, it
also writes all the other record variables for all the intervening
records 3, 4, ..., 100 with "fill values".  The size of the unlimited
dimension would subsequently be 100.  So after that if you wanted to
write an entire record variable, you'd have to supply 100 record's
worth of data.

Since the size of the unlimited variable can grow as records are
appended, it's just not usually a good idea to use the simple
interface for writing all the values of a record variable at once.
The intent was to append data for such variables a record slice (or
several record slices) at a time.

I will try to make this clearer in the documentation for the
n{f,c}_put_var_...() functions the next time we update the Users
Guides.  Thanks for pointing out the problem.

--Russ