Go to the previous, next section.

Back Out of Recent Definitions

The function ncabort (or NCABOR for FORTRAN), if not in define mode, closes the netCDF file. If the file is being created and is still in define mode, the file is deleted. If define mode was entered by a call to ncredef (or NCREDF), the netCDF file is restored to its state before definition mode was entered and the file is closed. The main reason for calling ncabort (or NCABOR) is to restore the netCDF to a known consistent state in case anything goes wrong during the definition of new dimensions, variables, or attributes.

This function is called automatically if ncclose (or NCCLOS) is called from define mode and the call to leave define mode before closing fails.

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

ncabort: C Interface

int ncabort(int ncid);

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

Here is an example using ncabort to back out of redefinitions of a file named `foo.nc':

#include "netcdf.h"
   ...
int ncid;
   ...
ncid = ncopen("foo.nc", NC_WRITE);  /* open for writing */
   ...
ncredef(ncid);                    /* enter define mode */
   ...
if (ncdimdef(ncid, "lat", 18L) == -1)
   ncabort(ncid);                 /* define failed, abort */

NCABOR: FORTRAN Interface

      SUBROUTINE NCABOR(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 NCABOR to back out of redefinitions of a file named `foo.nc':

      INCLUDE 'netcdf.inc'
         ...
      INTEGER NCID, RCODE, LATID
         ...
      NCID = NCOPN('foo.nc', NCWRITE, RCODE)
         ...
      CALL NCREDF(NCID, RCODE)
         ...
      LATID = NCDDEF(NCID, 'LAT', 18, RCODE)
      IF (RCODE .EQ. -1) THEN  ! dimension definition failed
         CALL NCABOR(NCID, RCODE)  ! abort redefinitions
      ENDIF
         ...

Go to the previous, next section.