/************************************************************ This example generate a data file with shuffle and bzip2 filters for other tests. This file is intended for use with HDF5 Library version 1.8 ************************************************************/ #include "hdf5.h" #include "h5bzip2.h" #include #include #define FILE "h5ex_dyn_read.h5" #define DATASET "DS-bzip2" #define DIM0 32 #define DIM1 64 #define CHUNK0 4 #define CHUNK1 8 int wdata[DIM0][DIM1]; /* Write buffer */ /* * Create a dataset with Shuffle and BZIP2 filters for testing * data reading. */ int create_data_of_double_filters(char *service) { hid_t file, space, dset, dcpl; /* Handles */ herr_t status; htri_t avail; H5Z_filter_t filter_type; hsize_t dims[2] = {DIM0, DIM1}, chunk[2] = {CHUNK0, CHUNK1}; size_t nelmts; unsigned int flags, filter_info; const unsigned cd_values[1] = {9}; /* bzip2 default level is 9 */ int rdata[DIM0][DIM1], /* Read buffer */ maxr, maxw, i, j; H5PLG_HANDLE handle = NULL; /* library handle */ H5PLG_DECL_ERROR; const H5Z_class2_t *H5Z_get_address = NULL; /* H5Z_BZIP2 structure address */ /* * Get a handle to the filter library. */ H5PLG_CLR_ERROR; /* Clear any existing error */ handle = H5PLG_LOAD_LIBRARY(service); H5PLG_CHECK_ERROR(handle); if (error != NULL) { fprintf(stderr, "failed to find bzip2 filter library: %s\n", error); exit(EXIT_FAILURE); } if(handle) { /* * Get function address to the H5Z_BZIP2 structure */ H5PLG_CLR_ERROR; /* Clear any existing error */ H5PLG_GET_FILTER_INFO(handle, H5Z_get_address); H5PLG_CHECK_ERROR(H5Z_get_address); if (error != NULL) { fprintf(stderr, "failed to find bzip2 filter library: %s.\n", error); exit(EXIT_FAILURE); } if(H5Z_get_address) { /* * Register bzip2 filter with the library */ printf ("bzip2_dyn filter id=%d is name: %s.\n", (H5Z_get_address)[0].id, (H5Z_get_address)[0].name); status = H5Zregister(H5Z_get_address); if(status < 0) { fprintf(stderr, "bzip2 filter failed to register.\n"); return(EXIT_FAILURE); } /* * Check if bzip2 compression is available and can be used for both * compression and decompression. Normally we do not perform error * checking in these examples for the sake of clarity, but in this * case we will make an exception because this filter is an * optional part of the hdf5 library. */ avail = H5Zfilter_avail(H5Z_FILTER_BZIP2); if (!avail) { fprintf(stderr, "bzip2 filter not available.\n"); return EXIT_FAILURE; } status = H5Zget_filter_info (H5Z_FILTER_BZIP2, &filter_info); if ( !(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) || !(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED) ) { fprintf(stderr, "bzip2 filter not available for encoding and decoding.\n"); return EXIT_FAILURE; } /* * Initialize data and find its maximum value to check later. */ for (i=0; i"); printf("Where is the filter library name."); exit(0); } serv = argv[1]; create_data_of_double_filters(serv); return EXIT_SUCCESS; }