netcdf.defVarDeflate
Define compression parameters for netCDF variable
Description
Examples
Create and Set Compression Level for NetCDF Variable
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
ncid
— File identifier
nonnegative integer scalar
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
varid
— NetCDF variable identifier
nonnegative integer scalar
NetCDF variable identifier, specified as a nonnegative integer scalar. A variable
identifier is returned by the netcdf.defVar
function.
Data Types: double
varid
— Variable identifier
nonnegative integer scalar
Identifier of netCDF variable, returned by netcdf.defVar
, specified as a nonnegative integer scalar.
Data Types: double
shuffle
— Status of shuffle filter
false
or 0
| true
or 1
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
deflate
— Status of deflate filter
false
or 0
| true
or 1
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
deflateLevel
— Level of compression
integer scalar value between 0
and 9
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
totrue
anddeflateLevel
to a positive value ifvarid
refers to a variable of typeNC_STRING
orNC_VLEN
.
Tips
This function corresponds to the
nc_def_var_deflate
function in the netCDF library C API.
Version History
Introduced in R2010bR2023b: Setting deflateLevel
to 0
disables the deflate filter
Setting the compression level to zero disables the deflate filter. Previously, the deflate filter could be enabled with a compression level of zero.
R2023b: Use compression and shuffle filter only with fixed-length data types
Compression and the shuffle filter can be used only with fixed-length data types and
generate an error if applied to variables of type NC_STRING
or
NC_VLEN
. Previously, if you specified compression or the shuffle filter
for NC_STRING
or NC_VLEN
variables, the specification
had no effect.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)