Next: , Previous: NF90_INQUIRE_VARIABLE, Up: Variables


6.7 Get the ID of a variable from the name: NF90_INQ_VARID

Given the name of a varaible, nf90_inq_varid finds the variable ID.

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
The variable name. The maximum possible length, in characters, of a variable name is given by the predefined constant NF90_MAX_NAME.
varid
Variable ID.

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

Example

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

         use netcdf
         implicit none
         integer                            :: status, ncid, &
                                               RhVarId       &
                                               numDims, numAtts
      integer, dimension(nf90_max_var_dims) :: rhDimIds
      ...
      status = nf90_open("foo.nc", nf90_NoWrite, ncid)
      if(status /= nf90_NoErr) call handle_error(status)
      ...
      status = nf90_inq_varid(ncid, "rh", RhVarId)
      if(status /= nf90_NoErr) call handle_err(status)
      status = nf90_inquire_variable(ncid, RhVarId, ndims = numDims, natts = numAtts)
      if(status /= nf90_NoErr) call handle_err(status)
      status = nf90_inquire_variable(ncid, RhVarId, dimids = rhDimIds(:numDims))
      if(status /= nf90_NoErr) call handle_err(status)