Go to the previous, next section.

Close an Open NetCDF File

The function ncclose (or NCCLOS for FORTRAN) closes an open netCDF file. If the file is in define mode, ncendef (or NCENDF) will be called before closing. (In this case, if ncendef [or NCENDF] returns an error, ncabort [or NCABOR] will automatically be called to restore the file to the consistent state before define mode was last entered.) After an open netCDF file is closed, its netCDF ID will be reassigned to the next netCDF file that is opened or created.

In case of an error, ncclose returns -1; NCCLOS returns a nonzero value in rcode. Possible causes of errors include:

ncclose: C Interface

int ncclose(int ncid);

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

Here is an example using ncclose to finish the definitions of a new netCDF file named `foo.nc' and release its netCDF ID:

#include "netcdf.h"
   ...
int ncid;
   ...
ncid = nccreate("foo.nc", NC_NOCLOBBER);

   ...      /* create dimensions, variables, attributes */

ncclose(ncid);       /* close netCDF file */

NCCLOS: FORTRAN Interface

SUBROUTINE NCCLOS(INTEGER NCID, INTEGER RCODE)

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

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

Here is an example using NCCLOS to finish the definitions of a new netCDF file named `foo.nc' and release its netCDF ID:

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID, RCODE
         ...
      NCID = NCCRE('foo.nc', NCNOCLOB, RCODE)

         ...  ! create dimensions, variables, attributes

      CALL NCCLOS(NCID, RCODE)

Go to the previous, next section.