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 <memory>
40 #include <hdf5.h>
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, \
61  __FILE__, \
62  __LINE__, \
63  "HDF5 error in API function " #func, \
64  0); \
65  ans = ret; \
66  }
67 #define H5_CALL(func, args) \
68  { \
69  herr_t ret = func args; \
70  if (ret < 0) \
71  ErrorUtil::Error(ErrorUtil::efatal, \
72  __FILE__, \
73  __LINE__, \
74  "HDF5 error in API function " #func, \
75  0); \
76  }
77 
78 
79 class Error : public std::exception
80 {
81 };
82 
83 // Forward declare
84 class Object;
85 typedef std::shared_ptr<Object> ObjectSharedPtr;
86 class DataType;
87 typedef std::shared_ptr<DataType> DataTypeSharedPtr;
88 class CompoundDataType;
89 typedef std::shared_ptr<CompoundDataType> CompoundDataTypeSharedPtr;
90 class DataSpace;
91 typedef std::shared_ptr<DataSpace> DataSpaceSharedPtr;
92 class CanHaveAttributes;
93 typedef std::shared_ptr<CanHaveAttributes> CanHaveAttributesSharedPtr;
94 class Attribute;
95 typedef std::shared_ptr<Attribute> AttributeSharedPtr;
97 typedef std::shared_ptr<CanHaveGroupsDataSets> CanHaveGroupsDataSetsSharedPtr;
98 class Group;
99 typedef std::shared_ptr<Group> GroupSharedPtr;
100 class File;
101 typedef std::shared_ptr<File> FileSharedPtr;
102 class DataSet;
103 typedef std::shared_ptr<DataSet> DataSetSharedPtr;
104 class PList;
105 typedef std::shared_ptr<PList> PListSharedPtr;
106 
107 /// HDF5 base class
108 class Object : public std::enable_shared_from_this<Object>
109 {
110 public:
111  virtual void Close() = 0;
112  inline hid_t GetId() const
113  {
114  return m_Id;
115  }
116  // Overload cast to the HDF5 ID type to make objects
117  // transparently usable in the HDF5 API.
118  inline operator hid_t() const
119  {
120  return GetId();
121  }
122 
123 protected:
124  Object();
125  Object(hid_t id);
126  virtual ~Object();
127  hid_t m_Id;
128 };
129 
130 // PropertyList objects
131 class PList : public Object
132 {
133 public:
134  /// Default options
135  static PListSharedPtr Default();
136  /// Properties for object creation
137  static PListSharedPtr ObjectCreate();
138  /// Properties for file creation
139  static PListSharedPtr FileCreate();
140  /// Properties for file access
141  static PListSharedPtr FileAccess();
142  /// Properties for dataset creation
143  static PListSharedPtr DatasetCreate();
144  /// Properties for dataset access
145  static PListSharedPtr DatasetAccess();
146  /// Properties for raw data transfer
147  static PListSharedPtr DatasetXfer();
148  /// Properties for file mounting
149  static PListSharedPtr FileMount();
150  /// Properties for group creation
151  static PListSharedPtr GroupCreate();
152  /// Properties for group access
153  static PListSharedPtr GroupAccess();
154  /// Properties for datatype creation
156  /// Properties for datatype access
158  /// Properties for character encoding when encoding strings or object names
159  static PListSharedPtr StringCreate();
160  /// Properties for attribute creation
162  /// Properties governing the object copying process
163  static PListSharedPtr ObjectCopy();
164  /// Properties governing link creation
165  static PListSharedPtr LinkCreate();
166  /// Properties governing link traversal when accessing objects
167  static PListSharedPtr LinkAccess();
168 
169  PList();
170  ~PList();
171  void Close();
172  void SetChunk(const std::vector<hsize_t> &dims);
173  void SetDeflate(const unsigned level = 1);
174  void SetMpio(CommSharedPtr comm);
175  void SetDxMpioCollective();
176  void SetDxMpioIndependent();
177 
178 private:
179  PList(hid_t cls);
180 };
181 
182 /// Mixin for objects that contain groups and datasets (Group and File)
183 class CanHaveGroupsDataSets : public virtual Object
184 {
185 public:
187  {
188  public:
189  LinkIterator(CanHaveGroupsDataSetsSharedPtr grp, hsize_t idx = 0);
190  const std::string &operator*();
192  bool operator==(const LinkIterator &other) const;
193  inline bool operator!=(const LinkIterator &other) const
194  {
195  return !(*this == other);
196  }
197  inline hsize_t GetPos() const
198  {
199  return m_idx;
200  }
201 
202  inline std::string GetName() const
203  {
204  return m_currentName;
205  }
206 
207  private:
208  static herr_t helper(hid_t g_id,
209  const char *name,
210  const H5L_info_t *info,
211  void *op_data);
213  hsize_t m_idx;
214  hsize_t m_next;
215  hsize_t m_size;
216  std::string m_currentName;
217  };
218 
219  // Create a group with the given name. The createPL can be
220  // omitted to use the default properties.
221  GroupSharedPtr CreateGroup(const std::string &name,
222  PListSharedPtr createPL = PList::Default(),
223  PListSharedPtr accessPL = PList::Default());
224 
225  // Create a dataset with the name, type and space.
226  // The createPL can be omitted to use the defaults.
227  DataSetSharedPtr CreateDataSet(const std::string &name,
228  DataTypeSharedPtr type,
229  DataSpaceSharedPtr space,
230  PListSharedPtr createPL = PList::Default(),
231  PListSharedPtr accessPL = PList::Default());
232 
233  // Create a dataset containing the data supplied
234  // The createPL can be omitted to use the defaults
235  template <class T>
237  const std::string &name,
238  const std::vector<T> &data,
239  PListSharedPtr createPL = PList::Default(),
240  PListSharedPtr accessPL = PList::Default());
241 
242  // Open an existing group.
243  // The accessPL can be omitted to use the defaults
244  GroupSharedPtr OpenGroup(const std::string &name,
245  PListSharedPtr accessPL = PList::Default()) const;
246 
247  // Open an existing dataset
248  // The accessPL can be omitted to use the defaults
250  const std::string &name,
251  PListSharedPtr accessPL = PList::Default()) const;
252 
253  bool ContainsDataSet(std::string nm);
254 
255  virtual hsize_t GetNumElements() = 0;
257  LinkIterator end();
258 
259  friend class key_iterator;
260 };
261 
262 /// Mixin for objects that can have attributes (Group, DataSet, DataType)
263 class CanHaveAttributes : public virtual Object
264 {
265 public:
267  {
268  public:
269  AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx = 0);
270  const std::string &operator*();
272  bool operator==(const AttrIterator &other) const;
273  inline bool operator!=(const AttrIterator &other) const
274  {
275  return !(*this == other);
276  }
277  inline hsize_t GetPos() const
278  {
279  return m_idx;
280  }
281 
282  private:
283  static herr_t helper(hid_t g_id,
284  const char *name,
285  const H5A_info_t *info,
286  void *op_data);
288  hsize_t m_idx;
289  hsize_t m_next;
290  hsize_t m_size;
291  std::string m_currentName;
292  };
293 
294  AttributeSharedPtr CreateAttribute(const std::string &name,
295  DataTypeSharedPtr type,
296  DataSpaceSharedPtr space);
297  AttributeSharedPtr OpenAttribute(const std::string &name);
298 
299  template <class T>
300  void SetAttribute(const std::string &name, const T &value);
301  template <class T>
302  void SetAttribute(const std::string &name, const std::vector<T> &value);
303 
304  template <class T> void GetAttribute(const std::string &name, T &value);
305  template <class T>
306  void GetAttribute(const std::string &name, std::vector<T> &value);
307 
308  int GetNumAttr() const;
311 };
312 
313 /// HDF5 DataSpace wrapper
314 class DataSpace : public Object
315 {
316 public:
317  static DataSpaceSharedPtr Null();
318  static DataSpaceSharedPtr Scalar();
319  static DataSpaceSharedPtr OneD(hsize_t size);
320 
321  DataSpace();
322  DataSpace(hsize_t size, hsize_t max = H5S_UNLIMITED - 1);
323  DataSpace(const std::vector<hsize_t> &dims);
324  DataSpace(const std::vector<hsize_t> &dims,
325  const std::vector<hsize_t> &max_dims);
326  ~DataSpace();
327 
328  void Close();
329 
330  void SelectRange(const hsize_t start, const hsize_t count);
331  void AppendRange(const hsize_t start, const hsize_t count);
332 
333  void SelectRange(const std::vector<hsize_t> start,
334  const std::vector<hsize_t> count);
335  void AppendRange(const std::vector<hsize_t> start,
336  const std::vector<hsize_t> count);
337 
338  void SetSelection(const hsize_t num_elmt,
339  const std::vector<hsize_t> &coords);
340 
341  void ClearRange();
342 
343  hsize_t GetSize();
344  std::vector<hsize_t> GetDims();
345 
346 private:
347  DataSpace(hid_t id);
348  friend class Attribute;
349  friend class DataSet;
350 };
351 
352 // Policy class for the DataTypesTraits controlling whether data
353 // has to be converted in anyway before writing. (It could perhaps
354 // be DataTypeTraitsTraits but that's too horrible a name.)
355 //
356 // Default policy is to not convert at all.
357 template <class T> struct DataTypeConversionPolicy
358 {
359  static const bool MustConvert = false;
360  typedef T ConvertedType;
362  static ConvertedType Convert(const T &obj);
363  static T Deconvert(const ConvertedType &obj);
364 };
365 
366 /// Traits class for HDF5 data types.
367 template <class T> struct DataTypeTraits
368 {
370 
371  /***
372  * Define this for a specialision for any HDF5 NATIVE type you want to use.
373  * See http://hdfgroup.org/HDF5/doc/UG/UG_frame11Datatypes.html
374  */
375  static const hid_t NativeType;
376 
378 
379  static ConvertedType Convert(const T &obj);
380  static T Deconvert(const ConvertedType &obj);
381  /**
382  * Get the address of the start of the data.
383  * Default implementation just uses "&"
384  */
385  static const void *GetAddress(const ConvertedType &obj);
386  static void *GetAddress(ConvertedType &obj);
387  /**
388  * Return a DataType object representing T.
389  * Default implementation just calls PredefinedDataType::Native<T>()
390  */
391  static DataTypeSharedPtr GetType();
392  static DataTypeSharedPtr GetType(const T &obj);
393 };
394 
395 /// Wrap and HDF5 data type object. Technically this can have attributes, but
396 /// not really bothered.
397 class DataType : public Object
398 {
399 public:
400  static DataTypeSharedPtr String(size_t len = 0);
401  template <class T> static DataTypeSharedPtr OfObject(const T &obj)
402  {
403  boost::ignore_unused(obj);
405  }
406  virtual void Close();
407  DataTypeSharedPtr Copy() const;
408 
409 protected:
410  DataType(hid_t id);
411 };
412 
414 {
415 public:
416  static CompoundDataTypeSharedPtr Create(size_t sz);
417 
418  void Add(std::string name, size_t offset, hid_t type)
419  {
420  H5Tinsert(m_Id, name.c_str(), offset, type);
421  }
422  void AddString(std::string name, size_t offset, size_t size)
423  {
424  hid_t strtype = H5Tcopy (H5T_C_S1);
425  H5Tset_size (strtype, size);
426  H5Tinsert(m_Id, name.c_str(), offset, strtype);
427  }
428  void Close();
429 private:
430  CompoundDataType(hid_t);
431 };
432 
433 /// Predefined HDF data types that must not be closed when done with.
435 {
436 public:
437  template <class T> static DataTypeSharedPtr Native();
438  static DataTypeSharedPtr CS1();
439  void Close();
440 
441 private:
442  PredefinedDataType(hid_t);
443 };
444 
445 /// HDF5 Attribute Wrapper
446 class Attribute : public Object
447 {
448 public:
449  ~Attribute();
450  void Close();
452 
453 private:
454  Attribute(hid_t id) : Object(id)
455  {
456  }
457  static AttributeSharedPtr Create(hid_t parent,
458  const std::string &name,
459  DataTypeSharedPtr type,
460  DataSpaceSharedPtr space);
461  static AttributeSharedPtr Open(hid_t parent, const std::string &name);
462  friend class CanHaveAttributes;
463 };
464 
465 /// HDF5 file wrapper
467 {
468 public:
469  static FileSharedPtr Create(const std::string &filename,
470  unsigned mode,
471  PListSharedPtr createPL = PList::Default(),
472  PListSharedPtr accessPL = PList::Default());
473  static FileSharedPtr Open(const std::string &filename,
474  unsigned mode,
475  PListSharedPtr accessPL = PList::Default());
476  ~File();
477  void Close();
478  virtual hsize_t GetNumElements();
479 
480 private:
481  File(hid_t id);
482 };
483 
484 /// HDF5 Group wrapper
486 {
487 public:
488  ~Group();
489  void Close();
490  virtual hsize_t GetNumElements();
491  std::vector<std::string> GetElementNames();
493  CanHaveAttributesSharedPtr operator[](const std::string &key);
494 
495 private:
496  Group(hid_t id);
497  friend class CanHaveGroupsDataSets;
498 };
499 
501 {
502 public:
503  ~DataSet();
504  void Close();
506 
507  template <class T> void Write(const std::vector<T> &data)
508  {
510  H5_CALL(
511  H5Dwrite,
512  (m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT, &data[0]));
513  }
514  template <class T>
515  void Write(const std::vector<T> &data,
516  DataSpaceSharedPtr filespace,
518  {
520  DataSpaceSharedPtr memspace = DataSpace::OneD(data.size());
521 
522  H5_CALL(H5Dwrite,
523  (m_Id, mem_t->GetId(), memspace->GetId(), filespace->GetId(),
524  dxpl->GetId(), &data[0]) );
525  }
526 
527  template <class T>
528  void Write(const std::vector<T> &data,
529  DataSpaceSharedPtr filespace,
532  {
533  DataSpaceSharedPtr memspace = DataSpace::OneD(data.size());
534 
535  H5Dwrite(m_Id,
536  dt->GetId(),
537  memspace->GetId(),
538  filespace->GetId(),
539  dxpl->GetId(),
540  &data[0]);
541  }
542 
543  void WriteString(std::string s,
544  DataSpaceSharedPtr filespace,
545  DataTypeSharedPtr type,
547  {
548  H5_CALL(
549  H5Dwrite,
550  (m_Id, type->GetId(), H5S_ALL, filespace->GetId(), dxpl->GetId(), s.c_str()));
551  }
552 
553  void WriteVectorString(std::vector<std::string> s,
554  DataSpaceSharedPtr filespace,
555  DataTypeSharedPtr type,
557  {
558  const char** ret;
559  ret = new const char*[s.size()];
560  for (size_t i = 0; i < s.size(); ++i) {
561  ret[i] = s[i].c_str();
562  }
563  H5Dwrite(m_Id, type->GetId(), H5S_ALL, filespace->GetId(), dxpl->GetId(), ret);
564  }
565 
566  template <class T> void Read(std::vector<T> &data)
567  {
569  DataSpaceSharedPtr space = GetSpace();
570  ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
571  "vector data not 1D");
572  hsize_t len, maxdim;
573  H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
574 
575  data.resize(len);
576 
577  H5_CALL(
578  H5Dread,
579  (m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT, &data[0]));
580  }
581  template <class T>
582  void Read(std::vector<T> &data,
583  DataSpaceSharedPtr filespace,
585  {
587  hsize_t len;
588  len = H5Sget_select_npoints(filespace->GetId());
589 
590  data.resize(len);
591 
592  DataSpaceSharedPtr memspace = DataSpace::OneD(len);
593  H5_CALL(H5Dread, (m_Id, mem_t->GetId(), memspace->GetId(),
594  filespace->GetId(), dxpl->GetId(), &data[0]));
595  }
596  template <class T>
597  void Read(std::vector<T> &data,
598  DataSpaceSharedPtr filespace,
599  std::vector<std::vector<int> > &coords,
601  {
603  hsize_t len;
604 
605  int w = coords[0].size();
606 
607  hsize_t *cds = new hsize_t[coords.size() * w];
608  for(int i = 0; i < coords.size(); i++)
609  {
610  for(int j = 0; j < coords[i].size(); j++)
611  {
612  cds[i * w + j] = hsize_t(coords[i][j]);
613  }
614  }
615 
616  H5Sselect_elements(filespace->GetId(),
617  H5S_SELECT_SET,
618  coords.size(),
619  cds);
620 
621  delete[] cds;
622 
623  len = H5Sget_select_npoints(filespace->GetId());
624  DataSpaceSharedPtr memspace = DataSpace::OneD(len);
625 
626  data.resize(len);
627 
628  H5_CALL(H5Dread, (m_Id, mem_t->GetId(), memspace->GetId(),
629  filespace->GetId(), dxpl->GetId(), &data[0]));
630 
631  H5Sselect_all(filespace->GetId());
632  }
633 
634  void ReadVectorString(std::vector<std::string> &data,
635  DataSpaceSharedPtr filespace,
637  {
638  char **rdata;
640  std::vector<hsize_t> dims = filespace->GetDims();
641  rdata = (char **) malloc (dims[0] * sizeof(char *));
642 
643  H5_CALL(H5Dread, (m_Id, tp->GetId(), H5S_ALL, filespace->GetId(), dxpl->GetId(), rdata));
644 
645  for(int i = 0; i < dims[0]; i++)
646  {
647  data.push_back(std::string(rdata[i]));
648  }
649  }
650 
651 private:
652  DataSet(hid_t id);
653  friend class CanHaveGroupsDataSets;
654 };
655 
656 template <class T>
658  T>::Convert(const T &obj)
659 {
660  return obj;
661 }
662 
663 template <class T>
665  const typename DataTypeConversionPolicy<T>::ConvertedType &obj)
666 {
667  return obj;
668 }
669 
671 {
672  return PredefinedDataType::Native<T>();
673 }
674 
675 template <class T>
678 {
679  return &obj;
680 }
681 
682 template <class T>
684 {
685  return &obj;
686 }
687 
688 template <class T>
690  const T &obj)
691 {
692  return Converter::Convert(obj);
693 }
694 
695 template <class T>
697  const typename DataTypeTraits<T>::ConvertedType &obj)
698 {
699  return Converter::Deconvert(obj);
700 }
701 template <> struct DataTypeConversionPolicy<std::string>
702 {
703  static const bool MustConvert = true;
704  typedef const char *ConvertedType;
705  typedef const char *ConvertedVectorElemType;
706  inline static ConvertedType Convert(const std::string &obj)
707  {
708  return obj.c_str();
709  }
710  inline static std::string Deconvert(const ConvertedType &obj)
711  {
712  return std::string(obj);
713  }
714 };
715 
717 {
718  return DataType::String();
719 }
720 
722 {
723  return DataTypeSharedPtr(
725 }
726 
727 template <typename T>
728 void CanHaveAttributes::SetAttribute(const std::string &name, const T &value)
729 {
732  AttributeSharedPtr attr = CreateAttribute(name, type, space);
733 
734  typename DataTypeTraits<T>::ConvertedType conv =
736  H5_CALL(
737  H5Awrite,
738  (attr->GetId(), type->GetId(), DataTypeTraits<T>::GetAddress(conv)));
739 }
740 
741 template <typename T>
742 void CanHaveAttributes::SetAttribute(const std::string &name,
743  const std::vector<T> &value)
744 {
745  typedef std::vector<
747  Vec;
748  Vec converted_vals;
750  DataSpaceSharedPtr space = DataSpace::OneD(value.size());
751  AttributeSharedPtr attr = CreateAttribute(name, type, space);
752 
753  const void *converted_buf = NULL;
755  {
756  converted_vals.resize(value.size());
757  for (size_t i = 0; i < value.size(); ++i)
758  {
759  converted_vals[i] = DataTypeConversionPolicy<T>::Convert(value[i]);
760  }
761  converted_buf = &converted_vals[0];
762  }
763  else
764  {
765  converted_buf = &value[0];
766  }
767 
768  H5_CALL(H5Awrite, (attr->GetId(), type->GetId(), converted_buf));
769 }
770 
771 template <typename T>
772 void CanHaveAttributes::GetAttribute(const std::string &name, T &value)
773 {
777 
778  typename DataTypeTraits<T>::ConvertedType conv;
779 
780  H5_CALL(
781  H5Aread,
782  (attr->GetId(), type->GetId(), DataTypeTraits<T>::GetAddress(conv)));
783  value = DataTypeTraits<T>::Deconvert(conv);
784 }
785 
786 template <typename T>
787 void CanHaveAttributes::GetAttribute(const std::string &name,
788  std::vector<T> &value)
789 {
790  typedef std::vector<
792  Vec;
793  Vec converted_vals;
796  DataSpaceSharedPtr space = attr->GetSpace();
797  ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
798  "vector data not 1D");
799  hsize_t len, maxdim;
800  H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
801 
802  value.resize(len);
803  void *converted_buf = NULL;
805  {
806  converted_vals.resize(len);
807  converted_buf = &converted_vals[0];
808  }
809  else
810  {
811  converted_buf = &value[0];
812  }
813 
814  H5_CALL(H5Aread, (attr->GetId(), type->GetId(), converted_buf));
815 
817  {
818  typename Vec::iterator src = converted_vals.begin(),
819  end = converted_vals.end();
820  typename std::vector<T>::iterator dest = value.begin();
821  for (; src != end; ++src, ++dest)
822  {
823  *dest = DataTypeTraits<T>::Deconvert(*src);
824  }
825  }
826 }
827 
828 template <class T>
830  const std::string &name,
831  const std::vector<T> &data,
832  PListSharedPtr createPL,
833  PListSharedPtr accessPL)
834 {
836  DataSpaceSharedPtr space = DataSpace::OneD(data.size());
837  DataSetSharedPtr dataset =
838  CreateDataSet(name, type, space, createPL, accessPL);
839  dataset->Write(data);
840  return dataset;
841 }
842 }
843 }
844 }
845 
846 #endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define H5_CALL(func, args)
Definition: H5.h:67
HDF5 Attribute Wrapper.
Definition: H5.h:447
static AttributeSharedPtr Open(hid_t parent, const std::string &name)
Definition: H5.cpp:607
DataSpaceSharedPtr GetSpace() const
Definition: H5.cpp:624
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:388
static herr_t helper(hid_t g_id, const char *name, const H5A_info_t *info, void *op_data)
Definition: H5.cpp:394
AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx=0)
Definition: H5.cpp:367
bool operator!=(const AttrIterator &other) const
Definition: H5.h:273
Mixin for objects that can have attributes (Group, DataSet, DataType)
Definition: H5.h:264
AttributeSharedPtr OpenAttribute(const std::string &name)
Definition: H5.cpp:340
void GetAttribute(const std::string &name, T &value)
Definition: H5.h:772
AttributeSharedPtr CreateAttribute(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:333
void SetAttribute(const std::string &name, const T &value)
Definition: H5.h:728
Mixin for objects that contain groups and datasets (Group and File)
Definition: H5.h:184
GroupSharedPtr OpenGroup(const std::string &name, PListSharedPtr accessPL=PList::Default()) const
Definition: H5.cpp:247
DataSetSharedPtr OpenDataSet(const std::string &name, PListSharedPtr accessPL=PList::Default()) const
Definition: H5.cpp:258
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:230
DataSetSharedPtr CreateWriteDataSet(const std::string &name, const std::vector< T > &data, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.h:829
void AddString(std::string name, size_t offset, size_t size)
Definition: H5.h:422
static CompoundDataTypeSharedPtr Create(size_t sz)
Definition: H5.cpp:559
void Add(std::string name, size_t offset, hid_t type)
Definition: H5.h:418
void Read(std::vector< T > &data)
Definition: H5.h:566
void Write(const std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:515
void ReadVectorString(std::vector< std::string > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:634
void WriteString(std::string s, DataSpaceSharedPtr filespace, DataTypeSharedPtr type, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:543
void Read(std::vector< T > &data, DataSpaceSharedPtr filespace, std::vector< std::vector< int > > &coords, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:597
DataSpaceSharedPtr GetSpace() const
Definition: H5.cpp:718
void Read(std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:582
void WriteVectorString(std::vector< std::string > s, DataSpaceSharedPtr filespace, DataTypeSharedPtr type, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:553
void Write(const std::vector< T > &data, DataSpaceSharedPtr filespace, DataTypeSharedPtr dt, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:528
void Write(const std::vector< T > &data)
Definition: H5.h:507
HDF5 DataSpace wrapper.
Definition: H5.h:315
void SelectRange(const hsize_t start, const hsize_t count)
Definition: H5.cpp:465
void AppendRange(const hsize_t start, const hsize_t count)
Definition: H5.cpp:470
static DataSpaceSharedPtr Null()
Definition: H5.cpp:405
static DataSpaceSharedPtr Scalar()
Definition: H5.cpp:412
std::vector< hsize_t > GetDims()
Definition: H5.cpp:511
static DataSpaceSharedPtr OneD(hsize_t size)
Definition: H5.cpp:418
void SetSelection(const hsize_t num_elmt, const std::vector< hsize_t > &coords)
Definition: H5.cpp:487
Wrap and HDF5 data type object. Technically this can have attributes, but not really bothered.
Definition: H5.h:398
static DataTypeSharedPtr OfObject(const T &obj)
Definition: H5.h:401
DataTypeSharedPtr Copy() const
Definition: H5.cpp:546
static DataTypeSharedPtr String(size_t len=0)
Definition: H5.cpp:522
HDF5 file wrapper.
Definition: H5.h:467
static FileSharedPtr Open(const std::string &filename, unsigned mode, PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:640
static FileSharedPtr Create(const std::string &filename, unsigned mode, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:632
virtual hsize_t GetNumElements()
Definition: H5.cpp:661
HDF5 Group wrapper.
Definition: H5.h:486
virtual hsize_t GetNumElements()
Definition: H5.cpp:684
std::vector< std::string > GetElementNames()
Definition: H5.cpp:691
CanHaveAttributesSharedPtr operator[](hsize_t idx)
CanHaveAttributesSharedPtr operator[](const std::string &key)
HDF5 base class.
Definition: H5.h:109
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:435
static DataTypeSharedPtr Native()
Definition: H5.h:721
static DataTypeSharedPtr CS1()
Definition: H5.cpp:554
std::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:90
std::shared_ptr< PList > PListSharedPtr
Definition: H5.h:104
std::shared_ptr< Object > ObjectSharedPtr
Definition: H5.h:84
std::shared_ptr< File > FileSharedPtr
Definition: H5.h:100
std::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:86
std::shared_ptr< CanHaveGroupsDataSets > CanHaveGroupsDataSetsSharedPtr
Definition: H5.h:96
std::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:94
std::shared_ptr< CompoundDataType > CompoundDataTypeSharedPtr
Definition: H5.h:88
std::shared_ptr< CanHaveAttributes > CanHaveAttributesSharedPtr
Definition: H5.h:92
std::shared_ptr< Group > GroupSharedPtr
Definition: FieldIOHdf5.h:49
std::shared_ptr< DataSet > DataSetSharedPtr
Definition: H5.h:102
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:710
static ConvertedType Convert(const std::string &obj)
Definition: H5.h:706
static ConvertedType Convert(const T &obj)
Definition: H5.h:658
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:664
Traits class for HDF5 data types.
Definition: H5.h:368
DataTypeConversionPolicy< T > Converter
Definition: H5.h:369
Converter::ConvertedType ConvertedType
Definition: H5.h:377
static DataTypeSharedPtr GetType()
Definition: H5.h:670
static ConvertedType Convert(const T &obj)
Definition: H5.h:689
static const hid_t NativeType
Definition: H5.h:375
static void * GetAddress(ConvertedType &obj)
static DataTypeSharedPtr GetType(const T &obj)
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:696
static const void * GetAddress(const ConvertedType &obj)