Next: , Previous: NF90_REDEF, Up: Datasets


2.8 NF90_ENDDEF

The function NF90_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 NF90_SET_FILL). The netCDF dataset is then placed in data mode, so variable data can be read or written.

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

Usage

      function nf90_enddef(ncid, h_minfree, v_align, v_minfree, r_align)
        integer,           intent( in) :: ncid
        integer, optional, intent( in) :: h_minfree, v_align, v_minfree, r_align
        integer                        :: nf90_enddef
ncid
NetCDF ID, from a previous call to NF90_OPEN or NF90_CREATE.

The following arguments allow additional performance tuning. Note: these arguments expose internals of the netcdf version 1 file format, and may not be available in future netcdf implementations.

The current netcdf file format has three sections: the "header" section, the data section for fixed size variables, and the data section for variables which have an unlimited dimension (record variables). The header begins at the beginning of the file. The index (offset) of the beginning of the other two sections is contained in the header. Typically, there is no space between the sections. This causes copying overhead to accrue if one wishes to change the size of the sections, as may happen when changing the names of things, text attribute values, adding attributes or adding variables. Also, for buffered i/o, there may be advantages to aligning sections in certain ways.

The following parameters allow one to control costs of future calls to nf90_redef or nf90_enddef by requesting that some space be available at the end of the section. The default value for both arguments is 0.
h_minfree
Size of the pad (in bytes) at the end of the "header" section.
v_minfree
Size of the pad (in bytes) at the end of the data section for fixed size variables.
The align parameters allow one to set the alignment of the beginning of the corresponding sections. The beginning of the section is rounded up to an index which is a multiple of the align parameter. The flag value NF90_ALIGN_CHUNK tells the library to use the chunksize (see above) as the align parameter. The default value for both arguments is 4 bytes.
v_align
The alignment of the beginning of the data section for fixed size variables.
r_align
The alignment of the beginning of the data section for variables which have an unlimited dimension (record variables).

Errors

NF90_ENDDEF returns the value NF90_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:

Example

Here is an example using NF90_ENDDEF to finish the definitions of a new netCDF dataset named foo.nc and put it into data mode:

      use netcdf
      implicit none
      integer :: ncid, status
      ...
      status = nf90_create("foo.nc", nf90_noclobber, ncid)
      if (status /= nf90_noerr) call handle_err(status)
      ...  !  create dimensions, variables, attributes
      status = nf90_enddef(ncid)
      if (status /= nf90_noerr) call handle_err(status)