Go to the previous, next section.

Create a Dimension

The function ncdimdef (or NCDDEF for FORTRAN) adds a new dimension to an open netCDF file in define mode. It returns a dimension ID, given the netCDF ID, the dimension name, and the dimension size. At most one unlimited size dimension, called the record dimension, may be defined for each netCDF file.

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

ncdimdef: C Interface

int ncdimdef(int ncid, const char* name, long size);

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

name
Dimension name. Must begin with an alphabetic character, followed by zero or more alphanumeric characters including the underscore (`_'). Case is significant.

size
Size of dimension; that is, number of values for this dimension as an index to variables that use it. This should be either a positive integer (of type long) or the predefined constant NC_UNLIMITED.

Here is an example using ncdimdef to create a dimension named lat of size 18 and a record dimension named rec in a new netCDF file named `foo.nc':

#include "netcdf.h"
   ...
int ncid, latid, recid;
   ...
ncid = nccreate("foo.nc", NC_NOCLOBBER);
   ...
latid = ncdimdef(ncid, "lat", 18L);
recid = ncdimdef(ncid, "rec", NC_UNLIMITED);

NCDDEF: FORTRAN Interface

      INTEGER FUNCTION NCDDEF (INTEGER NCID,
     +                   CHARACTER*(*) DIMNAM,
     +                   INTEGER DIMSIZ,
     +                   INTEGER RCODE)

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

DIMNAM
Dimension name. Must begin with an alphabetic character, followed by zero or more alphanumeric characters including the underscore (`_'). Case is significant.

DIMSIZ
Size of dimension; that is, number of values for this dimension as an index to variables that use it. This should be either a positive integer or the predefined constant NCUNLIM.

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

Here is an example using NCDDEF to create a dimension named lat of size 18 and a record dimension named rec in a new netCDF file named `foo.nc':

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID, RCODE, LATID, RECID
         ...
      NCID = NCCRE('foo.nc', NCNOCLOB, RCODE)
         ...
      LATID = NCDDEF(NCID, 'lat', 18, RCODE)
      RECID = NCDDEF(NCID, 'rec', NCUNLIM, RCODE)

Go to the previous, next section.