Main Content

netcdf.defVarFill

Define fill parameters for NetCDF variable

Syntax

netcdf.defVarFill(ncid,varid,noFillMode,fillValue)

Description

netcdf.defVarFill(ncid,varid,noFillMode,fillValue) sets the fill parameters for a variable in a NetCDF-4 file. varid identifies the variable and the ncid identifies the NetCDF-4 file.

For netCDF files, you can only specify fill values when the NetCDF is in definition mode (before calling netcdf.endDef). For NetCDF files in classic and 64-bit offset modes, you can turn no-fill mode on and off at any time.

Input Arguments

ncid

Identifier of a NetCDF-4 file, returned by netcdf.create or netcdf.open, or of a NetCDF group, returned by netcdf.defGrp.

varid

Identifier of a NetCDF variable, returned by netcdf.defVar.

noFillMode

Boolean value. When set to true, turns off use of fill values for the variable, which can be helpful in high performance applications. When true, netcdf.defVarFill ignores the value of the fillValue argument. To use the fill value, set this to false.

fillValue

Specifies the value to use in the variable when no other value is specified. The data type must be the same data type as the variable.

Examples

This example creates a NetCDF-4 file and defines a fill value for a variable.

ncid = netcdf.create('myfile.nc','NETCDF4');
dimid = netcdf.defDim(ncid,'latitude',180);
varid = netcdf.defVar(ncid,'latitude','double',dimid);
netcdf.defVarFill(ncid,varid,false,-999);
netcdf.close(ncid);

Limitations

  • You cannot specify noFillMode as true when writing data of type NC_STRING to NetCDF-4 files.

References

This function corresponds to the nc_def_var_fill function in the NetCDF library C API.