Next: , Previous: nc_close, Up: Datasets


2.12 Inquire about an Open NetCDF Dataset: nc_inq Family

Members of the nc_inq family of functions return information about an open netCDF dataset, given its netCDF ID. Dataset inquire functions may be called from either define mode or data mode. The first function, nc_inq, returns values for the number of dimensions, the number of variables, the number of global attributes, and the dimension ID of the dimension defined with unlimited length, if any. The other functions in the family each return just one of these items of information.

For C, these functions include nc_inq, nc_inq_ndims, nc_inq_nvars, nc_inq_natts, and nc_inq_unlimdim. An additional function, nc_inq_format, returns the (rarely needed) format version.

No I/O is performed when these functions are called, since the required information is available in memory for each open netCDF dataset.

Usage

     int nc_inq          (int ncid, int *ndimsp, int *nvarsp, int *ngattsp,
                          int *unlimdimidp);
     int nc_inq_ndims    (int ncid, int *ndimsp);
     int nc_inq_nvars    (int ncid, int *nvarsp);
     int nc_inq_natts    (int ncid, int *ngattsp);
     int nc_inq_unlimdim (int ncid, int *unlimdimidp);
     int nc_inq_format   (int ncid, int *formatp);
ncid
NetCDF ID, from a previous call to nc_open or nc_create.
ndimsp
Pointer to location for returned number of dimensions defined for this netCDF dataset.
nvarsp
Pointer to location for returned number of variables defined for this netCDF dataset.
ngattsp
Pointer to location for returned number of global attributes defined for this netCDF dataset.
unlimdimidp
Pointer to location for returned ID of the unlimited dimension, if there is one for this netCDF dataset. If no unlimited length dimension has been defined, -1 is returned.
formatp
Pointer to location for returned format version, one of NC_FORMAT_CLASSIC, NC_FORMAT_64BIT, NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC.

Errors

All members of the nc_inq family return 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 nc_inq to find out about a netCDF dataset named foo.nc:

     #include <netcdf.h>
        ...
     int status, ncid, ndims, nvars, ngatts, unlimdimid;
        ...
     status = nc_open("foo.nc", NC_NOWRITE, &ncid);
     if (status != NC_NOERR) handle_error(status);
        ...
     status = nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid);
     if (status != NC_NOERR) handle_error(status);