Next: , Previous: NF_INQ_VARID, Up: Variables


4.5 Get Information about a Variable from Its ID: NF_INQ_VAR family

A family of functions that returns information about a netCDF variable, given its ID. Information about a variable includes its name, type, number of dimensions, a list of dimension IDs describing the shape of the variable, and the number of variable attributes that have been assigned to the variable.

The function NF_INQ_VAR returns all the information about a netCDF variable, given its ID. The other functions each return just one item of information about a variable.

These other functions include NF_INQ_VARNAME, NF_INQ_VARTYPE, NF_INQ_VARNDIMS, NF_INQ_VARDIMID, and NF_INQ_VARNATTS.

Usage

     INTEGER FUNCTION NF_INQ_VAR      (INTEGER NCID, INTEGER VARID,
                                       CHARACTER*(*) name, INTEGER xtype,
                                       INTEGER ndims, INTEGER dimids(*),
                                       INTEGER natts)
     INTEGER FUNCTION NF_INQ_VARNAME  (INTEGER NCID, INTEGER VARID,
                                       CHARACTER*(*) name)
     INTEGER FUNCTION NF_INQ_VARTYPE  (INTEGER NCID, INTEGER VARID,
                                       INTEGER xtype)
     INTEGER FUNCTION NF_INQ_VARNDIMS (INTEGER NCID, INTEGER VARID,
                                       INTEGER ndims)
     INTEGER FUNCTION NF_INQ_VARDIMID (INTEGER NCID, INTEGER VARID,
                                       INTEGER dimids(*))
     INTEGER FUNCTION NF_INQ_VARNATTS (INTEGER NCID, INTEGER VARID,
                                       INTEGER natts)
NCID
NetCDF ID, from a previous call to NF_OPEN or NF_CREATE.
VARID
Variable ID.
NAME
Returned variable name. The caller must allocate space for the returned name. The maximum possible length, in characters, of a variable name is given by the predefined constant NF_MAX_NAME.
xtype
Returned variable type, one of the set of predefined netCDF external data types. The type of this parameter, NF_TYPE, is defined in the netCDF header file. The valid netCDF external data types are NF_BYTE, NF_CHAR, NF_SHORT, NF_INT, NF_FLOAT, AND NF_DOUBLE.
ndims
Returned number of dimensions the variable was defined as using. For example, 2 indicates a matrix, 1 indicates a vector, and 0 means the variable is a scalar with no dimensions.
dimids
Returned vector of *ndimsp dimension IDs corresponding to the variable dimensions. The caller must allocate enough space for a vector of at least *ndimsp integers to be returned. The maximum possible number of dimensions for a variable is given by the predefined constant NF_MAX_VAR_DIMS.
natts
Returned number of variable attributes assigned to this variable.

These functions return the value NF_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:

Example

Here is an example using NF_INQ_VAR to find out about a variable named rh in an existing netCDF dataset named foo.nc:

     INCLUDE 'netcdf.inc'
        ...
     INTEGER  STATUS, NCID
     INTEGER  RHID               ! variable ID
     CHARACTER*31 RHNAME         ! variable name
     INTEGER  RHTYPE             ! variable type
     INTEGER  RHN                ! number of dimensions
     INTEGER  RHDIMS(NF_MAX_VAR_DIMS)   ! variable shape
     INTEGER  RHNATT                    ! number of attributes
        ...
     STATUS = NF_OPEN ('foo.nc', NF_NOWRITE, NCID)
     IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
        ...
     STATUS = NF_INQ_VARID (NCID, 'rh', RHID)  ! get ID
     IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
     STATUS = NF_INQ_VAR (NCID, RHID, RHNAME, RHTYPE, RHN, RHDIMS, RHNATT)
     IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)