| kspaceFirstOrder3D-OMP 1.1 The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Friends Pages
HDF5_File.cpp
Go to the documentation of this file.
1 /**
2 * @file HDF5_File.cpp
3 * @author Jiri Jaros \n
4 * Faculty of Information Technology\n
5 * Brno University of Technology \n
6 * jarosjir@fit.vutbr.cz
7 *
8 * @brief The implementation file containing the HDF5 related classes
9 *
10 * @version kspaceFirstOrder3D 2.15
11 * @date 27 July 2012, 14:14 (created) \n
12 * 23 September 2014, 15:46 (revised)
13 *
14
15 * @section License
16 * This file is part of the C++ extension of the k-Wave Toolbox (http://www.k-wave.org).\n
17 * Copyright (C) 2014 Jiri Jaros and Bradley Treeby
18 *
19 * This file is part of k-Wave. k-Wave is free software: you can redistribute it
20 * and/or modify it under the terms of the GNU Lesser General Public License as
21 * published by the Free Software Foundation, either version 3 of the License,
22 * or (at your option) any later version.
23 *
24 * k-Wave is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 * See the GNU Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with k-Wave. If not, see <http://www.gnu.org/licenses/>.
31 */
32
33
34 #include <stdio.h>
35 #include <iostream>
36 #include <stdexcept>
37 #include <time.h>
38
39 // Linux build
40 #ifdef __linux__
41 #include <unistd.h>
42 #endif
43
44 //Windows 64 build
45 #ifdef _WIN64
46 #include<stdio.h>
47 #include<Winsock2.h>
48 #pragma comment(lib, "Ws2_32.lib")
49 #endif
50
51 #include <HDF5/HDF5_File.h>
52
53 #include <Parameters/Parameters.h>
54 #include <Utils/ErrorMessages.h>
55
56 //----------------------------------------------------------------------------//
57 //----------------------------- Constants----------------------------------//
58 //----------------------------------------------------------------------------//
59
60
61
62 //----------------------------------------------------------------------------//
63
64 const char * THDF5_File::HDF5_MatrixDomainTypeName = "domain_type";
65
66 const char * THDF5_File::HDF5_MatrixDataTypeName = "data_type";
67
68 const string THDF5_File::HDF5_MatrixDomainTypeNames[] = {"real","complex"};
69
70 const string THDF5_File::HDF5_MatrixDataTypeNames[] = {"float","long"};
71
72
73 const string THDF5_FileHeader::HDF5_FileTypesNames[] = {"input","output", "checkpoint", "unknown"};
74
75 const string THDF5_FileHeader::HDF5_MajorFileVersionsNames[] = {"1"};
76
77 const string THDF5_FileHeader::HDF5_MinorFileVersionsNames[] = {"0","1"};
78
79 //----------------------------------------------------------------------------//
80 //---------------------------- THDF5_File ------------------------------//
81 //------------------------------ Public -------------------------------//
82 //----------------------------------------------------------------------------//
83
84
85 /**
86 * Constructor.
87 */
88 THDF5_File::THDF5_File() :
89 HDF5_FileId(H5I_BADID), FileName("")
90 {
91
92 }// end of constructor
93 //------------------------------------------------------------------------------
94
95
96 /**
97 * Create an HDF5 file.
98 * @param [in] FileName - File name
99 * @param [in] Flags - Flags for the HDF5 runtime
100 * @throw ios:failure if an error happens.
101 *
102 */
103 void THDF5_File::Create(const char * FileName,
104 unsigned int Flags)
105 {
106 // file is opened
107 if (IsOpened())
108 {
109 char ErrorMessage[256];
110 sprintf(ErrorMessage,HDF5_ERR_FMT_FileCannotRecreated,FileName);
111 throw ios::failure(ErrorMessage);
112 }
113
114 // Create a new file using default properties.
115 this->FileName = FileName;
116
117 HDF5_FileId = H5Fcreate(FileName, Flags, H5P_DEFAULT, H5P_DEFAULT);
118
119 if (HDF5_FileId < 0)
120 {
121 char ErrorMessage[256];
122 sprintf(ErrorMessage,HDF5_ERR_FMT_FileNotCreated,FileName);
123 throw ios::failure(ErrorMessage);
124 }
125 }// end of Create
126 //------------------------------------------------------------------------------
127
128
129 /**
130 * Open the HDF5 file.
131 * @param [in] FileName
132 * @param [in] Flags - flags for the HDF5 runtime
133 * @throw ios:failure if error happened
134 *
135 */
136 void THDF5_File::Open(const char * FileName,
137 unsigned int Flags)
138 {
139 if (IsOpened())
140 {
141 char ErrorMessage[256];
142 sprintf(ErrorMessage,HDF5_ERR_FMT_FileCannotReopen,FileName);
143 throw ios::failure(ErrorMessage);
144 };
145
146 this->FileName = FileName;
147
148 if (H5Fis_hdf5(FileName) == 0)
149 {
150 char ErrorMessage[256];
151 sprintf(ErrorMessage,HDF5_ERR_FMT_NotHDF5File,FileName);
152 throw ios::failure(ErrorMessage);
153 }
154
155 HDF5_FileId = H5Fopen(FileName, Flags, H5P_DEFAULT);
156
157 if (HDF5_FileId < 0)
158 {
159 char ErrorMessage[256];
160 sprintf(ErrorMessage,HDF5_ERR_FMT_FileNotOpened,FileName);
161 throw ios::failure(ErrorMessage);
162 }
163 }// end of Open
164 //------------------------------------------------------------------------------
165
166 /**
167 * Close the HDF5 file.
168 */
169 void THDF5_File::Close()
170 {
171 // Terminate access to the file.
172 herr_t status = H5Fclose(HDF5_FileId);
173 if (status < 0)
174 {
175 char ErrorMessage[256];
176 sprintf(ErrorMessage,HDF5_ERR_FMT_FileNotClosed,FileName.c_str());
177 throw ios::failure(ErrorMessage);
178 }
179
180 FileName = "";
181 HDF5_FileId = H5I_BADID;
182 }// end of Close
183 //------------------------------------------------------------------------------
184
185 /**
186 * Destructor.
187 */
188 THDF5_File::~THDF5_File()
189 {
190 if (IsOpened()) Close();
191 }//end of ~THDF5_File
192 //------------------------------------------------------------------------------
193
194
195 /**
196 * Create a HDF5 group at a specified place in the file tree.
197 * @param [in] ParentGroup - Where to link the group at
198 * @param [in] GroupName - Group name
199 * @return a handle to the new group
200 */
201 hid_t THDF5_File::CreateGroup(const hid_t ParentGroup,
202 const char * GroupName)
203 {
204 hid_t HDF5_group_id = H5Gcreate(ParentGroup,
205 GroupName,
206 H5P_DEFAULT,
207 H5P_DEFAULT,
208 H5P_DEFAULT);
209
210 //if error
211 if (HDF5_group_id == H5I_INVALID_HID)
212 {
213 char ErrorMessage[256];
214 sprintf(ErrorMessage,HDF5_ERR_FMT_GroupNotCreated,GroupName, FileName.c_str());
215 throw ios::failure(ErrorMessage);
216 }
217
218 return HDF5_group_id;
219 };// end of CreateGroup
220 //------------------------------------------------------------------------------
221
222
223 /**
224 * Open a HDF5 group at a specified place in the file tree.
225 * @param [in] ParentGroup - parent group (where the group is)
226 * @param [in] GroupName - Group name
227 * @return
228 */
229 hid_t THDF5_File::OpenGroup(const hid_t ParentGroup,
230 const char * GroupName)
231 {
232 hid_t HDF5_group_id = H5Gopen(ParentGroup, GroupName, H5P_DEFAULT);
233
234 //if error
235 if (HDF5_group_id == H5I_INVALID_HID)
236 {
237 char ErrorMessage[256];
238 sprintf(ErrorMessage,HDF5_ERR_FMT_GroupNotOpened,GroupName, FileName.c_str());
239 throw ios::failure(ErrorMessage);
240 }
241
242 return HDF5_group_id;
243 }// end of OpenGroup
244 //------------------------------------------------------------------------------
245
246
247 /**
248 * Close a group.
249 * @param[in] HDF5_group_id
250 */
251 void THDF5_File::CloseGroup(const hid_t HDF5_group_id)
252 {
253 H5Gclose(HDF5_group_id);
254 }// end of CloseGroup
255 //------------------------------------------------------------------------------
256
257 /**
258 * Open the dataset at a specified place in the file tree.
259 * @param [in] ParentGroup
260 * @param [in] DatasetName
261 * @return Dataset id
262 * @throw ios::failure
263 */
264 hid_t THDF5_File::OpenDataset(const hid_t ParentGroup,
265 const char * DatasetName)
266 {
267 // Open dataset
268 hid_t HDF5_dataset_id = H5Dopen(ParentGroup, DatasetName, H5P_DEFAULT);
269
270 if (HDF5_dataset_id == H5I_INVALID_HID)
271 {
272 char ErrorMessage[256];
273 sprintf(ErrorMessage, HDF5_ERR_FMT_DatasetNotOpened, FileName.c_str(), DatasetName);
274 throw ios::failure(ErrorMessage);
275 }
276
277 return HDF5_dataset_id;
278 }// end of OpenDataset
279 //------------------------------------------------------------------------------
280
281
282 /**
283 * Create the HDF5 dataset at a specified place in the file tree.
284 * @param [in] ParentGroup - Parent group
285 * @param [in] DatasetName - Dataset name
286 * @param [in] DimensionSizes - Dimension sizes
287 * @param [in] ChunkSizes - Chunk sizes
288 * @param [in] CompressionLevel - Compression level
289 * @return a handle to the new dataset
290 */
291 hid_t THDF5_File::CreateFloatDataset(const hid_t ParentGroup,
292 const char * DatasetName,
293 const TDimensionSizes & DimensionSizes,
294 const TDimensionSizes & ChunkSizes,
295 const size_t CompressionLevel)
296 {
297 const int RANK = (DimensionSizes.Is3D()) ? 3 : 4;
298
299 hsize_t Dims [RANK];
300 hsize_t Chunk[RANK];
301
302
303 if (DimensionSizes.Is3D())
304 { // 3D dataset
305 Dims[0] = DimensionSizes.Z;
306 Dims[1] = DimensionSizes.Y;
307 Dims[2] = DimensionSizes.X;
308
309 Chunk[0] = ChunkSizes.Z;
310 Chunk[1] = ChunkSizes.Y;
311 Chunk[2] = ChunkSizes.X;
312 }
313 else
314 { // 4D dataset
315 Dims[0] = DimensionSizes.T;
316 Dims[1] = DimensionSizes.Z;
317 Dims[2] = DimensionSizes.Y;
318 Dims[3] = DimensionSizes.X;
319
320 Chunk[0] = ChunkSizes.T;
321 Chunk[1] = ChunkSizes.Z;
322 Chunk[2] = ChunkSizes.Y;
323 Chunk[3] = ChunkSizes.X;
324 }
325
326 hid_t Property_list;
327 herr_t Status;
328
329 hid_t Dataspace_id = H5Screate_simple(RANK, Dims, NULL);
330
331 // set chunk size
332 Property_list = H5Pcreate(H5P_DATASET_CREATE);
333
334 Status = H5Pset_chunk(Property_list, RANK, Chunk);
335 if (Status < 0)
336 {
337 char ErrorMessage[256];
338 sprintf(ErrorMessage, HDF5_ERR_FMT_DatasetNotOpened, FileName.c_str(), DatasetName);
339 throw ios::failure(ErrorMessage);
340 }
341
342 // set compression level
343 Status = H5Pset_deflate(Property_list, CompressionLevel);
344 if (Status < 0)
345 {
346 char ErrorMessage[256];
347 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotSetCompression, FileName.c_str(),
348 DatasetName, CompressionLevel);
349 throw ios::failure(ErrorMessage);
350 }
351
352 // create dataset
353 hid_t HDF5_dataset_id = H5Dcreate(ParentGroup,
354 DatasetName,
355 H5T_NATIVE_FLOAT,
356 Dataspace_id,
357 H5P_DEFAULT,
358 Property_list, H5P_DEFAULT);
359
360 // error checking
361 if (HDF5_dataset_id == H5I_INVALID_HID)
362 {
363 char ErrorMessage[256];
364 sprintf(ErrorMessage, HDF5_ERR_FMT_DatasetNotOpened, FileName.c_str(), DatasetName);
365 throw ios::failure(ErrorMessage);
366 }
367
368 H5Pclose(Property_list);
369
370 return HDF5_dataset_id;
371 }// end of CreateFloatDataset
372 //------------------------------------------------------------------------------
373
374
375 /**
376 * Create the HDF5 dataset at a specified place in the file tree (always 3D).
377 *
378 * @param [in] ParentGroup - Parent group
379 * @param [in] DatasetName - Dataset name
380 * @param [in] DimensionSizes - Dimension sizes
381 * @param [in] ChunkSizes - Chunk sizes
382 * @param [in] CompressionLevel - Compression level
383 * @return a handle to the new dataset
384 */
385 hid_t THDF5_File::CreateIndexDataset(const hid_t ParentGroup,
386 const char * DatasetName,
387 const TDimensionSizes & DimensionSizes,
388 const TDimensionSizes & ChunkSizes,
389 const size_t CompressionLevel)
390 {
391 const int RANK = 3;
392
393 hsize_t Dims [RANK] = {DimensionSizes.Z, DimensionSizes.Y, DimensionSizes.X};
394 hsize_t Chunk[RANK] = {ChunkSizes.Z, ChunkSizes.Y, ChunkSizes.X};
395
396 hid_t Property_list;
397 herr_t Status;
398
399 hid_t Dataspace_id = H5Screate_simple(RANK, Dims, NULL);
400
401 // set chunk size
402 Property_list = H5Pcreate(H5P_DATASET_CREATE);
403
404 Status = H5Pset_chunk(Property_list, RANK, Chunk);
405 if (Status < 0)
406 {
407 char ErrorMessage[256];
408 sprintf(ErrorMessage, HDF5_ERR_FMT_DatasetNotOpened, FileName.c_str(), DatasetName);
409 throw ios::failure(ErrorMessage);
410 }
411
412 // set compression level
413 Status = H5Pset_deflate(Property_list, CompressionLevel);
414 if (Status < 0)
415 {
416 char ErrorMessage[256];
417 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotSetCompression, FileName.c_str(), DatasetName, CompressionLevel);
418 throw ios::failure(ErrorMessage);
419 }
420
421 // create dataset
422 hid_t HDF5_dataset_id = H5Dcreate(ParentGroup,
423 DatasetName,
424 H5T_STD_U64LE,
425 Dataspace_id,
426 H5P_DEFAULT,
427 Property_list,
428 H5P_DEFAULT);
429
430 // error checking
431 if (HDF5_dataset_id == H5I_INVALID_HID)
432 {
433 char ErrorMessage[256];
434 sprintf(ErrorMessage, HDF5_ERR_FMT_DatasetNotOpened, FileName.c_str(), DatasetName);
435 throw ios::failure(ErrorMessage);
436 }
437
438 H5Pclose(Property_list);
439
440 return HDF5_dataset_id;
441
442 }// end of CreateIndexDataset
443 //------------------------------------------------------------------------------
444
445
446 /**
447 * Close dataset.
448 * @param [in] HDF5_Dataset_id
449 *
450 */
451 void THDF5_File::CloseDataset(const hid_t HDF5_Dataset_id)
452 {
453 H5Dclose (HDF5_Dataset_id);
454 }// end of CloseDataset
455 //------------------------------------------------------------------------------
456
457
458 /**
459 * Write a hyperslab into the dataset.
460 *
461 * @param [in] HDF5_Dataset_id - Dataset id
462 * @param [in] Position - Position in the dataset
463 * @param [in] Size - Size of the hyperslab
464 * @param [in] Data - Data to be written
465 * @throw ios::failure
466 */
467 void THDF5_File::WriteHyperSlab(const hid_t HDF5_Dataset_id,
468 const TDimensionSizes & Position,
469 const TDimensionSizes & Size,
470 const float * Data)
471 {
472 herr_t status;
473 hid_t HDF5_Filespace,HDF5_Memspace;
474
475 // Get File Space, to find out number of dimensions
476 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
477 const int Rank = H5Sget_simple_extent_ndims(HDF5_Filespace);
478
479 // Select sizes and positions
480 hsize_t ElementCount[Rank];
481 hsize_t Offset [Rank];
482
483
484 if (Rank == 3)
485 { // 3D dataset
486 ElementCount[0] = Size.Z;
487 ElementCount[1] = Size.Y;
488 ElementCount[2] = Size.X;
489
490 Offset[0] = Position.Z;
491 Offset[1] = Position.Y;
492 Offset[2] = Position.X;
493 }
494 else
495 { // 4D dataset
496 ElementCount[0] = Size.T;
497 ElementCount[1] = Size.Z;
498 ElementCount[2] = Size.Y;
499 ElementCount[3] = Size.X;
500
501 Offset[0] = Position.T;
502 Offset[1] = Position.Z;
503 Offset[2] = Position.Y;
504 Offset[3] = Position.X;
505 }
506
507 // select hyperslab
508 status = H5Sselect_hyperslab(HDF5_Filespace,
509 H5S_SELECT_SET,
510 Offset,
511 NULL,
512 ElementCount,
513 NULL);
514 if (status < 0)
515 {
516 char ErrorMessage[256];
517 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
518 throw ios::failure(ErrorMessage);
519 }
520
521 // assign memspace
522 HDF5_Memspace = H5Screate_simple(Rank, ElementCount, NULL);
523
524 status = H5Dwrite(HDF5_Dataset_id,
525 H5T_NATIVE_FLOAT,
526 HDF5_Memspace,
527 HDF5_Filespace,
528 H5P_DEFAULT,
529 Data);
530 if (status < 0)
531 {
532 char ErrorMessage[256];
533 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
534 throw ios::failure(ErrorMessage);
535 }
536
537 H5Sclose(HDF5_Memspace);
538 H5Sclose(HDF5_Filespace);
539 }// end of WriteHyperSlab
540 //------------------------------------------------------------------------------
541
542
543 /**
544 * Write hyperslab.
545 *
546 * @param [in] HDF5_Dataset_id - Dataset id
547 * @param [in] Position - Position in the dataset
548 * @param [in] Size - Size of the hyperslab
549 * @param [in] Data - Data to be written
550 * @throw ios::failure
551 */
552 void THDF5_File::WriteHyperSlab(const hid_t HDF5_Dataset_id,
553 const TDimensionSizes & Position,
554 const TDimensionSizes & Size,
555 const size_t * Data)
556 {
557 herr_t status;
558 hid_t HDF5_Filespace,HDF5_Memspace;
559
560 // Get File Space, to find out number of dimensions
561 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
562 const int Rank = H5Sget_simple_extent_ndims(HDF5_Filespace);
563
564 // Set sizes and offsets
565 hsize_t ElementCount[Rank];
566 hsize_t Offset [Rank];
567
568 if (Rank == 3)
569 { // 3D dataset
570 ElementCount[0] = Size.Z;
571 ElementCount[1] = Size.Y;
572 ElementCount[2] = Size.X;
573
574 Offset[0] = Position.Z;
575 Offset[1] = Position.Y;
576 Offset[2] = Position.X;
577 }
578 else
579 { // 4D dataset
580 ElementCount[0] = Size.T;
581 ElementCount[1] = Size.Z;
582 ElementCount[2] = Size.Y;
583 ElementCount[3] = Size.X;
584
585 Offset[0] = Position.T;
586 Offset[1] = Position.Z;
587 Offset[2] = Position.Y;
588 Offset[3] = Position.X;
589 }
590
591
592 // select hyperslab
593 status = H5Sselect_hyperslab(HDF5_Filespace,
594 H5S_SELECT_SET,
595 Offset,
596 NULL,
597 ElementCount,
598 NULL);
599 if (status < 0)
600 {
601 char ErrorMessage[256];
602 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
603 throw ios::failure(ErrorMessage);
604 }
605
606 // assign memspace
607 HDF5_Memspace = H5Screate_simple(Rank, ElementCount, NULL);
608
609 status = H5Dwrite(HDF5_Dataset_id, H5T_STD_U64LE, HDF5_Memspace, HDF5_Filespace, H5P_DEFAULT, Data);
610 if (status < 0)
611 {
612 char ErrorMessage[256];
613 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
614 throw ios::failure(ErrorMessage);
615 }
616
617 H5Sclose(HDF5_Memspace);
618 H5Sclose(HDF5_Filespace);
619 }// end of WriteHyperSlab
620 //------------------------------------------------------------------------------
621
622
623 /**
624 * Write a cuboid selected inside MatrixData into a Hyperslab.
625 * The routine writes 3D cuboid into a 4D dataset (only intended for raw time series)
626 * @param [in] HDF5_Dataset_id - Dataset to write MatrixData into
627 * @param [in] HyperslabPosition - Position in the dataset (hyperslab) - may be 3D/4D
628 * @param [in] CuboidPosition - Position of the cuboid in MatrixData (what to sample) - must be 3D
629 * @param [in] CuboidSize - Cuboid size (size of data being sampled) - must by 3D
630 * @param [in] MatrixDimensions - Size of the original matrix (the sampled one)
631 * @param [in] MatrixData - C array of MatrixData
632 */
633 void THDF5_File::WriteCuboidToHyperSlab(const hid_t HDF5_Dataset_id,
634 const TDimensionSizes & HyperslabPosition,
635 const TDimensionSizes & CuboidPosition,
636 const TDimensionSizes & CuboidSize,
637 const TDimensionSizes & MatrixDimensions,
638 const float * MatrixData)
639 {
640 herr_t status;
641 hid_t HDF5_Filespace, HDF5_Memspace;
642
643 const int Rank = 4;
644
645 // Select sizes and positions
646 // The T here is always 1 (only one timestep)
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};
651
652
653 // select hyperslab in the HDF5 dataset
654 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
655 status = H5Sselect_hyperslab(HDF5_Filespace,
656 H5S_SELECT_SET,
657 OffsetInDataset,
658 NULL,
659 SlabSize,
660 NULL);
661 if (status < 0)
662 {
663 char ErrorMessage[256];
664 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
665 throw ios::failure(ErrorMessage);
666 }
667
668
669 // assign memspace and select the cuboid in the sampled matrix
670 HDF5_Memspace = H5Screate_simple(3, MatrixSize, NULL);
671 status = H5Sselect_hyperslab(HDF5_Memspace,
672 H5S_SELECT_SET,
673 OffsetInMatrixData,
674 NULL,
675 SlabSize + 1, // Slab size has to be 3D in this case (done by skipping the T dimension)
676 NULL);
677 if (status < 0)
678 {
679 char ErrorMessage[256];
680 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
681 throw ios::failure(ErrorMessage);
682 }
683
684 // Write the data
685 status = H5Dwrite(HDF5_Dataset_id,
686 H5T_NATIVE_FLOAT,
687 HDF5_Memspace,
688 HDF5_Filespace,
689 H5P_DEFAULT,
690 MatrixData);
691 if (status < 0)
692 {
693 char ErrorMessage[256];
694 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
695 throw ios::failure(ErrorMessage);
696 }
697
698 // close memspace and filespace
699 H5Sclose(HDF5_Memspace);
700 H5Sclose(HDF5_Filespace);
701 }// end of WriteCuboidToHyperSlab
702 //------------------------------------------------------------------------------
703
704 /**
705 * Write sensor data selected by the sensor mask.
706 * The routine picks elements from the MatixData based on the Sensor Data and store
707 * them into a single hyperslab of size [Nsens, 1, 1]
708 * @param [in] HDF5_Dataset_id - Dataset to write MaatrixData into
709 * @param [in] HyperslabPosition - 3D position in the dataset (hyperslab)
710 * @param [in] IndexSensorSize - Size of the index based sensor mask
711 * @param [in] IndexSensorData - Index based sensor mask
712 * @param [in] MatrixDimensions - Size of the sampled matrix
713 * @param [in] MatrixData - Matrix data
714 * @warning - very slow at this version of HDF5 for orthogonal planes-> DO NOT USE
715 */
716 void THDF5_File::WriteSensorByMaskToHyperSlab(const hid_t HDF5_Dataset_id,
717 const TDimensionSizes & HyperslabPosition,
718 const size_t IndexSensorSize,
719 const size_t * IndexSensorData,
720 const TDimensionSizes & MatrixDimensions,
721 const float * MatrixData)
722 {
723 herr_t status;
724 hid_t HDF5_Filespace, HDF5_Memspace;
725
726 const int Rank = 3;
727
728 // Select sizes and positions
729 // Only one timestep
730 hsize_t SlabSize[Rank] = {1, 1, IndexSensorSize};
731 hsize_t OffsetInDataset[Rank] = {HyperslabPosition.Z,
732 HyperslabPosition.Y,
733 HyperslabPosition.X };
734 // treat as a 1D array
735 //hsize_t MatrixSize [] = {MatrixDimensions.Z * MatrixDimensions.Y * MatrixDimensions.X};
736 hsize_t MatrixSize = MatrixDimensions.Z * MatrixDimensions.Y * MatrixDimensions.X;
737
738
739 // select hyperslab in the HDF5 dataset
740 HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
741 status = H5Sselect_hyperslab(HDF5_Filespace,
742 H5S_SELECT_SET,
743 OffsetInDataset,
744 NULL,
745 SlabSize,
746 NULL);
747 if (status < 0)
748 {
749 char ErrorMessage[256];
750 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
751 throw ios::failure(ErrorMessage);
752 }
753
754 // assign 1D memspace and select the elements within the array
755 HDF5_Memspace = H5Screate_simple(1, &MatrixSize, NULL);
756 status = H5Sselect_elements(HDF5_Memspace,
757 H5S_SELECT_SET,
758 IndexSensorSize,
759 ( hsize_t *) (IndexSensorData));
760 if (status < 0)
761 {
762 char ErrorMessage[256];
763 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
764 throw ios::failure(ErrorMessage);
765 }
766
767 // Write the data
768 status = H5Dwrite(HDF5_Dataset_id,
769 H5T_NATIVE_FLOAT,
770 HDF5_Memspace,
771 HDF5_Filespace,
772 H5P_DEFAULT,
773 MatrixData);
774 if (status < 0)
775 {
776 char ErrorMessage[256];
777 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
778 throw ios::failure(ErrorMessage);
779 }
780
781 // close memspace and filespace
782 H5Sclose(HDF5_Memspace);
783 H5Sclose(HDF5_Filespace);
784 }// end of WriteSensorbyMaskToHyperSlab
785 //------------------------------------------------------------------------------
786
787 /**
788 * Write the scalar value at a specified place in the file tree.
789 * (no chunks, no compression)
790 * @param [in] ParentGroup
791 * @param [in] DatasetName
792 * @param [in] Value
793 */
794 void THDF5_File::WriteScalarValue(const hid_t ParentGroup,
795 const char * DatasetName,
796 const float Value)
797 {
798 const int Rank = 3;
799 const hsize_t Dims[] = {1,1,1};
800
801 hid_t Dataset_id = H5I_INVALID_HID;
802 hid_t Dataspace_id = H5I_INVALID_HID;
803 herr_t Status;
804
805 if (H5LTfind_dataset(ParentGroup, DatasetName) == 1)
806 { // dataset already exists (from previous leg) open it
807 Dataset_id = OpenDataset(ParentGroup,
808 DatasetName);
809 }
810 else
811 { // dataset does not exist yet -> create it
812 Dataspace_id = H5Screate_simple (Rank, Dims, NULL);
813 Dataset_id = H5Dcreate(ParentGroup,
814 DatasetName,
815 H5T_NATIVE_FLOAT,
816 Dataspace_id,
817 H5P_DEFAULT,
818 H5P_DEFAULT,
819 H5P_DEFAULT);
820 }
821
822 // was created correctly?
823 if (Dataset_id == H5I_INVALID_HID)
824 {
825 char ErrorMessage[256];
826 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotWriteTo, DatasetName);
827 throw ios::failure(ErrorMessage);
828 }
829
830 Status = H5Dwrite(Dataset_id,
831 H5T_NATIVE_FLOAT,
832 H5S_ALL,
833 H5S_ALL,
834 H5P_DEFAULT,
835 &Value);
836
837 // was written correctly?
838 if (Status < 0)
839 {
840 char ErrorMessage[256];
841 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotWriteTo, DatasetName);
842 throw ios::failure(ErrorMessage);
843 }
844
845 WriteMatrixDataType (ParentGroup, DatasetName, hdf5_mdt_float);
846 WriteMatrixDomainType(ParentGroup, DatasetName, hdf5_mdt_real);
847 } // end of WriteScalarValue (float)
848 //------------------------------------------------------------------------------
849
850 /**
851 * Write a scalar value at a specified place in the file tree.
852 * (no chunks, no compression)
853 * @param [in] ParentGroup
854 * @param [in] DatasetName
855 * @param [in] Value
856 *
857 */
858 void THDF5_File::WriteScalarValue(const hid_t ParentGroup,
859 const char * DatasetName,
860 const size_t Value)
861 {
862 const int Rank = 3;
863 const hsize_t Dims[] = {1,1,1};
864
865 hid_t Dataset_id = H5I_INVALID_HID;
866 hid_t Dataspace_id = H5I_INVALID_HID;
867 herr_t Error;
868
869
870 if (H5LTfind_dataset(ParentGroup, DatasetName) == 1)
871 { // dataset already exists (from previous leg) open it
872 Dataset_id = OpenDataset(ParentGroup,
873 DatasetName);
874 }
875 else
876 { // dataset does not exist yet -> create it
877 Dataspace_id = H5Screate_simple (Rank, Dims, NULL);
878 Dataset_id = H5Dcreate(ParentGroup,
879 DatasetName,
880 H5T_STD_U64LE,
881 Dataspace_id,
882 H5P_DEFAULT,
883 H5P_DEFAULT,
884 H5P_DEFAULT);
885 }
886
887 // was created correctly?
888 if (Dataset_id == H5I_INVALID_HID)
889 {
890 char ErrorMessage[256];
891 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotWriteTo, DatasetName);
892 throw ios::failure(ErrorMessage);
893 }
894
895 Error = H5Dwrite(Dataset_id,
896 H5T_STD_U64LE,
897 H5S_ALL,
898 H5S_ALL,
899 H5P_DEFAULT,
900 &Value);
901
902 // was written correctly?
903 if (Error < 0)
904 {
905 char ErrorMessage[256];
906 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotWriteTo, DatasetName);
907 throw ios::failure(ErrorMessage);
908 }
909
910 WriteMatrixDataType (ParentGroup, DatasetName, hdf5_mdt_long);
911 WriteMatrixDomainType(ParentGroup, DatasetName, hdf5_mdt_real);
912 }// end of WriteScalarValue
913 //------------------------------------------------------------------------------
914
915
916 /**
917 * Read the scalar value under a specified group - float value.
918 * @param[in] ParentGroup
919 * @param[in] DatasetName
920 * @param[out] Value
921 */
922 void THDF5_File::ReadScalarValue(const hid_t ParentGroup,
923 const char * DatasetName,
924 float & Value)
925 {
926 ReadCompleteDataset(ParentGroup, DatasetName, TDimensionSizes(1,1,1), &Value);
927 } // end of ReadScalarValue
928 //------------------------------------------------------------------------------
929
930
931 /**
932 * Read the scalar value under a specified group - index value.
933 * @param[in] ParentGroup
934 * @param[in] DatasetName
935 * @param[out] Value
936 */
937 void THDF5_File::ReadScalarValue(const hid_t ParentGroup,
938 const char * DatasetName,
939 size_t & Value)
940 {
941 ReadCompleteDataset(ParentGroup, DatasetName, TDimensionSizes(1,1,1), &Value);
942 }// end of ReadScalarValue
943 //------------------------------------------------------------------------------
944
945 /**
946 * Read data from the dataset at a specified place in the file tree.
947 *
948 * @param [in] ParentGroup
949 * @param [in] DatasetName
950 * @param [in] DimensionSizes
951 * @param [out] Data
952 * @throw ios::failure
953 */
954 void THDF5_File::ReadCompleteDataset (const hid_t ParentGroup,
955 const char * DatasetName,
956 const TDimensionSizes & DimensionSizes,
957 float * Data)
958 {
959 // Check Dimensions sizes
960 if (GetDatasetDimensionSizes(ParentGroup, DatasetName).GetElementCount() !=
961 DimensionSizes.GetElementCount())
962 {
963 char ErrorMessage[256];
964 sprintf(ErrorMessage, HDF5_ERR_FMT_WrongDimensionSizes, DatasetName);
965 throw ios::failure(ErrorMessage);
966 }
967
968 /* read dataset */
969 herr_t status = H5LTread_dataset_float(ParentGroup, DatasetName, Data);
970 if (status < 0)
971 {
972 char ErrorMessage[256];
973 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotReadFrom, DatasetName);
974 throw ios::failure(ErrorMessage);
975 }
976 }// end of ReadDataset (float)
977 //------------------------------------------------------------------------------
978
979 /**
980 * Read data from the dataset at a specified place in the file tree.
981 *
982 * @param [in] ParentGroup
983 * @param [in] DatasetName
984 * @param [in] DimensionSizes
985 * @param [out] Data
986 * @throw ios::failure
987 */
988 void THDF5_File::ReadCompleteDataset (const hid_t ParentGroup,
989 const char * DatasetName,
990 const TDimensionSizes & DimensionSizes,
991 size_t * Data)
992 {
993 if (GetDatasetDimensionSizes(ParentGroup, DatasetName).GetElementCount() !=
994 DimensionSizes.GetElementCount())
995 {
996 char ErrorMessage[256];
997 sprintf(ErrorMessage, HDF5_ERR_FMT_WrongDimensionSizes, DatasetName);
998 throw ios::failure(ErrorMessage);
999 }
1000
1001 /* read dataset */
1002 herr_t status = H5LTread_dataset(ParentGroup,
1003 DatasetName,
1004 H5T_STD_U64LE,
1005 Data);
1006 if (status < 0)
1007 {
1008 char ErrorMessage[256];
1009 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotReadFrom, DatasetName);
1010 throw ios::failure(ErrorMessage);
1011 }
1012 }// end of ReadCompleteDataset
1013 //------------------------------------------------------------------------------
1014
1015
1016 /**
1017 * Get dimension sizes of the dataset at a specified place in the file tree.
1018 *
1019 * @param [in] ParentGroup
1020 * @param [in] DatasetName
1021 * @return DimensionSizes
1022 * @throw ios::failure
1023 */
1024 TDimensionSizes THDF5_File::GetDatasetDimensionSizes(const hid_t ParentGroup,
1025 const char * DatasetName)
1026 {
1027 const size_t NoDims = GetDatasetNumberOfDimensions(ParentGroup, DatasetName);
1028 hsize_t Dims[NoDims];
1029
1030 for (size_t i = 0; i < NoDims; i++) Dims[i] = 0;
1031
1032 herr_t status = H5LTget_dataset_info(ParentGroup,
1033 DatasetName,
1034 Dims,
1035 NULL,
1036 NULL);
1037 if (status < 0)
1038 {
1039 char ErrorMessage[256];
1040 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotReadFrom, DatasetName);
1041 throw ios::failure(ErrorMessage);
1042 }
1043
1044 if (NoDims == 3)
1045 {
1046 return TDimensionSizes(Dims[2], Dims[1], Dims[0]);
1047 }
1048 else
1049 {
1050 return TDimensionSizes(Dims[3], Dims[2], Dims[1], Dims[0]);
1051 }
1052 }// end of GetDatasetDimensionSizes
1053 //------------------------------------------------------------------------------
1054
1055 /**
1056 * Get number of dimensions of the dataset under a specified group.
1057 * @param [in] ParentGroup
1058 * @param [in] DatasetName
1059 * @return - Number of dimensions
1060 */
1061 size_t THDF5_File::GetDatasetNumberOfDimensions(const hid_t ParentGroup,
1062 const char * DatasetName)
1063 {
1064 int NoDims = 0;
1065
1066 herr_t status = H5LTget_dataset_ndims(ParentGroup, DatasetName, &NoDims);
1067 if (status < 0)
1068 {
1069 char ErrorMessage[256];
1070 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotReadFrom, DatasetName);
1071 throw ios::failure(ErrorMessage);
1072 }
1073
1074 return NoDims;
1075 }// end of GetDatasetNumberOfDimensions
1076 //------------------------------------------------------------------------------
1077
1078
1079 /**
1080 * Get dataset element count at a specified place in the file tree.
1081 *
1082 * @param [in] ParentGroup
1083 * @param [in] DatasetName
1084 * @return Number of elements
1085 * @throw ios::failure
1086 */
1087 size_t THDF5_File::GetDatasetElementCount(const hid_t ParentGroup,
1088 const char * DatasetName)
1089 {
1090 hsize_t Dims[3] = {0, 0, 0};
1091
1092 herr_t status = H5LTget_dataset_info(ParentGroup,
1093 DatasetName,
1094 Dims,
1095 NULL,
1096 NULL);
1097 if (status < 0)
1098 {
1099 char ErrorMessage[256];
1100 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotReadFrom, DatasetName);
1101 throw ios::failure(ErrorMessage);
1102 }
1103
1104 return Dims[0] * Dims[1] * Dims[2];
1105 }// end of GetDatasetElementCount
1106 //-----------------------------------------------------------------------------
1107
1108
1109 /**
1110 * Write matrix data type into the dataset at a specified place in the file tree.
1111 *
1112 * @param [in] ParentGroup
1113 * @param [in] DatasetName
1114 * @param [in] MatrixDataType
1115 */
1116 void THDF5_File::WriteMatrixDataType(const hid_t ParentGroup,
1117 const char * DatasetName,
1118 const THDF5_MatrixDataType & MatrixDataType)
1119 {
1120 WriteStringAttribute(ParentGroup,
1121 DatasetName,
1122 HDF5_MatrixDataTypeName,
1123 HDF5_MatrixDataTypeNames[MatrixDataType]);
1124 }// end of WriteMatrixDataType
1125 //------------------------------------------------------------------------------
1126
1127
1128 /**
1129 * Write matrix data type into the dataset at a specified place in the file tree.
1130 *
1131 * @param [in] ParentGroup
1132 * @param [in] DatasetName
1133 * @param [in] MatrixDomainType
1134 */
1135 void THDF5_File::WriteMatrixDomainType(const hid_t ParentGroup,
1136 const char * DatasetName,
1137 const THDF5_MatrixDomainType & MatrixDomainType)
1138 {
1139 WriteStringAttribute(ParentGroup,
1140 DatasetName,
1141 HDF5_MatrixDomainTypeName,
1142 HDF5_MatrixDomainTypeNames[MatrixDomainType]);
1143 }// end of WriteMatrixDomainType
1144 //------------------------------------------------------------------------------
1145
1146
1147 /**
1148 * Read matrix data type from the dataset at a specified place in the file tree.
1149 *
1150 * @param [in] ParentGroup
1151 * @param [in] DatasetName
1152 * @return MatrixDataType
1153 * @throw ios::failure
1154 */
1155 THDF5_File::THDF5_MatrixDataType THDF5_File::ReadMatrixDataType(const hid_t ParentGroup,
1156 const char * DatasetName)
1157 {
1158 string ParamValue;
1159
1160 ParamValue = ReadStringAttribute(ParentGroup, DatasetName, HDF5_MatrixDataTypeName);
1161
1162 if (ParamValue == HDF5_MatrixDataTypeNames[0])
1163 {
1164 return static_cast<THDF5_MatrixDataType>(0);
1165 }
1166 if (ParamValue == HDF5_MatrixDataTypeNames[1])
1167 {
1168 return static_cast<THDF5_MatrixDataType>(1);
1169 }
1170
1171 char ErrorMessage[256];
1172 sprintf(ErrorMessage, HDF5_ERR_FMT_BadAttributeValue, DatasetName,
1173 HDF5_MatrixDataTypeName, ParamValue.c_str());
1174 throw ios::failure(ErrorMessage);
1175
1176 // this will never be executed (just to prevent warning)
1177 return static_cast<THDF5_MatrixDataType> (0);
1178 }// end of ReadMatrixDataType
1179 //------------------------------------------------------------------------------
1180
1181
1182 /**
1183 * Read matrix dataset domain type at a specified place in the file tree.
1184 *
1185 * @param [in] ParentGroup
1186 * @param [in] DatasetName
1187 * @return DomainType
1188 * @throw ios::failure
1189 */
1190 THDF5_File::THDF5_MatrixDomainType THDF5_File::ReadMatrixDomainType(const hid_t ParentGroup,
1191 const char * DatasetName)
1192 {
1193 string ParamValue;
1194
1195 ParamValue = ReadStringAttribute(ParentGroup, DatasetName, HDF5_MatrixDomainTypeName);
1196
1197 if (ParamValue == HDF5_MatrixDomainTypeNames[0])
1198 {
1199 return static_cast<THDF5_MatrixDomainType> (0);
1200 }
1201 if (ParamValue == HDF5_MatrixDomainTypeNames[1])
1202 {
1203 return static_cast<THDF5_MatrixDomainType> (1);
1204 }
1205
1206 char ErrorMessage[256];
1207 sprintf(ErrorMessage, HDF5_ERR_FMT_BadAttributeValue, DatasetName, HDF5_MatrixDomainTypeName, ParamValue.c_str());
1208 throw ios::failure(ErrorMessage);
1209
1210 // This line will never be executed (just to prevent warning)
1211 return static_cast<THDF5_MatrixDomainType> (0);
1212 }// end of ReadMatrixDomainType
1213 //------------------------------------------------------------------------------
1214
1215
1216 /**
1217 * Write integer attribute at a specified place in the file tree.
1218 *
1219 * @param [in] ParentGroup
1220 * @param [in] DatasetName
1221 * @param [in] AttributeName
1222 * @param [in] Value
1223 * @throw ios::failure
1224 */
1225 inline void THDF5_File::WriteStringAttribute(const hid_t ParentGroup,
1226 const char * DatasetName,
1227 const char * AttributeName,
1228 const string & Value)
1229 {
1230 herr_t Status = H5LTset_attribute_string(ParentGroup,
1231 DatasetName,
1232 AttributeName,
1233 Value.c_str());
1234 if (Status < 0)
1235 {
1236 char ErrorMessage[256];
1237 sprintf(ErrorMessage, HDF5_ERR_FMT_CouldNotWriteToAttribute, AttributeName, DatasetName);
1238 throw ios::failure(ErrorMessage);
1239 }
1240 }// end of WriteIntAttribute
1241 //------------------------------------------------------------------------------
1242
1243
1244
1245 /**
1246 * Read integer attribute at a specified place in the file tree.
1247 *
1248 * @param [in] ParentGroup
1249 * @param [in] DatasetName
1250 * @param [in] AttributeName
1251 * @return Attribute value
1252 * @throw ios::failure
1253 */
1254 inline string THDF5_File::ReadStringAttribute(const hid_t ParentGroup,
1255 const char * DatasetName,
1256 const char * AttributeName)
1257 {
1258 char Value[256] = "";
1259 herr_t Status = H5LTget_attribute_string(ParentGroup,
1260 DatasetName,
1261 AttributeName,
1262 Value);
1263 if (Status < 0)
1264 {
1265 char ErrorMessage[256];
1266 sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotReadFromAttribute,AttributeName, DatasetName);
1267 throw ios::failure(ErrorMessage);
1268 }
1269
1270 return Value;
1271 }// end of ReadIntAttribute
1272 //------------------------------------------------------------------------------
1273
1274
1275 //----------------------------------------------------------------------------//
1276 //---------------------------- THDF5_File ------------------------------//
1277 //---------------------------- Protected ------------------------------//
1278 //----------------------------------------------------------------------------//
1279
1280
1281
1282
1283
1284
1285
1286
1287 //----------------------------------------------------------------------------//
1288 //------------------------ THDF5_File_Header ------------------------------//
1289 //----------------------------- Public --------------------------------//
1290 //----------------------------------------------------------------------------//
1291
1292 /**
1293 * Constructor.
1294 */
1295 THDF5_FileHeader::THDF5_FileHeader()
1296 {
1297 HDF5_FileHeaderValues.clear();
1298 PopulateHeaderFileMap();
1299 }// end of constructor
1300 //------------------------------------------------------------------------------
1301
1302
1303 /**
1304 * Copy constructor.
1305 * @param [in] other
1306 */
1307 THDF5_FileHeader::THDF5_FileHeader(const THDF5_FileHeader & other)
1308 {
1309 HDF5_FileHeaderValues = other.HDF5_FileHeaderValues;
1310 HDF5_FileHeaderNames = other.HDF5_FileHeaderNames;
1311 }// end of copy constructor
1312 //------------------------------------------------------------------------------
1313
1314
1315 /**
1316 * Destructor.
1317 *
1318 */
1319 THDF5_FileHeader::~THDF5_FileHeader()
1320 {
1321 HDF5_FileHeaderValues.clear();
1322 HDF5_FileHeaderNames.clear();
1323 }// end of destructor
1324 //------------------------------------------------------------------------------
1325
1326
1327
1328 /**
1329 * Read header from the input file.
1330 * @param [in] InputFile - Input file to read from
1331 */
1332 void THDF5_FileHeader::ReadHeaderFromInputFile(THDF5_File & InputFile)
1333 {
1334 // Get file root handle
1335 hid_t FileRootHandle = InputFile.GetRootGroup();
1336 // read file type
1337 HDF5_FileHeaderValues[hdf5_fhi_file_type] =
1338 InputFile.ReadStringAttribute(FileRootHandle,"/",
1339 HDF5_FileHeaderNames[hdf5_fhi_file_type].c_str());
1340
1341 if (GetFileType() == hdf5_ft_input)
1342 {
1343 HDF5_FileHeaderValues[hdf5_fhi_created_by]
1344 = InputFile.ReadStringAttribute(FileRootHandle, "/",
1345 HDF5_FileHeaderNames[hdf5_fhi_created_by].c_str());
1346 HDF5_FileHeaderValues[hdf5_fhi_creation_date]
1347 = InputFile.ReadStringAttribute(FileRootHandle, "/",
1348 HDF5_FileHeaderNames[hdf5_fhi_creation_date].c_str());
1349 HDF5_FileHeaderValues[hdf5_fhi_file_description]
1350 = InputFile.ReadStringAttribute(FileRootHandle, "/",
1351 HDF5_FileHeaderNames[hdf5_fhi_file_description].c_str());
1352 HDF5_FileHeaderValues[hdf5_fhi_major_version]
1353 = InputFile.ReadStringAttribute(FileRootHandle, "/",
1354 HDF5_FileHeaderNames[hdf5_fhi_major_version].c_str());
1355 HDF5_FileHeaderValues[hdf5_fhi_minor_version]
1356 = InputFile.ReadStringAttribute(FileRootHandle, "/",
1357 HDF5_FileHeaderNames[hdf5_fhi_minor_version].c_str());
1358 }
1359 else
1360 {
1361 throw ios::failure(HDF5_ERR_FMT_BadInputFileType);
1362 }
1363 }// end of ReadHeaderFromInputFile
1364 //------------------------------------------------------------------------------
1365
1366
1367 /**
1368 * Read header from output file (necessary for checkpoint-restart).
1369 * Read only execution times (the others are read from the input file, or
1370 * calculated based on the very last leg of the simulation).
1371 * This function is called only if checkpoint-restart is enabled.
1372 * @param [in] OutputFile
1373 */
1374 void THDF5_FileHeader::ReadHeaderFromOutputFile(THDF5_File & OutputFile)
1375 {
1376 // Get file root handle
1377 hid_t FileRootHandle = OutputFile.GetRootGroup();
1378
1379 HDF5_FileHeaderValues[hdf5_fhi_file_type]
1380 = OutputFile.ReadStringAttribute(FileRootHandle, "/",
1381 HDF5_FileHeaderNames[hdf5_fhi_file_type].c_str());
1382
1383 if (GetFileType() == hdf5_ft_output)
1384 {
1385 HDF5_FileHeaderValues[hdf5_fhi_total_execution_time]
1386 = OutputFile.ReadStringAttribute(FileRootHandle, "/",
1387 HDF5_FileHeaderNames[hdf5_fhi_total_execution_time].c_str());
1388 HDF5_FileHeaderValues[hdf5_fhi_data_load_time]
1389 = OutputFile.ReadStringAttribute(FileRootHandle, "/",
1390 HDF5_FileHeaderNames[hdf5_fhi_data_load_time].c_str());
1391 HDF5_FileHeaderValues[hdf5_fhi_preprocessing_time]
1392 = OutputFile.ReadStringAttribute(FileRootHandle, "/",
1393 HDF5_FileHeaderNames[hdf5_fhi_preprocessing_time].c_str());
1394 HDF5_FileHeaderValues[hdf5_fhi_simulation_time]
1395 = OutputFile.ReadStringAttribute(FileRootHandle, "/",
1396 HDF5_FileHeaderNames[hdf5_fhi_simulation_time].c_str());
1397 HDF5_FileHeaderValues[hdf5_fhi_postprocessing_time]
1398 = OutputFile.ReadStringAttribute(FileRootHandle, "/",
1399 HDF5_FileHeaderNames[hdf5_fhi_postprocessing_time].c_str());
1400 }
1401 else
1402 {
1403 throw ios::failure(HDF5_ERR_FMT_BadOutputFileType);
1404 }
1405 }// end of ReadHeaderFromOutputFile
1406 //------------------------------------------------------------------------------
1407
1408 /**
1409 * Read the file header form the checkpoint file. We need the header to verify
1410 * the file version and type
1411 * @param [in] CheckpointFile
1412 */
1413 void THDF5_FileHeader::ReadHeaderFromCheckpointFile(THDF5_File & CheckpointFile)
1414 {
1415 // Get file root handle
1416 hid_t FileRootHandle = CheckpointFile.GetRootGroup();
1417 // read file type
1418 HDF5_FileHeaderValues[hdf5_fhi_file_type] =
1419 CheckpointFile.ReadStringAttribute(FileRootHandle,"/",
1420 HDF5_FileHeaderNames[hdf5_fhi_file_type].c_str());
1421
1422 if (GetFileType() == hdf5_ft_checkpoint)
1423 {
1424 HDF5_FileHeaderValues[hdf5_fhi_created_by]
1425 = CheckpointFile.ReadStringAttribute(FileRootHandle, "/",
1426 HDF5_FileHeaderNames[hdf5_fhi_created_by].c_str());
1427 HDF5_FileHeaderValues[hdf5_fhi_creation_date]
1428 = CheckpointFile.ReadStringAttribute(FileRootHandle, "/",
1429 HDF5_FileHeaderNames[hdf5_fhi_creation_date].c_str());
1430 HDF5_FileHeaderValues[hdf5_fhi_file_description]
1431 = CheckpointFile.ReadStringAttribute(FileRootHandle, "/",
1432 HDF5_FileHeaderNames[hdf5_fhi_file_description].c_str());
1433 HDF5_FileHeaderValues[hdf5_fhi_major_version]
1434 = CheckpointFile.ReadStringAttribute(FileRootHandle, "/",
1435 HDF5_FileHeaderNames[hdf5_fhi_major_version].c_str());
1436 HDF5_FileHeaderValues[hdf5_fhi_minor_version]
1437 = CheckpointFile.ReadStringAttribute(FileRootHandle, "/",
1438 HDF5_FileHeaderNames[hdf5_fhi_minor_version].c_str());
1439 }
1440 else
1441 {
1442 throw ios::failure(HDF5_ERR_FMT_BadCheckpointFileType);
1443 }
1444 }// end of ReadHeaderFromCheckpointFile
1445 //------------------------------------------------------------------------------
1446
1447 /**
1448 * Write header into the output file.
1449 * @param [in] OutputFile
1450 */
1451 void THDF5_FileHeader::WriteHeaderToOutputFile(THDF5_File & OutputFile)
1452 {
1453 // Get file root handle
1454 hid_t FileRootHandle = OutputFile.GetRootGroup();
1455
1456 for (map<THDF5_FileHeaderItems, string>::iterator it = HDF5_FileHeaderNames.begin();
1457 it != HDF5_FileHeaderNames.end();
1458 it++)
1459 {
1460 OutputFile.WriteStringAttribute(FileRootHandle,
1461 "/",
1462 it->second.c_str(),
1463 HDF5_FileHeaderValues[it->first]);
1464 }
1465 }// end of WriteHeaderToOutputFile
1466 //------------------------------------------------------------------------------
1467
1468
1469 /**
1470 * Write header to the output file (only a subset of all possible fields are written).
1471 * @param [in] CheckpointFile
1472 */
1473 void THDF5_FileHeader::WriteHeaderToCheckpointFile(THDF5_File & CheckpointFile)
1474 {
1475 // Get file root handle
1476 hid_t FileRootHandle = CheckpointFile.GetRootGroup();
1477
1478 // Write header
1479 CheckpointFile.WriteStringAttribute(FileRootHandle,
1480 "/",
1481 HDF5_FileHeaderNames [hdf5_fhi_file_type].c_str(),
1482 HDF5_FileHeaderValues[hdf5_fhi_file_type].c_str());
1483
1484 CheckpointFile.WriteStringAttribute(FileRootHandle,
1485 "/",
1486 HDF5_FileHeaderNames [hdf5_fhi_created_by].c_str(),
1487 HDF5_FileHeaderValues[hdf5_fhi_created_by].c_str());
1488
1489 CheckpointFile.WriteStringAttribute(FileRootHandle,
1490 "/",
1491 HDF5_FileHeaderNames [hdf5_fhi_creation_date].c_str(),
1492 HDF5_FileHeaderValues[hdf5_fhi_creation_date].c_str());
1493
1494 CheckpointFile.WriteStringAttribute(FileRootHandle,
1495 "/",
1496 HDF5_FileHeaderNames [hdf5_fhi_file_description].c_str(),
1497 HDF5_FileHeaderValues[hdf5_fhi_file_description].c_str());
1498
1499 CheckpointFile.WriteStringAttribute(FileRootHandle, "/",
1500 HDF5_FileHeaderNames [hdf5_fhi_major_version].c_str(),
1501 HDF5_FileHeaderValues[hdf5_fhi_major_version].c_str());
1502
1503 CheckpointFile.WriteStringAttribute(FileRootHandle,
1504 "/",
1505 HDF5_FileHeaderNames [hdf5_fhi_minor_version].c_str(),
1506 HDF5_FileHeaderValues[hdf5_fhi_minor_version].c_str());
1507 }// end of WriteHeaderToCheckpointFile
1508 //------------------------------------------------------------------------------
1509
1510 /**
1511 * Get File type.
1512 * @return FileType
1513 */
1514 THDF5_FileHeader::THDF5_FileType THDF5_FileHeader::GetFileType()
1515 {
1516 for (int i = hdf5_ft_input; i < hdf5_ft_unknown ; i++)
1517 {
1518 if (HDF5_FileHeaderValues[hdf5_fhi_file_type] == HDF5_FileTypesNames[static_cast<THDF5_FileType >(i)])
1519 {
1520 return static_cast<THDF5_FileType >(i);
1521 }
1522 }
1523
1524 return THDF5_FileHeader::hdf5_ft_unknown;
1525 }// end of GetFileType
1526 //------------------------------------------------------------------------------
1527
1528 /**
1529 * Set file type.
1530 * @param [in] FileType
1531 */
1532 void THDF5_FileHeader::SetFileType(const THDF5_FileHeader::THDF5_FileType FileType)
1533 {
1534 HDF5_FileHeaderValues[hdf5_fhi_file_type] = HDF5_FileTypesNames[FileType];
1535 }// end of SetFileType
1536 //------------------------------------------------------------------------------
1537
1538
1539 /**
1540 * Get File Version an enum
1541 * @return file version as an enum
1542 */
1543 THDF5_FileHeader::THDF5_FileVersion THDF5_FileHeader::GetFileVersion()
1544 {
1545 if ((HDF5_FileHeaderValues[hdf5_fhi_major_version] == HDF5_MajorFileVersionsNames[0]) &&
1546 (HDF5_FileHeaderValues[hdf5_fhi_minor_version] == HDF5_MinorFileVersionsNames[0]))
1547 {
1548 return hdf5_fv_10;
1549 }
1550
1551 if ((HDF5_FileHeaderValues[hdf5_fhi_major_version] == HDF5_MajorFileVersionsNames[0]) &&
1552 (HDF5_FileHeaderValues[hdf5_fhi_minor_version] == HDF5_MinorFileVersionsNames[1]))
1553 {
1554 return hdf5_fv_11;
1555 }
1556
1557 return hdf5_fv_unknown;
1558 }// end of GetFileVersion
1559 //------------------------------------------------------------------------------
1560
1561 /**
1562 * Set actual date and time.
1563 *
1564 */
1565 void THDF5_FileHeader::SetActualCreationTime()
1566 {
1567 struct tm *current;
1568 time_t now;
1569 time(&now);
1570 current = localtime(&now);
1571
1572 char DateString[20];
1573
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);
1577
1578 HDF5_FileHeaderValues[hdf5_fhi_creation_date] = DateString;
1579 }// end of SetCreationTime
1580 //------------------------------------------------------------------------------
1581
1582 /**
1583 * Set Host name.
1584 *
1585 */
1586 void THDF5_FileHeader::SetHostName()
1587 {
1588 char HostName[256];
1589
1590 //Linux build
1591 #ifdef __linux__
1592 gethostname(HostName, 256);
1593 #endif
1594
1595 //Windows build
1596 #ifdef _WIN64
1597 WSADATA wsaData;
1598 WSAStartup(MAKEWORD(2, 2), &wsaData);
1599 gethostname(HostName, 256);
1600
1601 WSACleanup();
1602 #endif
1603
1604 HDF5_FileHeaderValues[hdf5_fhi_host_name] = HostName;
1605 }// end of SetHostName
1606 //------------------------------------------------------------------------------
1607
1608
1609 /**
1610 * Set memory consumption.
1611 * @param [in] TotalMemory
1612 */
1613 void THDF5_FileHeader::SetMemoryConsumption(size_t TotalMemory)
1614 {
1615 char Text[20] = "";
1616 sprintf(Text, "%ld MB",TotalMemory);
1617
1618 HDF5_FileHeaderValues[hdf5_fhi_total_memory_consumption] = Text;
1619
1620 sprintf(Text, "%ld MB",TotalMemory / TParameters::GetInstance()->GetNumberOfThreads());
1621 HDF5_FileHeaderValues[hdf5_fhi_peak_core_memory_consumption] = Text;
1622 }// end of SetMemoryConsumption
1623 //------------------------------------------------------------------------------
1624
1625
1626 /**
1627 * Set execution times in file header.
1628 * @param [in] TotalTime
1629 * @param [in] LoadTime
1630 * @param [in] PreProcessingTime
1631 * @param [in] SimulationTime
1632 * @param [in] PostprocessingTime
1633 */
1634 void THDF5_FileHeader::SetExecutionTimes(const double TotalTime,
1635 const double LoadTime,
1636 const double PreProcessingTime,
1637 const double SimulationTime,
1638 const double PostprocessingTime)
1639 {
1640 char Text [30] = "";
1641
1642 sprintf(Text,"%8.2fs", TotalTime);
1643 HDF5_FileHeaderValues[hdf5_fhi_total_execution_time] = Text;
1644
1645 sprintf(Text,"%8.2fs", LoadTime);
1646 HDF5_FileHeaderValues[hdf5_fhi_data_load_time] = Text;
1647
1648 sprintf(Text,"%8.2fs", PreProcessingTime);
1649 HDF5_FileHeaderValues[hdf5_fhi_preprocessing_time] = Text;
1650
1651
1652 sprintf(Text,"%8.2fs", SimulationTime);
1653 HDF5_FileHeaderValues[hdf5_fhi_simulation_time] = Text;
1654
1655 sprintf(Text,"%8.2fs", PostprocessingTime);
1656 HDF5_FileHeaderValues[hdf5_fhi_postprocessing_time] = Text;
1657 }// end of SetExecutionTimes
1658 //------------------------------------------------------------------------------
1659
1660 /**
1661 * Get execution times stored in the output file header
1662 * @param [out] TotalTime
1663 * @param [out] LoadTime
1664 * @param [out] PreProcessingTime
1665 * @param [out] SimulationTime
1666 * @param [out] PostprocessingTime
1667 */
1668 void THDF5_FileHeader::GetExecutionTimes(double& TotalTime,
1669 double& LoadTime,
1670 double& PreProcessingTime,
1671 double& SimulationTime,
1672 double& PostprocessingTime)
1673 {
1674 TotalTime = atof(HDF5_FileHeaderValues[hdf5_fhi_total_execution_time].c_str());
1675 LoadTime = atof(HDF5_FileHeaderValues[hdf5_fhi_data_load_time].c_str());
1676 PreProcessingTime = atof(HDF5_FileHeaderValues[hdf5_fhi_preprocessing_time].c_str());
1677 SimulationTime = atof(HDF5_FileHeaderValues[hdf5_fhi_simulation_time].c_str());
1678 PostprocessingTime = atof(HDF5_FileHeaderValues[hdf5_fhi_postprocessing_time].c_str());
1679 }// end of GetExecutionTimes
1680 //------------------------------------------------------------------------------
1681
1682 /**
1683 * Set Number of cores.
1684 *
1685 */
1686 void THDF5_FileHeader::SetNumberOfCores()
1687 {
1688 char Text[12] = "";
1689 sprintf(Text, "%ld",TParameters::GetInstance()->GetNumberOfThreads());
1690
1691 HDF5_FileHeaderValues[hdf5_fhi_number_of_cores] = Text;
1692 }// end of SetNumberOfCores
1693 //------------------------------------------------------------------------------
1694
1695 //----------------------------------------------------------------------------//
1696 //------------------------ THDF5_File_Header ------------------------------//
1697 //--------------------------- Protected --------------------------------//
1698 //----------------------------------------------------------------------------//
1699
1700
1701 /**
1702 * Create map with names for the header.
1703 *
1704 */
1705 void THDF5_FileHeader::PopulateHeaderFileMap()
1706 {
1707 HDF5_FileHeaderNames.clear();
1708
1709 HDF5_FileHeaderNames[hdf5_fhi_created_by] = "created_by";
1710 HDF5_FileHeaderNames[hdf5_fhi_creation_date] = "creation_date";
1711 HDF5_FileHeaderNames[hdf5_fhi_file_description] = "file_description";
1712 HDF5_FileHeaderNames[hdf5_fhi_major_version] = "major_version";
1713 HDF5_FileHeaderNames[hdf5_fhi_minor_version] = "minor_version";
1714 HDF5_FileHeaderNames[hdf5_fhi_file_type] = "file_type";
1715
1716 HDF5_FileHeaderNames[hdf5_fhi_host_name] = "host_names";
1717 HDF5_FileHeaderNames[hdf5_fhi_number_of_cores] = "number_of_cpu_cores" ;
1718 HDF5_FileHeaderNames[hdf5_fhi_total_memory_consumption] = "total_memory_in_use";
1719 HDF5_FileHeaderNames[hdf5_fhi_peak_core_memory_consumption] = "peak_core_memory_in_use";
1720
1721 HDF5_FileHeaderNames[hdf5_fhi_total_execution_time] = "total_execution_time";
1722 HDF5_FileHeaderNames[hdf5_fhi_data_load_time] = "data_loading_phase_execution_time";
1723 HDF5_FileHeaderNames[hdf5_fhi_preprocessing_time] = "pre-processing_phase_execution_time";
1724 HDF5_FileHeaderNames[hdf5_fhi_simulation_time] = "simulation_phase_execution_time";
1725 HDF5_FileHeaderNames[hdf5_fhi_postprocessing_time] = "post-processing_phase_execution_time";
1726 }// end of PopulateHeaderFileMap
1727 //------------------------------------------------------------------------------
THDF5_FileHeader
Class for HDF5 header.
Definition: HDF5_File.h:749
TDimensionSizes::Z
size_t Z
Z dimension size.
Definition: DimensionSizes.h:70
THDF5_FileHeader::HDF5_FileHeaderValues
map< THDF5_FileHeaderItems, string > HDF5_FileHeaderValues
map for the header values.
Definition: HDF5_File.h:907
THDF5_File::CreateGroup
hid_t CreateGroup(const hid_t ParentGroup, const char *GroupName)
Create a HDF5 group at a specified place in the file tree.
Definition: HDF5_File.cpp:201
THDF5_File::FileName
string FileName
File name.
Definition: HDF5_File.h:735
THDF5_File::ReadMatrixDataType
THDF5_File::THDF5_MatrixDataType ReadMatrixDataType(const hid_t ParentGroup, const char *DatasetName)
Read matrix data type from the dataset.
Definition: HDF5_File.cpp:1155
HDF5_ERR_FMT_GroupNotOpened
const char *const HDF5_ERR_FMT_GroupNotOpened
HDF5 error message.
Definition: ErrorMessages.h:70
THDF5_File::HDF5_MatrixDomainTypeName
static const char * HDF5_MatrixDomainTypeName
String representation of the Domain type in the HDF5 file.
Definition: HDF5_File.h:723
THDF5_FileHeader::THDF5_FileHeader
THDF5_FileHeader()
Constructor.
Definition: HDF5_File.cpp:1295
THDF5_File::WriteStringAttribute
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.
Definition: HDF5_File.cpp:1225
THDF5_File::WriteScalarValue
void WriteScalarValue(const hid_t ParentGroup, const char *DatasetName, const float Value)
Write the scalar value under a specified group - float value.
Definition: HDF5_File.cpp:794
THDF5_File::OpenGroup
hid_t OpenGroup(const hid_t ParentGroup, const char *GroupName)
Open a HDF5 group at a specified place in the file tree.
Definition: HDF5_File.cpp:229
THDF5_FileHeader::WriteHeaderToOutputFile
void WriteHeaderToOutputFile(THDF5_File &OutputFile)
Write header to the output file.
Definition: HDF5_File.cpp:1451
HDF5_ERR_FMT_DatasetNotOpened
const char *const HDF5_ERR_FMT_DatasetNotOpened
HDF5 error message.
Definition: ErrorMessages.h:58
HDF5_ERR_FMT_CouldNotReadFrom
const char *const HDF5_ERR_FMT_CouldNotReadFrom
HDF5 error message.
Definition: ErrorMessages.h:50
THDF5_FileHeader::HDF5_MajorFileVersionsNames
static const string HDF5_MajorFileVersionsNames[]
String representations of Major file versions.
Definition: HDF5_File.h:914
HDF5_ERR_FMT_FileNotClosed
const char *const HDF5_ERR_FMT_FileNotClosed
HDF5 error message.
Definition: ErrorMessages.h:46
THDF5_File::WriteCuboidToHyperSlab
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.
Definition: HDF5_File.cpp:633
THDF5_FileHeader::THDF5_FileVersion
THDF5_FileVersion
HDF5 file version.
Definition: HDF5_File.h:787
THDF5_File::IsOpened
bool IsOpened() const
Is the file opened?
Definition: HDF5_File.h:539
THDF5_FileHeader::GetFileType
THDF5_FileHeader::THDF5_FileType GetFileType()
Get File type.
Definition: HDF5_File.cpp:1514
THDF5_File::ReadScalarValue
void ReadScalarValue(const hid_t ParentGroup, const char *DatasetName, float &Value)
Read the scalar value under a specified group - float value.
Definition: HDF5_File.cpp:922
THDF5_FileHeader::THDF5_FileType
THDF5_FileType
HDF5 file type.
Definition: HDF5_File.h:778
HDF5_ERR_FMT_NotHDF5File
const char *const HDF5_ERR_FMT_NotHDF5File
HDF5 error message.
Definition: ErrorMessages.h:56
HDF5_ERR_FMT_BadCheckpointFileType
const char *const HDF5_ERR_FMT_BadCheckpointFileType
HDF5 error message.
Definition: ErrorMessages.h:76
THDF5_File::WriteSensorByMaskToHyperSlab
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! ...
Definition: HDF5_File.cpp:716
THDF5_File::Close
void Close()
Close file.
Definition: HDF5_File.cpp:169
HDF5_File.h
The header file containing the HDF5 related classes.
TDimensionSizes::X
size_t X
X dimension size.
Definition: DimensionSizes.h:66
Parameters.h
The header file containing the parameters of the simulation.
THDF5_File::GetDatasetDimensionSizes
TDimensionSizes GetDatasetDimensionSizes(const hid_t ParentGroup, const char *DatasetName)
Get dimension sizes of the dataset under a specified group.
Definition: HDF5_File.cpp:1024
THDF5_FileHeader::PopulateHeaderFileMap
void PopulateHeaderFileMap()
Populate the map with the header items.
Definition: HDF5_File.cpp:1705
THDF5_File::GetDatasetElementCount
size_t GetDatasetElementCount(const hid_t ParentGroup, const char *DatasetName)
Get dataset element count under a specified group.
Definition: HDF5_File.cpp:1087
HDF5_ERR_FMT_BadOutputFileType
const char *const HDF5_ERR_FMT_BadOutputFileType
HDF5 error message.
Definition: ErrorMessages.h:74
THDF5_File::WriteHyperSlab
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.
Definition: HDF5_File.cpp:467
THDF5_FileHeader::SetExecutionTimes
void SetExecutionTimes(const double TotalTime, const double LoadTime, const double PreProcessingTime, const double SimulationTime, const double PostprocessingTime)
Set execution times.
Definition: HDF5_File.cpp:1634
THDF5_FileHeader::HDF5_FileTypesNames
static const string HDF5_FileTypesNames[]
String representation of different file types.
Definition: HDF5_File.h:912
THDF5_File::HDF5_MatrixDataTypeName
static const char * HDF5_MatrixDataTypeName
String representation of the Data type in the HDF5 file.
Definition: HDF5_File.h:725
THDF5_File::THDF5_File
THDF5_File()
Constructor of the class.
Definition: HDF5_File.cpp:88
THDF5_FileHeader::SetHostName
void SetHostName()
Set host name.
Definition: HDF5_File.cpp:1586
THDF5_File::HDF5_FileId
hid_t HDF5_FileId
HDF file handle.
Definition: HDF5_File.h:733
THDF5_File::WriteMatrixDataType
void WriteMatrixDataType(const hid_t ParentGroup, const char *DatasetName, const THDF5_MatrixDataType &MatrixDataType)
Write matrix data type into the dataset under a specified group.
Definition: HDF5_File.cpp:1116
THDF5_FileHeader::ReadHeaderFromCheckpointFile
void ReadHeaderFromCheckpointFile(THDF5_File &CheckpointFile)
Read Header from checkpoint file (necessary for checkpoint-restart).
Definition: HDF5_File.cpp:1413
THDF5_FileHeader::ReadHeaderFromOutputFile
void ReadHeaderFromOutputFile(THDF5_File &OutputFile)
Read Header from output file (necessary for checkpoint-restart).
Definition: HDF5_File.cpp:1374
THDF5_File::WriteMatrixDomainType
void WriteMatrixDomainType(const hid_t ParentGroup, const char *DatasetName, const THDF5_MatrixDomainType &MatrixDomainType)
Write matrix domain type into the dataset under the root group.
Definition: HDF5_File.cpp:1135
THDF5_File::GetDatasetNumberOfDimensions
size_t GetDatasetNumberOfDimensions(const hid_t ParentGroup, const char *DatasetName)
Get number of dimensions of the dataset under a specified group.
Definition: HDF5_File.cpp:1061
HDF5_ERR_FMT_WrongDimensionSizes
const char *const HDF5_ERR_FMT_WrongDimensionSizes
HDF5 error message.
Definition: ErrorMessages.h:52
HDF5_ERR_FMT_CouldNotSetCompression
const char *const HDF5_ERR_FMT_CouldNotSetCompression
HDF5 error message.
Definition: ErrorMessages.h:60
THDF5_File::GetRootGroup
hid_t GetRootGroup() const
Get handle to the root group.
Definition: HDF5_File.h:581
HDF5_ERR_FMT_FileCannotReopen
const char *const HDF5_ERR_FMT_FileCannotReopen
HDF5 error message.
Definition: ErrorMessages.h:44
ErrorMessages.h
The header file containing all error messages of the project.
THDF5_FileHeader::ReadHeaderFromInputFile
void ReadHeaderFromInputFile(THDF5_File &InputFile)
Read header from the input file.
Definition: HDF5_File.cpp:1332
THDF5_File::Open
void Open(const char *FileName, unsigned int Flags=H5F_ACC_RDONLY)
Open the file.
Definition: HDF5_File.cpp:136
THDF5_FileHeader::~THDF5_FileHeader
~THDF5_FileHeader()
Destructor.
Definition: HDF5_File.cpp:1319
THDF5_File::CreateFloatDataset
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).
Definition: HDF5_File.cpp:291
TDimensionSizes::GetElementCount
size_t GetElementCount() const
Get element count, in 3D only spatial domain, in 4D with time.
Definition: DimensionSizes.h:93
THDF5_File::OpenDataset
hid_t OpenDataset(const hid_t ParentGroup, const char *DatasetName)
Open the HDF5 dataset at a specified place in the file tree.
Definition: HDF5_File.cpp:264
HDF5_ERR_FMT_BadInputFileType
const char *const HDF5_ERR_FMT_BadInputFileType
HDF5 error message.
Definition: ErrorMessages.h:72
THDF5_File::ReadMatrixDomainType
THDF5_File::THDF5_MatrixDomainType ReadMatrixDomainType(const hid_t ParentGroup, const char *DatasetName)
Read matrix domain type from the dataset under a specified group.
Definition: HDF5_File.cpp:1190
HDF5_ERR_FMT_CouldNotWriteToAttribute
const char *const HDF5_ERR_FMT_CouldNotWriteToAttribute
HDF5 error message.
Definition: ErrorMessages.h:64
TDimensionSizes::Y
size_t Y
Y dimension size.
Definition: DimensionSizes.h:68
THDF5_FileHeader::HDF5_MinorFileVersionsNames
static const string HDF5_MinorFileVersionsNames[]
String representations of Major file versions.
Definition: HDF5_File.h:916
THDF5_FileHeader::SetActualCreationTime
void SetActualCreationTime()
Set creation time.
Definition: HDF5_File.cpp:1565
THDF5_File::ReadCompleteDataset
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.
Definition: HDF5_File.cpp:954
HDF5_ERR_FMT_FileNotOpened
const char *const HDF5_ERR_FMT_FileNotOpened
HDF5 error message.
Definition: ErrorMessages.h:54
TDimensionSizes::T
size_t T
Number of time steps (for time series datasets).
Definition: DimensionSizes.h:72
THDF5_File::CloseGroup
void CloseGroup(const hid_t Group)
Close HDF5 group.
Definition: HDF5_File.cpp:251
THDF5_FileHeader::WriteHeaderToCheckpointFile
void WriteHeaderToCheckpointFile(THDF5_File &CheckpointFile)
Write header to the output file.
Definition: HDF5_File.cpp:1473
THDF5_FileHeader::HDF5_FileHeaderNames
map< THDF5_FileHeaderItems, string > HDF5_FileHeaderNames
map for the header names.
Definition: HDF5_File.h:909
THDF5_File::Create
void Create(const char *FileName, unsigned int Flags=H5F_ACC_TRUNC)
Create the file, overwrite if exist.
Definition: HDF5_File.cpp:103
HDF5_ERR_FMT_CouldNotWriteTo
const char *const HDF5_ERR_FMT_CouldNotWriteTo
HDF5 error message.
Definition: ErrorMessages.h:48
THDF5_FileHeader::SetNumberOfCores
void SetNumberOfCores()
Set number of cores.
Definition: HDF5_File.cpp:1686
THDF5_FileHeader::GetFileVersion
THDF5_FileVersion GetFileVersion()
Set major file version in a string.
Definition: HDF5_File.cpp:1543
THDF5_File::ReadStringAttribute
string ReadStringAttribute(const hid_t ParentGroup, const char *DatasetName, const char *AttributeName)
Read string attribute from the dataset under the root group.
Definition: HDF5_File.cpp:1254
THDF5_FileHeader::SetFileType
void SetFileType(const THDF5_FileHeader::THDF5_FileType FileType)
Set file type.
Definition: HDF5_File.cpp:1532
HDF5_ERR_FMT_GroupNotCreated
const char *const HDF5_ERR_FMT_GroupNotCreated
HDF5 error message.
Definition: ErrorMessages.h:68
HDF5_ERR_FMT_FileCannotRecreated
const char *const HDF5_ERR_FMT_FileCannotRecreated
HDF5 error message.
Definition: ErrorMessages.h:42
THDF5_FileHeader::SetMemoryConsumption
void SetMemoryConsumption(size_t TotalMemory)
Set memory consumption.
Definition: HDF5_File.cpp:1613
HDF5_ERR_FMT_BadAttributeValue
const char *const HDF5_ERR_FMT_BadAttributeValue
HDF5 error message.
Definition: ErrorMessages.h:62
THDF5_File::CreateIndexDataset
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).
Definition: HDF5_File.cpp:385
HDF5_ERR_FMT_CouldNotReadFromAttribute
const char *const HDF5_ERR_FMT_CouldNotReadFromAttribute
HDF5 error message.
Definition: ErrorMessages.h:66
THDF5_File::HDF5_MatrixDomainTypeNames
static const string HDF5_MatrixDomainTypeNames[]
String representation of different domain types.
Definition: HDF5_File.h:728
THDF5_File::~THDF5_File
virtual ~THDF5_File()
Destructor.
Definition: HDF5_File.cpp:188
THDF5_File::HDF5_MatrixDataTypeNames
static const string HDF5_MatrixDataTypeNames[]
String representation of different data types.
Definition: HDF5_File.h:730
THDF5_File::THDF5_MatrixDomainType
THDF5_MatrixDomainType
HDF5 Matrix domain type (real or complex).
Definition: HDF5_File.h:520
THDF5_File::CloseDataset
void CloseDataset(const hid_t HDF5_Dataset_id)
Close the HDF5 dataset.
Definition: HDF5_File.cpp:451
THDF5_File
Class wrapping the HDF5 routines.
Definition: HDF5_File.h:506
THDF5_File::THDF5_MatrixDataType
THDF5_MatrixDataType
HDF5 matrix data type (float or uint64).
Definition: HDF5_File.h:514
TDimensionSizes
Structure with 4D dimension sizes (3 in space and 1 in time).
Definition: DimensionSizes.h:63
TDimensionSizes::Is3D
bool Is3D() const
Is it a 3D object?
Definition: DimensionSizes.h:100
THDF5_FileHeader::GetExecutionTimes
void GetExecutionTimes(double &TotalTime, double &LoadTime, double &PreProcessingTime, double &SimulationTime, double &PostprocessingTime)
Get execution times stored in the output file header.
Definition: HDF5_File.cpp:1668
HDF5_ERR_FMT_FileNotCreated
const char *const HDF5_ERR_FMT_FileNotCreated
HDF5 error message.
Definition: ErrorMessages.h:40
TParameters::GetInstance
static TParameters * GetInstance()
Get instance of the singleton class.
Definition: Parameters.cpp:74