4.4 Get a Variable ID from Its Name: NF90_INQ_VARID
The function NF90_INQ_VARID returns the ID of a netCDF variable, given
its name.
Usage
function nf90_inq_varid(ncid, name, varid)
integer, intent( in) :: ncid
character (len = *), intent( in) :: name
integer, intent(out) :: varid
integer :: nf90_inq_varid
ncid- NetCDF ID, from a previous call to NF90_OPEN or NF90_CREATE.
name- Variable name for which ID is desired.
varid- Returned variable ID.
Errors
NF90_INQ_VARID returns the value NF90_NOERR if no errors
occurred. Otherwise, the returned status indicates an error. Possible
causes of errors include:
- The specified variable name is not a valid name for a variable in the
specified netCDF dataset.
- The specified netCDF ID does not refer to an open netCDF dataset.
Example
Here is an example using NF90_INQ_VARID to find out the ID of a variable
named rh in an existing netCDF dataset named foo.nc:
use netcdf
implicit none
integer :: status, ncid, RhVarId
...
status = nf90_open("foo.nc", nf90_NoWrite, ncid)
if(status /= nf90_NoErr) call handle_err(status)
...
status = nf90_inq_varid(ncid, "rh", RhVarId)
if(status /= nf90_NoErr) call handle_err(status)