Main Content

netcdf.defVarDeflate

Define compression parameters for netCDF variable

Description

example

netcdf.defVarDeflate(ncid,varid,shuffle,deflate,deflateLevel) sets the compression parameters for the netCDF variable specified by varid, in the location specified by ncid.

Examples

collapse all

This example creates a variable with dimensions [1800 3600] and a compression level of 5. The result is a chunked layout that is a 10-by-10 grid. Use the netcdf.defVarChunking function to define your own chunking, otherwise netcdf.defVarDeflate uses the default library values.

ncid = netcdf.create("myfile.nc","NETCDF4");
latdimid = netcdf.defDim(ncid,"lat",1800);
londimid = netcdf.defDim(ncid,"col",3600);
varid = netcdf.defVar(ncid,"earthgrid","double",[latdimid londimid]);
netcdf.defVarChunking(ncid,varid,"CHUNKED",[180 360]);
netcdf.defVarDeflate(ncid,varid,true,true,5);
netcdf.close(ncid);

Input Arguments

collapse all

Identifier of a netCDF file, returned by netcdf.create or netcdf.open, or of a netCDF group, returned by netcdf.defGrp, specified as a nonnegative integer scalar.

Data Types: double

NetCDF variable identifier, specified as a nonnegative integer scalar. A variable identifier is returned by the netcdf.defVar function.

Data Types: double

Identifier of netCDF variable, returned by netcdf.defVar, specified as a nonnegative integer scalar.

Data Types: double

Status of the shuffle filter, specified as a numeric or logical 0 (false) or 1 (true). A value of false disables the shuffle filter, and true enables it. The shuffle filter assists with the compression of integer data by changing the byte order in the data stream. You cannot set shuffle to true if varid refers to a variable of type NC_STRING or NC_VLEN.

Data Types: logical

Status of the deflate filter, specified as a numeric or logical 0 (false) or 1 (true). Specify deflate as true to enable compression, and then specify deflateLevel as the intended positive compression level. Specify deflate as false to disable compression. The value of deflate is automatically set to false if deflateLevel is specified as 0.

Data Types: logical

Level of compression, specified as an integer scalar value between 0 and 9. A value of 0 indicates no compression and is equivalent to specifying the value of deflate as false. A value of 1 indicates the least compression, and a value of 9 indicates the most. The value of deflateLevel is ignored if deflate is false.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Limitations

  • You cannot set deflate to true and deflateLevel to a positive value if varid refers to a variable of type NC_STRING or NC_VLEN.

Tips

  • This function corresponds to the nc_def_var_deflate function in the netCDF library C API.

Version History

Introduced in R2010b

expand all