Go to the previous, next section.

Rename a Dimension

The function ncdimrename (or NCDREN for FORTRAN) renames an existing dimension in a netCDF file open for writing. If the new name is longer than the old name, the netCDF must be in define mode. You cannot rename a dimension to have the same name as another dimension.

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

ncdimrename: C Interface

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

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
New dimension name.

Here is an example using ncdimrename to rename the dimension lat to latitude in an existing netCDF file named `foo.nc':

#include "netcdf.h"
   ...
int ncid, latid;
   ...
ncid = ncopen("foo.nc", NC_WRITE);  /* open for writing */
   ...
ncredef(ncid);  /* put in define mode to rename dimension */
latid = ncdimid(ncid, "lat");
ncdimrename(ncid, latid, "latitude");
ncendef(ncid);  /* leave define mode */

NCDREN: FORTRAN Interface

      SUBROUTINE NCDREN (INTEGER NCID, INTEGER DIMID,
     +                   CHARACTER*(*) DIMNAME, 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
New name for the dimension.

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

Here is an example using NCDREN to rename the dimension "lat" to "latitude" in an existing netCDF file named `foo.nc':

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID, RCODE, LATID
         ...
      NCID = NCOPN('foo.nc', NCWRITE, RCODE)
         ...
* put in define mode to rename dimension
      CALL NCREDF(NCID, RCODE)
      LATID = NCDID(NCID, 'lat', RCODE)
      CALL NCDREN(NCID, LATID, 'latitude', RCODE)
* leave define mode
      CALL NCENDF(NCID, RCODE)

Go to the previous, next section.