Next: , Previous: nc__enddef, Up: Datasets


2.14 Close an Open NetCDF Dataset: nc_close

The function nc_close closes an open netCDF dataset.

If the dataset in define mode, nc_enddef will be called before closing. (In this case, if nc_enddef returns an error, nc_abort will automatically be called to restore the dataset to the consistent state before define mode was last entered.) After an open netCDF dataset is closed, its netCDF ID may be reassigned to the next netCDF dataset that is opened or created.

Usage

For netCDF-4 files, the ncid of the root group must be passed into nc_close.

     int nc_close(int ncid);
ncid
NetCDF ID, from a previous call to nc_open or nc_create.

Errors

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

NC_NOERR
No error.
NC_EBADID
Invalid id passed.
NC_EBADGRPID
ncid did not contain the root group id of this file. (NetCDF-4 only).

Example

Here is an example using nc_close to finish the definitions of a new netCDF dataset named foo.nc and release its netCDF ID:

     #include <netcdf.h>
        ...
     int status;
     int ncid;
        ...
     status = nc_create("foo.nc", NC_NOCLOBBER, &ncid);
     if (status != NC_NOERR) handle_error(status);
     
        ...       /* create dimensions, variables, attributes */
     
     status = nc_close(ncid);       /* close netCDF dataset */
     if (status != NC_NOERR) handle_error(status);