Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Previous: Fill Values, Up: Variables



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:

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)
 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690