Last modified: 8 October 2010
Name: H5Pset_filter
Signature:
herr_t H5Pset_filter(hid_t plist_id, H5Z_filter_t filter_id, unsigned int flags, size_t cd_nelmts, const unsigned int cd_values[] )

Purpose:
Adds a filter to the filter pipeline.

Description:
H5Pset_filter adds the specified filter_id and corresponding properties to the end of an output filter pipeline.

plist_id must be either a dataset creation property list or group creation property list identifier. If plist_id is a dataset creation property list identifier, the filter is added to the raw data filter pipeline.

If plist_id is a group creation property list identifier, the filter is added to the link filter pipeline, which filters the fractal heap used to store the most of link metadata in certain types of groups. The only predefined filters that can be set in a group creation property list are the gzip filter (H5Z_FILTER_DEFLATE) and the Fletcher32 error detection filter (H5Z_FILTER_FLETCHER32).

The array cd_values contains cd_nelmts integers which are auxiliary data for the filter. The integer values will be stored in the dataset object header as part of the filter information.

The flags argument is a bit vector with the following fields specifying certain general properties of the filter:

H5Z_FLAG_OPTIONAL If this bit is set then the filter is optional. If the filter fails (see below) during an H5Dwrite operation then the filter is just excluded from the pipeline for the chunk for which it failed; the filter will not participate in the pipeline during an H5Dread of the chunk. This is commonly used for compression filters: if the filter result would be larger than the input, then the compression filter returns failure and the uncompressed data is stored in the file.

This flag should not be set for the Fletcher32 checksum filter as it will bypass the checksum filter without reporting checksum errors to an application.

H5Z_FLAG_MANDATORY    If the filter is required, that is, set to mandatory, and the filter fails, the library’s behavior depends on whether the chunk cache is in use:
  • If the chunk cache is enabled, data chunks will be flushed to the file during H5Dclose and the library will return the failure in H5Dclose.
  • When the chunk cache is disabled or not big enough, or the chunk is being evicted from the cache, the failure will happen during H5Dwrite.
In each case, the library will still write to the file all data chunks that were processed by the filter before the failure occured.

For example, assume that an application creates a dataset of four chunks, the chunk cache is enabled and is big enough to hold all four chunks, and the filter fails when it tries to write the fourth chunk. The actual flush of the chunks will happen during H5Dclose, not H5Dwrite. By the time H5Dclose fails, the first three chunks will have been written to the file. Even though H5Dclose fails, all the resources will be released and the file can be closed properly.

If, however, the filter fails on the second chunk, only the first chunk will be written to the file as nothing further can be written once the filter fails.

The filter_id parameter specifies the filter to be set. Valid pre-defined filter identifiers are as follows:

H5Z_FILTER_DEFLATE Data compression filter, employing the gzip algorithm
H5Z_FILTER_SHUFFLE Data shuffling filter
H5Z_FILTER_FLETCHER32   Error detection filter, employing the Fletcher32 checksum algorithm
H5Z_FILTER_SZIP Data compression filter, employing the SZIP algorithm
H5Z_FILTER_NBIT Data compression filter, employing the N-Bit algorithm
H5Z_FILTER_SCALEOFFSET Data compression filter, employing the scale-offset algorithm

Also see H5Pset_edc_check and H5Pset_filter_callback.

Notes:
When a non-empty filter pipeline is used with a group creation property list, the group will be created with the new group file format (see “Group Implementations in HDF5”). The filters will come into play only when dense storage is used (see H5Pset_link_phase_change) and will be applied to the group’s fractal heap. The fractal heap will contain most of the the group’s link metadata, including link names.

When working with group creation property lists, if you are adding a filter that is not in HDF5’s set of predefined filters, i.e., a user-defined or third-party filter, you must first determine that the filter will work for a group. See the discussion of the set local and can apply callback functions in H5Zregister.

If multiple filters are set for a property list, they will be applied to each chunk of raw data for datasets or each block of the fractal heap for groups in the order in which they were set.

See Also:
For a discussion of optional versus required (mandatory) filter behavior, see “Filter Behavior in HDF5.”

For a discussion of the chunk cache, see H5Pset_cache.

For a discussion of the various types of HDF5 groups, see “Group Implementations in HDF5.”

Related functions: H5Pset_link_phase_change, H5Pset_edc_check, H5Pset_filter_callback, H5Pset_deflate, H5Pset_shuffle, H5Pset_fletcher32, H5Pset_szip, H5Pset_nbit, H5Pset_scaleoffset

Parameters:
hid_t plist_id IN: Dataset or group creation property list identifier.
H5Z_filter_t filter_id IN: Filter identifier for the filter to be added to the pipeline.
unsigned int flags IN: Bit vector specifying certain general properties of the filter.
size_t cd_nelmts IN: Number of elements in cd_values.
const unsigned int cd_values[]     IN: Auxiliary data for the filter.

Returns:
Returns a non-negative value if successful; otherwise returns a negative value.

Fortran90 Interface: h5pset_filter_f
SUBROUTINE h5pset_filter_f(prp_id, filter, flags, cd_nelmts, cd_values,  hdferr)
  IMPLICIT NONE
  INTEGER(HID_T), INTENT(IN) :: prp_id  ! Gropu or dataset creation property 
                                        ! list identifier
  INTEGER, INTENT(IN) :: filter         ! Filter to be added to the pipeline
  INTEGER, INTENT(IN) :: flags          ! Bit vector specifying certain 
                                        ! general properties of the filter
  INTEGER(SIZE_T), INTENT(IN) :: cd_nelmts        
                                        ! Number of elements in cd_values
  INTEGER, DIMENSION(*), INTENT(IN) :: cd_values  
                                        ! Auxiliary data for the filter
  INTEGER, INTENT(OUT) :: hdferr        ! Error code
                                        ! 0 on success and -1 on failure
END SUBROUTINE h5pset_filter_f
        

History: