Main Content

cdflib.setCompression

Specify compression settings

Syntax

cdflib.setCompression(cdfid,ctype,cparam)

Description

cdflib.setCompression(cdfid,ctype,cparam) specifies compression settings of a Common Data Format (CDF) file.

This function sets the compression for the CDF file itself, not that of any variables in the file.

Input Arguments

cdfid

Identifier of a CDF file, returned by a call to the cdflib.create or cdflib.open function.

ctype

One of these string scalars or character vectors specifying the compression type.

ValueCompression Type
"NO_COMPRESSION"No compression
"RLE_COMPRESSION"Run-length encoding compression
"HUFF_COMPRESSION"Huffman compression
"AHUFF_COMPRESSION"Adaptive Huffman compression
"GZIP_COMPRESSION"GNU's zip compression

You can also use the numeric equivalents of these constants, which you can determine by using the cdflib.getConstantValue function.

cparam

Optional parameter specifying any additional parameters required by the compression type. Currently, the only compression type that uses this parameter is "GZIP_COMPRESSION". For this compression type, use cparam to specify the level of compression as a numeric value between 1 and 9.

Examples

collapse all

Create a new CDF file and check its default compression parameters.

cdfid = cdflib.create("my_file.cdf");
[defaultType,defaultParam,defaultPercentage] = cdflib.getCompression(cdfid)
defaultType = 
'NO_COMPRESSION'
defaultParam =

     []
defaultPercentage = 
100

Specify Huffman compression for the file. Then check its updated compression parameters.

newType = "HUFF_COMPRESSION";
cdflib.setCompression(cdfid,newType)
[updatedType,updatedParam,updatedPercentage] = cdflib.getCompression(cdfid)
updatedType = 
'HUFF_COMPRESSION'
updatedParam = 
'OPTIMAL_ENCODING_TREES'
updatedPercentage = 
0

Remove the CDF file and the cdfid variable.

cdflib.delete(cdfid)
clear cdfid

Tips

  • This function corresponds to the CDF library C API routine CDFsetCompression.

  • To use this function, you must be familiar with the CDF C interface. You can access the CDF documentation at the CDF website.