Next: , Previous: Dimensions Introduction, Up: Dimensions


3.2 Create a Dimension: nc_def_dim

The function nc_def_dim adds a new dimension to an open netCDF dataset in define mode. It returns (as an argument) a dimension ID, given the netCDF ID, the dimension name, and the dimension length. At most one unlimited length dimension, called the record dimension, may be defined for each netCDF dataset.

Usage

     int nc_def_dim (int ncid, const char *name, size_t len, int *dimidp);
ncid
NetCDF ID, from a previous call to nc_open or nc_create.
name
Dimension name. Must begin with an alphabetic character, followed by zero or more alphanumeric characters including the underscore ('_'). Case is significant.
len
Length 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 size_t) or the predefined constant NC_UNLIMITED.
dimidp
Pointer to location for returned dimension ID.

Errors

nc_def_dim returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:

Example

Here is an example using nc_def_dim to create a dimension named lat of length 18 and a unlimited dimension named rec in a new netCDF dataset named foo.nc:

     #include <netcdf.h>
        ...
     int status, ncid, latid, recid;
        ...
     status = nc_create("foo.nc", NC_NOCLOBBER, &ncid);
     if (status != NC_NOERR) handle_error(status);
        ...
     status = nc_def_dim(ncid, "lat", 18L, &latid);
     if (status != NC_NOERR) handle_error(status);
     status = nc_def_dim(ncid, "rec", NC_UNLIMITED, &recid);
     if (status != NC_NOERR) handle_error(status);