Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Next: , Previous: nc_inq_dim Family, Up: Dimensions



4.5 Rename a Dimension: nc_rename_dim

The function nc_rename_dim renames an existing dimension in a netCDF dataset open for writing. You cannot rename a dimension to have the same name as another dimension.

For netCDF classic and 64-bit offset files, if the new name is longer than the old name, the netCDF dataset must be in define mode.

For netCDF-4 files the dataset is switched to define more for the rename, regardless of the name length.

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);
 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690