Here we consider the case where you know the names of not only the netCDF datasets, but also the names of their dimensions, variables, and attributes. (Otherwise you would have to do "inquire" calls.) The order of typical C calls to read data from those variables in a netCDF dataset is:
NF90_OPEN ! open existing netCDF dataset ... NF90_INQ_DIMID ! get dimension IDs ... NF90_INQ_VARID ! get variable IDs ... NF90_GET_ATT ! get attribute values ... NF90_GET_VAR ! get values of variables ... NF90_CLOSE ! close netCDF dataset
First, a single call opens the netCDF dataset, given the dataset name, and returns a netCDF ID that is used to refer to the open netCDF dataset in all subsequent calls.
Next, a call to NF90_INQ_DIMID for each dimension of interest gets the dimension ID from the dimension name. Similarly, each required variable ID is determined from its name by a call to NF90_INQ_VARID. Once variable IDs are known, variable attribute values can be retrieved using the netCDF ID, the variable ID, and the desired attribute name as input to NF90_GET_ATT for each desired attribute. Variable data values can be directly accessed from the netCDF dataset with calls to NF90_GET_VAR.
Finally, the netCDF dataset is closed with NF90_CLOSE. There is no need to close a dataset open only for reading.