Go to the previous, next section.

Inquire about an Open NetCDF File

The function ncinquire (NCINQ for FORTRAN) returns information about an open netCDF file, given its netCDF ID. It can be called from either define mode or data mode. It 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 size, if any. No I/O is required when this or any other `inquire' function in the netCDF interface is called, since the functions merely return information that is stored in a table for each open netCDF file.

In case of an error, ncinquire returns -1; NCINQ returns a nonzero value in rcode. Possible cause of errors includes:

ncinquire: C Interface

int ncinquire(int ncid, int* ndims, int* nvars, int* ngatts,
              int* recdim);

ncid
NetCDF ID, returned from a previous call to ncopen or nccreate.

ndims
Returned number of dimensions defined for this netCDF file. If this parameter is given as `(int *) 0', the number of dimensions will not be returned so no variable to hold this information needs to be declared.

nvars
Returned number of variables defined for this netCDF file. If this parameter is given as `(int *) 0', the number of variables will not be returned so no variable to hold this information needs to be declared.

ngatts
Returned number of global attributes defined for this netCDF file. If this parameter is given as `(int *) 0', the number of global attributes will not be returned so no variable to hold this information needs to be declared.

recdim
Returned ID of the unlimited dimension, if there is one for this netCDF file. If no unlimited size dimension has been defined, -1 is returned for the value of recdim. If this parameter is given as `(int *) 0', the record dimension ID will not be returned so no variable to hold this information needs to be declared.

Here is an example using ncinquire to find out about a netCDF file named `foo.nc':

#include "netcdf.h"
   ...
int ncid, ndims, nvars, ngatts, recdim;
   ...
ncid = ncopen("foo.nc", NC_NOWRITE);
   ...
ncinquire(ncid, &ndims, &nvars, &ngatts, &recdim);

NCINQ: FORTRAN Interface

      SUBROUTINE NCINQ(INTEGER NCID, INTEGER NDIMS, INTEGER NVARS,
     *                 INTEGER NGATTS, INTEGER RECDIM, INTEGER RCODE)

NCID
NetCDF ID, returned from a previous call to NCOPN or NCCRE.

NDIMS
Returned number of dimensions defined for this netCDF file.

NVARS
Returned number of variables defined for this netCDF file.

NGATTS
Returned number of global attributes defined for this netCDF file.

RECDIM
Returned ID of the unlimited dimension, if there is one for this netCDF file. If no unlimited size dimension has been defined, -1 is returned for the value of RECDIM.

RCODE
Returned error code. If no errors occurred, 0 is returned.

Here is an example using NCINQ to find out about a netCDF file named `foo.nc':

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID, NDIMS, NVARS, NATTS, RECDIM, RCODE
         ...
      NCID = NCOPN('foo.nc', NCNOWRIT, RCODE)
         ...
      CALL NCINQ(NCID, NDIMS, NVARS, NATTS, RECDIM, RCODE)

Go to the previous, next section.