First use nc_inq, which will tell you how many variables and global attributes there are in the file.
Start with global attribute 0, and proceed to natts - 1, the number of global attributes minus one. The nc_inq_att function will tell you the name, type, and length of each global attribute.
Then start with dimid 0, and proceed to dimid ndims - 1, calling nc_inq_dim. This will tell you the name and length of each dimension, and whether it is unlimited.
Then start with varid 0, and proceed to varid nvars - 1, calling nc_inq_var. This will tell you the number of dimensions of this variable, and their associated IDs. It will also get the name and type of this variable, and whether there are any attributes attached. If there are attributes attached, use the nc_inq_att function to get their names, types, and lengths.
(To read an attribute, use the appropriate nc_get_att_<TYPE> function, like nc_get_att_int() to get the data from an attribute that is an array of integers.)
There are also functions that return an item's ID, given its name. To find IDs from the names, use functions nc_inq_dimid, nc_inq_attnum, and nc_inq_varid.
For a typical sequence of calls to these functions see Reading a netCDF Dataset with Unknown Names.
With any of the C inquiry functions, a NULL pointer can be used to ignore a return parameter. Consider the nc_inq function:
EXTERNL int nc_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp);
If you call this with NULL for the last three parameters, you can learn the number of dimensions without bothering about the number of variables, number of global attributes, and the ID of the unlimited dimension.
For further convenience, we provide functions like nc_inq_ndims, which only finds the number of dimensions, exactly as if you had called nc_inq, with NULLs in all parameters except ndimsp. (In fact, this is just what the nc_inq_ndims functions does).
nc_inq | Find number of dimensions, variables, and global attributes, and the unlimited dimid.
|
nc_inq_att | Find attribute name, type, and length.
|
nc_inq_dim Family | Find dimension name and length.
|
nc_inq_var | Find variable name, type, num dimensions, dim IDs, and num attributes.
|
nc_inq_dimid | Find dimension ID from its name.
|
nc_inq_varid | Find variable ID from its name.
|
nc_inq_format | Find file format: classic or 64-bit offset
|
nc_inq_libvers | Find the netCDF version. (Currently 3.6.2).
|