2.17 Back Out of Recent Definitions: nc_abort
You no longer need to call this function, since it is called
automatically by nc_close in case the dataset is in define mode and
something goes wrong with committing the changes. The function
nc_abort just closes the netCDF dataset, if not in define mode. If the
dataset is being created and is still in define mode, the dataset is
deleted. If define mode was entered by a call to nc_redef, the netCDF
dataset is restored to its state before definition mode was entered
and the dataset is closed.
Usage
int nc_abort(int ncid);
ncid- NetCDF ID, from a previous call to nc_open or nc_create.
Errors
nc_abort returns the value NC_NOERR if no errors occurred. Otherwise,
the returned status indicates an error. Possible causes of errors
include:
- When called from define mode while creating a netCDF dataset, deletion
of the dataset failed.
- The specified netCDF ID does not refer to an open netCDF dataset.
Example
Here is an example using nc_abort to back out of redefinitions of a
dataset named foo.nc:
#include <netcdf.h>
...
int ncid, status, latid;
...
status = nc_open("foo.nc", NC_WRITE, &ncid);/* open for writing */
if (status != NC_NOERR) handle_error(status);
...
status = nc_redef(ncid); /* enter define mode */
if (status != NC_NOERR) handle_error(status);
...
status = nc_def_dim(ncid, "lat", 18L, &latid);
if (status != NC_NOERR) {
handle_error(status);
status = nc_abort(ncid); /* define failed, abort */
if (status != NC_NOERR) handle_error(status);
}