6.19 NF_GET_VAR1_ type
The functions NF_GET_VAR1_ type get a single data value from a
variable of an open netCDF dataset that is in data mode. Inputs are
the netCDF ID, the variable ID, a multidimensional index that
specifies which value to get, and the address of a location into which
the data value will be read. The value is converted from the external
data type of the variable, if necessary.
Usage
INTEGER FUNCTION NF_GET_VAR1_TEXT(INTEGER NCID, INTEGER VARID,
INTEGER INDEX(*), CHARACTER CHVAL)
INTEGER FUNCTION NF_GET_VAR1_INT1(INTEGER NCID, INTEGER VARID,
INTEGER INDEX(*), INTEGER*1 I1VAL)
INTEGER FUNCTION NF_GET_VAR1_INT2(INTEGER NCID, INTEGER VARID,
INTEGER INDEX(*), INTEGER*2 I2VAL)
INTEGER FUNCTION NF_GET_VAR1_INT (INTEGER NCID, INTEGER VARID,
INTEGER INDEX(*), INTEGER IVAL)
INTEGER FUNCTION NF_GET_VAR1_REAL(INTEGER NCID, INTEGER VARID,
INTEGER INDEX(*), REAL RVAL)
INTEGER FUNCTION NF_GET_VAR1_DOUBLE(INTEGER NCID, INTEGER VARID,
INTEGER INDEX(*), DOUBLE DVAL)
INTEGER FUNCTION NF_GET_VAR1(INTEGER NCID, INTEGER VARID,
INTEGER INDEX(*), VAL)
NCID- NetCDF ID, from a previous call to NF_OPEN or NF_CREATE.
VARID- Variable ID.
INDEX- The index of the data value to be read. The indices are relative to 1,
so for example, the first data value of a two-dimensional variable has
index (1,1). The elements of index correspond to the variable's
dimensions. Hence, if the variable is a record variable, the last
index is the record number.
CHVALI1VALI2VALIVALRVALDVALVAL- The location into which the data value will be read. You cannot get
CHARACTER data from a numeric variable or numeric data from a
character variable. For numeric data, if the type of data differs from
the netCDF variable type, type conversion will occur. (see Type Conversion (The NetCDF Users Guide)).
Errors
NF_GET_VAR1_ type returns the value NF_NOERR if no errors
occurred. Otherwise, the returned status indicates an error. Possible
causes of errors include:
- The variable ID is invalid for the specified netCDF dataset.
- The specified indices were out of range for the rank of the specified
variable. For example, a negative index or an index that is larger
than the corresponding dimension length will cause an error.
- The value is out of the range of values representable by the desired
data type.
- The specified netCDF is in define mode rather than data mode.
- The specified netCDF ID does not refer to an open netCDF dataset.
Example
Here is an example using NF_GET_VAR1_DOUBLE to get the (4,3,2) element
of the variable named rh in an existing netCDF dataset named
foo.nc. For simplicity in this example, we assume that we know that rh
is dimensioned with lon, lat, and time, so we want to get the value of
rh that corresponds to the fourth lon value, the third lat value, and
the second time value:
INCLUDE 'netcdf.inc'
...
INTEGER STATUS, NCID
INTEGER RHID ! variable ID
INTEGER RHINDX(3) ! where to get value
DOUBLE PRECISION RHVAL ! put it here
DATA RHINDX /4, 3, 2/
...
STATUS = NF_OPEN ('foo.nc', NF_NOWRITE, NCID)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
...
STATUS = NF_INQ_VARID (NCID, 'rh', RHID)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)
STATUS = NF_GET_VAR1_DOUBLE (NCID, RHID, RHINDX, RHVAL)
IF (STATUS .NE. NF_NOERR) CALL HANDLE_ERR(STATUS)