1010
1111#include " hdf5functions_blosc.h"
1212#include < array>
13- #include < string>
14- #include < memory>
1513
16- // TODO: This is not supported for UWP, find a replacement
17- #ifdef _WINDOWS
18- #define popen _popen
19- #define pclose _pclose
20- #endif
21-
22- std::string exec_blosc (const char * cmd) {
23- std::array<char , 128 > buffer;
24- std::string result;
25- std::shared_ptr<FILE> pipe (popen (cmd, " r" ), pclose);
26- if (!pipe) throw std::runtime_error (" popen() failed!" );
27- while (!feof (pipe.get ())) {
28- if (fgets (buffer.data (), 128 , pipe.get ()) != NULL )
29- result += buffer.data ();
30- }
31- return result;
32- }
3314
3415void register_bosc (){
3516 /* Register the filter with the library */
@@ -51,65 +32,6 @@ void hdf5_load_data_blosc(hid_t obj_id,hid_t data_type,void* buff, const char* d
5132 H5Dclose (data_id);
5233}
5334
54- void hdf5_write_data_blosc (hid_t obj_id,hid_t type_id,const char * ds_name,hsize_t rank,hsize_t * dims, void * data ){
55- // writes data to the hdf5 file or group identified by obj_id of hdf5 datatype data_type
56-
57- unsigned int cd_values[7 ];
58- // Declare the required hdf5 shiz
59- hid_t space_id,dset_id,plist_id;
60- hsize_t *cdims = new hsize_t [rank]; // chunking dims
61-
62- // compression parameters
63-
64-
65- // int szip_options_mask = H5_SZIP_NN_OPTION_MASK;
66- // int szip_pixels_per_block = 8;
67-
68- // dataspace id
69- space_id = H5Screate_simple (rank, dims, NULL );
70- plist_id = H5Pcreate (H5P_DATASET_CREATE);
71-
72- /* Dataset must be chunked for compression */
73- // cdims[0] = 20; //Could try playing with these for compression performance
74- // cdims[1] = 20;
75-
76- uint64_t max_size = 100000 ;
77-
78- if (rank == 1 ) {
79- if (dims[0 ] < max_size){
80- cdims[0 ] = dims[0 ];
81- }else {
82- cdims[0 ] = max_size;
83- }
84- }
85- else {
86- cdims[0 ] = 100 ;
87- cdims[1 ] = 100 ;
88- }
89-
90- H5Pset_chunk (plist_id, rank, cdims);
91-
92- // ///SET COMPRESSION TYPE /////
93-
94- /* But you can also taylor Blosc parameters to your needs */
95- /* 0 to 3 (inclusive) param slots are reserved. */
96- cd_values[4 ] = 6 ; /* compression level */
97- cd_values[5 ] = 2 ; /* 0: shuffle not active, 1: shuffle active */
98- cd_values[6 ] = BLOSC_ZSTD; /* the actual compressor to use */
99-
100- /* Set the filter with 7 params */
101- H5Pset_filter (plist_id, FILTER_BLOSC, H5Z_FLAG_OPTIONAL, 7 , cd_values);
102-
103- // create write and close
104- dset_id = H5Dcreate2 (obj_id,ds_name,type_id,space_id,H5P_DEFAULT,plist_id,H5P_DEFAULT);
105-
106- H5Dwrite (dset_id,type_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,data);
107-
108- H5Dclose (dset_id);
109-
110-
111- }
112-
11335void hdf5_write_data_blosc (hid_t obj_id,hid_t type_id,const char * ds_name,hsize_t rank,hsize_t * dims, void * data ,unsigned int comp_type,unsigned int comp_level,unsigned int shuffle){
11436 // writes data to the hdf5 file or group identified by obj_id of hdf5 datatype data_type
11537
0 commit comments