The function ncmpi_enddef takes an opened netCDF file out of define mode. The changes made to the netCDF file 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 ncmpi_set_fill. The netCDF file is then placed in data mode, so variable data can be read or written.
This call may involve moving (shifting) data under some circumstances. For instance, when opening an existing file and entering redefine more to add more metadata which causes file header to expands, all fixed-size and record variables will be moved to higher file offsets to make room for the new file header. Such operations can be very expensive. Users are encouraged to use PnetCDF hint nc_header_align_size to reserve a sufficient large space for file header if it is expected to expand.
This API is a collective routine: all processes must provide the same value for ncid.
This API must be called while the file is in define mode.
int ncmpi_enddef(int ncid);
NetCDF ID, from a previous call to ncmpi_open or ncmpi_create.
ncmpi_enddef returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:
Here is an example using ncmpi_enddef to finish the definitions of a new netCDF file named foo.nc and put it into data mode:
#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 */ err = ncmpi_enddef(ncid); /*leave define mode and enter data mode */ if (err != NC_NOERR) printf("Error: %s\n",ncmpi_strerror(err));