Next: , Previous: nc_copy_att, Up: Attributes


5.6 Rename an Attribute: nc_rename_att

The function nc_rename_att changes the name of an attribute. If the new name is longer than the original name, the netCDF dataset must be in define mode. You cannot rename an attribute to have the same name as another attribute of the same variable.

Usage

     int nc_rename_att (int ncid, int varid, const char* name,
                        const char* newname);
ncid
NetCDF ID, from a previous call to nc_open or nc_create
varid
ID of the attribute's variable, or NC_GLOBAL for a global attribute
name
The current attribute name.
newname
The new name to be assigned to the specified attribute. If the new name is longer than the current name, the netCDF dataset must be in define mode.

Errors

nc_rename_att 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_att to rename the variable attribute units to Units for a variable rh in an existing netCDF dataset named foo.nc:

     #include <netcdf.h>
        ...
     int  status;      /* error status */
     int  ncid;        /* netCDF ID */
     int  rh_id;       /* variable id */
        ...
     status = nc_open("foo.nc", NC_NOWRITE, &ncid);
     if (status != NC_NOERR) handle_error(status);
        ...
     status = nc_inq_varid (ncid, "rh", &rh_id);
     if (status != NC_NOERR) handle_error(status);
        ...
     /* rename attribute */
     status = nc_rename_att(ncid, rh_id, "units", "Units");
     if (status != NC_NOERR) handle_error(status);