Next: , Previous: nc_redef, Up: Datasets


2.12 Leave Define Mode: nc_enddef

The function nc_enddef takes an open netCDF dataset out of define mode. The changes made to the netCDF dataset while it was in define mode are checked and committed to disk if no problems occurred. Non-record variables may be initialized to a "fill value" as well. See nc_set_fill. The netCDF dataset is then placed in data mode, so variable data can be read or written.

It's not necessary to call nc_enddef for netCDF-4 files. With netCDF-4 files, nc_enddef is called when needed by the netcdf-4 library. User calls to nc_enddef for netCDF-4 files still flush the metadata to disk.

This call may involve copying data under some circumstances. For a more extensive discussion see File Structure and Performance.

For netCDF-4/HDF5 format files there are some variable settings (the compression, endianness, fletcher32 error correction, and fill value) which must be set (if they are going to be set at all) between the nc_def_var and the next nc_enddef. Once the nc_enddef is called, these settings can no longer be changed for a variable.

Usage

     int nc_enddef(int ncid);
ncid
NetCDF ID, from a previous call to nc_open or nc_create. If you use a group id, the enddef will apply to the entire file. That all, the enddef will not just end define mode in one group, but in the entire file.

Errors

nc_enddef 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 nc_enddef to finish the definitions of a new netCDF dataset named foo.nc and put it into data mode:

     #include <netcdf.h>
        ...
     int status;
     int ncid;
        ...
     status = nc_create("foo.nc", NC_NOCLOBBER, &ncid);
     if (status != NC_NOERR) handle_error(status);
     
        ...       /* create dimensions, variables, attributes */
     
     status = nc_enddef(ncid);  /*leave define mode*/
     if (status != NC_NOERR) handle_error(status);