kspaceFirstOrder3D-OMP
1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
|
Class wrapping the HDF5 routines. More...
#include <Hdf5File.h>
Public Types | |
enum | MatrixDataType { MatrixDataType::kFloat = 0, MatrixDataType::kLong = 1 } |
HDF5 matrix data type (float or uint64). More... | |
enum | MatrixDomainType { MatrixDomainType::kReal = 0, MatrixDomainType::kComplex = 1 } |
HDF5 Matrix domain type (real or complex). More... | |
Public Member Functions | |
Hdf5File () | |
Constructor of the class. More... | |
Hdf5File (const Hdf5File &)=delete | |
Copy constructor is not allowed. | |
virtual | ~Hdf5File () |
Destructor. More... | |
Hdf5File & | operator= (const Hdf5File &)=delete |
Operator = is not allowed. | |
void | create (const std::string &fileName, unsigned int flags=H5F_ACC_TRUNC) |
Create the HDF5 file. More... | |
void | open (const std::string &fileName, unsigned int flags=H5F_ACC_RDONLY) |
Open the HDF5 file. More... | |
bool | isOpen () const |
Is the file opened? More... | |
void | close () |
Close the HDF5 file. More... | |
hid_t | createGroup (const hid_t parentGroup, MatrixName &groupName) |
Create a HDF5 group at a specified place in the file tree. More... | |
hid_t | openGroup (const hid_t parentGroup, MatrixName &groupName) |
Open a HDF5 group at a specified place in the file tree. More... | |
void | closeGroup (const hid_t group) |
Close a group. More... | |
hid_t | getRootGroup () const |
Get handle to the root group of the file. More... | |
hid_t | openDataset (const hid_t parentGroup, MatrixName &datasetName) |
Open a dataset at a specified place in the file tree. More... | |
hid_t | createDataset (const hid_t parentGroup, MatrixName &datasetName, const DimensionSizes &dimensionSizes, const DimensionSizes &chunkSizes, const MatrixDataType matrixDataType, const size_t compressionLevel) |
Create a float HDF5 dataset at a specified place in the file tree (3D/4D). More... | |
void | closeDataset (const hid_t dataset) |
Close dataset. More... | |
template<class T > | |
void | writeHyperSlab (const hid_t dataset, const DimensionSizes &position, const DimensionSizes &size, const T *data) |
Write a hyperslab into the dataset. More... | |
void | writeCuboidToHyperSlab (const hid_t dataset, const DimensionSizes &hyperslabPosition, const DimensionSizes &cuboidPosition, const DimensionSizes &cuboidSize, const DimensionSizes &matrixDimensions, const float *matrixData) |
Write a cuboid selected within the matrixData into a hyperslab. More... | |
void | writeSensorByMaskToHyperSlab (const hid_t dataset, const DimensionSizes &hyperslabPosition, const size_t indexSensorSize, const size_t *indexSensorData, const DimensionSizes &matrixDimensions, const float *matrixData) |
Write sensor data selected by the sensor mask - Occasionally very slow, do not use! More... | |
template<class T > | |
void | writeScalarValue (const hid_t parentGroup, MatrixName &datasetName, const T value) |
Write the scalar value under a specified group. More... | |
template<class T > | |
void | readScalarValue (const hid_t parentGroup, MatrixName &datasetName, T &value) |
Read the scalar value under a specified group. More... | |
template<class T > | |
void | readCompleteDataset (const hid_t parentGroup, MatrixName &datasetName, const DimensionSizes &dimensionSizes, T *data) |
Read data from the dataset at a specified place in the file tree. More... | |
DimensionSizes | getDatasetDimensionSizes (const hid_t parentGroup, MatrixName &datasetName) |
Get dimension sizes of the dataset under a specified group. More... | |
size_t | getDatasetNumberOfDimensions (const hid_t parentGroup, MatrixName &datasetName) |
Get number of dimensions of the dataset under a specified group. More... | |
size_t | getDatasetSize (const hid_t parentGroup, MatrixName &datasetName) |
Get dataset element count at a specified place in the file tree. More... | |
void | writeMatrixDataType (const hid_t parentGroup, MatrixName &datasetName, const MatrixDataType &matrixDataType) |
Write matrix data type into the dataset at a specified place in the file tree. More... | |
void | writeMatrixDomainType (const hid_t parentGroup, MatrixName &datasetName, const MatrixDomainType &matrixDomainType) |
Write matrix data type into the dataset at a specified place in the file tree. More... | |
MatrixDataType | readMatrixDataType (const hid_t parentGroup, MatrixName &datasetName) |
Read matrix data type from the dataset at a specified place in the file tree. More... | |
MatrixDomainType | readMatrixDomainType (const hid_t parentGroup, MatrixName &datasetName) |
Read matrix dataset domain type at a specified place in the file tree. More... | |
void | writeStringAttribute (const hid_t parentGroup, MatrixName &datasetName, MatrixName &attributeName, const std::string &value) |
Write string attribute into the dataset under the root group. More... | |
std::string | readStringAttribute (const hid_t parentGroup, MatrixName &datasetName, MatrixName &attributeName) |
Read string attribute from the dataset under the root group. More... | |
Static Public Member Functions | |
static bool | canAccess (const std::string &fileName) |
Can I access the file. More... | |
Private Attributes | |
hid_t | mFile |
HDF file handle. | |
std::string | mFileName |
File name. | |
Static Private Attributes | |
static const std::string | kMatrixDomainTypeName = "domain_type" |
String representation of the Domain type in the HDF5 file. | |
static const std::string | kMatrixDataTypeName = "data_type" |
String representation of the Data type in the HDF5 file. | |
static const std::string | kMatrixDomainTypeNames [] = {"real", "complex"} |
String representation of different domain types. | |
static const std::string | kMatrixDataTypeNames [] = {"float", "long"} |
String representation of different data types. | |
This class is responsible for working with HDF5 files. It offers routines to manage files (create, open, close) as well as creating, reading and modifying the contents (groups and datasets).
Definition at line 490 of file Hdf5File.h.
|
strong |
HDF5 matrix data type (float or uint64).
Enumerator | |
---|---|
kFloat | The matrix is stored in floating point 32b wide format. |
kLong | The matrix is stored in fixed point point 64b wide format. |
Definition at line 499 of file Hdf5File.h.
|
strong |
HDF5 Matrix domain type (real or complex).
Enumerator | |
---|---|
kReal | The matrix is defined on real domain. |
kComplex | The matrix is defined on complex domain. |
Definition at line 512 of file Hdf5File.h.
Hdf5File::Hdf5File | ( | ) |
Constructor.
Definition at line 73 of file Hdf5File.cpp.
|
virtual |
Destructor.
Definition at line 83 of file Hdf5File.cpp.
|
static |
Can the code access the file, e.g. does it exist, do we have enough privileges, etc.
[in] | fileName | - Name of the file. |
Can I access the file.
Definition at line 146 of file Hdf5File.cpp.
void Hdf5File::close | ( | ) |
ios::failure | - If an error happens |
Close the HDF5 file.
Definition at line 161 of file Hdf5File.cpp.
void Hdf5File::closeDataset | ( | const hid_t | dataset | ) |
[in] | dataset | - Dataset to close. |
Close dataset.
Definition at line 325 of file Hdf5File.cpp.
void Hdf5File::closeGroup | ( | const hid_t | group | ) |
void Hdf5File::create | ( | const std::string & | fileName, |
unsigned int | flags = H5F_ACC_TRUNC |
||
) |
The file is always created in read write mode mode, by default overwriting an old file of the same name. Other HDF5 flags are set to default.
[in] | fileName | - File name. |
[in] | flags | - How to create the file, by default overwrite existing file. |
ios:failure | - If error happened (file is open or cannot be created). |
Create an HDF5 file.
Definition at line 93 of file Hdf5File.cpp.
hid_t Hdf5File::createDataset | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
const DimensionSizes & | dimensionSizes, | ||
const DimensionSizes & | chunkSizes, | ||
const MatrixDataType | matrixDataType, | ||
const size_t | compressionLevel | ||
) |
Other HDF5 flags are set to default.
[in] | parentGroup | - Parent group id. |
[in] | datasetName | - Dataset name. |
[in] | dimensionSizes | - Dimension sizes. |
[in] | chunkSizes | - Chunk sizes. |
[in] | matrixDataType | - Matrix data type |
[in] | compressionLevel | - Compression level. |
ios::failure | - If error happens. |
Create dataset.
Definition at line 241 of file Hdf5File.cpp.
hid_t Hdf5File::createGroup | ( | const hid_t | parentGroup, |
MatrixName & | groupName | ||
) |
Other HDF5 flags are set to default.
[in] | parentGroup | - Where to link the group at. |
[in] | groupName | - Group name. |
ios::failure | - If error happens. |
Create a HDF5 group at a specified place in the file tree.
Definition at line 178 of file Hdf5File.cpp.
DimensionSizes Hdf5File::getDatasetDimensionSizes | ( | const hid_t | parentGroup, |
MatrixName & | datasetName | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
ios::failure | - If error happens. |
Get dimension sizes of the dataset at a specified place in the file tree.
Definition at line 731 of file Hdf5File.cpp.
size_t Hdf5File::getDatasetNumberOfDimensions | ( | const hid_t | parentGroup, |
MatrixName & | datasetName | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
ios::failure | - If error happens. |
Get number of dimensions of the dataset under a specified group.
Definition at line 757 of file Hdf5File.cpp.
size_t Hdf5File::getDatasetSize | ( | const hid_t | parentGroup, |
MatrixName & | datasetName | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
ios::failure | - If error happens. |
Get dataset element count at a specified place in the file tree.
Definition at line 775 of file Hdf5File.cpp.
|
inline |
Get handle to the root group of the file.
Definition at line 608 of file Hdf5File.h.
|
inline |
void Hdf5File::open | ( | const std::string & | fileName, |
unsigned int | flags = H5F_ACC_RDONLY |
||
) |
The file is opened in read only mode by default. Other HDF5 flags are set to default.
[in] | fileName | - File name |
[in] | flags | - Open mode, by default read only. |
ios:failure | - If error happened (file not found, file is not a HDF5 file, file is already open). |
Open the HDF5 file.
Definition at line 117 of file Hdf5File.cpp.
hid_t Hdf5File::openDataset | ( | const hid_t | parentGroup, |
MatrixName & | datasetName | ||
) |
Other HDF5 flags are set to default.
[in] | parentGroup | - Parent group id (can be the file id for root).. |
[in] | datasetName | - Dataset name. |
ios::failure | - If error happens. |
Open a dataset at a specified place in the file tree.
Definition at line 223 of file Hdf5File.cpp.
hid_t Hdf5File::openGroup | ( | const hid_t | parentGroup, |
MatrixName & | groupName | ||
) |
Other HDF5 flags are set to default.
[in] | parentGroup | - Parent group. |
[in] | groupName | - Group name. |
ios::failure | - If error happens. |
Open a HDF5 group at a specified place in the file tree.
Definition at line 196 of file Hdf5File.cpp.
template void Hdf5File::readCompleteDataset< size_t > | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
const DimensionSizes & | dimensionSizes, | ||
T * | data | ||
) |
T | - Data type to be written. |
[in] | parentGroup | - Where is the dataset situated. |
[in] | datasetName | - Dataset name. |
[in] | dimensionSizes | - Dimension sizes. |
[out] | data | - Pointer to data. |
ios::failure | - If error happens. |
Read data from the dataset at a specified place in the file tree, float version.
Read data from the dataset at a specified place in the file tree, float version explicit instance.
Read data from the dataset at a specified place in the file tree, index version explicit instance.
Definition at line 678 of file Hdf5File.cpp.
Hdf5File::MatrixDataType Hdf5File::readMatrixDataType | ( | const hid_t | parentGroup, |
MatrixName & | datasetName | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
ios::failure | - If error happens. |
Read matrix data type from the dataset at a specified place in the file tree.
Definition at line 821 of file Hdf5File.cpp.
Hdf5File::MatrixDomainType Hdf5File::readMatrixDomainType | ( | const hid_t | parentGroup, |
MatrixName & | datasetName | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
ios::failure | - If error happens. |
Read matrix dataset domain type at a specified place in the file tree.
Definition at line 848 of file Hdf5File.cpp.
template void Hdf5File::readScalarValue< size_t > | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
T & | value | ||
) |
T | - Data type to be written. |
[in] | parentGroup | - Where to link the scalar dataset. |
[in] | datasetName | - HDF5 dataset name. |
[out] | value | - Data to be read. |
ios::failure | - If error happens. |
Read the scalar value under a specified group.
Read the scalar value under a specified group, float value, explicit instance.
Read the scalar value under a specified group, float value, explicit instance
Definition at line 646 of file Hdf5File.cpp.
string Hdf5File::readStringAttribute | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
MatrixName & | attributeName | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
[in] | attributeName | - Attribute name. |
ios::failure | - If error happens. |
Read integer attribute at a specified place in the file tree.
Definition at line 892 of file Hdf5File.cpp.
void Hdf5File::writeCuboidToHyperSlab | ( | const hid_t | dataset, |
const DimensionSizes & | hyperslabPosition, | ||
const DimensionSizes & | cuboidPosition, | ||
const DimensionSizes & | cuboidSize, | ||
const DimensionSizes & | matrixDimensions, | ||
const float * | matrixData | ||
) |
The routine writes 3D cuboid into a 4D dataset (only intended for raw time series).
[in] | dataset | - Dataset to write MatrixData into. |
[in] | hyperslabPosition | - Position in the dataset (hyperslab) - may be 3D/4D. |
[in] | cuboidPosition | - Position of the cuboid in MatrixData (what to sample) - must be 3D. |
[in] | cuboidSize | - Cuboid size (size of data being sampled) - must by 3D. |
[in] | matrixDimensions | - Size of the original matrix (the sampled one). |
[in] | matrixData | - C array of matrix data. |
ios::failure | - If error happens. |
Write a cuboid selected within the matrixData into a hyperslab.
Definition at line 431 of file Hdf5File.cpp.
template void Hdf5File::writeHyperSlab< size_t > | ( | const hid_t | dataset, |
const DimensionSizes & | position, | ||
const DimensionSizes & | size, | ||
const T * | data | ||
) |
T | - Data type to be written. |
[in] | dataset | - Dataset id. |
[in] | position | - Position in the dataset. |
[in] | size | - Size of the hyperslab. |
[in] | data | - Data to be written. |
ios::failure | - If error happens. |
Write a hyperslab into the dataset, float version.
Write a hyperslab into the dataset, float version explicit instance.
Write a hyperslab into the dataset, index version explicit instance.
Definition at line 335 of file Hdf5File.cpp.
void Hdf5File::writeMatrixDataType | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
const MatrixDataType & | matrixDataType | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
[in] | matrixDataType | - Matrix data type in the file. |
ios::failure | - If error happens. |
Write matrix data type into the dataset at a specified place in the file tree.
Definition at line 793 of file Hdf5File.cpp.
void Hdf5File::writeMatrixDomainType | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
const MatrixDomainType & | matrixDomainType | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
[in] | matrixDomainType | - Matrix domain type. |
ios::failure | - If error happens. |
Write matrix data type into the dataset at a specified place in the file tree.
Definition at line 807 of file Hdf5File.cpp.
template void Hdf5File::writeScalarValue< size_t > | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
const T | value | ||
) |
No chunks and no compression is used.
T | - Data type to be written. |
[in] | parentGroup | - Where to link the scalar dataset. |
[in] | datasetName | - HDF5 dataset name. |
[in] | value | - data to be written. |
ios::failure | - If error happens. |
Write a scalar value at a specified place in the file tree.
Write the scalar value under a specified group, float value explicit instance.
Write the scalar value under a specified group, index value explicit instance.
Definition at line 559 of file Hdf5File.cpp.
void Hdf5File::writeSensorByMaskToHyperSlab | ( | const hid_t | dataset, |
const DimensionSizes & | hyperslabPosition, | ||
const size_t | indexSensorSize, | ||
const size_t * | indexSensorData, | ||
const DimensionSizes & | matrixDimensions, | ||
const float * | matrixData | ||
) |
Write sensor data selected by the sensor mask. The routine picks elements from the MatixData based on the Sensor Data and store them into a single hyperslab of size [Nsens, 1, 1]
[in] | dataset | - Dataset to write MaatrixData into |
[in] | hyperslabPosition | - 3D position in the dataset (hyperslab) |
[in] | indexSensorSize | - Size of the index based sensor mask |
[in] | indexSensorData | - Index based sensor mask |
[in] | matrixDimensions | - Size of the sampled matrix |
[in] | matrixData | - Matrix data |
Write sensor data selected by the sensor mask.
Definition at line 492 of file Hdf5File.cpp.
void Hdf5File::writeStringAttribute | ( | const hid_t | parentGroup, |
MatrixName & | datasetName, | ||
MatrixName & | attributeName, | ||
const std::string & | value | ||
) |
[in] | parentGroup | - Where the dataset is. |
[in] | datasetName | - Dataset name. |
[in] | attributeName | - Attribute name. |
[in] | value | - Data to write. |
ios::failure | - If error happens. |
Write integer attribute at a specified place in the file tree.
Definition at line 876 of file Hdf5File.cpp.