hdf5_utils.hpp
Go to the documentation of this file.
1 
6 #ifndef HDF5_UTILS_HPP
7 #define HDF5_UTILS_HPP 1
8 
9 #include <string>
10 #include <vector>
11 #include <H5Cpp.h>
12 
13 using std::string;
14 using std::vector;
15 using std::pair;
16 using H5::Group;
17 using H5::H5File;
18 using H5::PredType;
19 using H5::DataSpace;
20 using H5::DSetCreatPropList;
21 using H5::DataSet;
22 using H5::DataType;
23 
30 template<class T> void write_std_vector_to_hdf5
31 (const Group& file,
32  const vector<T>& data,
33  const string& caption,
34  const DataType& dt)
35 {
36  hsize_t dimsf[1];
37  dimsf[0] = static_cast<hsize_t>(data.size());
38  DataSpace dataspace(1, dimsf);
39 
40  DSetCreatPropList plist;
41  if(dimsf[0]>100000)
42  dimsf[0] = 100000;
43  plist.setChunk(1,dimsf);
44  plist.setDeflate(6);
45 
46  DataSet dataset = file.createDataSet
47  (H5std_string(caption),
48  dt,
49  dataspace,
50  plist);
51  dataset.write(&data[0],dt);
52 }
53 
60 (const Group& file,
61  const vector<double>& data,
62  const string& caption);
63 
70 (const Group& file,
71  const vector<int>& data,
72  const string& caption);
73 
76 {
77 public:
78 
82  explicit HDF5Shortcut(const string& fname);
83 
89  HDF5Shortcut& operator()(const string& field_name,
90  const vector<double>& data_set);
91 
97  HDF5Shortcut& operator()(const string& field_name,
98  const vector<int>& data_set);
99 
101  ~HDF5Shortcut(void);
102 
103 private:
104  const string fname_;
105  vector<pair<string,vector<double> > > double_data_;
106  vector<pair<string,vector<int> > > int_data_;
107 };
108 
109 #endif // HDF5_UTILS_HPP
Facilitates writing hdf5 files.
Definition: hdf5_utils.hpp:75
void write_std_vector_to_hdf5(const Group &file, const vector< T > &data, const string &caption, const DataType &dt)
Master function for writing vectors to hdf5 files.
Definition: hdf5_utils.hpp:31
~HDF5Shortcut(void)
Class destructor. This is the stage when the file is written.
Definition: hdf5_utils.cpp:53
HDF5Shortcut(const string &fname)
Class constructor.
Definition: hdf5_utils.cpp:6
HDF5Shortcut & operator()(const string &field_name, const vector< double > &data_set)
adds dataset
Definition: hdf5_utils.cpp:9