48 #pragma comment(lib, "Ws2_32.lib")
89 HDF5_FileId(H5I_BADID), FileName(
"")
109 char ErrorMessage[256];
111 throw ios::failure(ErrorMessage);
117 HDF5_FileId = H5Fcreate(FileName, Flags, H5P_DEFAULT, H5P_DEFAULT);
121 char ErrorMessage[256];
123 throw ios::failure(ErrorMessage);
141 char ErrorMessage[256];
143 throw ios::failure(ErrorMessage);
148 if (H5Fis_hdf5(FileName) == 0)
150 char ErrorMessage[256];
152 throw ios::failure(ErrorMessage);
155 HDF5_FileId = H5Fopen(FileName, Flags, H5P_DEFAULT);
159 char ErrorMessage[256];
161 throw ios::failure(ErrorMessage);
175 char ErrorMessage[256];
177 throw ios::failure(ErrorMessage);
202 const char * GroupName)
204 hid_t HDF5_group_id = H5Gcreate(ParentGroup,
211 if (HDF5_group_id == H5I_INVALID_HID)
213 char ErrorMessage[256];
215 throw ios::failure(ErrorMessage);
218 return HDF5_group_id;
230 const char * GroupName)
232 hid_t HDF5_group_id = H5Gopen(ParentGroup, GroupName, H5P_DEFAULT);
235 if (HDF5_group_id == H5I_INVALID_HID)
237 char ErrorMessage[256];
239 throw ios::failure(ErrorMessage);
242 return HDF5_group_id;
253 H5Gclose(HDF5_group_id);
265 const char * DatasetName)
268 hid_t HDF5_dataset_id = H5Dopen(ParentGroup, DatasetName, H5P_DEFAULT);
270 if (HDF5_dataset_id == H5I_INVALID_HID)
272 char ErrorMessage[256];
274 throw ios::failure(ErrorMessage);
277 return HDF5_dataset_id;
292 const char * DatasetName,
295 const size_t CompressionLevel)
297 const int RANK = (DimensionSizes.
Is3D()) ? 3 : 4;
303 if (DimensionSizes.
Is3D())
305 Dims[0] = DimensionSizes.
Z;
306 Dims[1] = DimensionSizes.
Y;
307 Dims[2] = DimensionSizes.
X;
309 Chunk[0] = ChunkSizes.
Z;
310 Chunk[1] = ChunkSizes.
Y;
311 Chunk[2] = ChunkSizes.
X;
315 Dims[0] = DimensionSizes.
T;
316 Dims[1] = DimensionSizes.
Z;
317 Dims[2] = DimensionSizes.
Y;
318 Dims[3] = DimensionSizes.
X;
320 Chunk[0] = ChunkSizes.
T;
321 Chunk[1] = ChunkSizes.
Z;
322 Chunk[2] = ChunkSizes.
Y;
323 Chunk[3] = ChunkSizes.
X;
329 hid_t Dataspace_id = H5Screate_simple(RANK, Dims, NULL);
332 Property_list = H5Pcreate(H5P_DATASET_CREATE);
334 Status = H5Pset_chunk(Property_list, RANK, Chunk);
337 char ErrorMessage[256];
339 throw ios::failure(ErrorMessage);
343 Status = H5Pset_deflate(Property_list, CompressionLevel);
346 char ErrorMessage[256];
348 DatasetName, CompressionLevel);
349 throw ios::failure(ErrorMessage);
353 hid_t HDF5_dataset_id = H5Dcreate(ParentGroup,
358 Property_list, H5P_DEFAULT);
361 if (HDF5_dataset_id == H5I_INVALID_HID)
363 char ErrorMessage[256];
365 throw ios::failure(ErrorMessage);
368 H5Pclose(Property_list);
370 return HDF5_dataset_id;
386 const char * DatasetName,
389 const size_t CompressionLevel)
393 hsize_t Dims [RANK] = {DimensionSizes.
Z, DimensionSizes.
Y, DimensionSizes.
X};
394 hsize_t Chunk[RANK] = {ChunkSizes.
Z, ChunkSizes.
Y, ChunkSizes.
X};
399 hid_t Dataspace_id = H5Screate_simple(RANK, Dims, NULL);
402 Property_list = H5Pcreate(H5P_DATASET_CREATE);
404 Status = H5Pset_chunk(Property_list, RANK, Chunk);
407 char ErrorMessage[256];
409 throw ios::failure(ErrorMessage);
413 Status = H5Pset_deflate(Property_list, CompressionLevel);
416 char ErrorMessage[256];
418 throw ios::failure(ErrorMessage);
422 hid_t HDF5_dataset_id = H5Dcreate(ParentGroup,
431 if (HDF5_dataset_id == H5I_INVALID_HID)
433 char ErrorMessage[256];
435 throw ios::failure(ErrorMessage);
438 H5Pclose(Property_list);
440 return HDF5_dataset_id;
453 H5Dclose (HDF5_Dataset_id);
473 hid_t HDF5_Filespace,HDF5_Memspace;
476 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
477 const int Rank = H5Sget_simple_extent_ndims(HDF5_Filespace);
480 hsize_t ElementCount[Rank];
481 hsize_t Offset [Rank];
486 ElementCount[0] = Size.
Z;
487 ElementCount[1] = Size.
Y;
488 ElementCount[2] = Size.
X;
490 Offset[0] = Position.
Z;
491 Offset[1] = Position.
Y;
492 Offset[2] = Position.
X;
496 ElementCount[0] = Size.
T;
497 ElementCount[1] = Size.
Z;
498 ElementCount[2] = Size.
Y;
499 ElementCount[3] = Size.
X;
501 Offset[0] = Position.
T;
502 Offset[1] = Position.
Z;
503 Offset[2] = Position.
Y;
504 Offset[3] = Position.
X;
508 status = H5Sselect_hyperslab(HDF5_Filespace,
516 char ErrorMessage[256];
518 throw ios::failure(ErrorMessage);
522 HDF5_Memspace = H5Screate_simple(Rank, ElementCount, NULL);
524 status = H5Dwrite(HDF5_Dataset_id,
532 char ErrorMessage[256];
534 throw ios::failure(ErrorMessage);
537 H5Sclose(HDF5_Memspace);
538 H5Sclose(HDF5_Filespace);
558 hid_t HDF5_Filespace,HDF5_Memspace;
561 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
562 const int Rank = H5Sget_simple_extent_ndims(HDF5_Filespace);
565 hsize_t ElementCount[Rank];
566 hsize_t Offset [Rank];
570 ElementCount[0] = Size.
Z;
571 ElementCount[1] = Size.
Y;
572 ElementCount[2] = Size.
X;
574 Offset[0] = Position.
Z;
575 Offset[1] = Position.
Y;
576 Offset[2] = Position.
X;
580 ElementCount[0] = Size.
T;
581 ElementCount[1] = Size.
Z;
582 ElementCount[2] = Size.
Y;
583 ElementCount[3] = Size.
X;
585 Offset[0] = Position.
T;
586 Offset[1] = Position.
Z;
587 Offset[2] = Position.
Y;
588 Offset[3] = Position.
X;
593 status = H5Sselect_hyperslab(HDF5_Filespace,
601 char ErrorMessage[256];
603 throw ios::failure(ErrorMessage);
607 HDF5_Memspace = H5Screate_simple(Rank, ElementCount, NULL);
609 status = H5Dwrite(HDF5_Dataset_id, H5T_STD_U64LE, HDF5_Memspace, HDF5_Filespace, H5P_DEFAULT, Data);
612 char ErrorMessage[256];
614 throw ios::failure(ErrorMessage);
617 H5Sclose(HDF5_Memspace);
618 H5Sclose(HDF5_Filespace);
638 const float * MatrixData)
641 hid_t HDF5_Filespace, HDF5_Memspace;
647 hsize_t SlabSize[Rank] = {1, CuboidSize.
Z, CuboidSize.
Y, CuboidSize.
X};
648 hsize_t OffsetInDataset[Rank] = {HyperslabPosition.
T, HyperslabPosition.
Z, HyperslabPosition.
Y, HyperslabPosition.
X };
649 hsize_t OffsetInMatrixData[] = {CuboidPosition.
Z, CuboidPosition.
Y, CuboidPosition.
X};
650 hsize_t MatrixSize [] = {MatrixDimensions.
Z, MatrixDimensions.
Y, MatrixDimensions.
X};
654 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
655 status = H5Sselect_hyperslab(HDF5_Filespace,
663 char ErrorMessage[256];
665 throw ios::failure(ErrorMessage);
670 HDF5_Memspace = H5Screate_simple(3, MatrixSize, NULL);
671 status = H5Sselect_hyperslab(HDF5_Memspace,
679 char ErrorMessage[256];
681 throw ios::failure(ErrorMessage);
685 status = H5Dwrite(HDF5_Dataset_id,
693 char ErrorMessage[256];
695 throw ios::failure(ErrorMessage);
699 H5Sclose(HDF5_Memspace);
700 H5Sclose(HDF5_Filespace);
718 const size_t IndexSensorSize,
719 const size_t * IndexSensorData,
721 const float * MatrixData)
724 hid_t HDF5_Filespace, HDF5_Memspace;
730 hsize_t SlabSize[Rank] = {1, 1, IndexSensorSize};
731 hsize_t OffsetInDataset[Rank] = {HyperslabPosition.
Z,
733 HyperslabPosition.
X };
736 hsize_t MatrixSize = MatrixDimensions.
Z * MatrixDimensions.
Y * MatrixDimensions.
X;
740 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
741 status = H5Sselect_hyperslab(HDF5_Filespace,
749 char ErrorMessage[256];
751 throw ios::failure(ErrorMessage);
755 HDF5_Memspace = H5Screate_simple(1, &MatrixSize, NULL);
756 status = H5Sselect_elements(HDF5_Memspace,
759 ( hsize_t *) (IndexSensorData));
762 char ErrorMessage[256];
764 throw ios::failure(ErrorMessage);
768 status = H5Dwrite(HDF5_Dataset_id,
776 char ErrorMessage[256];
778 throw ios::failure(ErrorMessage);
782 H5Sclose(HDF5_Memspace);
783 H5Sclose(HDF5_Filespace);
795 const char * DatasetName,
799 const hsize_t Dims[] = {1,1,1};
801 hid_t Dataset_id = H5I_INVALID_HID;
802 hid_t Dataspace_id = H5I_INVALID_HID;
805 if (H5LTfind_dataset(ParentGroup, DatasetName) == 1)
812 Dataspace_id = H5Screate_simple (Rank, Dims, NULL);
813 Dataset_id = H5Dcreate(ParentGroup,
823 if (Dataset_id == H5I_INVALID_HID)
825 char ErrorMessage[256];
827 throw ios::failure(ErrorMessage);
830 Status = H5Dwrite(Dataset_id,
840 char ErrorMessage[256];
842 throw ios::failure(ErrorMessage);
859 const char * DatasetName,
863 const hsize_t Dims[] = {1,1,1};
865 hid_t Dataset_id = H5I_INVALID_HID;
866 hid_t Dataspace_id = H5I_INVALID_HID;
870 if (H5LTfind_dataset(ParentGroup, DatasetName) == 1)
877 Dataspace_id = H5Screate_simple (Rank, Dims, NULL);
878 Dataset_id = H5Dcreate(ParentGroup,
888 if (Dataset_id == H5I_INVALID_HID)
890 char ErrorMessage[256];
892 throw ios::failure(ErrorMessage);
895 Error = H5Dwrite(Dataset_id,
905 char ErrorMessage[256];
907 throw ios::failure(ErrorMessage);
923 const char * DatasetName,
938 const char * DatasetName,
955 const char * DatasetName,
963 char ErrorMessage[256];
965 throw ios::failure(ErrorMessage);
969 herr_t status = H5LTread_dataset_float(ParentGroup, DatasetName, Data);
972 char ErrorMessage[256];
974 throw ios::failure(ErrorMessage);
989 const char * DatasetName,
996 char ErrorMessage[256];
998 throw ios::failure(ErrorMessage);
1002 herr_t status = H5LTread_dataset(ParentGroup,
1008 char ErrorMessage[256];
1010 throw ios::failure(ErrorMessage);
1025 const char * DatasetName)
1028 hsize_t Dims[NoDims];
1030 for (
size_t i = 0; i < NoDims; i++) Dims[i] = 0;
1032 herr_t status = H5LTget_dataset_info(ParentGroup,
1039 char ErrorMessage[256];
1041 throw ios::failure(ErrorMessage);
1062 const char * DatasetName)
1066 herr_t status = H5LTget_dataset_ndims(ParentGroup, DatasetName, &NoDims);
1069 char ErrorMessage[256];
1071 throw ios::failure(ErrorMessage);
1088 const char * DatasetName)
1090 hsize_t Dims[3] = {0, 0, 0};
1092 herr_t status = H5LTget_dataset_info(ParentGroup,
1099 char ErrorMessage[256];
1101 throw ios::failure(ErrorMessage);
1104 return Dims[0] * Dims[1] * Dims[2];
1117 const char * DatasetName,
1136 const char * DatasetName,
1156 const char * DatasetName)
1171 char ErrorMessage[256];
1174 throw ios::failure(ErrorMessage);
1191 const char * DatasetName)
1206 char ErrorMessage[256];
1208 throw ios::failure(ErrorMessage);
1226 const char * DatasetName,
1227 const char * AttributeName,
1228 const string & Value)
1230 herr_t Status = H5LTset_attribute_string(ParentGroup,
1236 char ErrorMessage[256];
1238 throw ios::failure(ErrorMessage);
1255 const char * DatasetName,
1256 const char * AttributeName)
1258 char Value[256] =
"";
1259 herr_t Status = H5LTget_attribute_string(ParentGroup,
1265 char ErrorMessage[256];
1267 throw ios::failure(ErrorMessage);
1516 for (
int i = hdf5_ft_input; i < hdf5_ft_unknown ; i++)
1524 return THDF5_FileHeader::hdf5_ft_unknown;
1557 return hdf5_fv_unknown;
1570 current = localtime(&now);
1572 char DateString[20];
1574 sprintf(DateString,
"%02i/%02i/%02i, %02i:%02i:%02i",
1575 current->tm_mday, current->tm_mon+1, current->tm_year-100,
1576 current->tm_hour, current->tm_min, current->tm_sec);
1592 gethostname(HostName, 256);
1598 WSAStartup(MAKEWORD(2, 2), &wsaData);
1599 gethostname(HostName, 256);
1616 sprintf(Text,
"%ld MB",TotalMemory);
1635 const double LoadTime,
1636 const double PreProcessingTime,
1637 const double SimulationTime,
1638 const double PostprocessingTime)
1640 char Text [30] =
"";
1642 sprintf(Text,
"%8.2fs", TotalTime);
1645 sprintf(Text,
"%8.2fs", LoadTime);
1648 sprintf(Text,
"%8.2fs", PreProcessingTime);
1652 sprintf(Text,
"%8.2fs", SimulationTime);
1655 sprintf(Text,
"%8.2fs", PostprocessingTime);
1670 double& PreProcessingTime,
1671 double& SimulationTime,
1672 double& PostprocessingTime)
size_t Z
Z dimension size.
hid_t CreateGroup(const hid_t ParentGroup, const char *GroupName)
Create a HDF5 group at a specified place in the file tree.
string FileName
File name.
THDF5_File::THDF5_MatrixDataType ReadMatrixDataType(const hid_t ParentGroup, const char *DatasetName)
Read matrix data type from the dataset.
const char *const HDF5_ERR_FMT_GroupNotOpened
HDF5 error message.
static const char * HDF5_MatrixDomainTypeName
String representation of the Domain type in the HDF5 file.
void WriteStringAttribute(const hid_t ParentGroup, const char *DatasetName, const char *AttributeName, const string &Value)
Write string attribute into the dataset under the root group.
void WriteScalarValue(const hid_t ParentGroup, const char *DatasetName, const float Value)
Write the scalar value under a specified group - float value.
hid_t OpenGroup(const hid_t ParentGroup, const char *GroupName)
Open a HDF5 group at a specified place in the file tree.
const char *const HDF5_ERR_FMT_DatasetNotOpened
HDF5 error message.
const char *const HDF5_ERR_FMT_CouldNotReadFrom
HDF5 error message.
const char *const HDF5_ERR_FMT_FileNotClosed
HDF5 error message.
void WriteCuboidToHyperSlab(const hid_t HDF5_Dataset_id, const TDimensionSizes &HyperslabPosition, const TDimensionSizes &CuboidPosition, const TDimensionSizes &CuboidSize, const TDimensionSizes &MatrixDimensions, const float *MatrixData)
Write a cuboid selected inside MatrixData into a Hyperslab.
bool IsOpened() const
Is the file opened?
void ReadScalarValue(const hid_t ParentGroup, const char *DatasetName, float &Value)
Read the scalar value under a specified group - float value.
const char *const HDF5_ERR_FMT_NotHDF5File
HDF5 error message.
const char *const HDF5_ERR_FMT_BadCheckpointFileType
HDF5 error message.
void WriteSensorByMaskToHyperSlab(const hid_t HDF5_Dataset_id, 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! ...
The header file containing the HDF5 related classes.
size_t X
X dimension size.
The header file containing the parameters of the simulation.
TDimensionSizes GetDatasetDimensionSizes(const hid_t ParentGroup, const char *DatasetName)
Get dimension sizes of the dataset under a specified group.
size_t GetDatasetElementCount(const hid_t ParentGroup, const char *DatasetName)
Get dataset element count under a specified group.
const char *const HDF5_ERR_FMT_BadOutputFileType
HDF5 error message.
void WriteHyperSlab(const hid_t HDF5_Dataset_id, const TDimensionSizes &Position, const TDimensionSizes &Size, const float *Data)
Write a hyper-slab into the dataset - float dataset.
static const char * HDF5_MatrixDataTypeName
String representation of the Data type in the HDF5 file.
THDF5_File()
Constructor of the class.
hid_t HDF5_FileId
HDF file handle.
void WriteMatrixDataType(const hid_t ParentGroup, const char *DatasetName, const THDF5_MatrixDataType &MatrixDataType)
Write matrix data type into the dataset under a specified group.
void WriteMatrixDomainType(const hid_t ParentGroup, const char *DatasetName, const THDF5_MatrixDomainType &MatrixDomainType)
Write matrix domain type into the dataset under the root group.
size_t GetDatasetNumberOfDimensions(const hid_t ParentGroup, const char *DatasetName)
Get number of dimensions of the dataset under a specified group.
const char *const HDF5_ERR_FMT_WrongDimensionSizes
HDF5 error message.
const char *const HDF5_ERR_FMT_CouldNotSetCompression
HDF5 error message.
hid_t GetRootGroup() const
Get handle to the root group.
const char *const HDF5_ERR_FMT_FileCannotReopen
HDF5 error message.
The header file containing all error messages of the project.
void Open(const char *FileName, unsigned int Flags=H5F_ACC_RDONLY)
Open the file.
hid_t CreateFloatDataset(const hid_t ParentGroup, const char *DatasetName, const TDimensionSizes &DimensionSizes, const TDimensionSizes &ChunkSizes, const size_t CompressionLevel)
Create the HDF5 dataset at a specified place in the file tree (3D/4D).
size_t GetElementCount() const
Get element count, in 3D only spatial domain, in 4D with time.
hid_t OpenDataset(const hid_t ParentGroup, const char *DatasetName)
Open the HDF5 dataset at a specified place in the file tree.
const char *const HDF5_ERR_FMT_BadInputFileType
HDF5 error message.
THDF5_File::THDF5_MatrixDomainType ReadMatrixDomainType(const hid_t ParentGroup, const char *DatasetName)
Read matrix domain type from the dataset under a specified group.
const char *const HDF5_ERR_FMT_CouldNotWriteToAttribute
HDF5 error message.
size_t Y
Y dimension size.
void ReadCompleteDataset(const hid_t ParentGroup, const char *DatasetName, const TDimensionSizes &DimensionSizes, float *Data)
Read data from the dataset under a specified group - float dataset.
const char *const HDF5_ERR_FMT_FileNotOpened
HDF5 error message.
size_t T
Number of time steps (for time series datasets).
void CloseGroup(const hid_t Group)
Close HDF5 group.
void Create(const char *FileName, unsigned int Flags=H5F_ACC_TRUNC)
Create the file, overwrite if exist.
const char *const HDF5_ERR_FMT_CouldNotWriteTo
HDF5 error message.
string ReadStringAttribute(const hid_t ParentGroup, const char *DatasetName, const char *AttributeName)
Read string attribute from the dataset under the root group.
const char *const HDF5_ERR_FMT_GroupNotCreated
HDF5 error message.
const char *const HDF5_ERR_FMT_FileCannotRecreated
HDF5 error message.
const char *const HDF5_ERR_FMT_BadAttributeValue
HDF5 error message.
hid_t CreateIndexDataset(const hid_t ParentGroup, const char *DatasetName, const TDimensionSizes &DimensionSizes, const TDimensionSizes &ChunkSizes, const size_t CompressionLevel)
Create the HDF5 dataset at a specified place in the file tree (3D only).
const char *const HDF5_ERR_FMT_CouldNotReadFromAttribute
HDF5 error message.
static const string HDF5_MatrixDomainTypeNames[]
String representation of different domain types.
virtual ~THDF5_File()
Destructor.
static const string HDF5_MatrixDataTypeNames[]
String representation of different data types.
THDF5_MatrixDomainType
HDF5 Matrix domain type (real or complex).
void CloseDataset(const hid_t HDF5_Dataset_id)
Close the HDF5 dataset.
Class wrapping the HDF5 routines.
THDF5_MatrixDataType
HDF5 matrix data type (float or uint64).
Structure with 4D dimension sizes (3 in space and 1 in time).
bool Is3D() const
Is it a 3D object?
const char *const HDF5_ERR_FMT_FileNotCreated
HDF5 error message.
static TParameters * GetInstance()
Get instance of the singleton class.