6.10 Define Fill Parameters for a Variable: nc_def_var_fill
The function nc_def_var_fill sets the fill parameters for a
variable in a netCDF-4 file.
This function must be called after the variable is defined, but before
nc_enddef is called.
Usage
int nc_def_var_fill(int ncid, int varid, int no_fill, void *fill_value);
ncid
- NetCDF ID, from a previous call to nc_open or nc_create.
varid
- Variable ID.
no_fill
- Set no_fill mode on a variable. When this mode is on, fill values will
not be written for the variable. This is helpful in high performance
applications. For netCDF-4/HDF5 files (whether classic model or not),
this may only be changed after the variable is defined, but before it
is committed to disk (i.e. before the first nc_enddef after the
nc_def_var.) For classic and 64-bit offset file, the no_fill mode may
be turned on and off at any time.
*fill_value
- A pointer to a value which will be used as the fill value for the
variable. Must be the same type as the variable. This will be written
to a _FillValue attribute, created for this purpose. If NULL, this
argument will be ignored.
Return Codes
NC_NOERR
- No error.
NC_BADID
- Bad ncid.
NC_ENOTNC4
- Not a netCDF-4 file.
NC_ENOTVAR
- Can't find this variable.
NC_ELATEDEF
- This variable has already been the subject of a nc_enddef call. In
netCDF-4 files nc_enddef will be called automatically for any data
read or write. Once enddef has been called, it is impossible to set
the fill for a variable.
NC_ENOTINDEFINE
- Not in define mode. This is returned for netCDF classic or 64-bit
offset files, or for netCDF-4 files, when they were been created with
NC_STRICT_NC3 flag. (see nc_create).
NC_EPERM
- Attempt to create object in read-only file.
Example
This example is from libsrc4/tst_vars.c
int dimids[NDIMS];
size_t index[NDIMS];
int varid;
int no_fill;
unsigned short ushort_data = 42, ushort_data_in, fill_value_in;
/* Create a netcdf-4 file with one dim and 1 NC_USHORT var. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR;
if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids,
&varid)) ERR;
if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR;