Advanced Multi-Physics (AMP)
On-Line Documentation
HDF.h
Go to the documentation of this file.
1// This file contains helper functions and interfaces for reading/writing HDF5
2#ifndef included_AMP_HDF5_h
3#define included_AMP_HDF5_h
4
5#include "AMP/AMP_TPLs.h"
6#include "AMP/utils/AMP_MPI.h"
7#include "AMP/utils/ArraySize.h"
8
9#include <cstddef>
10#include <cstring>
11#include <memory>
12#include <string>
13#include <tuple>
14#include <vector>
15
16
17// Include the headers and define some basic types
18#ifdef AMP_USE_HDF5
19 // Using HDF5
20 #include "hdf5.h"
21#else
22// Not using HDF5
23typedef int64_t hid_t;
24typedef size_t hsize_t;
25#endif
26
27
28namespace AMP::IO {
29
30
31enum class Compression : uint8_t { None, GZIP, SZIP };
32
33
39
40
55hid_t openHDF5( const std::string &filename,
56 const char *mode,
57 Compression compress = Compression::None );
58
59
66void closeHDF5( hid_t fid, bool printLeaks = false );
67
68
75
76
85hid_t createChunk( AMP::ArraySize dims, Compression compress, size_t objSize = 0 );
86
87
98template<class T>
99void writeHDF5( hid_t fid, const std::string &name, const T &data );
100
101
112template<class T>
113void readHDF5( hid_t fid, const std::string &name, T &data );
114
115
126template<class T>
127std::unique_ptr<T> readHDF5( hid_t fid, const std::string &name, AMP_MPI comm = AMP_COMM_SELF );
128
129
138void writeHDF5( hid_t fid, const std::string &name, size_t N_bytes, const void *data );
139
140
149void readHDF5( hid_t fid, const std::string &name, size_t N_bytes, void *data );
150
151
158bool H5Gexists( hid_t fid, const std::string &name );
159
160
167bool H5Dexists( hid_t fid, const std::string &name );
168
169
176hid_t createGroup( hid_t fid, const std::string &name );
177
178
186hid_t openGroup( hid_t fid, const std::string &name, bool create = false );
187
188
194void closeGroup( hid_t fid );
195
201void closeDataset( hid_t fid );
202
209
216
217
224hid_t getHDF5datatype( hid_t fid, const std::string &name );
225
226
231template<class T>
233
234
242std::tuple<std::vector<hid_t>,
243 std::vector<hid_t>,
244 std::vector<hid_t>,
245 std::vector<hid_t>,
246 std::vector<hid_t>>
248
249
250} // namespace AMP::IO
251
252#endif
#define AMP_COMM_SELF
Definition AMP_MPI.h:31
int64_t hid_t
Definition HDF.h:23
size_t hsize_t
Definition HDF.h:24
Provides C++ wrapper around MPI routines.
Definition AMP_MPI.h:63
Simple class to store the array dimensions.
Definition ArraySize.h:138
void closeHDF5(hid_t fid, bool printLeaks=false)
Open an HDF5 file.
std::string filename(const std::string &filename)
Return the filename (strip the path)
Compression
Definition HDF.h:31
bool HDF5enabled()
Is HDF5 enabled.
void closeDatatype(hid_t fid)
Close a datatype.
hid_t createGroup(hid_t fid, const std::string &name)
Create a group.
void readHDF5(hid_t fid, const std::string &name, T &data)
Read a structure from HDF5.
void closeDataspace(hid_t fid)
Close a dataspace.
hid_t getHDF5datatype()
Get HDF5 data type.
void closeDataset(hid_t fid)
Close a dataset.
Compression defaultCompression(hid_t fid)
Retrun the the default compression.
bool H5Gexists(hid_t fid, const std::string &name)
Check if group exists.
void writeHDF5(hid_t fid, const std::string &name, const T &data)
Write a structure to HDF5.
hid_t openGroup(hid_t fid, const std::string &name, bool create=false)
Open a group.
bool H5Dexists(hid_t fid, const std::string &name)
Check if dataset exists.
std::tuple< std::vector< hid_t >, std::vector< hid_t >, std::vector< hid_t >, std::vector< hid_t >, std::vector< hid_t > > openObjects(hid_t fid)
list open objects
hid_t openHDF5(const std::string &filename, const char *mode, Compression compress=Compression::None)
Open an HDF5 file.
void closeGroup(hid_t fid)
Close a group.
hid_t createChunk(AMP::ArraySize dims, Compression compress, size_t objSize=0)
Open an HDF5 file.



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page