Go to the previous, next section.
The function ncattinq
(or NCAINQ
for FORTRAN) returns
information about a netCDF attribute, given its variable ID and name.
The information returned is the type and length of the attribute.
In case of an error, ncattinq
returns -1; NCAINQ
returns a
nonzero value in rcode
. Possible causes of errors include:
int ncattinq(int ncid, int varid, const char* name, nc_type* datatype, int* len);
ncid
ncopen
or nccreate
.
varid
NC_GLOBAL
for a
global attribute.
name
datatype
nc_type
, is defined in the netCDF
header file. The valid netCDF data types are NC_BYTE
,
NC_CHAR
, NC_SHORT
, NC_LONG
, NC_FLOAT
, and
NC_DOUBLE
. If this parameter is given as `(nc_type *) 0',
no type will be returned so no variable to hold the type needs to be
declared.
len
NC_CHAR
, this is one more than the string
length (since the terminating null character is stored). If this
parameter is given as `(int *) 0', no length will be returned so no
variable to hold this information needs to be declared.
Here is an example using ncattinq
to find out the type and length
of a variable attribute named valid_range
for a netCDF variable
named rh
and a global attribute named title
in an existing
netCDF file named `foo.nc':
#include "netcdf.h" ... int ncid; /* netCDF ID */ int rh_id; /* variable ID */ nc_type vr_type, t_type; /* attribute types */ int vr_len, t_len; /* attribute lengths *' ... ncid = ncopen("foo.nc", NC_NOWRITE); ... rh_id = ncvarid (ncid, "rh"); ... ncattinq (ncid, rh_id, "valid_range", &vr_type, &vr_len); ncattinq (ncid, NC_GLOBAL, "title", &t_type, &t_len); ...
SUBROUTINE NCAINQ (INTEGER NCID, INTEGER VARID, + CHARACTER*(*) ATTNAM, INTEGER ATTYPE, + INTEGER ATTLEN,INTEGER RCODE)
NCID
NCOPN
or NCCRE
.
VARID
NCGLOBAL
for a
global attribute.
ATTNAM
ATTYPE
NCBYTE
, NCCHAR
,
NCSHORT
, NCLONG
, NCFLOAT
, and NCDOUBLE
.
ATTLEN
RCODE
Here is an example using NCAINQ
to add a variable attribute
named valid_range
for a netCDF variable named rh
and a
global attribute named title
to an existing netCDF file named
`foo.nc':
INCLUDE 'netcdf.inc' ... INTEGER NCID, RCODE INTEGER RHID ! variable ID INTEGER VRTYPE, TTYPE ! attribute types INTEGER VRLEN, TLEN ! attribute lengths ... NCID = NCOPN ('foo.nc', NCNOWRIT, RCODE) ... RHID = NCVID (NCID, 'rh', RCODE)! get ID ... CALL NCAINQ (NCID, RHID, 'valid_range', VRTYPE, VRLEN, + RCODE) CALL NCAINQ (NCID, NCGLOBAL, 'title', TTYPE, TLEN, + RCODE)
Go to the previous, next section.