Next: , Previous: , Up: Variables   [Index]


4.7 Get a Variable ID from Its Name: ncmpi_inq_varid

The function ncmpi_inq_varid returns the ID of a netCDF variable, given its name.

Operational Mode

This API is an independent subroutine.

This API can be called while the file is in either define or data mode (collective or independent).

Usage

int ncmpi_inq_varid(int         ncid,
                    const char *name,
                    int        *varidp);
ncid

NetCDF ID, from a previous call to ncmpi_open or ncmpi_create.

name

Variable name for which ID is desired.

varidp

Pointer to location for returned variable ID.

Return Error Codes

ncmpi_inq_varid returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:

Example

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);

Full example C program


Next: , Previous: , Up: Variables   [Index]