Main Content

cdflib.setCompression

Specify compression settings

Syntax

cdflib.setCompression(cdfId,ctype,cparms)

Description

cdflib.setCompression(cdfId,ctype,cparms) 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 cdflib.create or cdflib.open.

ctype

One of the following character vectors or string scalars specifying the compression type, or its numeric equivalent.

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

To get the numeric equivalent of these constants, use cdflib.getConstantValue.

cparms

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 cparms to specify the level of compression as a numeric value between 1 and 9.

Examples

Create a CDF file and set the compression setting of the file. To run this example, your current folder must be writable.

cdfId = cdflib.create("your_file.cdf");

% Determine the file's default compression setting
[ctype,cparms,cpercent] = cdflib.getCompression(cdfId)
ctype =

    'NO_COMPRESSION'


cparms =

     []


cpercent =

   100
% Specify new compression setting
cdflib.setCompression(cdfId,"HUFF_COMPRESSION")

% Check the file's compression setting
[ctype,cparms,cpercent] = cdflib.getCompression(cdfId)
ctype =

    'HUFF_COMPRESSION'


cparms =

    'OPTIMAL_ENCODING_TREES'


cpercent =

     0
% Clean up
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.