Next: , Previous: , Up: Attributes   [Index]


5.6 Rename an Attribute: ncmpi_rename_att

The function ncmpi_rename_att changes the name of an attribute. It is illegal to rename an attribute to the same name as another attribute of the same variable.

Operational Mode

This API is a collective subroutine.

If the new name is longer than the original name, the netCDF file must be in define mode. Otherwise, the netCDF file can be in either define or data mode.

Usage

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

NetCDF ID, from a previous call to ncmpi_open or ncmpi_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 file must be in define mode.

Return Error Codes

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

#include <pnetcdf.h>
   ... 
int  status;      /* error status */
int  ncid;        /* netCDF ID */
int  rh_id;       /* variable id */
   ... 
status = ncmpi_open(MPI_COMM_WORLD, "foo.nc", NC_NOWRITE, MPI_INFO_NULL, &ncid);
if (status != NC_NOERR) handle_error(status);
   ... 
status = ncmpi_inq_varid(ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
   ... 
/* rename attribute */
status = ncmpi_rename_att(ncid, rh_id, "units", "Units");
if (status != NC_NOERR) handle_error(status);

Next: , Previous: , Up: Attributes   [Index]