Go to the previous, next section.
The function ncdiminq
(or NCDINQ
for FORTRAN) returns the
name and size of a dimension, given its ID. The size for the
unlimited dimension, if any, is the maximum value used so far in
writing data for that dimension (which is the same as the current
maximum record number).
In case of an error, ncdiminq
returns -1; NCDINQ
returns a
nonzero value in rcode
. Possible causes of errors include:
int ncdiminq(int ncid, int dimid, char* name, long* size);
ncid
ncopen
or nccreate
.
dimid
ncdimid
or
ncdimdef
.
name
MAX_NC_NAME
.
If the name parameter is given as `(char *) 0', no name will be
returned so no space needs to be allocated.
size
Here is an example using ncdiminq
to determine the size of a
dimension named lat
, and the name and current maximum size of the
unlimited (or record) dimension for an existing netCDF file named
`foo.nc':
#include "netcdf.h" ... int ncid, latid, ndims, nvars, ngatts, recid; long latsize, recs; char recname[MAX_NC_NAME]; ... ncid = ncopen("foo.nc", NC_NOWRITE); /* open for reading */ ... latid = ncdimid(ncid, "lat"); /* get lat size, but don't get name, since we already know it */ ncdiminq(ncid, latid, (char *) 0, &latsize); /* get ID of record dimension (among other things) */ ncinquire(ncid, &ndims, &nvars, &ngatts, &recid); /* get record dimension name and current size */ ncdiminq(ncid, recid, recname, &recs);
SUBROUTINE NCDINQ (INTEGER NCID, INTEGER DIMID, + CHARACTER*(*) DIMNAM, INTEGER DIMSIZ, + INTEGER RCODE)
NCID
NCOPN
or NCCRE
.
DIMID
NCDID
or NCDDEF
.
DIMNAM
MAXNCNAM
.
DIMSIZ
RCODE
Here is an example using NCDINQ
to determine the size of a
dimension named lat
, and the name and current maximum size of the
unlimited (or record) dimension for an existing netCDF file named
`foo.nc':
INCLUDE 'netcdf.inc' ... INTEGER NCID, RCODE, LATID, LATSIZ INTEGER NDIMS, NVARS, NGATTS, RECID, NRECS * 31 in following statement is parameter MAXNCNAM CHARACTER*31 LATNAM, RECNAM ... NCID = NCOPN('foo.nc', NCNOWRIT, RCODE) ... LATID = NCDID(NCID, 'lat', RCODE) * get lat name and size, (even though we already know name) CALL NCDINQ(NCID, LATID, LATNAM, LATSIZ, RCODE) * get ID of record dimension (among other things) CALL NCINQ(NCID, NDIMS, NVARS, NGATTS, RECID, RCODE) * get record dimension name and current size CALL NCDINQ(NCID, RECID, RECNAME, NRECS, RCODE)
Go to the previous, next section.