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
46
48{
49
50#define H5_CONSTRUCT(ans, func, args) \
51 { \
52 hid_t ret = func args; \
53 if (ret < 0) \
54 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, \
55 "HDF5 error in API function " #func, 0); \
56 ans = ret; \
57 }
58#define H5_CALL(func, args) \
59 { \
60 herr_t ret = func args; \
61 if (ret < 0) \
62 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, \
63 "HDF5 error in API function " #func, 0); \
64 }
65
66class Error : public std::exception
67{
68};
69
70// Forward declare
71class Object;
72typedef std::shared_ptr<Object> ObjectSharedPtr;
73class DataType;
74typedef std::shared_ptr<DataType> DataTypeSharedPtr;
76typedef std::shared_ptr<CompoundDataType> CompoundDataTypeSharedPtr;
77class DataSpace;
78typedef std::shared_ptr<DataSpace> DataSpaceSharedPtr;
80typedef std::shared_ptr<CanHaveAttributes> CanHaveAttributesSharedPtr;
81class Attribute;
82typedef std::shared_ptr<Attribute> AttributeSharedPtr;
84typedef std::shared_ptr<CanHaveGroupsDataSets> CanHaveGroupsDataSetsSharedPtr;
85class Group;
86typedef std::shared_ptr<Group> GroupSharedPtr;
87class File;
88typedef std::shared_ptr<File> FileSharedPtr;
89class DataSet;
90typedef std::shared_ptr<DataSet> DataSetSharedPtr;
91class PList;
92typedef std::shared_ptr<PList> PListSharedPtr;
93
94/// HDF5 base class
95class Object : public std::enable_shared_from_this<Object>
96{
97public:
98 void Close()
99 {
100 v_Close();
101 }
102 inline hid_t GetId() const
103 {
104 return m_Id;
105 }
106 // Overload cast to the HDF5 ID type to make objects
107 // transparently usable in the HDF5 API.
108 inline operator hid_t() const
109 {
110 return GetId();
111 }
112
113protected:
114 Object();
115 Object(hid_t id);
116 virtual ~Object();
117 hid_t m_Id;
118 virtual void v_Close() = 0;
119};
120
121// PropertyList objects
122class PList : public Object
123{
124public:
125 /// Default options
126 static PListSharedPtr Default();
127 /// Properties for object creation
129 /// Properties for file creation
130 static PListSharedPtr FileCreate();
131 /// Properties for file access
132 static PListSharedPtr FileAccess();
133 /// Properties for dataset creation
135 /// Properties for dataset access
137 /// Properties for raw data transfer
139 /// Properties for file mounting
140 static PListSharedPtr FileMount();
141 /// Properties for group creation
143 /// Properties for group access
145 /// Properties for datatype creation
147 /// Properties for datatype access
149 /// Properties for character encoding when encoding strings or object names
151 /// Properties for attribute creation
153 /// Properties governing the object copying process
154 static PListSharedPtr ObjectCopy();
155 /// Properties governing link creation
156 static PListSharedPtr LinkCreate();
157 /// Properties governing link traversal when accessing objects
158 static PListSharedPtr LinkAccess();
159
160 PList();
161 ~PList() override;
162 void SetChunk(const std::vector<hsize_t> &dims);
163 void SetDeflate(const unsigned level = 1);
164 void SetMpio(CommSharedPtr comm);
165 void SetDxMpioCollective();
167
168protected:
169 void v_Close() override;
170
171private:
172 PList(hid_t cls);
173};
174
175/// Mixin for objects that contain groups and datasets (Group and File)
176class CanHaveGroupsDataSets : public virtual Object
177{
178public:
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,
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
246 {
247 return v_GetNumElements();
248 }
249
250protected:
251 virtual hsize_t v_GetNumElements() = 0;
254
255 friend class key_iterator;
256};
257
258/// Mixin for objects that can have attributes (Group, DataSet, DataType)
259class CanHaveAttributes : public virtual Object
260{
261public:
263 {
264 public:
265 AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx = 0);
266 const std::string &operator*();
268 bool operator==(const AttrIterator &other) const;
269 inline bool operator!=(const AttrIterator &other) const
270 {
271 return !(*this == other);
272 }
273 inline hsize_t GetPos() const
274 {
275 return m_idx;
276 }
277
278 private:
279 static herr_t helper(hid_t g_id, const char *name,
280 const H5A_info_t *info, void *op_data);
282 hsize_t m_idx;
283 hsize_t m_next;
284 hsize_t m_size;
285 std::string m_currentName;
286 };
287
288 AttributeSharedPtr CreateAttribute(const std::string &name,
290 DataSpaceSharedPtr space);
291 AttributeSharedPtr OpenAttribute(const std::string &name);
292
293 template <class T>
294 void SetAttribute(const std::string &name, const T &value);
295 template <class T>
296 void SetAttribute(const std::string &name, const std::vector<T> &value);
297
298 template <class T> void GetAttribute(const std::string &name, T &value);
299 template <class T>
300 void GetAttribute(const std::string &name, std::vector<T> &value);
301
302 int GetNumAttr() const;
305};
306
307/// HDF5 DataSpace wrapper
308class DataSpace : public Object
309{
310public:
311 static DataSpaceSharedPtr Null();
312 static DataSpaceSharedPtr Scalar();
313 static DataSpaceSharedPtr OneD(hsize_t size);
314
315 DataSpace();
316 DataSpace(hsize_t size, hsize_t max = H5S_UNLIMITED - 1);
317 DataSpace(const std::vector<hsize_t> &dims);
318 DataSpace(const std::vector<hsize_t> &dims,
319 const std::vector<hsize_t> &max_dims);
320 ~DataSpace() override;
321
322 void SelectRange(const hsize_t start, const hsize_t count);
323 void AppendRange(const hsize_t start, const hsize_t count);
324
325 void SelectRange(const std::vector<hsize_t> start,
326 const std::vector<hsize_t> count);
327 void AppendRange(const std::vector<hsize_t> start,
328 const std::vector<hsize_t> count);
329
330 void SetSelection(const hsize_t num_elmt,
331 const std::vector<hsize_t> &coords);
332
333 void ClearRange();
334
335 hsize_t GetSize();
336 std::vector<hsize_t> GetDims();
337
338protected:
339 void v_Close() override;
340
341private:
342 DataSpace(hid_t id);
343 friend class Attribute;
344 friend class DataSet;
345};
346
347// Policy class for the DataTypesTraits controlling whether data
348// has to be converted in anyway before writing. (It could perhaps
349// be DataTypeTraitsTraits but that's too horrible a name.)
350//
351// Default policy is to not convert at all.
352template <class T> struct DataTypeConversionPolicy
353{
354 static const bool MustConvert = false;
355 typedef T ConvertedType;
357 static ConvertedType Convert(const T &obj);
358 static T Deconvert(const ConvertedType &obj);
359};
360
361/// Traits class for HDF5 data types.
362template <class T> struct DataTypeTraits
363{
365
366 /***
367 * Define this for a specialision for any HDF5 NATIVE type you want to use.
368 * See http://hdfgroup.org/HDF5/doc/UG/UG_frame11Datatypes.html
369 */
370 static const hid_t NativeType;
371
373
374 static ConvertedType Convert(const T &obj);
375 static T Deconvert(const ConvertedType &obj);
376 /**
377 * Get the address of the start of the data.
378 * Default implementation just uses "&"
379 */
380 static const void *GetAddress(const ConvertedType &obj);
381 static void *GetAddress(ConvertedType &obj);
382 /**
383 * Return a DataType object representing T.
384 * Default implementation just calls PredefinedDataType::Native<T>()
385 */
386 static DataTypeSharedPtr GetType();
387 static DataTypeSharedPtr GetType(const T &obj);
388};
389
390/// Wrap and HDF5 data type object. Technically this can have attributes, but
391/// not really bothered.
392class DataType : public Object
393{
394public:
395 static DataTypeSharedPtr String(size_t len = 0);
396 template <class T>
397 static DataTypeSharedPtr OfObject([[maybe_unused]] const T &obj)
398 {
400 }
401 DataTypeSharedPtr Copy() const;
402
403protected:
404 void v_Close() override;
405 DataType(hid_t id);
406};
407
409{
410public:
411 static CompoundDataTypeSharedPtr Create(size_t sz);
412
413 void Add(std::string name, size_t offset, hid_t type)
414 {
415 H5Tinsert(m_Id, name.c_str(), offset, type);
416 }
417 void AddString(std::string name, size_t offset, size_t size)
418 {
419 hid_t strtype = H5Tcopy(H5T_C_S1);
420 H5Tset_size(strtype, size);
421 H5Tinsert(m_Id, name.c_str(), offset, strtype);
422 }
423
424protected:
425 void v_Close() override;
426
427private:
428 CompoundDataType(hid_t);
429};
430
431/// Predefined HDF data types that must not be closed when done with.
433{
434public:
435 template <class T> static DataTypeSharedPtr Native();
436 static DataTypeSharedPtr CS1();
437
438protected:
439 void v_Close() override;
440
441private:
442 PredefinedDataType(hid_t);
443};
444
445/// HDF5 Attribute Wrapper
446class Attribute : public Object
447{
448public:
449 ~Attribute() override;
451
452protected:
453 void v_Close() override;
454
455private:
456 Attribute(hid_t id) : Object(id)
457 {
458 }
459 static AttributeSharedPtr Create(hid_t parent, const std::string &name,
461 DataSpaceSharedPtr space);
462 static AttributeSharedPtr Open(hid_t parent, const std::string &name);
463 friend class CanHaveAttributes;
464};
465
466/// HDF5 file wrapper
468{
469public:
470 static FileSharedPtr Create(const std::string &filename, unsigned mode,
471 PListSharedPtr createPL = PList::Default(),
472 PListSharedPtr accessPL = PList::Default());
473 static FileSharedPtr Open(const std::string &filename, unsigned mode,
474 PListSharedPtr accessPL = PList::Default());
475 ~File() override;
476
477protected:
478 void v_Close() override;
479 hsize_t v_GetNumElements() override;
480
481private:
482 File(hid_t id);
483};
484
485/// HDF5 Group wrapper
487{
488public:
489 ~Group() override;
490 std::vector<std::string> GetElementNames();
492 CanHaveAttributesSharedPtr operator[](const std::string &key);
493
494protected:
495 void v_Close() override;
496 hsize_t v_GetNumElements() override;
497
498private:
499 Group(hid_t id);
501};
502
504{
505public:
506 ~DataSet() override;
508
509 template <class T> void Write(const std::vector<T> &data)
510 {
512 H5_CALL(H5Dwrite, (m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT,
513 &data[0]));
514 }
515 template <class T>
516 void Write(const std::vector<T> &data, DataSpaceSharedPtr filespace,
518 {
520 DataSpaceSharedPtr memspace = DataSpace::OneD(data.size());
521
522 H5_CALL(H5Dwrite, (m_Id, mem_t->GetId(), memspace->GetId(),
523 filespace->GetId(), dxpl->GetId(), &data[0]));
524 }
525
526 template <class T>
527 void Write(const std::vector<T> &data, DataSpaceSharedPtr filespace,
529 {
530 DataSpaceSharedPtr memspace = DataSpace::OneD(data.size());
531
532 H5Dwrite(m_Id, dt->GetId(), memspace->GetId(), filespace->GetId(),
533 dxpl->GetId(), &data[0]);
534 }
535
536 void WriteString(std::string s, DataSpaceSharedPtr filespace,
539 {
540 H5_CALL(H5Dwrite, (m_Id, type->GetId(), H5S_ALL, filespace->GetId(),
541 dxpl->GetId(), s.c_str()));
542 }
543
544 void WriteVectorString(std::vector<std::string> s,
547 {
548 const char **ret;
549 ret = new const char *[s.size()];
550 for (size_t i = 0; i < s.size(); ++i)
551 {
552 ret[i] = s[i].c_str();
553 }
554 H5Dwrite(m_Id, type->GetId(), H5S_ALL, filespace->GetId(),
555 dxpl->GetId(), ret);
556 }
557
558 template <class T> void Read(std::vector<T> &data)
559 {
562 ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
563 "vector data not 1D");
564 hsize_t len, maxdim;
565 H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
566
567 data.resize(len);
568
569 H5_CALL(H5Dread, (m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT,
570 &data[0]));
571 }
572 template <class T>
573 void Read(std::vector<T> &data, DataSpaceSharedPtr filespace,
575 {
577 hsize_t len;
578 len = H5Sget_select_npoints(filespace->GetId());
579
580 data.resize(len);
581
582 DataSpaceSharedPtr memspace = DataSpace::OneD(len);
583 H5_CALL(H5Dread, (m_Id, mem_t->GetId(), memspace->GetId(),
584 filespace->GetId(), dxpl->GetId(), &data[0]));
585 }
586 template <class T>
587 void Read(std::vector<T> &data, DataSpaceSharedPtr filespace,
588 std::vector<std::vector<int>> &coords,
590 {
592 hsize_t len;
593
594 int w = coords[0].size();
595
596 hsize_t *cds = new hsize_t[coords.size() * w];
597 for (int i = 0; i < coords.size(); i++)
598 {
599 for (int j = 0; j < coords[i].size(); j++)
600 {
601 cds[i * w + j] = hsize_t(coords[i][j]);
602 }
603 }
604
605 H5Sselect_elements(filespace->GetId(), H5S_SELECT_SET, coords.size(),
606 cds);
607
608 delete[] cds;
609
610 len = H5Sget_select_npoints(filespace->GetId());
611 DataSpaceSharedPtr memspace = DataSpace::OneD(len);
612
613 data.resize(len);
614
615 H5_CALL(H5Dread, (m_Id, mem_t->GetId(), memspace->GetId(),
616 filespace->GetId(), dxpl->GetId(), &data[0]));
617
618 H5Sselect_all(filespace->GetId());
619 }
620
621 void ReadVectorString(std::vector<std::string> &data,
622 DataSpaceSharedPtr filespace,
624 {
625 char **rdata;
627 std::vector<hsize_t> dims = filespace->GetDims();
628 rdata = (char **)malloc(dims[0] * sizeof(char *));
629
630 H5_CALL(H5Dread, (m_Id, tp->GetId(), H5S_ALL, filespace->GetId(),
631 dxpl->GetId(), rdata));
632
633 for (int i = 0; i < dims[0]; i++)
634 {
635 data.push_back(std::string(rdata[i]));
636 }
637 }
638
639protected:
640 void v_Close() override;
641
642private:
643 DataSet(hid_t id);
645};
646
647template <class T>
649 T>::Convert(const T &obj)
650{
651 return obj;
652}
653
654template <class T>
657{
658 return obj;
659}
660
662{
663 return PredefinedDataType::Native<T>();
664}
665
666template <class T>
669{
670 return &obj;
671}
672
673template <class T>
675{
676 return &obj;
677}
678
679template <class T>
681 const T &obj)
682{
683 return Converter::Convert(obj);
684}
685
686template <class T>
688 const typename DataTypeTraits<T>::ConvertedType &obj)
689{
690 return Converter::Deconvert(obj);
691}
692template <> struct DataTypeConversionPolicy<std::string>
693{
694 static const bool MustConvert = true;
695 typedef const char *ConvertedType;
696 typedef const char *ConvertedVectorElemType;
697 inline static ConvertedType Convert(const std::string &obj)
698 {
699 return obj.c_str();
700 }
701 inline static std::string Deconvert(const ConvertedType &obj)
702 {
703 return std::string(obj);
704 }
705};
706
708{
709 return DataType::String();
710}
711
713{
714 return DataTypeSharedPtr(
716}
717
718template <typename T>
719void CanHaveAttributes::SetAttribute(const std::string &name, const T &value)
720{
723 AttributeSharedPtr attr = CreateAttribute(name, type, space);
724
727 H5_CALL(H5Awrite, (attr->GetId(), type->GetId(),
729}
730
731template <typename T>
732void CanHaveAttributes::SetAttribute(const std::string &name,
733 const std::vector<T> &value)
734{
735 typedef std::vector<
737 Vec;
738 Vec converted_vals;
740 DataSpaceSharedPtr space = DataSpace::OneD(value.size());
741 AttributeSharedPtr attr = CreateAttribute(name, type, space);
742
743 const void *converted_buf = nullptr;
745 {
746 converted_vals.resize(value.size());
747 for (size_t i = 0; i < value.size(); ++i)
748 {
749 converted_vals[i] = DataTypeConversionPolicy<T>::Convert(value[i]);
750 }
751 converted_buf = &converted_vals[0];
752 }
753 else
754 {
755 converted_buf = &value[0];
756 }
757
758 H5_CALL(H5Awrite, (attr->GetId(), type->GetId(), converted_buf));
759}
760
761template <typename T>
762void CanHaveAttributes::GetAttribute(const std::string &name, T &value)
763{
767
769
770 H5_CALL(H5Aread, (attr->GetId(), type->GetId(),
772 value = DataTypeTraits<T>::Deconvert(conv);
773}
774
775template <typename T>
776void CanHaveAttributes::GetAttribute(const std::string &name,
777 std::vector<T> &value)
778{
779 typedef std::vector<
781 Vec;
782 Vec converted_vals;
785 DataSpaceSharedPtr space = attr->GetSpace();
786 ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
787 "vector data not 1D");
788 hsize_t len, maxdim;
789 H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
790
791 value.resize(len);
792 void *converted_buf = nullptr;
794 {
795 converted_vals.resize(len);
796 converted_buf = &converted_vals[0];
797 }
798 else
799 {
800 converted_buf = &value[0];
801 }
802
803 H5_CALL(H5Aread, (attr->GetId(), type->GetId(), converted_buf));
804
806 {
807 typename Vec::iterator src = converted_vals.begin(),
808 end = converted_vals.end();
809 typename std::vector<T>::iterator dest = value.begin();
810 for (; src != end; ++src, ++dest)
811 {
812 *dest = DataTypeTraits<T>::Deconvert(*src);
813 }
814 }
815}
816
817template <class T>
819 const std::string &name, const std::vector<T> &data,
820 PListSharedPtr createPL, PListSharedPtr accessPL)
821{
823 DataSpaceSharedPtr space = DataSpace::OneD(data.size());
824 DataSetSharedPtr dataset =
825 CreateDataSet(name, type, space, createPL, accessPL);
826 dataset->Write(data);
827 return dataset;
828}
829} // namespace Nektar::LibUtilities::H5
830
831#endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#define H5_CALL(func, args)
Definition: H5.h:58
HDF5 Attribute Wrapper.
Definition: H5.h:447
static AttributeSharedPtr Open(hid_t parent, const std::string &name)
Definition: H5.cpp:602
DataSpaceSharedPtr GetSpace() const
Definition: H5.cpp:619
static AttributeSharedPtr Create(hid_t parent, const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:591
bool operator==(const AttrIterator &other) const
Definition: H5.cpp:382
static herr_t helper(hid_t g_id, const char *name, const H5A_info_t *info, void *op_data)
Definition: H5.cpp:388
AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx=0)
Definition: H5.cpp:361
bool operator!=(const AttrIterator &other) const
Definition: H5.h:269
Mixin for objects that can have attributes (Group, DataSet, DataType)
Definition: H5.h:260
AttributeSharedPtr OpenAttribute(const std::string &name)
Definition: H5.cpp:334
void GetAttribute(const std::string &name, T &value)
Definition: H5.h:762
AttributeSharedPtr CreateAttribute(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
Definition: H5.cpp:327
void SetAttribute(const std::string &name, const T &value)
Definition: H5.h:719
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:242
DataSetSharedPtr OpenDataSet(const std::string &name, PListSharedPtr accessPL=PList::Default()) const
Definition: H5.cpp:253
GroupSharedPtr CreateGroup(const std::string &name, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:213
DataSetSharedPtr CreateDataSet(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:225
DataSetSharedPtr CreateWriteDataSet(const std::string &name, const std::vector< T > &data, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.h:818
void AddString(std::string name, size_t offset, size_t size)
Definition: H5.h:417
static CompoundDataTypeSharedPtr Create(size_t sz)
Definition: H5.cpp:554
void Add(std::string name, size_t offset, hid_t type)
Definition: H5.h:413
void Read(std::vector< T > &data)
Definition: H5.h:558
void Write(const std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:516
void ReadVectorString(std::vector< std::string > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:621
void WriteString(std::string s, DataSpaceSharedPtr filespace, DataTypeSharedPtr type, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:536
void Read(std::vector< T > &data, DataSpaceSharedPtr filespace, std::vector< std::vector< int > > &coords, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:587
DataSpaceSharedPtr GetSpace() const
Definition: H5.cpp:714
void Read(std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:573
void WriteVectorString(std::vector< std::string > s, DataSpaceSharedPtr filespace, DataTypeSharedPtr type, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:544
void v_Close() override
Definition: H5.cpp:708
void Write(const std::vector< T > &data, DataSpaceSharedPtr filespace, DataTypeSharedPtr dt, PListSharedPtr dxpl=PList::Default())
Definition: H5.h:527
void Write(const std::vector< T > &data)
Definition: H5.h:509
HDF5 DataSpace wrapper.
Definition: H5.h:309
void SelectRange(const hsize_t start, const hsize_t count)
Definition: H5.cpp:460
void AppendRange(const hsize_t start, const hsize_t count)
Definition: H5.cpp:465
static DataSpaceSharedPtr Null()
Definition: H5.cpp:398
static DataSpaceSharedPtr Scalar()
Definition: H5.cpp:405
std::vector< hsize_t > GetDims()
Definition: H5.cpp:506
static DataSpaceSharedPtr OneD(hsize_t size)
Definition: H5.cpp:411
void SetSelection(const hsize_t num_elmt, const std::vector< hsize_t > &coords)
Definition: H5.cpp:482
Wrap and HDF5 data type object. Technically this can have attributes, but not really bothered.
Definition: H5.h:393
static DataTypeSharedPtr OfObject(const T &obj)
Definition: H5.h:397
DataTypeSharedPtr Copy() const
Definition: H5.cpp:541
static DataTypeSharedPtr String(size_t len=0)
Definition: H5.cpp:517
HDF5 file wrapper.
Definition: H5.h:468
static FileSharedPtr Open(const std::string &filename, unsigned mode, PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:636
static FileSharedPtr Create(const std::string &filename, unsigned mode, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
Definition: H5.cpp:627
hsize_t v_GetNumElements() override
Definition: H5.cpp:657
void v_Close() override
Definition: H5.cpp:652
HDF5 Group wrapper.
Definition: H5.h:487
std::vector< std::string > GetElementNames()
Definition: H5.cpp:687
hsize_t v_GetNumElements() override
Definition: H5.cpp:680
CanHaveAttributesSharedPtr operator[](hsize_t idx)
void v_Close() override
Definition: H5.cpp:674
CanHaveAttributesSharedPtr operator[](const std::string &key)
HDF5 base class.
Definition: H5.h:96
static PListSharedPtr ObjectCreate()
Properties for object creation.
Definition: H5.cpp:79
static PListSharedPtr DatasetXfer()
Properties for raw data transfer.
Definition: H5.cpp:109
static PListSharedPtr StringCreate()
Properties for character encoding when encoding strings or object names.
Definition: H5.cpp:145
static PListSharedPtr FileAccess()
Properties for file access.
Definition: H5.cpp:91
void SetMpio(CommSharedPtr comm)
Definition: H5.cpp:207
void SetDeflate(const unsigned level=1)
Definition: H5.cpp:177
static PListSharedPtr FileCreate()
Properties for file creation.
Definition: H5.cpp:85
static PListSharedPtr GroupAccess()
Properties for group access.
Definition: H5.cpp:127
static PListSharedPtr DatasetAccess()
Properties for dataset access.
Definition: H5.cpp:103
static PListSharedPtr Default()
Default options.
Definition: H5.cpp:73
static PListSharedPtr FileMount()
Properties for file mounting.
Definition: H5.cpp:115
static PListSharedPtr ObjectCopy()
Properties governing the object copying process.
Definition: H5.cpp:157
static PListSharedPtr DatasetCreate()
Properties for dataset creation.
Definition: H5.cpp:97
static PListSharedPtr GroupCreate()
Properties for group creation.
Definition: H5.cpp:121
void SetChunk(const std::vector< hsize_t > &dims)
Definition: H5.cpp:173
static PListSharedPtr AttributeCreate()
Properties for attribute creation.
Definition: H5.cpp:151
static PListSharedPtr LinkAccess()
Properties governing link traversal when accessing objects.
Definition: H5.cpp:169
static PListSharedPtr LinkCreate()
Properties governing link creation.
Definition: H5.cpp:163
static PListSharedPtr DatatypeCreate()
Properties for datatype creation.
Definition: H5.cpp:133
static PListSharedPtr DatatypeAccess()
Properties for datatype access.
Definition: H5.cpp:139
void v_Close() override
Definition: H5.cpp:66
Predefined HDF data types that must not be closed when done with.
Definition: H5.h:433
static DataTypeSharedPtr Native()
Definition: H5.h:712
static DataTypeSharedPtr CS1()
Definition: H5.cpp:549
std::shared_ptr< DataSpace > DataSpaceSharedPtr
Definition: H5.h:78
std::shared_ptr< PList > PListSharedPtr
Definition: H5.h:92
std::shared_ptr< Object > ObjectSharedPtr
Definition: H5.h:72
std::shared_ptr< File > FileSharedPtr
Definition: H5.h:88
std::shared_ptr< DataType > DataTypeSharedPtr
Definition: H5.h:74
std::shared_ptr< CanHaveGroupsDataSets > CanHaveGroupsDataSetsSharedPtr
Definition: H5.h:84
std::shared_ptr< Attribute > AttributeSharedPtr
Definition: H5.h:82
std::shared_ptr< CompoundDataType > CompoundDataTypeSharedPtr
Definition: H5.h:76
std::shared_ptr< CanHaveAttributes > CanHaveAttributesSharedPtr
Definition: H5.h:80
std::shared_ptr< Group > GroupSharedPtr
Definition: FieldIOHdf5.h:48
std::shared_ptr< DataSet > DataSetSharedPtr
Definition: H5.h:90
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
std::vector< double > w(NPUPPER)
static std::string Deconvert(const ConvertedType &obj)
Definition: H5.h:701
static ConvertedType Convert(const std::string &obj)
Definition: H5.h:697
static ConvertedType Convert(const T &obj)
Definition: H5.h:649
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:655
Traits class for HDF5 data types.
Definition: H5.h:363
DataTypeConversionPolicy< T > Converter
Definition: H5.h:364
Converter::ConvertedType ConvertedType
Definition: H5.h:372
static const void * GetAddress(const ConvertedType &obj)
static void * GetAddress(ConvertedType &obj)
static DataTypeSharedPtr GetType()
Definition: H5.h:661
static ConvertedType Convert(const T &obj)
Definition: H5.h:680
static const hid_t NativeType
Definition: H5.h:370
static DataTypeSharedPtr GetType(const T &obj)
static T Deconvert(const ConvertedType &obj)
Definition: H5.h:687