Next: , Previous: , Up: Files   [Index]


2.12 Close an Open NetCDF File: ncmpi_close

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

Operational Mode

This API is a collective subroutine (must be called by all MPI processes that open the file.)

This API can be called while the file is in either define or data mode (collective or independent).

Usage

int ncmpi_close(int ncid);
ncid

NetCDF ID, from a previous call to ncmpi_open or ncmpi_create.

Return Error Codes

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

Example

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

#include <pnetcdf.h>
   ... 
int err, ncid, cmode = NC_NOCLOBBER | NC_64BIT_DATA;
   ... 
err = ncmpi_create(MPI_COMM_WORLD, "foo.nc", cmode, MPI_INFO_NULL, &ncid);
if (err != NC_NOERR) printf("Error: %s\n",ncmpi_strerror(err));

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

err = ncmpi_close(ncid);       /* close netCDF file */
if (err != NC_NOERR) printf("Error: %s\n",ncmpi_strerror(err));

Next: , Previous: , Up: Files   [Index]