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

Re: tbl2ncdf ?



> Organization: NASA
> Keywords: 199401172157.AA12785

Hi Ata,

> On another note I would sure appreciate it if someone told me how find out
> which dimension of a variable is its record dimension in the general case (ie
> NC_UNLIMITED dimension exists or not).

If NC_UNLIMITED dimension doesn't exist, none of the dimensions of a
variable are its record dimension :-).  If NC_UNLIMITED dimension exists,
the (first in C, last in Fortran) dimension of a record variable is its
record dimension.  To determine whether a variable is a record variable or
not, just see if the ID of its first (last for Fortran) dimension is the
same as the ID of the record dimension (determined via ncinquire() or
NCINQ).  As an example, I've appended the code for a C function that does
some of this.

--Russ

/*
 * Returns record size (in bytes) of the record variable with a specified
 * variable id.  Returns 0 if not a record variable.  Returns -1 on error.
 */
long
ncrecsize(ncid,vid)
     int ncid;
     int vid;
{
    int recdimid;
    nc_type type;
    int ndims;
    int dimids[MAX_NC_DIMS];
    int id;
    long size;

    /* Get the ID of the record dimension, if any */
    if (ncinquire(ncid, 0, 0, 0, &recdimid) == -1)
      return -1;

    /* Get the dimension IDs for this variable */
    if (ncvarinq(ncid, vid, 0, &type, &ndims, dimids, 0) == -1)
      return -1;

    /* See if this is a record variable */
    if (ndims == 0 || dimids[0] != recdimid)
      return 0;

    /* Compute the size of a record's worth of data for this variable */
    size = nctypelen(type);
    for (id = 1; id < ndims; id++) {
        long len;
        (void) ncdiminq(ncid, dimids[id], 0, &len);
        size *= len;
    }
    return size;
}

/*
 * Returns record size (in bytes) of the record variable with a specified
 * variable id.  Returns 0 if not a record variable.  Returns -1 on error.
 */
long
ncrecsize(ncid,vid)
     int ncid;
     int vid;
{
    int recdimid;
    nc_type type;
    int ndims;
    int dimids[MAX_NC_DIMS];
    int id;
    long size;

    /* Get the ID of the record dimension, if any */
    if (ncinquire(ncid, 0, 0, 0, &recdimid) == -1)
      return -1;

    /* Get the dimension IDs for this variable */
    if (ncvarinq(ncid, vid, 0, &type, &ndims, dimids, 0) == -1)
      return -1;

    /* See if this is a record variable */
    if (ndims == 0 || dimids[0] != recdimid)
      return 0;

    /* Compute the size of a record's worth of data for this variable */
    size = nctypelen(type);
    for (id = 1; id < ndims; id++) {
        long len;
        (void) ncdiminq(ncid, dimids[id], 0, &len);
        size *= len;
    }
    return size;
}