7.6 NF_COPY_ATT
The function NF_COPY_ATT copies an attribute from one open netCDF
dataset to another. It can also be used to copy an attribute from one
variable to another within the same netCDF.
Usage
INTEGER FUNCTION NF_COPY_ATT (INTEGER NCID_IN, INTEGER VARID_IN,
CHARACTER*(*) NAME, INTEGER NCID_OUT,
INTEGER VARID_OUT)
NCID_IN- The netCDF ID of an input netCDF dataset from which the attribute
will be copied, from a previous call to NF_OPEN or NF_CREATE.
VARID_IN- ID of the variable in the input netCDF dataset from which the
attribute will be copied, or NF_GLOBAL for a global attribute.
NAME- Name of the attribute in the input netCDF dataset to be copied.
NCID_OUT- The netCDF ID of the output netCDF dataset to which the attribute
will be copied, from a previous call to NF_OPEN or NF_CREATE. It is
permissible for the input and output netCDF IDs to be the same. The
output netCDF dataset should be in define mode if the attribute to be
copied does not already exist for the target variable, or if it would
cause an existing target attribute to grow.
VARID_OUT- ID of the variable in the output netCDF dataset to which the
attribute will be copied, or NF_GLOBAL to copy to a global attribute.
Errors
NF_COPY_ATT returns the value NF_NOERR if no errors
occurred. Otherwise, the returned status indicates an error. Possible
causes of errors include:
- The input or output variable ID is invalid for the specified netCDF
dataset.
- The specified attribute does not exist.
- The output netCDF is not in define mode and the attribute is new for
the output dataset is larger than the existing attribute.
- The input or output netCDF ID does not refer to an open netCDF
dataset.
Example
Here is an example using NF_COPY_ATT to copy the variable attribute
units from the variable rh in an existing netCDF dataset named foo.nc
to the variable avgrh in another existing netCDF dataset named bar.nc,
assuming that the variable avgrh already exists, but does not yet have
a units attribute:
INCLUDE 'netcdf.inc'
...
INTEGER STATUS ! error status
INTEGER NCID1, NCID2 ! netCDF IDs
INTEGER RHID, AVRHID ! variable IDs
...
STATUS = NF_OPEN ('foo.nc', NF_NOWRITE, NCID1)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
STATUS = NF_OPEN ('bar.nc', NF_WRITE, NCID2)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
...
STATUS = NF_INQ_VARID (NCID1, 'rh', RHID)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
STATUS = NF_INQ_VARID (NCID2, 'avgrh', AVRHID)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
...
STATUS = NF_REDEF (NCID2) ! enter define mode
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
! copy variable attribute from "rh" to "avgrh"
STATUS = NF_COPY_ATT (NCID1, RHID, 'units', NCID2, AVRHID)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
...
STATUS = NC_ENDDEF (NCID2) ! leave define mode
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)