Nektar++
H5.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File H5.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Simple OO wrapper around HDF5
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_H5_H
36 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_H5_H
37 
38 #include <exception>
39 #include <hdf5.h>
40 #include <memory>
41 #include <string>
42 #include <vector>
43 
44 #include <boost/core/ignore_unused.hpp>
45 
48 
49 namespace Nektar
50 {
51 namespace LibUtilities
52 {
53 namespace H5
54 {
55 
56 #define H5_CONSTRUCT(ans, func, args) \
57  { \
58  hid_t ret = func args; \
59  if (ret < 0) \
60  ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, \
61  "HDF5 error in API function " #func, 0); \
62  ans = ret; \
63  }
64 #define H5_CALL(func, args) \
65  { \
66  herr_t ret = func args; \
67  if (ret < 0) \
68  ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, \
69  "HDF5 error in API function " #func, 0); \
70  }
71 
72 class Error : public std::exception
73 {
74 };
75 
76 // Forward declare
77 class Object;
78 typedef std::shared_ptr<Object> ObjectSharedPtr;
79 class DataType;
80 typedef std::shared_ptr<DataType> DataTypeSharedPtr;
81 class CompoundDataType;
82 typedef std::shared_ptr<CompoundDataType> CompoundDataTypeSharedPtr;
83 class DataSpace;
84 typedef std::shared_ptr<DataSpace> DataSpaceSharedPtr;
85 class CanHaveAttributes;
86 typedef std::shared_ptr<CanHaveAttributes> CanHaveAttributesSharedPtr;
87 class Attribute;
88 typedef std::shared_ptr<Attribute> AttributeSharedPtr;
90 typedef std::shared_ptr<CanHaveGroupsDataSets> CanHaveGroupsDataSetsSharedPtr;
91 class Group;
92 typedef std::shared_ptr<Group> GroupSharedPtr;
93 class File;
94 typedef std::shared_ptr<File> FileSharedPtr;
95 class DataSet;
96 typedef std::shared_ptr<DataSet> DataSetSharedPtr;
97 class PList;
98 typedef std::shared_ptr<PList> PListSharedPtr;
99 
100 /// HDF5 base class
101 class Object : public std::enable_shared_from_this<Object>
102 {
103 public:
104  virtual void Close() = 0;
105  inline hid_t GetId() const
106  {
107  return m_Id;
108  }
109  // Overload cast to the HDF5 ID type to make objects
110  // transparently usable in the HDF5 API.
111  inline operator hid_t() const
112  {
113  return GetId();
114  }
115 
116 protected:
117  Object();
118  Object(hid_t id);
119  virtual ~Object();
120  hid_t m_Id;
121 };
122 
123 // PropertyList objects
124 class PList : public Object
125 {
126 public:
127  /// Default options
128  static PListSharedPtr Default();
129  /// Properties for object creation
130  static PListSharedPtr ObjectCreate();
131  /// Properties for file creation
132  static PListSharedPtr FileCreate();
133  /// Properties for file access
134  static PListSharedPtr FileAccess();
135  /// Properties for dataset creation
136  static PListSharedPtr DatasetCreate();
137  /// Properties for dataset access
138  static PListSharedPtr DatasetAccess();
139  /// Properties for raw data transfer
140  static PListSharedPtr DatasetXfer();
141  /// Properties for file mounting
142  static PListSharedPtr FileMount();
143  /// Properties for group creation
144  static PListSharedPtr GroupCreate();
145  /// Properties for group access
146  static PListSharedPtr GroupAccess();
147  /// Properties for datatype creation
149  /// Properties for datatype access
151  /// Properties for character encoding when encoding strings or object names
152  static PListSharedPtr StringCreate();
153  /// Properties for attribute creation
155  /// Properties governing the object copying process
156  static PListSharedPtr ObjectCopy();
157  /// Properties governing link creation
158  static PListSharedPtr LinkCreate();
159  /// Properties governing link traversal when accessing objects
160  static PListSharedPtr LinkAccess();
161 
162  PList();
163  ~PList();
164  void Close();
165  void SetChunk(const std::vector<hsize_t> &dims);
166  void SetDeflate(const unsigned level = 1);
167  void SetMpio(CommSharedPtr comm);
168  void SetDxMpioCollective();
169  void SetDxMpioIndependent();
170 
171 private:
172  PList(hid_t cls);
173 };
174 
175 /// Mixin for objects that contain groups and datasets (Group and File)
176 class CanHaveGroupsDataSets : public virtual Object
177 {
178 public:
180  {
181  public:
182  LinkIterator(CanHaveGroupsDataSetsSharedPtr grp, hsize_t idx = 0);
183  const std::string &operator*();
185  bool operator==(const LinkIterator &other) const;
186  inline bool operator!=(const LinkIterator &other) const
187  {
188  return !(*this == other);
189  }
190  inline hsize_t GetPos() const
191  {
192  return m_idx;
193  }
194 
195  inline std::string GetName() const
196  {
197  return m_currentName;
198  }
199 
200  private:
201  static herr_t helper(hid_t g_id, const char *name,
202  const H5L_info_t *info, void *op_data);
204  hsize_t m_idx;
205  hsize_t m_next;
206  hsize_t m_size;
207  std::string m_currentName;
208  };
209 
210  // Create a group with the given name. The createPL can be
211  // omitted to use the default properties.
212  GroupSharedPtr CreateGroup(const std::string &name,
213  PListSharedPtr createPL = PList::Default(),
214  PListSharedPtr accessPL = PList::Default());
215 
216  // Create a dataset with the name, type and space.
217  // The createPL can be omitted to use the defaults.
218  DataSetSharedPtr CreateDataSet(const std::string &name,
219  DataTypeSharedPtr type,
220  DataSpaceSharedPtr space,
221  PListSharedPtr createPL = PList::Default(),
222  PListSharedPtr accessPL = PList::Default());
223 
224  // Create a dataset containing the data supplied
225  // The createPL can be omitted to use the defaults
226  template <class T>
228  const std::string &name, const std::vector<T> &data,
229  PListSharedPtr createPL = PList::Default(),
230  PListSharedPtr accessPL = PList::Default());
231 
232  // Open an existing group.
233  // The accessPL can be omitted to use the defaults
234  GroupSharedPtr OpenGroup(const std::string &name,
235  PListSharedPtr accessPL = PList::Default()) const;
236 
237  // Open an existing dataset
238  // The accessPL can be omitted to use the defaults
240  const std::string &name,
241  PListSharedPtr accessPL = PList::Default()) const;
242 
243  bool ContainsDataSet(std::string nm);
244 
245  virtual hsize_t GetNumElements() = 0;
247  LinkIterator end();
248 
249  friend class key_iterator;
250 };
251 
252 /// Mixin for objects that can have attributes (Group, DataSet, DataType)
253 class CanHaveAttributes : public virtual Object
254 {
255 public:
257  {
258  public:
259  AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx = 0);
260  const std::string &operator*();
262  bool operator==(const AttrIterator &other) const;
263  inline bool operator!=(const AttrIterator &other) const
264  {
265  return !(*this == other);
266  }
267  inline hsize_t GetPos() const
268  {
269  return m_idx;
270  }
271 
272  private:
273  static herr_t helper(hid_t g_id, const char *name,
274  const H5A_info_t *info, void *op_data);
276  hsize_t m_idx;
277  hsize_t m_next;
278  hsize_t m_size;
279  std::string m_currentName;
280  };
281 
282  AttributeSharedPtr CreateAttribute(const std::string &name,
283  DataTypeSharedPtr type,
284  DataSpaceSharedPtr space);
285  AttributeSharedPtr OpenAttribute(const std::string &name);
286 
287  template <class T>
288  void SetAttribute(const std::string &name, const T &value);
289  template <class T>
290  void SetAttribute(const std::string &name, const std::vector<T> &value);
291 
292  template <class T> void GetAttribute(const std::string &name, T &value);
293  template <class T>
294  void GetAttribute(const std::string &name, std::vector<T> &value);
295 
296  int GetNumAttr() const;
299 };
300 
301 /// HDF5 DataSpace wrapper
302 class DataSpace : public Object
303 {
304 public:
305  static DataSpaceSharedPtr Null();
306  static DataSpaceSharedPtr Scalar();
307  static DataSpaceSharedPtr OneD(hsize_t size);
308 
309  DataSpace();
310  DataSpace(hsize_t size, hsize_t max = H5S_UNLIMITED - 1);
311  DataSpace(const std::vector<hsize_t> &dims);
312  DataSpace(const std::vector<hsize_t> &dims,
313  const std::vector<hsize_t> &max_dims);
314  ~DataSpace();
315 
316  void Close();
317 
318  void SelectRange(const hsize_t start, const hsize_t count);
319  void AppendRange(const hsize_t start, const hsize_t count);
320 
321  void SelectRange(const std::vector<hsize_t> start,
322  const std::vector<hsize_t> count);
323  void AppendRange(const std::vector<hsize_t> start,
324  const std::vector<hsize_t> count);
325 
326  void SetSelection(const hsize_t num_elmt,
327  const std::vector<hsize_t> &coords);
328 
329  void ClearRange();
330 
331  hsize_t GetSize();
332  std::vector<hsize_t> GetDims();
333 
334 private:
335  DataSpace(hid_t id);
336  friend class Attribute;
337  friend class DataSet;
338 };
339 
340 // Policy class for the DataTypesTraits controlling whether data
341 // has to be converted in anyway before writing. (It could perhaps
342 // be DataTypeTraitsTraits but that's too horrible a name.)
343 //
344 // Default policy is to not convert at all.
345 template <class T> struct DataTypeConversionPolicy
346 {
347  static const bool MustConvert = false;
348  typedef T ConvertedType;
350  static ConvertedType Convert(const T &obj);
351  static T Deconvert(const ConvertedType &obj);
352 };
353 
354 /// Traits class for HDF5 data types.
355 template <class T> struct DataTypeTraits
356 {
358 
359  /***
360  * Define this for a specialision for any HDF5 NATIVE type you want to use.
361  * See http://hdfgroup.org/HDF5/doc/UG/UG_frame11Datatypes.html
362  */
363  static const hid_t NativeType;
364 
366 
367  static ConvertedType Convert(const T &obj);
368  static T Deconvert(const ConvertedType &obj);
369  /**
370  * Get the address of the start of the data.
371  * Default implementation just uses "&"
372  */
373  static const void *GetAddress(const ConvertedType &obj);
374  static void *GetAddress(ConvertedType &obj);
375  /**
376  * Return a DataType object representing T.
377  * Default implementation just calls PredefinedDataType::Native<T>()
378  */
379  static DataTypeSharedPtr GetType();
380  static DataTypeSharedPtr GetType(const T &obj);
381 };
382 
383 /// Wrap and HDF5 data type object. Technically this can have attributes, but
384 /// not really bothered.
385 class DataType : public Object
386 {
387 public:
388  static DataTypeSharedPtr String(size_t len = 0);
389  template <class T> static DataTypeSharedPtr OfObject(const T &obj)
390  {
391  boost::ignore_unused(obj);
393  }
394  virtual void Close();
395  DataTypeSharedPtr Copy() const;
396 
397 protected:
398  DataType(hid_t id);
399 };
400 
402 {
403 public:
404  static CompoundDataTypeSharedPtr Create(size_t sz);
405 
406  void Add(std::string name, size_t offset, hid_t type)
407  {
408  H5Tinsert(m_Id, name.c_str(), offset, type);
409  }
410  void AddString(std::string name, size_t offset, size_t size)
411  {
412  hid_t strtype = H5Tcopy(H5T_C_S1);
413  H5Tset_size(strtype, size);
414  H5Tinsert(m_Id, name.c_str(), offset, strtype);
415  }
416  void Close();
417 
418 private:
419  CompoundDataType(hid_t);
420 };
421 
422 /// Predefined HDF data types that must not be closed when done with.
424 {
425 public:
426  template <class T> static DataTypeSharedPtr Native();
427  static DataTypeSharedPtr CS1();
428  void Close();
429 
430 private:
431  PredefinedDataType(hid_t);
432 };
433 
434 /// HDF5 Attribute Wrapper
435 class Attribute : public Object
436 {
437 public:
438  ~Attribute();
439  void Close();
441 
442 private:
443  Attribute(hid_t id) : Object(id)
444  {
445  }
446  static AttributeSharedPtr Create(hid_t parent, const std::string &name,
447  DataTypeSharedPtr type,
448  DataSpaceSharedPtr space);
449  static AttributeSharedPtr Open(hid_t parent, const std::string &name);
450  friend class CanHaveAttributes;
451 };
452 
453 /// HDF5 file wrapper
455 {
456 public:
457  static FileSharedPtr Create(const std::string &filename, unsigned mode,
458  PListSharedPtr createPL = PList::Default(),
459  PListSharedPtr accessPL = PList::Default());
460  static FileSharedPtr Open(const std::string &filename, unsigned mode,
461  PListSharedPtr accessPL = PList::Default());
462  ~File();
463  void Close();
464  virtual hsize_t GetNumElements();
465 
466 private:
467  File(hid_t id);
468 };
469 
470 /// HDF5 Group wrapper
472 {
473 public:
474  ~Group();
475  void Close();
476  virtual hsize_t GetNumElements();
477  std::vector<std::string> GetElementNames();
479  CanHaveAttributesSharedPtr operator[](const std::string &key);
480 
481 private:
482  Group(hid_t id);
483  friend class CanHaveGroupsDataSets;
484 };
485 
487 {
488 public:
489  ~DataSet();
490  void Close();
492 
493  template <class T> void Write(const std::vector<T> &data)
494  {
496  H5_CALL(H5Dwrite, (m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT,
497  &data[0]));
498  }
499  template <class T>
500  void Write(const std::vector<T> &data, DataSpaceSharedPtr filespace,
502  {
504  DataSpaceSharedPtr memspace = DataSpace::OneD(data.size());
505 
506  H5_CALL(H5Dwrite, (m_Id, mem_t->GetId(), memspace->GetId(),
507  filespace->GetId(), dxpl->GetId(), &data[0]));
508  }
509 
510  template <class T>
511  void Write(const std::vector<T> &data, DataSpaceSharedPtr filespace,
513  {
514  DataSpaceSharedPtr memspace = DataSpace::OneD(data.size());
515 
516  H5Dwrite(m_Id, dt->GetId(), memspace->GetId(), filespace->GetId(),
517  dxpl->GetId(), &data[0]);
518  }
519 
520  void WriteString(std::string s, DataSpaceSharedPtr filespace,
521  DataTypeSharedPtr type,
523  {
524  H5_CALL(H5Dwrite, (m_Id, type->GetId(), H5S_ALL, filespace->GetId(),
525  dxpl->GetId(), s.c_str()));
526  }
527 
528  void WriteVectorString(std::vector<std::string> s,
529  DataSpaceSharedPtr filespace, DataTypeSharedPtr type,
531  {
532  const char **ret;
533  ret = new const char *[s.size()];
534  for (size_t i = 0; i < s.size(); ++i)
535  {
536  ret[i] = s[i].c_str();
537  }
538  H5Dwrite(m_Id, type->GetId(), H5S_ALL, filespace->GetId(),
539  dxpl->GetId(), ret);
540  }
541 
542  template <class T> void Read(std::vector<T> &data)
543  {
545  DataSpaceSharedPtr space = GetSpace();
546  ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
547  "vector data not 1D");
548  hsize_t len, maxdim;
549  H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
550 
551  data.resize(len);
552 
553  H5_CALL(H5Dread, (m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT,
554  &data[0]));
555  }
556  template <class T>
557  void Read(std::vector<T> &data, DataSpaceSharedPtr filespace,
559  {
561  hsize_t len;
562  len = H5Sget_select_npoints(filespace->GetId());
563 
564  data.resize(len);
565 
566  DataSpaceSharedPtr memspace = DataSpace::OneD(len);
567  H5_CALL(H5Dread, (m_Id, mem_t->GetId(), memspace->GetId(),
568  filespace->GetId(), dxpl->GetId(), &data[0]));
569  }
570  template <class T>
571  void Read(std::vector<T> &data, DataSpaceSharedPtr filespace,
572  std::vector<std::vector<int>> &coords,
574  {
576  hsize_t len;
577 
578  int w = coords[0].size();
579 
580  hsize_t *cds = new hsize_t[coords.size() * w];
581  for (int i = 0; i < coords.size(); i++)
582  {
583  for (int j = 0; j < coords[i].size(); j++)
584  {
585  cds[i * w + j] = hsize_t(coords[i][j]);
586  }
587  }
588 
589  H5Sselect_elements(filespace->GetId(), H5S_SELECT_SET, coords.size(),
590  cds);
591 
592  delete[] cds;
593 
594  len = H5Sget_select_npoints(filespace->GetId());
595  DataSpaceSharedPtr memspace = DataSpace::OneD(len);
596 
597  data.resize(len);
598 
599  H5_CALL(H5Dread, (m_Id, mem_t->GetId(), memspace->GetId(),
600  filespace->GetId(), dxpl->GetId(), &data[0]));
601 
602  H5Sselect_all(filespace->GetId());
603  }
604 
605  void ReadVectorString(std::vector<std::string> &data,
606  DataSpaceSharedPtr filespace,
608  {
609  char **rdata;
611  std::vector<hsize_t> dims = filespace->GetDims();
612  rdata = (char **)malloc(dims[0] * sizeof(char *));
613 
614  H5_CALL(H5Dread, (m_Id, tp->GetId(), H5S_ALL, filespace->GetId(),
615  dxpl->GetId(), rdata));
616 
617  for (int i = 0; i < dims[0]; i++)
618  {
619  data.push_back(std::string(rdata[i]));
620  }
621  }
622 
623 private:
624  DataSet(hid_t id);
625  friend class CanHaveGroupsDataSets;
626 };
627 
628 template <class T>
630  T>::Convert(const T &obj)
631 {
632  return obj;
633 }
634 
635 template <class T>
637  const typename DataTypeConversionPolicy<T>::ConvertedType &obj)
638 {
639  return obj;
640 }
641 
643 {
644  return PredefinedDataType::Native<T>();
645 }
646 
647 template <class T>
650 {
651  return &obj;
652 }
653 
654 template <class T>
656 {
657  return &obj;
658 }
659 
660 template <class T>
662  const T &obj)
663 {
664  return Converter::Convert(obj);
665 }
666 
667 template <class T>
669  const typename DataTypeTraits<T>::ConvertedType &obj)
670 {
671  return Converter::Deconvert(obj);
672 }
673 template <> struct DataTypeConversionPolicy<std::string>
674 {
675  static const bool MustConvert = true;
676  typedef const char *ConvertedType;
677  typedef const char *ConvertedVectorElemType;
678  inline static ConvertedType Convert(const std::string &obj)
679  {
680  return obj.c_str();
681  }
682  inline static std::string Deconvert(const ConvertedType &obj)
683  {
684  return std::string(obj);
685  }
686 };
687 
689 {
690  return DataType::String();
691 }
692 
694 {
695  return DataTypeSharedPtr(
697 }
698 
699 template <typename T>
700 void CanHaveAttributes::SetAttribute(const std::string &name, const T &value)
701 {
704  AttributeSharedPtr attr = CreateAttribute(name, type, space);
705 
706  typename DataTypeTraits<T>::ConvertedType conv =
708  H5_CALL(H5Awrite, (attr->GetId(), type->GetId(),
710 }
711 
712 template <typename T>
713 void CanHaveAttributes::SetAttribute(const std::string &name,
714  const std::vector<T> &value)
715 {
716  typedef std::vector<
718  Vec;
719  Vec converted_vals;
721  DataSpaceSharedPtr space = DataSpace::OneD(value.size());
722  AttributeSharedPtr attr = CreateAttribute(name, type, space);
723 
724  const void *converted_buf = NULL;
726  {
727  converted_vals.resize(value.size());
728  for (size_t i = 0; i < value.size(); ++i)
729  {
730  converted_vals[i] = DataTypeConversionPolicy<T>::Convert(value[i]);
731  }
732  converted_buf = &converted_vals[0];
733  }
734  else
735  {
736  converted_buf = &value[0];
737  }
738 
739  H5_CALL(H5Awrite, (attr->GetId(), type->GetId(), converted_buf));
740 }
741 
742 template <typename T>
743 void CanHaveAttributes::GetAttribute(const std::string &name, T &value)
744 {
748 
749  typename DataTypeTraits<T>::ConvertedType conv;
750 
751  H5_CALL(H5Aread, (attr->GetId(), type->GetId(),
753  value = DataTypeTraits<T>::Deconvert(conv);
754 }
755 
756 template <typename T>
757 void CanHaveAttributes::GetAttribute(const std::string &name,
758  std::vector<T> &value)
759 {
760  typedef std::vector<
762  Vec;
763  Vec converted_vals;
766  DataSpaceSharedPtr space = attr->GetSpace();
767  ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
768  "vector data not 1D");
769  hsize_t len, maxdim;
770  H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
771 
772  value.resize(len);
773  void *converted_buf = NULL;
775  {
776  converted_vals.resize(len);
777  converted_buf = &converted_vals[0];
778  }
779  else
780  {
781  converted_buf = &value[0];
782  }
783 
784  H5_CALL(H5Aread, (attr->GetId(), type->GetId(), converted_buf));
785 
787  {
788  typename Vec::iterator src = converted_vals.begin(),
789  end = converted_vals.end();
790  typename std::vector<T>::iterator dest = value.begin();
791  for (; src != end; ++src, ++dest)
792  {
793  *dest = DataTypeTraits<T>::Deconvert(*src);
794  }
795  }
796 }
797 
798 template <class T>
800  const std::string &name, const std::vector<T> &data,
801  PListSharedPtr createPL, PListSharedPtr accessPL)
802 {
804  DataSpaceSharedPtr space = DataSpace::OneD(data.size());
805  DataSetSharedPtr dataset =
806  CreateDataSet(name, type, space, createPL, accessPL);
807  dataset->Write(data);
808  return dataset;
809 }
810 } // namespace H5
811 } // namespace LibUtilities
812 } // namespace Nektar
813 
814 #endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define H5_CALL(func, args)
Definition: H5.h:64
HDF5 Attribute Wrapper.
Definition: H5.h:436
static AttributeSharedPtr Open(hid_t parent, const std::string &name)
Definition: H5.cpp:608
DataSpaceSharedPtr GetSpace() const
Definition: H5.cpp:625
static AttributeSharedPtr Create(hid_t parent, const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:597
bool operator==(const AttrIterator &other) const
Definition: H5.cpp:389
static herr_t helper(hid_t g_id, const char *name, const H5A_info_t *info, void *op_data)
Definition: H5.cpp:395
AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx=0)
Definition: H5.cpp:368
bool operator!=(const AttrIterator &other) const
Definition: H5.h:263
Mixin for objects that can have attributes (Group, DataSet, DataType)
Definition: H5.h:254
AttributeSharedPtr OpenAttribute(const std::string &name)
Definition: H5.cpp:341
void GetAttribute(const std::string &name, T &value)
Definition: H5.h:743
AttributeSharedPtr CreateAttribute(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:334
void SetAttribute(const std::string &name, const T &value)
Definition: H5.h:700
Mixin for objects that contain groups and datasets (Group and File)
Definition: H5.h:177
GroupSharedPtr OpenGroup(const std::string &name, PListSharedPtr accessPL=PList::Default()) const
Definition: H5.cpp:248
DataSetSharedPtr OpenDataSet(const std::string &name, PListSharedPtr accessPL=PList::Default()) const
Definition: H5.cpp:259
GroupSharedPtr CreateGroup(const std::string &name, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:219
DataSetSharedPtr CreateDataSet(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:231
DataSetSharedPtr CreateWriteDataSet(const std::string &name, const std::vector< T > &data, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.h:799
void AddString(std::string name, size_t offset, size_t size)
Definition: H5.h:410
static CompoundDataTypeSharedPtr Create(size_t sz)
Definition: H5.cpp:560
void Add(std::string name, size_t offset, hid_t type)
Definition: H5.h:406
void Read(std::vector< T > &data)
Definition: H5.h:542
void Write(const std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:500
void ReadVectorString(std::vector< std::string > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:605
void WriteString(std::string s, DataSpaceSharedPtr filespace, DataTypeSharedPtr type, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:520
DataSpaceSharedPtr GetSpace() const
Definition: H5.cpp:720
void Read(std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:557
void WriteVectorString(std::vector< std::string > s, DataSpaceSharedPtr filespace, DataTypeSharedPtr type, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:528
void Read(std::vector< T > &data, DataSpaceSharedPtr filespace, std::vector< std::vector< int >> &coords, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:571
void Write(const std::vector< T > &data, DataSpaceSharedPtr filespace, DataTypeSharedPtr dt, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:511
void Write(const std::vector< T > &data)
Definition: H5.h:493
HDF5 DataSpace wrapper.
Definition: H5.h:303
void SelectRange(const hsize_t start, const hsize_t count)
Definition: H5.cpp:466
void AppendRange(const hsize_t start, const hsize_t count)
Definition: H5.cpp:471
static DataSpaceSharedPtr Null()
Definition: H5.cpp:406
static DataSpaceSharedPtr Scalar()
Definition: H5.cpp:413
std::vector< hsize_t > GetDims()
Definition: H5.cpp:512
static DataSpaceSharedPtr OneD(hsize_t size)
Definition: H5.cpp:419
void SetSelection(const hsize_t num_elmt, const std::vector< hsize_t > &coords)
Definition: H5.cpp:488
Wrap and HDF5 data type object. Technically this can have attributes, but not really bothered.
Definition: H5.h:386
static DataTypeSharedPtr OfObject(const T &obj)
Definition: H5.h:389
DataTypeSharedPtr Copy() const
Definition: H5.cpp:547
static DataTypeSharedPtr String(size_t len=0)
Definition: H5.cpp:523
HDF5 file wrapper.
Definition: H5.h:455
static FileSharedPtr Open(const std::string &filename, unsigned mode, PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:642
static FileSharedPtr Create(const std::string &filename, unsigned mode, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:633
virtual hsize_t GetNumElements()
Definition: H5.cpp:663
HDF5 Group wrapper.
Definition: H5.h:472
virtual hsize_t GetNumElements()
Definition: H5.cpp:686
std::vector< std::string > GetElementNames()
Definition: H5.cpp:693
CanHaveAttributesSharedPtr operator[](hsize_t idx)
CanHaveAttributesSharedPtr operator[](const std::string &key)
HDF5 base class.
Definition: H5.h:102
static PListSharedPtr ObjectCreate()
Properties for object creation.
Definition: H5.cpp:85
static PListSharedPtr DatasetXfer()
Properties for raw data transfer.
Definition: H5.cpp:115
static PListSharedPtr StringCreate()
Properties for character encoding when encoding strings or object names.
Definition: H5.cpp:151
static PListSharedPtr FileAccess()
Properties for file access.
Definition: H5.cpp:97
void SetMpio(CommSharedPtr comm)
Definition: H5.cpp:213
void SetDeflate(const unsigned level=1)
Definition: H5.cpp:183
static PListSharedPtr FileCreate()
Properties for file creation.
Definition: H5.cpp:91
static PListSharedPtr GroupAccess()
Properties for group access.
Definition: H5.cpp:133
static PListSharedPtr DatasetAccess()
Properties for dataset access.
Definition: H5.cpp:109
static PListSharedPtr Default()
Default options.
Definition: H5.cpp:79
static PListSharedPtr FileMount()
Properties for file mounting.
Definition: H5.cpp:121
static PListSharedPtr ObjectCopy()
Properties governing the object copying process.
Definition: H5.cpp:163
static PListSharedPtr DatasetCreate()
Properties for dataset creation.
Definition: H5.cpp:103
static PListSharedPtr GroupCreate()
Properties for group creation.
Definition: H5.cpp:127
void SetChunk(const std::vector< hsize_t > &dims)
Definition: H5.cpp:179
static PListSharedPtr AttributeCreate()
Properties for attribute creation.
Definition: H5.cpp:157
static PListSharedPtr LinkAccess()
Properties governing link traversal when accessing objects.
Definition: H5.cpp:175
static PListSharedPtr LinkCreate()
Properties governing link creation.
Definition: H5.cpp:169
static PListSharedPtr DatatypeCreate()
Properties for datatype creation.
Definition: H5.cpp:139
static PListSharedPtr DatatypeAccess()
Properties for datatype access.
Definition: H5.cpp:145
Predefined HDF data types that must not be closed when done with.
Definition: H5.h:424
static DataTypeSharedPtr Native()
Definition: H5.h:693
static DataTypeSharedPtr CS1()
Definition: H5.cpp:555
std::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:83
std::shared_ptr< PList > PListSharedPtr
Definition: H5.h:97
std::shared_ptr< Object > ObjectSharedPtr
Definition: H5.h:77
std::shared_ptr< File > FileSharedPtr
Definition: H5.h:93
std::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:79
std::shared_ptr< CanHaveGroupsDataSets > CanHaveGroupsDataSetsSharedPtr
Definition: H5.h:89
std::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:87
std::shared_ptr< CompoundDataType > CompoundDataTypeSharedPtr
Definition: H5.h:81
std::shared_ptr< CanHaveAttributes > CanHaveAttributesSharedPtr
Definition: H5.h:85
std::shared_ptr< Group > GroupSharedPtr
Definition: FieldIOHdf5.h:49
std::shared_ptr< DataSet > DataSetSharedPtr
Definition: H5.h:95
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
static std::string Deconvert(const ConvertedType &obj)
Definition: H5.h:682
static ConvertedType Convert(const std::string &obj)
Definition: H5.h:678
static ConvertedType Convert(const T &obj)
Definition: H5.h:630
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:636
Traits class for HDF5 data types.
Definition: H5.h:356
DataTypeConversionPolicy< T > Converter
Definition: H5.h:357
Converter::ConvertedType ConvertedType
Definition: H5.h:365
static DataTypeSharedPtr GetType()
Definition: H5.h:642
static ConvertedType Convert(const T &obj)
Definition: H5.h:661
static const hid_t NativeType
Definition: H5.h:363
static void * GetAddress(ConvertedType &obj)
static DataTypeSharedPtr GetType(const T &obj)
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:668
static const void * GetAddress(const ConvertedType &obj)