The function ncmpi_inq_varid returns the ID of a netCDF variable, given its name.
This API is an independent subroutine.
This API can be called while the file is in either define or data mode (collective or independent).
int ncmpi_inq_varid(int ncid, const char *name, int *varidp);
NetCDF ID, from a previous call to ncmpi_open or ncmpi_create.
Variable name for which ID is desired.
Pointer to location for returned variable ID.
ncmpi_inq_varid returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:
Here is an example using ncmpi_inq_varid to find out the ID of a variable named rh in an existing netCDF file named foo.nc:
#include <pnetcdf.h> ... int status, ncid, rh_id; ... status = ncmpi_open(MPI_COMM_WORLD, "foo.nc", NC_NOWRITE, MPI_INFO_NULL, &ncid); if (status != NC_NOERR) handle_error(status); ... status = ncmpi_inq_varid(ncid, "rh", &rh_id); if (status != NC_NOERR) handle_error(status);