Re: NetCDF library problems

NOTE: The decoders mailing list is no longer active. The list archives are made available for historical reasons.

On Wed, 30 Jun 2004, Jason Thaxter wrote:

One quick question, as I'm wrapping up...

There are two ways I can see to get the values for a variable: one is via
recget, which is mostly what I use.

Another one is via varget. It *looks* as if I should be able to get the whole
(possibly 2-dimensional) array with varget.  And for variables that are
dimensions, I can. e.g., in the attached file, I can get the contents of lat,
lon, depth, and time. But at the first real "data" variable, current_u, I get:

ncvarget: ncid 3; varid 4: Index exceeds dimension bound


Jason,

A problem appeared for me on the varget until i changed the start
and count syntax from \($i, 0, 0, 0) to [ $i, 0, 0, 0 ]. Then everything
started working correctly, ie

NetCDF::varget
           ( $ncid, $current_u_id, [ $i, 0, 0, 0 ], [ 1, 30, 1, 1 ], \@data ) ;

Also, one could:

           @start = ( $i, 0, 0, 0 ) ;
           @count = ( 1, 30, 1, 1 ) ;
           NetCDF::varget
           ( $ncid, $current_u_id, \@start, \@count, \@data ) ;

This looks like a bug in the perl interpreter.

A test script is attached to this message.

Some netCDF documentation is include about varget and a url to all the
netCDF documentation.  The parameters are the same for the netcdf-perl
invocations. Also all the values matched the dump from the test2.nc file
for current_u variable.

Robb...




The varget documentation:

The members of the nc_get_vara_ type family of functions read an array of
values from a netCDF variable of an open netCDF dataset. The array is
specified by giving a corner and a vector of edge lengths. The values are
read into consecutive locations with the last dimension varying fastest.
The netCDF dataset must be in data mode.



Usage

int nc_get_vara_text  (int ncid, int varid, const size_t start[],
                      const size_t count[] char *tp);
int nc_get_vara_uchar (int ncid, int varid, const size_t start[],
                      const size_t count[] unsigned char *up);
int nc_get_vara_schar (int ncid, int varid, const size_t start[],
                      const size_t count[] signed char *cp);
int nc_get_vara_short (int ncid, int varid, const size_t start[],
                      const size_t count[] short *sp);
int nc_get_vara_int   (int ncid, int varid, const size_t start[],
                      const size_t count[] int *ip);
int nc_get_vara_long  (int ncid, int varid, const size_t start[],
                      const size_t count[] long *lp);
int nc_get_vara_float (int ncid, int varid, const size_t start[],
                      const size_t count[] float *fp);
int nc_get_vara_double(int ncid, int varid, const size_t start[],
                      const size_t count[] double *dp);

ncid


NetCDF ID, from a previous call to nc_open or nc_create.

varid


Variable ID.

start


A vector of size_t integers specifying the index in the variable where the
first of the data values will be read. The indices are relative to 0, so
for example, the first data value of a variable would have index (0, 0,
... , 0). The length of start must be the same as the number of dimensions
of the specified variable. The elements of start correspond, in order, to
the variable's dimensions. Hence, if the variable is a record variable,
the first index would correspond to the starting record number for reading
the data values.

count


A vector of size_t integers specifying the edge lengths along each
dimension of the block of data values to be read. To read a single value,
for example, specify count as (1, 1, ... , 1). The length of count is the
number of dimensions of the specified variable. The elements of count
correspond, in order, to the variable's dimensions. Hence, if the variable
is a record variable, the first element of count corresponds to a count of
the number of records to read.

tp, up, cp, sp, ip, lp, fp, or, dp


Pointer to the location into which the data value is read. If the type of
data value differs from the netCDF variable type, type conversion will
occur. See Section 3.3 "Type Conversion," page 20, for details.





http://my.unidata.ucar.edu/content/software/netcdf/guidec/guidec-12.html#HEADING12-0



I'm not giving a dimension bound; if I were, I'd expect this function to be
called ncdimget... Am I missing something? Since the script I'm writing apes
the output of ncdump, I thought I might get somewhere by going through the
ncdump code, but in fact it calls some function vardata, which appears to step
through the binary chunks of data on its own, as opposed to using an interface
into the library such as varget.

Obviously there's something fundamental about NetCDF that I'm not getting
here, but the nice thing about intefaces is that you usually don't have to
understand the whole thing. Time to dive in, I guess.

Anyway, if you consider this a blind alley, I can show that via
NetCDF::recget, I can extract our data, but the variable made of bytes arrays
comes back with zilch. I can just strip my little demo down to that example
and send it on...

Thanks,
Jason

--
----------------------------------------------
Jason Thaxter
GoMOOS, P.O. Box 4919, Portland, ME 04112-4919
Office Location: 1 Canal Plaza, 7th Floor
Office: 207.773.0423
Fax:    207.773.8672
Email:  thaxter@xxxxxxxxxx
------------www.gomoos.org--------------------


==============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
rkambic@xxxxxxxxxxxxxxxx                   WWW: http://www.unidata.ucar.edu/
==============================================================================
  • 2004 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the decoders archives: