The CDF_COMPRESSION procedure sets or returns the compression mode for a CDF file or variables. Compression parameters should be set before values are written to the CDF file.
Temporary File Location
CDF creates temporary files whenever files or variables are compressed or uncompressed. By default, these files are created in the current directory. UNIX users can set the environment variable CDF_TMP to set the temporary directory explicitly.
Examples
id=CDF_CREATE('demo.cdf',[10,20],/CLOBBER,/SINGLE_FILE)
CDF_COMPRESSION,id,SET_COMPRESSION=1
att_id=CDF_ATTCREATE(id, 'Date',/GLOBAL)
CDF_ATTPUT,id,'Date',att_id,systime()
CDF_COMPRESSION,id,SET_GZIP_LEVEL=7
CDF_COMPRESSION,id,GET_GZIP_LEVEL=glevel,GET_COMPRESSION=gcomp
HELP,glevel,gcomp
rid=CDF_VARCREATE(id,'rvar0',[1,1],/CDF_FLOAT)
CDF_COMPRESSION,id,SET_VAR_COMPRESSION=2,VARIABLE='rvar0'
CDF_VARPUT,id,'rvar0',findgen(10,20,5)
CDF_COMPRESSION,id,GET_VAR_COMPRESSION=v_comp, $
VARIABLE=rid,GET_VAR_GZIP_LEVEL=v_glevel
HELP,v_comp,v_glevel
zid=CDF_varcreate(id,'zvar0',[1,1,1],DIM=[10,20,30], $
/ZVARIABLE, /CDF_DOUBLE)
CDF_COMPRESSION, id, SET_VAR_GZIP_LEVEL=9, VARIABLE=zid, $
/ZVARIABLE, GET_VAR_GZIP_LEVEL=v_gzip
HELP,v_gzip
CDF_VARPUT,id,zid,dindgen(10,20,30),/ZVARIABLE
CDF_COMPRESSION, id, GET_VAR_COMPRESSION=v_comp, $
VARIABLE='zvar0', /ZVARIABLE, SET_COMPRESSION=2, $
GET_COMPRESSION=file_comp
HELP,file_comp,v_comp
CDF_DELETE,id
IDL prints:
GLEVEL LONG = 7
GCOMP LONG = 5
V_COMP LONG = 2
V_GLEVEL LONG = 0
(Note that V_GLEVEL is 0, since the variable compression is not GZIP.)
V_GZIP LONG = 9
FILE_COMP LONG = 2
V_COMP LONG = 5
Syntax
CDF_COMPRESSION, Id [, GET_COMPRESSION=variable] [, GET_GZIP_LEVEL=variable] [, GET_VAR_BLOCKINGFACTOR=variable] [, GET_VAR_COMPRESSION=variable] [, GET_VAR_GZIP_LEVEL=variable] [, SET_COMPRESSION={0 | 1 | 2 | 3 | 5}] [, SET_GZIP_LEVEL=integer{1 to 9}] [, SET_VAR_BLOCKINGFACTOR=] [, SET_VAR_COMPRESSION={0 | 1 | 2 | 3 | 5}] [, SET_VAR_GZIP_LEVEL=integer{1 to 9}]
[, VARIABLE=variable name or index] [, /ZVARIABLE]
Arguments
Id
The CDF ID of the file being compressed or queried, as returned from a previous call to CDF_OPEN or CDF_CREATE. Note that CDF compression only works for single-file CDF files (see CDF_CREATE).
Keywords
GET_COMPRESSION
Set this keyword to a named variable to retrieve the compression type used for the single-file CDF file. Note that individual CDF variables may compression types different that the one for the rest of the CDF file.
GET_GZIP_LEVEL
Set this keyword to a named variable in which the current GZIP effort level (1-9) for the CDF file is returned. If the compression type for the file is not GZIP (5), then a value of zero is returned.
GET_VAR_BLOCKINGFACTOR
Set this keyword to a named variable to retrieve the blocking factor for compression for the VARIABLE variable. The blocking factor is an integer giving the number of records that were compressed together.
GET_VAR_COMPRESSION
Set this keyword to a named variable to retrieve the compression type for the VARIABLE variable.
GET_VAR_GZIP_LEVEL
Set this keyword to a named variable in which the GZIP effort level (1-9) for variable specified by the VARIABLE keyword is returned. If the compression type for the variable is not GZIP (5), then a value of zero is returned.
SET_COMPRESSION
Set this keyword to the compression type to be used for the single-file CDF file. Note that individual CDF variables may use compression types different than the one for the rest of the CDF file. Valid compression types are:
- 0 = No Compression
- 1 = Run-Length Encoding
- 2 = Huffman
- 3 = Adaptive Huffman
- 5 = GZIP (see the optional GZIP_LEVEL keyword)
SET_GZIP_LEVEL
This keyword is used to indicate the desired effort for the GZIP compression. This effort must be expressed as a scalar in the range (1-9). If GZIP_LEVEL is not specified upon entry then the default effort level is taken to be 5. If the SET_GZIP_LEVEL keyword is set to a valid value, and the keyword SET_COMPRESSION is not specified, the SET_COMPRESSION is set to GZIP (5).
SET_VAR_BLOCKINGFACTOR
Set this keyword to a scalar integer giving the blocking factor for compression for the VARIABLE variable. The blocking factor is the number of records that are compressed together.
SET_VAR_COMPRESSION
Set this keyword to the compression type for the VARIABLE variable. If the variable is a zVariable, and is referred to by index in the VARIABLE keyword, then the keyword ZVARIABLE must be set. The desired variable compression should be set before variable data is added with CDF_VARPUT. Valid compression types are:
- 0 = No Compression
- 1 = Run-Length Encoding
- 2 = Huffman
- 3 = Adaptive Huffman
- 5 = GZIP (see the optional GZIP_LEVEL keyword)
SET_VAR_GZIP_LEVEL
Set this keyword to the GZIP effort level (1-9). If the compression type for the variable is not GZIP (5), no action is performed.
VARIABLE
Set this keyword to the name of a variable or a variable index to set the current variable. This keyword is mandatory when queering/setting the compression parameters of a rVariable or zVariable. Note that if VARIABLE is set to the index of a zVARIABLE, the ZVARIABLE keyword must also be set. If ZVARIABLE is not set, the variable is assumed to be an rVariable.
ZVARIABLE
Set this keyword if the current variable is a zVARIABLE and is referred to by index in the VARIABLE keyword. For example:
CDF_COMPRESSION, id, VARIABLE=0, /ZVARIABLE,$ GET_VAR_COMPRESSION=vComp
Version History
5.3 |
Introduced |
8.6.1 |
Added GET_VAR_BLOCKINGFACTOR and SET_VAR_BLOCKINGFACTOR keywords
|
See Also
CDF_CONTROL, CDF_CREATE, CDF_OPEN, CDF_VARNUM