46 #pragma comment(lib, "Ws2_32.lib")
83 file(H5I_BADID), fileName(
"")
109 file = H5Fcreate(fileName.c_str(), flags, H5P_DEFAULT, H5P_DEFAULT);
130 const char* cFileName = fileName.c_str();
139 if (H5Fis_hdf5(cFileName) == 0)
144 file = H5Fopen(cFileName, flags, H5P_DEFAULT);
161 return (access(fileName.c_str(), F_OK) == 0);
165 return (_access_s(fileName.c_str(), 0) == 0 );
178 herr_t status = H5Fclose(
file);
211 hid_t group = H5Gcreate(parentGroup, groupName.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
213 if (group == H5I_INVALID_HID)
235 hid_t group = H5Gopen(parentGroup, groupName.c_str(), H5P_DEFAULT);
237 if (group == H5I_INVALID_HID)
272 hid_t dataset = H5Dopen(parentGroup, datasetName.c_str(), H5P_DEFAULT);
274 if (dataset == H5I_INVALID_HID)
278 datasetName.c_str()));
300 const size_t compressionLevel)
302 const int rank = (dimensionSizes.
Is3D()) ? 3 : 4;
309 if (dimensionSizes.
Is3D())
311 dims[0] = dimensionSizes.
nz;
312 dims[1] = dimensionSizes.
ny;
313 dims[2] = dimensionSizes.
nx;
315 chunk[0] = chunkSizes.
nz;
316 chunk[1] = chunkSizes.
ny;
317 chunk[2] = chunkSizes.
nx;
321 dims[0] = dimensionSizes.
nt;
322 dims[1] = dimensionSizes.
nz;
323 dims[2] = dimensionSizes.
ny;
324 dims[3] = dimensionSizes.
nx;
326 chunk[0] = chunkSizes.
nt;
327 chunk[1] = chunkSizes.
nz;
328 chunk[2] = chunkSizes.
ny;
329 chunk[3] = chunkSizes.
nx;
335 hid_t dataspace = H5Screate_simple(rank, dims, NULL);
338 propertyList = H5Pcreate(H5P_DATASET_CREATE);
340 status = H5Pset_chunk(propertyList, rank, chunk);
345 datasetName.c_str()));
349 status = H5Pset_deflate(propertyList, compressionLevel);
359 hid_t dataset = H5Dcreate(parentGroup,
367 if (dataset == H5I_INVALID_HID)
371 datasetName.c_str()));
374 H5Pclose(propertyList);
396 const size_t compressionLevel)
400 hsize_t dims [rank] = {dimensionSizes.
nz, dimensionSizes.
ny, dimensionSizes.
nx};
401 hsize_t chunk[rank] = {chunkSizes.
nz, chunkSizes.
ny, chunkSizes.
nx};
406 hid_t dataspace = H5Screate_simple(rank, dims, NULL);
409 propertyList = H5Pcreate(H5P_DATASET_CREATE);
411 status = H5Pset_chunk(propertyList, rank, chunk);
416 datasetName.c_str()));
420 status = H5Pset_deflate(propertyList, compressionLevel);
430 hid_t dataset = H5Dcreate(parentGroup,
438 if (dataset == H5I_INVALID_HID)
442 datasetName.c_str()));
445 H5Pclose(propertyList);
479 hid_t filespace, memspace;
482 filespace = H5Dget_space(dataset);
483 const int rank = H5Sget_simple_extent_ndims(filespace);
492 nElement[0] = size.
nz;
493 nElement[1] = size.
ny;
494 nElement[2] = size.
nx;
496 offset[0] = position.
nz;
497 offset[1] = position.
ny;
498 offset[2] = position.
nx;
502 nElement[0] = size.
nt;
503 nElement[1] = size.
nz;
504 nElement[2] = size.
ny;
505 nElement[3] = size.
nx;
507 offset[0] = position.
nt;
508 offset[1] = position.
nz;
509 offset[2] = position.
ny;
510 offset[3] = position.
nx;
514 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, nElement, NULL);
521 memspace = H5Screate_simple(rank, nElement, NULL);
523 status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace, filespace, H5P_DEFAULT, data);
550 hid_t filespace, memspace;
553 filespace = H5Dget_space(dataset);
554 const int rank = H5Sget_simple_extent_ndims(filespace);
563 nElement[0] = size.
nz;
564 nElement[1] = size.
ny;
565 nElement[2] = size.
nx;
567 offset[0] = position.
nz;
568 offset[1] = position.
ny;
569 offset[2] = position.
nx;
573 nElement[0] = size.
nt;
574 nElement[1] = size.
nz;
575 nElement[2] = size.
ny;
576 nElement[3] = size.
nx;
578 offset[0] = position.
nt;
579 offset[1] = position.
nz;
580 offset[2] = position.
ny;
581 offset[3] = position.
nx;
585 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, nElement, NULL);
592 memspace = H5Screate_simple(rank, nElement, NULL);
594 status = H5Dwrite(dataset, H5T_STD_U64LE, memspace, filespace, H5P_DEFAULT, data);
623 const float* matrixData)
626 hid_t filespace, memspace;
632 hsize_t slabSize[rank] = {1, cuboidSize.
nz, cuboidSize.
ny, cuboidSize.
nx};
633 hsize_t offsetInDataset[rank] = {hyperslabPosition.
nt, hyperslabPosition.
nz, hyperslabPosition.
ny, hyperslabPosition.
nx};
634 hsize_t offsetInMatrixData[] = {cuboidPosition.
nz, cuboidPosition.
ny, cuboidPosition.
nx};
635 hsize_t matrixSize [] = {matrixDimensions.
nz, matrixDimensions.
ny, matrixDimensions.
nx};
639 filespace = H5Dget_space(dataset);
640 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offsetInDataset, NULL, slabSize, NULL);
647 memspace = H5Screate_simple(3, matrixSize, NULL);
648 status = H5Sselect_hyperslab(memspace,
660 status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace, filespace, H5P_DEFAULT, matrixData);
688 const size_t indexSensorSize,
689 const size_t* indexSensorData,
691 const float* matrixData)
694 hid_t filespace, memspace;
700 hsize_t slabSize[Rank] = {1, 1, indexSensorSize};
701 hsize_t offsetInDataset[Rank] = {hyperslabPosition.
nz, hyperslabPosition.
ny, hyperslabPosition.
nx};
704 hsize_t matrixSize = matrixDimensions.
nz * matrixDimensions.
ny * matrixDimensions.
nx;
708 filespace = H5Dget_space(dataset);
709 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offsetInDataset, NULL, slabSize, NULL);
716 memspace = H5Screate_simple(1, &matrixSize, NULL);
717 status = H5Sselect_elements(memspace,
720 (hsize_t*) (indexSensorData));
727 status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, memspace, filespace, H5P_DEFAULT, matrixData);
754 const hsize_t dims[] = {1, 1, 1};
756 hid_t dataset = H5I_INVALID_HID;
757 hid_t dataspace = H5I_INVALID_HID;
760 const char* cDatasetName = datasetName.c_str();
761 if (H5LTfind_dataset(parentGroup, cDatasetName) == 1)
767 dataspace = H5Screate_simple(rank, dims, NULL);
768 dataset = H5Dcreate(parentGroup,
778 if (dataset == H5I_INVALID_HID)
783 status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
808 const hsize_t dims[] = {1, 1, 1};
810 hid_t dataset = H5I_INVALID_HID;
811 hid_t dataspace = H5I_INVALID_HID;
814 const char* cDatasetName = datasetName.c_str();
815 if (H5LTfind_dataset(parentGroup, cDatasetName) == 1)
821 dataspace = H5Screate_simple(rank, dims, NULL);
822 dataset = H5Dcreate(parentGroup,
832 if (dataset == H5I_INVALID_HID)
837 status = H5Dwrite(dataset, H5T_STD_U64LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
892 const char* cDatasetName = datasetName.c_str();
901 herr_t status = H5LTread_dataset_float(parentGroup, cDatasetName, data);
924 const char* cDatasetName = datasetName.c_str();
932 herr_t status = H5LTread_dataset(parentGroup, cDatasetName, H5T_STD_U64LE, data);
954 hsize_t dims[4] = {0, 0, 0, 0};
956 herr_t status = H5LTget_dataset_info(parentGroup, datasetName.c_str(), dims, NULL, NULL);
987 herr_t status = H5LTget_dataset_ndims(parentGroup, datasetName.c_str(), &dims);
1009 hsize_t dims[3] = {0, 0, 0};
1011 herr_t status = H5LTget_dataset_info(parentGroup, datasetName.c_str(), dims, NULL, NULL);
1017 return dims[0] * dims[1] * dims[2];
1083 datasetName.c_str(),
1085 paramValue.c_str()));
1116 datasetName.c_str(),
1118 paramValue.c_str()));
1138 const string& value)
1140 herr_t status = H5LTset_attribute_string(parentGroup,
1141 datasetName.c_str(),
1142 attributeName.c_str(),
1147 attributeName.c_str(),
1148 datasetName.c_str()));
1167 char value[256] =
"";
1168 herr_t status = H5LTget_attribute_string(parentGroup,
1169 datasetName.c_str(),
1170 attributeName.c_str(),
1176 attributeName.c_str(),
1177 datasetName.c_str()));
1180 return string(value);
1434 current = localtime(&now);
1437 current->tm_mday, current->tm_mon + 1, current->tm_year - 100,
1438 current->tm_hour, current->tm_min, current->tm_sec);
1461 return VERSION_UNKNOWN;
1474 for (
int i = INPUT; i < UNKNOWN ; i++)
1482 return THDF5_FileHeader::UNKNOWN;
1509 gethostname(hostName, 256);
1515 WSAStartup(MAKEWORD(2, 2), &wsaData);
1516 gethostname(hostName, 256);
1553 const double loadTime,
1554 const double preProcessingTime,
1555 const double simulationTime,
1556 const double postprocessingTime)
1577 double& preProcessingTime,
1578 double& simulationTime,
1579 double& postprocessingTime)
1581 totalTime = std::stof(
headerValues[TOTAL_EXECUTION_TIME]);
1583 preProcessingTime = std::stof(
headerValues[PREPROCESSING_TIME]);
1584 simulationTime = std::stof(
headerValues[SIMULATION_TIME]);
1585 postprocessingTime = std::stof(
headerValues[POST_PROCESSING_TIME]);
1615 headerNames[FILE_DESCRIPTION] =
"file_description";
1621 headerNames[NUMBER_OF_CORES] =
"number_of_cpu_cores";
1622 headerNames[TOTAL_MEMORY_CONSUMPTION] =
"total_memory_in_use";
1623 headerNames[PEAK_CORE_MEMORY_CONSUMPTION] =
"peak_core_memory_in_use";
1625 headerNames[TOTAL_EXECUTION_TIME] =
"total_execution_time";
1626 headerNames[DATA_LOAD_TIME] =
"data_loading_phase_execution_time";
1627 headerNames[PREPROCESSING_TIME] =
"pre-processing_phase_execution_time";
1628 headerNames[SIMULATION_TIME] =
"simulation_phase_execution_time";
1629 headerNames[POST_PROCESSING_TIME] =
"post-processing_phase_execution_time";
TErrorMessage ERR_FMT_CANNOT_CREATE_GROUP
HDF5 error message.
size_t nx
number of elements in the x direction
size_t GetDatasetNumberOfDimensions(const hid_t parentGroup, TMatrixName &datasetName)
Get number of dimensions of the dataset under a specified group.
hid_t CreateFloatDataset(const hid_t parentGroup, TMatrixName &datasetName, const TDimensionSizes &dimensionSizes, const TDimensionSizes &chunkSizes, const size_t compressionLevel)
Create a float HDF5 dataset at a specified place in the file tree (3D/4D).
void WriteMatrixDomainType(const hid_t parentGroup, TMatrixName &datasetName, const TMatrixDomainType &matrixDomainType)
Write matrix domain type into the dataset under the root group.
std::string ReadStringAttribute(const hid_t parentGroup, TMatrixName &datasetName, TMatrixName &attributeName)
Read string attribute from the dataset under the root group.
TMatrixDataType
HDF5 matrix data type (float or uint64).
TErrorMessage ERR_FMT_CANNOT_RECREATE_FILE
HDF5 error message.
size_t nt
Number of time steps (for time series datasets).
TErrorMessage ERR_FMT_CANNOT_OPEN_GROUP
HDF5 error message.
static const std::string matrixDomainTypeName
String representation of the Domain type in the HDF5 file.
void Open(const std::string &fileName, unsigned int flags=H5F_ACC_RDONLY)
Open a file.
TErrorMessage ERR_FMT_CANNOT_CREATE_FILE
HDF5 error message.
TMatrixDomainType
HDF5 Matrix domain type (real or complex).
TErrorMessage ERR_FMT_CANNOT_OPEN_DATASET
HDF5 error message.
TErrorMessage ERR_FMT_BAD_ATTRIBUTE_VALUE
HDF5 error message.
static TParameters & GetInstance()
Get instance of the singleton class.
TErrorMessage ERR_FMT_FILE_NOT_OPEN
HDF5 error message.
TErrorMessage ERR_FMT_CANNOT_WRITE_DATASET
HDF5 error message.
hid_t CreateGroup(const hid_t parentGroup, TMatrixName &groupName)
Create a HDF5 group at a specified place in the file tree.
THDF5_File::TMatrixDataType ReadMatrixDataType(const hid_t parentGroup, TMatrixName &datasetName)
Read matrix data type from the dataset.
void WriteScalarValue(const hid_t parentGroup, TMatrixName &datasetName, const float value)
Write the scalar value under a specified group, float value.
TErrorMessage ERR_FMT_BAD_CHECKPOINT_FILE_TYPE
HDF5 error message.
void WriteCuboidToHyperSlab(const hid_t dataset, const TDimensionSizes &hyperslabPosition, const TDimensionSizes &cuboidPosition, const TDimensionSizes &cuboidSize, const TDimensionSizes &matrixDimensions, const float *mMatrixData)
Write a cuboid selected within the matrixData into a hyperslab.
TErrorMessage ERR_FMT_NOT_HDF5_FILE
HDF5 error message.
The header file containing the HDF5 related classes.
The header file containing the parameters of the simulation.
bool IsOpen() const
Is the file opened?
hid_t file
HDF file handle.
const std::string TMatrixName
Datatype for matrix names.
TDimensionSizes GetDatasetDimensionSizes(const hid_t parentGroup, TMatrixName &datasetName)
Get dimension sizes of the dataset under a specified group.
void WriteMatrixDataType(const hid_t parentGroup, TMatrixName &datasetName, const TMatrixDataType &matrixDataType)
Write matrix data type into the dataset under a specified group.
THDF5_File()
Constructor of the class.
The header file containing a class responsible for printing out info and error messages (stdout...
TErrorMessage ERR_FMT_CANNOT_SET_COMPRESSION
HDF5 error message.
void ReadScalarValue(const hid_t parentGroup, TMatrixName &datasetName, float &value)
Read the scalar value under a specified group, float value.
static const std::string matrixDataTypeNames[]
String representation of different data types.
TErrorMessage ERR_FMT_CANNOT_CLOSE_FILE
HDF5 error message.
void WriteStringAttribute(const hid_t parentGroup, TMatrixName &datasetName, TMatrixName &attributeName, const std::string &value)
Write string attribute into the dataset under the root group.
static bool IsHDF5(const std::string &fileName)
Does the file exist?
hid_t GetRootGroup() const
Get handle to the root group.
The header file containing routines for error messages and error messages common for both linux and w...
size_t GetElementCount() const
Get element count, in 3D only spatial domain, in 4D with time.
size_t ny
number of elements in the y direction
static const std::string matrixDomainTypeNames[]
String representation of different domain types.
void Create(const std::string &fileName, unsigned int flags=H5F_ACC_TRUNC)
Create a file.
TErrorMessage ERR_FMT_CANNOT_REOPEN_FILE
HDF5 error message.
void WriteDataByMaskToHyperSlab(const hid_t dataset, const TDimensionSizes &hyperslabPosition, const size_t indexSensorSize, const size_t *indexSensorData, const TDimensionSizes &matrixDimensions, const float *matrixData)
Write sensor data selected by the sensor mask - Occasionally very slow, do not use! ...
hid_t CreateIndexDataset(const hid_t parentGroup, TMatrixName &datasetName, const TDimensionSizes &dimensionSizes, const TDimensionSizes &chunkSizes, const size_t compressionLevel)
Create an index HDF5 dataset at a specified place in the file tree (3D only).
static std::string FormatMessage(const std::string &format, Args...args)
C++-11 replacement for sprintf that works with std::string instead of char *.
TErrorMessage ERR_FMT_BAD_OUTPUT_FILE_TYPE
HDF5 error message.
THDF5_File::TMatrixDomainType ReadMatrixDomainType(const hid_t parentGroup, TMatrixName &datasetName)
Read matrix domain type from the dataset under a specified group.
void WriteHyperSlab(const hid_t dataset, const TDimensionSizes &position, const TDimensionSizes &size, const float *data)
Write a hyper-slab into the dataset - float dataset.
static const std::string matrixDataTypeName
String representation of the Data type in the HDF5 file.
TErrorMessage ERR_FMT_CANNOT_READ_DATASET
HDF5 error message.
TErrorMessage ERR_FMT_CANNOT_READ_ATTRIBUTE
HDF5 error message.
TErrorMessage ERR_FMT_BAD_DIMENSION_SIZES
HDF5 error message.
hid_t OpenGroup(const hid_t parentGroup, TMatrixName &groupName)
Open a HDF5 group at a specified place in the file tree.
size_t nz
number of elements in the z direction
void CloseGroup(const hid_t group)
Close group.
virtual ~THDF5_File()
Destructor.
size_t GetDatasetElementCount(const hid_t parentGroup, TMatrixName &datasetName)
Get dataset element count under a specified group.
void ReadCompleteDataset(const hid_t parentGroup, TMatrixName &datasetName, const TDimensionSizes &dimensionSizes, float *data)
Read data from the dataset under a specified group, float dataset.
TErrorMessage ERR_FMT_CANNOT_WRITE_ATTRIBUTE
HDF5 error message.
std::string fileName
File name.
void CloseDataset(const hid_t dataset)
Close the HDF5 dataset.
TErrorMessage ERR_FMT_BAD_INPUT_FILE_TYPE
HDF5 error message.
Class wrapping the HDF5 routines.
Structure with 4D dimension sizes (3 in space and 1 in time).
bool Is3D() const
Does the object include spatial dimensions only?
hid_t OpenDataset(const hid_t parentGroup, TMatrixName &datasetName)
Open the HDF5 dataset at a specified place in the file tree.