Go to the previous, next section.

Get a Dimension ID from Its Name

The function ncdimid (or NCDID for FORTRAN) returns the ID of a netCDF dimension, given the name of the dimension. If ndims is the number of dimensions defined for a netCDF file, each dimension has an ID between 0 and ndims-1 (or 1 and ndims for FORTRAN).

In case of an error, ncdimid returns -1; NCDID returns a nonzero value in rcode. Possible causes of errors include:

ncdimid: C Interface

int ncdimid(int ncid, const char* name);

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

name
Dimension name, a character string beginning with a letter and followed by any sequence of letters, digits, or underscore (`_') characters. Case is significant in dimension names.

Here is an example using ncdimid to determine the dimension ID of a dimension named lat, assumed to have been defined previously in an existing netCDF file named `foo.nc':

#include "netcdf.h"
   ...
int ncid, latid;
   ...
ncid = ncopen("foo.nc", NC_NOWRITE);  /* open for reading */
   ...
latid = ncdimid(ncid, "lat");

NCDID: FORTRAN Interface

      INTEGER FUNCTION NCDID (INTEGER NCID,
     +                        CHARACTER*(*) DIMNAME,
     +                        INTEGER RCODE)

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

DIMNAME
Dimension name, a character string beginning with a letter and followed by any sequence of letters, digits, or underscore (`_') characters. Case is significant in dimension names.

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

Here is an example using NCDID to determine the dimension ID of a dimension named lat, assumed to have been defined previously in an existing netCDF file named `foo.nc':

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID, RCODE, LATID
         ...
      NCID = NCOPN('foo.nc', NCNOWRIT, RCODE)
         ...
      LATID = NCDID(NCID, 'lat', RCODE)

Go to the previous, next section.