Previous: nc_inq_dim Family, Up: Dimensions


3.5 Rename a Dimension: nc_rename_dim

The function nc_rename_dim renames an existing dimension in a netCDF dataset open for writing. If the new name is longer than the old name, the netCDF dataset must be in define mode. You cannot rename a dimension to have the same name as another dimension.

Usage

int nc_rename_dim(int ncid, int dimid, const char* name);

ncid
NetCDF ID, from a previous call to nc_open or nc_create.
dimid
Dimension ID, from a previous call to nc_inq_dimid or nc_def_dim.
name
New dimension name.

Errors

nc_rename_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_rename_dim to rename the dimension lat to latitude in an existing netCDF dataset named foo.nc:

     #include <netcdf.h>
        ...
     int status, ncid, latid;
        ...
     status = nc_open("foo.nc", NC_WRITE, &ncid);  /* open for writing */
     if (status != NC_NOERR) handle_error(status);
        ...
     status = nc_redef(ncid);  /* put in define mode to rename dimension */
     if (status != NC_NOERR) handle_error(status);
     status = nc_inq_dimid(ncid, "lat", &latid);
     if (status != NC_NOERR) handle_error(status);
     status = nc_rename_dim(ncid, latid, "latitude");
     if (status != NC_NOERR) handle_error(status);
     status = nc_enddef(ncid); /* leave define mode */
     if (status != NC_NOERR) handle_error(status);