Go to the previous, next section.
The function ncattname (or NCANAM for FORTRAN) gets the
name of an attribute, given its variable ID and number.
This function is useful in generic applications that
need to get the names of all the attributes associated with a variable,
since attributes are accessed by name rather than number in all other
attribute functions. The number of an attribute is more volatile than
the name, since it can change when other attributes of the same variable
are deleted. This is why an attribute number is not called an attribute
ID.
In case of an error, ncattname returns -1; NCANAM returns a
nonzero value in rcode. Possible causes of errors include:
int ncattname (int ncid, int varid, int attnum, char* name);
ncid
ncopen or nccreate.
varid
NC_GLOBAL for a global
attribute.
attnum
nvatts-1, where nvatts is
the number of attributes for the variable, as returned from a call to
ncvarinq.
name
MAX_NC_NAME.
If the name parameter is given as (char *) 0, no name will be
returned and no space needs to be allocated.
Here is an example using ncattname to determine the name of the
first attribute of the variable rh in an existing netCDF file
named `foo.nc':
#include "netcdf.h"
...
int ncid; /* netCDF ID */
int rh_id; /* variable ID */
char attname[MAX_NC_NAME]; /* maximum-size attribute name */
...
ncid = ncopen("foo.nc", NC_NOWRITE);
...
rh_id = ncvarid (ncid, "rh");
...
/* get name of first attribute (number 0) */
ncattname(ncid, rh_id, 0, attname);
SUBROUTINE NCANAM (INTEGER NCID, INTEGER VARID,
+ INTEGER ATTNUM, CHARACTER*(*) ATTNAM,
+ INTEGER RCODE)
NCID
NCOPN or NCCRE.
VARID
NCGLOBAL for a global
attribute.
ATTNUM
NVATTS, where NVATTS is
the number of attributes for the variable, as returned from a call to
NCVINQ.
ATTNAM
MAXNCNAM.
RCODE
Here is an example using NCANAM determine the name of the
first attribute of the variable rh in an existing netCDF file
named `foo.nc':
INCLUDE 'netcdf.inc'
...
INTEGER NCID ! netCDF ID
INTEGER RHID ! variable ID
* 31 in the following should be MAXNCNAM
CHARACTER*31 ATTNAM
...
NCID = NCOPN ('foo.nc', NCNOWRIT, RCODE)
...
RHID = NCVID (NCID, 'rh', RCODE)
...
* get name of first attribute (number 1)
CALL NCANAM (NCID, RHID, 1, ATTNAM, RCODE)
Go to the previous, next section.