7.7 Rename an Attribute: NF90_RENAME_ATT
The function NF90_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
function nf90_rename_att(ncid, varid, curname, newname)
integer, intent( in) :: ncid, varid
character (len = *), intent( in) :: curname, newname
integer :: nf90_rename_att
ncid- NetCDF ID, from a previous call to NF90_OPEN or NF90_CREATE
varid- ID of the attribute's variable, or NF90_GLOBAL for a global attribute
curname- 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
NF90_RENAME_ATT returns the value NF90_NOERR if no errors
occurred. Otherwise, the returned status indicates an error. Possible
causes of errors include:
- The specified variable ID is not valid.
- The new attribute name is already in use for another attribute of the
specified variable.
- The specified netCDF dataset is in data mode and the new name is
longer than the old name.
- The specified attribute does not exist.
- The specified netCDF ID does not refer to an open netCDF dataset.
Example
Here is an example using NF90_RENAME_ATT to rename the variable
attribute units to Units for a variable rh in an existing netCDF
dataset named foo.nc:
use netcdf
implicit none
integer :: ncid1, status
integer :: RHVarID ! Variable ID
...
status = nf90_open("foo.nc", nf90_nowrite, ncid)
if (status /= nf90_noerr) call handle_err(status)
...
! Find the IDs of the variables
status = nf90_inq_varid(ncid, "rh", RHVarID)
if (status /= nf90_noerr) call handle_err(status)
...
status = nf90_rename_att(ncid, RHVarID, "units", "Units")
if (status /= nf90_noerr) call handle_err(status)