6.17 NF90_RENAME_VAR
The function NF90_RENAME_VAR changes the name of a netCDF variable in an
open netCDF dataset. If the new name is longer than the old name, the
netCDF dataset must be in define mode. You cannot rename a variable to
have the name of any existing variable.
Usage
function nf90_rename_var(ncid, varid, newname)
integer, intent( in) :: ncid, varid
character (len = *), intent( in) :: newname
integer :: nf90_rename_var
ncid- NetCDF ID, from a previous call to NF90_OPEN or NF90_CREATE.
varid- Variable ID.
newname- New name for the specified variable.
Errors
NF90_RENAME_VAR returns the value NF90_NOERR if no errors
occurred. Otherwise, the returned status indicates an error. Possible
causes of errors include:
- The new name is in use as the name of another variable.
- The variable ID is invalid for the specified netCDF dataset.
- The specified netCDF ID does not refer to an open netCDF dataset.
Example
Here is an example using NF90_RENAME_VAR to rename the variable rh to
rel_hum in an existing netCDF dataset named foo.nc:
use netcdf
implicit none
integer :: ncId, rhVarId, status
...
status = nf90_open("foo.nc", nf90_Write, ncid)
if(status /= nf90_NoErr) call handle_err(status)
...
status = nf90_inq_varid(ncid, "rh", rhVarId)
if(status /= nf90_NoErr) call handle_err(status)
status = nf90_redef(ncid) ! Enter define mode to change variable name
if(status /= nf90_NoErr) call handle_err(status)
status = nf90_rename_var(ncid, rhVarId, "rel_hum")
if(status /= nf90_NoErr) call handle_err(status)
status = nf90_enddef(ncid) ! Leave define mode
if(status /= nf90_NoErr) call handle_err(status)