Go to the previous, next section.

Rename an Attribute

The function ncattrename (or NCAREN for FORTRAN) changes the name of an attribute. If the new name is longer than the original name, the netCDF must be in define mode. You cannot rename an attribute to have the same name as another attribute of the same variable.

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

ncattrename: C Interface

int ncattrename (int ncid, int varid, const char* name, const char* newname);

ncid
NetCDF ID, returned from a previous call to ncopen or nccreate
varid
ID of the attribute's variable, or NC_GLOBAL for a global attribute
name
The original attribute name.
newname
The new name to be assigned to the specified attribute. If the new name is longer than the old name, the netCDF file must be in define mode.

Here is an example using ncattrename to rename the variable attribute units to Units for a variable rh in an existing netCDF file named `foo.nc':

#include "netcdf.h"
   ...
int  ncid;        /* netCDF ID */
int  rh_id;       /* variable id */
   ...
ncid = ncopen("foo.nc", NC_NOWRITE);
   ...
rh_id = ncvarid (ncid, "rh");
   ...
/* rename attribute */
ncattrename(ncid, rh_id, "units", "Units");

NCAREN: FORTRAN Interface

      SUBROUTINE NCAREN (INTEGER NCID, INTEGER VARID,
     +                   CHARACTER*(*) ATTNAM,
     +                   CHARACTER*(*) NEWNAM, INTEGER RCODE)

NCID
NetCDF ID, returned from a previous call to NCOPN or NCCRE
VARID
ID of the attribute's variable, or NCGLOBAL for a global attribute
ATTNAM
The original attribute name.
NEWNAM
The new name to be assigned to the specified attribute. If the new name is longer than the old name, the netCDF file must be in define mode.
RCODE
Returned error code. If no errors occurred, 0 is returned.

Here is an example using NCAREN to rename the variable attribute units to Units for a variable rh in an existing netCDF file named `foo.nc':

      INCLUDE "netcdf.inc"
         ...
      INTEGER  NCID     ! netCDF ID
      INTEGER  RHID      ! variable ID
         ...
      NCID = NCOPN ("foo.nc", NCNOWRIT, RCODE)
         ...
      RHID = NCVID (NCID, "rh", RCODE)
         ...
* rename attribute
      CALL NCAREN (NCID, RHID, "units", "Units", RCODE)

Go to the previous, next section.