The function NF90_PUT_ATTadds or changes a variable attribute or global attribute of an open netCDF dataset. If this attribute is new, or if the space required to store the attribute is greater than before, the netCDF dataset must be in define mode.
Although it's possible to create attributes of all types, text and double attributes are adequate for most purposes.
function nf90_put_att(ncid, varid, name, values)
integer, intent( in) :: ncid, varid
character(len = *), intent( in) :: name
any valid type, scalar or array of rank 1, &
intent( in) :: values
integer :: nf90_put_att
ncidvaridnamevaluesNF90_PUT_ATT returns the value NF90_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:
Here is an example using NF90_PUT_ATT to add a variable attribute named valid_range for a netCDF variable named rh and a global attribute named title to an existing netCDF dataset named foo.nc:
use netcdf
implicit none
integer :: ncid, status, RHVarID
...
status = nf90_open("foo.nc", nf90_write, ncid)
if (status /= nf90_noerr) call handle_err(status)
...
! Enter define mode so we can add the attribute
status = nf90_redef(ncid)
if (status /= nf90_noerr) call handle_err(status)
! Get the variable ID for "rh"...
status = nf90_inq_varid(ncid, "rh", RHVarID)
if (status /= nf90_noerr) call handle_err(status)
! ... put the range attribute, setting it to eight byte reals...
status = nf90_put_att(ncid, RHVarID, "valid_range", real((/ 0, 100 /))
! ... and the title attribute.
if (status /= nf90_noerr) call handle_err(status)
status = nf90_put_att(ncid, RHVarID, "title", "example netCDF dataset") )
if (status /= nf90_noerr) call handle_err(status)
! Leave define mode
status = nf90_enddef(ncid)
if (status /= nf90_noerr) call handle_err(status)