Go to the previous, next section.

Inquire about a Dimension

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:

ncdiminq: C Interface

int ncdiminq(int ncid, int dimid, char* name, long* size);

ncid
NetCDF ID, returned from a previous call to ncopen or nccreate.

dimid
Dimension ID, as returned from a previous call to ncdimid or ncdimdef.

name
Returned dimension name. The caller must allocate space for the returned name. The maximum possible length, in characters, of a dimension name is given by the predefined constant 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
Returned size of dimension. For the unlimited dimension, this is the current maximum value used for writing any variables with this dimension, that is the maximum record number. If this parameter is given as `(long *) 0', the size will not be returned, so no space for this information need be declared or allocated.

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);

NCDINQ: FORTRAN Interface

      SUBROUTINE NCDINQ (INTEGER NCID, INTEGER DIMID,
     +                   CHARACTER*(*) DIMNAM, INTEGER DIMSIZ,
     +                   INTEGER RCODE)

NCID
NetCDF ID, returned from a previous call to NCOPN or NCCRE.

DIMID
Dimension ID, as returned from a previous call to NCDID or NCDDEF.

DIMNAM
Returned dimension name. The caller must allocate space for the returned name. The maximum possible length, in characters, of a dimension name is given by the predefined constant MAXNCNAM.

DIMSIZ
Returned size of dimension. For the unlimited dimension, this is the current maximum value used for writing any variables with this dimension, that is the maximum record number.

RCODE
Returned error code. If no errors occurred, 0 is returned.

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.