Example of Szip Usage in HDF5
The following sample program illustrates the use of Szip compression in HDF5.
#include "hdf5.h"
int main(void)
{
hid_t file, data_space, dataset32, properties;
float ff[500][600];
float inff[500][600];
hsize_t dims[2], chunk_size[2];
unsigned szip_options_mask=H5_SZIP_ALLOW_K13_OPTION_MASK|H5_SZIP_NN_OPTION_MASK;
unsigned szip_pixels_per_block=16;
/* Describe the size of the array */
dims[0] = 500;
dims[1] = 600;
data_space = H5Screate_simple (2, dims, NULL);
/*
* Create a new file using with read/write access,
* default file creation properties, and default file
* access properties.
*/
file = H5Fcreate ("test.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Set the dataset creation plist to specify that
* the raw data is to be partitioned into 100x100 element
* chunks and that each chunk is to be compressed.
*/
chunk_size[0] = chunk_size[1] = 100;
properties = H5Pcreate (H5P_DATASET_CREATE);
H5Pset_chunk (properties, 2, chunk_size);
/*
* Set up Szip compression, with the parameters set as above.
*/
H5Pset_szip (properties, szip_options_mask, szip_pixels_per_block);
/*
* Create a new dataset within the file. The datatype
* and data space describe the data on disk, which may
* be different than the format used in the application's
* memory.
*/
dataset32 = H5Dcreate (file, "datasetF32", H5T_NATIVE_FLOAT,
data_space, properties);
/*
* Write the array to the file. The datatype and data
* space describe the format of the data in the `dd'
* buffer. The raw data is translated to the format
* required on disk defined above. We use default raw
* data transfer properties.
*/
H5Dwrite (dataset32, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, ff);
/*
* Read the array. This is similar to writing
* data except the data flows in the opposite direction.
* Note: the decompression is automatic.
*/
H5Dread (dataset32, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, inff);
H5Dclose (dataset32);
H5Sclose (data_space);
H5Pclose (properties);
H5Fclose (file);
}
HDF Help Desk
Describes HDF5 Release 1.6.0, July 2003
Last modified: 14 May 2003