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


2.15 Back Out of Recent Definitions: ncmpi_abort

You no longer need to call this function, since it is called automatically by ncmpi_close in case the file is in define mode and something goes wrong with committing the changes. The function ncmpi_abort just closes the netCDF file, if not in define mode. If the file is being created and is still in define mode, the dataset is deleted. If define mode was entered by a call to ncmpi_redef, the netCDF file is restored to its state before definition mode was entered and the file is closed.

Operational Mode

This API is a collective subroutine.

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

Usage

int ncmpi_abort(int ncid);
ncid

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

Return Error Codes

ncmpi_abort 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_abort to back out of redefinitions of a file named foo.nc:

#include <pnetcdf.h>
   ...
int ncid, status, latid;
   ...
status = ncmpi_open(MPI_COMM_WORLD, "foo.nc", NC_NOWRITE, MPI_INFO_NULL,  &ncid); /* open for read only */
if (status != NC_NOERR) handle_error(status);
   ...
status = ncmpi_redef(ncid);                    /* enter define mode */
if (status != NC_NOERR) handle_error(status);
   ...
status = ncmpi_def_dim(ncid, "lat", 18L, &latid);
if (status != NC_NOERR) {
   handle_error(status);
   status = ncmpi_abort(ncid);                 /* define failed, abort */
   if (status != NC_NOERR) handle_error(status);
}

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