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