Next: , Previous: nc_open_par, Up: Datasets


2.11 Put Open NetCDF Dataset into Define Mode: nc_redef

The function nc_redef puts an open netCDF dataset into define mode, so dimensions, variables, and attributes can be added or renamed and attributes can be deleted.

Usage

For netCDF-4 files (i.e. files created with NC_NETCDF4 in the cmode, see nc_create), it is not necessary to call nc_redef unless the file was also created with NC_STRICT_NC3. For straight-up netCDF-4 files, nc_redef is called automatically, as needed.

For all netCDF-4 files, the root ncid must be used. This is the ncid returned by nc_open and nc_create, and points to the root of the hierarchy tree for netCDF-4 files.

     int nc_redef(int ncid);
ncid
netCDF ID, from a previous call to nc_open or nc_create.

Errors

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

Errors

NC_NOERR
No error.
NC_EBADID
Bad ncid.
NC_EBADGRPID
The ncid must refer to the root group of the file, that is, the group returned by nc_open or nc_create. (see nc_open see nc_create).
NC_EINDEFINE
Already in define mode.
NC_EPERM
File is read-only.

Example

Here is an example using nc_redef to open an existing netCDF dataset named foo.nc and put it into define mode:

     #include <netcdf.h>
        ...
     int status;
     int ncid;
        ...
     status = nc_open("foo.nc", NC_WRITE, &ncid);  /* open dataset */
     if (status != NC_NOERR) handle_error(status);
        ...
     status = nc_redef(ncid);                      /* put in define mode */
     if (status != NC_NOERR) handle_error(status);