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

- Main Page
- Classes
- Files

- File List
- File Members

HDF5/HDF5_File.cpp
Go to the documentation of this file.

    00001
    00033 #include <stdio.h>
    00034 #include <iostream>
    00035 #include <stdexcept>
    00036
    00037 #include <HDF5/HDF5_File.h>
    00038
    00039 #include <Parameters/Parameters.h>
    00040 #include <Utils/ErrorMessages.h>
    00041
    00042 //----------------------------------------------------------------------------//
    00043 //-----------------------------    Constants----------------------------------//
    00044 //----------------------------------------------------------------------------//
    00045
    00046
    00047
    00048 //----------------------------------------------------------------------------//
    00049
    00050 const char * THDF5_File::HDF5_MatrixDomainTypeName    = "domain_type";
    00051
    00052 const char * THDF5_File::HDF5_MatrixDataTypeName      = "data_type";
    00053
    00054 const string THDF5_File::HDF5_MatrixDomainTypeNames[] = {"real","complex"};
    00055
    00056 const string THDF5_File::HDF5_MatrixDataTypeNames[]   = {"float","long"};
    00057
    00058
    00059 const string THDF5_FileHeader::HDF5_FileTypesNames[]  = {"input","output", "checkpoint", "unknown"};
    00060
    00061
    00062
    00063 //----------------------------------------------------------------------------//
    00064 //----------------------------    THDF5_File    ------------------------------//
    00065 //------------------------------    Public     -------------------------------//
    00066 //----------------------------------------------------------------------------//
    00067
    00068
    00072 THDF5_File::THDF5_File() :
    00073         HDF5_FileId(H5I_BADID), FileName("")
    00074 {
    00075
    00076 }// end of constructor
    00077 //------------------------------------------------------------------------------
    00078
    00079
    00080
    00081
    00089 void THDF5_File::Create(const char * FileName, unsigned int Flags){
    00090
    00091     // file is opened
    00092     if (IsOpened()) {
    00093         char ErrorMessage[256];
    00094         sprintf(ErrorMessage,HDF5_ERR_FMT_FileCannotRecreated,FileName);
    00095         throw ios::failure(ErrorMessage);
    00096     }
    00097
    00098
    00099    // Create a new file using default properties.
    00100     this->FileName = FileName;
    00101
    00102     HDF5_FileId = H5Fcreate(FileName, Flags, H5P_DEFAULT, H5P_DEFAULT);
    00103
    00104
    00105     if (HDF5_FileId < 0) {
    00106         char ErrorMessage[256];
    00107         sprintf(ErrorMessage,HDF5_ERR_FMT_FileNotCreated,FileName);
    00108         throw ios::failure(ErrorMessage);
    00109     }
    00110
    00111 }// end of Create
    00112 //------------------------------------------------------------------------------
    00113
    00114
    00122 void THDF5_File::Open(const char * FileName, unsigned int Flags){
    00123
    00124     if (IsOpened())  {
    00125         char ErrorMessage[256];
    00126         sprintf(ErrorMessage,HDF5_ERR_FMT_FileCannotReopen,FileName);
    00127         throw ios::failure(ErrorMessage);
    00128     };
    00129
    00130
    00131     this->FileName = FileName;
    00132
    00133     if (H5Fis_hdf5(FileName) == 0){
    00134         char ErrorMessage[256];
    00135         sprintf(ErrorMessage,HDF5_ERR_FMT_NotHDF5File,FileName);
    00136         throw ios::failure(ErrorMessage);
    00137
    00138     }
    00139
    00140     HDF5_FileId = H5Fopen( FileName, Flags, H5P_DEFAULT );
    00141
    00142     if (HDF5_FileId < 0) {
    00143         char ErrorMessage[256];
    00144         sprintf(ErrorMessage,HDF5_ERR_FMT_FileNotOpened,FileName);
    00145         throw ios::failure(ErrorMessage);
    00146     }
    00147
    00148
    00149 }// end of Open
    00150 //------------------------------------------------------------------------------
    00151
    00155 void THDF5_File::Close(){
    00156
    00157     // Terminate access to the file.
    00158     herr_t status = H5Fclose(HDF5_FileId);
    00159     if (status < 0) {
    00160         char ErrorMessage[256];
    00161         sprintf(ErrorMessage,HDF5_ERR_FMT_FileNotClosed,FileName.c_str());
    00162
    00163         throw ios::failure(ErrorMessage);
    00164     }
    00165
    00166     FileName    = "";
    00167     HDF5_FileId = H5I_BADID;
    00168
    00169 }// end of Close
    00170 //------------------------------------------------------------------------------
    00171
    00175 THDF5_File::~THDF5_File(){
    00176
    00177   if (IsOpened()) Close();
    00178
    00179 }//end of ~THDF5_File
    00180 //------------------------------------------------------------------------------
    00181
    00182
    00183
    00191 hid_t THDF5_File::OpenDataset  (const char * DatasetName){
    00192
    00193       // Open dataset
    00194     hid_t HDF5_dataset_id = H5Dopen(HDF5_FileId, DatasetName, H5P_DEFAULT);
    00195
    00196     if (HDF5_dataset_id == H5I_INVALID_HID ){
    00197         char ErrorMessage[256];
    00198         sprintf(ErrorMessage,HDF5_ERR_FMT_DatasetNotOpened,FileName.c_str(), DatasetName);
    00199         throw ios::failure(ErrorMessage);
    00200     }
    00201
    00202     return HDF5_dataset_id;
    00203
    00204 }// end of OpenDataset
    00205 //------------------------------------------------------------------------------
    00206
    00207
    00218 hid_t THDF5_File::CreateFloatDataset(const char * DatasetName, const TDimensionSizes & DimensionSizes, const TDimensionSizes & ChunkSizes, const int CompressionLevel){
    00219
    00220     const int RANK = 3;
    00221     hsize_t    Dims [RANK] = {DimensionSizes.Z, DimensionSizes.Y, DimensionSizes.X};
    00222     hsize_t    Chunk[RANK] = {ChunkSizes.Z, ChunkSizes.Y, ChunkSizes.X};
    00223     hid_t      Property_list;
    00224     herr_t     Status;
    00225
    00226     hid_t dataspace_id = H5Screate_simple (RANK, Dims, NULL);
    00227
    00228
    00229     // set chunk size
    00230     Property_list  = H5Pcreate (H5P_DATASET_CREATE);
    00231
    00232     Status = H5Pset_chunk(Property_list, RANK, Chunk);
    00233     if (Status < 0 ){
    00234         char ErrorMessage[256];
    00235         sprintf(ErrorMessage,HDF5_ERR_FMT_DatasetNotOpened,FileName.c_str(), DatasetName);
    00236         throw ios::failure(ErrorMessage);
    00237
    00238     }
    00239
    00240     // set compression level
    00241     Status = H5Pset_deflate (Property_list, CompressionLevel);
    00242     if (Status < 0 ){
    00243         char ErrorMessage[256];
    00244         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotSetCompression,FileName.c_str(), DatasetName, CompressionLevel);
    00245         throw ios::failure(ErrorMessage);
    00246
    00247     }
    00248
    00249     // create dataset
    00250     hid_t HDF5_dataset_id = H5Dcreate (HDF5_FileId, DatasetName, H5T_NATIVE_FLOAT, dataspace_id,
    00251                             H5P_DEFAULT, Property_list, H5P_DEFAULT);
    00252
    00253     if (HDF5_dataset_id == H5I_INVALID_HID ){
    00254         char ErrorMessage[256];
    00255         sprintf(ErrorMessage,HDF5_ERR_FMT_DatasetNotOpened,FileName.c_str(), DatasetName);
    00256         throw ios::failure(ErrorMessage);
    00257
    00258     }
    00259
    00260     H5Pclose (Property_list);
    00261
    00262     return HDF5_dataset_id;
    00263
    00264 }// end of CreateDataset
    00265 //------------------------------------------------------------------------------
    00266
    00267
    00268
    00269
    00275 void  THDF5_File::CloseDataset(const hid_t& HDF5_Dataset_id){
    00276
    00277     H5Dclose (HDF5_Dataset_id);
    00278
    00279 }// end of CloseDataset
    00280 //------------------------------------------------------------------------------
    00281
    00282
    00283
    00284
    00293 void THDF5_File::WriteCompleteDataset(const char * DatasetName, const TDimensionSizes & DimensionSizes, const float * Data){
    00294
    00295   const int rank = 3;
    00296   const hsize_t dims[]={DimensionSizes.Z, DimensionSizes.Y,DimensionSizes.X};
    00297
    00298   // write to dataset
    00299   herr_t  status = H5LTmake_dataset_float(HDF5_FileId,DatasetName,rank,dims, Data);
    00300
    00301    if (status < 0) {
    00302         char ErrorMessage[256];
    00303         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,DatasetName);
    00304
    00305         throw ios::failure(ErrorMessage);
    00306     }
    00307
    00308 }// end of WriteDataset (float)
    00309 //------------------------------------------------------------------------------
    00310
    00311
    00320 void THDF5_File::WriteCompleteDataset (const char * DatasetName, const TDimensionSizes & DimensionSizes, const long  * Data){
    00321   const int     rank = 3;
    00322   const hsize_t dims[]={DimensionSizes.Z, DimensionSizes.Y,DimensionSizes.X};
    00323
    00324   // write to dataset
    00325   herr_t  status = H5LTmake_dataset(HDF5_FileId,DatasetName,rank,dims, H5T_STD_U64LE, Data);
    00326
    00327    if (status < 0) {
    00328         char ErrorMessage[256];
    00329         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,DatasetName);
    00330
    00331         throw ios::failure(ErrorMessage);
    00332     }
    00333
    00334 }// end of WriteDataset (long)
    00335 //------------------------------------------------------------------------------
    00336
    00337
    00338
    00349 void THDF5_File::WriteHyperSlab(const hid_t HDF5_Dataset_id, const TDimensionSizes & Position , const TDimensionSizes & Size, const float * Data){
    00350
    00351
    00352
    00353      // Select hyperslab
    00354     const int MatrixRank = 3;
    00355     hsize_t ElementCount[MatrixRank] = {Size.Z, Size.Y, Size.X};
    00356     hsize_t Offset[MatrixRank] = {Position.Z,Position.Y,Position.X};
    00357
    00358     herr_t status;
    00359     hid_t  HDF5_Filespace,HDF5_Memspace;
    00360
    00361     // Select hyperslab in the file.
    00362     HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
    00363
    00364
    00365     status = H5Sselect_hyperslab(HDF5_Filespace, H5S_SELECT_SET, Offset, 0, ElementCount, NULL);
    00366     if (status < 0) {
    00367         char ErrorMessage[256];
    00368         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
    00369         throw ios::failure(ErrorMessage);
    00370      }
    00371
    00372
    00373     // assign memspace
    00374     HDF5_Memspace = H5Screate_simple(MatrixRank, ElementCount, NULL);
    00375
    00376
    00377      status = H5Dwrite(HDF5_Dataset_id, H5T_NATIVE_FLOAT, HDF5_Memspace, HDF5_Filespace,  H5P_DEFAULT, Data);
    00378      if (status < 0) {
    00379         char ErrorMessage[256];
    00380         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
    00381
    00382         throw ios::failure(ErrorMessage);
    00383      }
    00384
    00385     H5Sclose(HDF5_Memspace);
    00386     H5Sclose(HDF5_Filespace);
    00387
    00388
    00389
    00390 }// end of WriteHyperSlab
    00391 //------------------------------------------------------------------------------
    00392
    00393
    00403 void THDF5_File::WriteHyperSlab(const hid_t HDF5_Dataset_id, const TDimensionSizes & Position , const TDimensionSizes & Size, const long * Data){
    00404
    00405
    00406
    00407      // Select hyperslab
    00408     const int MatrixRank = 3;
    00409     hsize_t ElementCount[MatrixRank] = {Size.Z, Size.Y, Size.X};
    00410     hsize_t Offset[MatrixRank] = {Position.Z,Position.Y,Position.X};
    00411
    00412     herr_t status;
    00413     hid_t  HDF5_Filespace,HDF5_Memspace;
    00414
    00415     // Select hyperslab in the file.
    00416     HDF5_Filespace = H5Dget_space(HDF5_Dataset_id);
    00417
    00418
    00419     status = H5Sselect_hyperslab(HDF5_Filespace, H5S_SELECT_SET, Offset, 0, ElementCount, NULL);
    00420     if (status < 0) {
    00421         char ErrorMessage[256];
    00422         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
    00423         throw ios::failure(ErrorMessage);
    00424      }
    00425
    00426
    00427     // assign memspace
    00428     HDF5_Memspace = H5Screate_simple(MatrixRank, ElementCount, NULL);
    00429
    00430
    00431      status = H5Dwrite(HDF5_Dataset_id, H5T_STD_U64LE, HDF5_Memspace, HDF5_Filespace,  H5P_DEFAULT, Data);
    00432      if (status < 0) {
    00433         char ErrorMessage[256];
    00434         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteTo,"");
    00435
    00436         throw ios::failure(ErrorMessage);
    00437      }
    00438
    00439     H5Sclose(HDF5_Memspace);
    00440     H5Sclose(HDF5_Filespace);
    00441
    00442
    00443
    00444 }// end of WriteHyperSlab
    00445 //------------------------------------------------------------------------------
    00446
    00447
    00448
    00455 void THDF5_File::WriteScalarValue(const char * DatasetName, const float Value){
    00456
    00457     WriteCompleteDataset (DatasetName, TDimensionSizes(1,1,1), &Value);
    00458     WriteMatrixDataType  (DatasetName, hdf5_mdt_float);
    00459     WriteMatrixDomainType(DatasetName, hdf5_mdt_real);
    00460
    00461
    00462 }// end of WriteScalarValue (float)
    00463 //------------------------------------------------------------------------------
    00464
    00471 void THDF5_File::WriteScalarValue(const char * DatasetName, const long Value){
    00472
    00473     WriteCompleteDataset (DatasetName, TDimensionSizes(1,1,1), &Value);
    00474     WriteMatrixDataType  (DatasetName, hdf5_mdt_long);
    00475     WriteMatrixDomainType(DatasetName, hdf5_mdt_real);
    00476
    00477
    00478
    00479 }// end of WriteScalarValue
    00480 //------------------------------------------------------------------------------
    00481
    00482
    00491 void THDF5_File::ReadCompleteDataset (const char * DatasetName, const TDimensionSizes & DimensionSizes, float * Data){
    00492
    00493     if (GetDatasetDimensionSizes(DatasetName).GetElementCount() !=
    00494                                DimensionSizes.GetElementCount()) {
    00495         char ErrorMessage[256];
    00496         sprintf(ErrorMessage,HDF5_ERR_FMT_WrongDimensionSizes,DatasetName);
    00497         throw ios::failure(ErrorMessage);
    00498     }
    00499
    00500      /* read dataset */
    00501     herr_t status = H5LTread_dataset_float(HDF5_FileId,DatasetName,Data);
    00502     if (status < 0) {
    00503         char ErrorMessage[256];
    00504         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotReadFrom,DatasetName);
    00505
    00506         throw ios::failure(ErrorMessage);
    00507     }
    00508
    00509 }// end of ReadDataset (float)
    00510 //------------------------------------------------------------------------------
    00511
    00520 void THDF5_File::ReadCompleteDataset  (const char * DatasetName, const TDimensionSizes & DimensionSizes,long  * Data){
    00521
    00522     if (GetDatasetDimensionSizes(DatasetName).GetElementCount() !=
    00523                                DimensionSizes.GetElementCount()) {
    00524         char ErrorMessage[256];
    00525         sprintf(ErrorMessage,HDF5_ERR_FMT_WrongDimensionSizes,DatasetName);
    00526         throw ios::failure(ErrorMessage);
    00527     }
    00528
    00529      /* read dataset */
    00530     herr_t status = H5LTread_dataset(HDF5_FileId,DatasetName,H5T_STD_U64LE, Data);
    00531     if (status < 0) {
    00532         char ErrorMessage[256];
    00533         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotReadFrom,DatasetName);
    00534
    00535         throw ios::failure(ErrorMessage);
    00536     }
    00537 }// end of ReadDataset(long)
    00538 //------------------------------------------------------------------------------
    00539
    00540
    00541
    00548  TDimensionSizes THDF5_File::GetDatasetDimensionSizes(const char * DatasetName){
    00549
    00550      hsize_t dims[3] = {0,0,0};
    00551
    00552      herr_t status = H5LTget_dataset_info(HDF5_FileId,DatasetName,dims,NULL,NULL);
    00553      if (status < 0) {
    00554         char ErrorMessage[256];
    00555         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotReadFrom,DatasetName);
    00556
    00557         throw ios::failure(ErrorMessage);
    00558      }
    00559
    00560      return TDimensionSizes(dims[2],dims[1],dims[0]);
    00561
    00562  }// end of CheckDatasetDimensions
    00563  //------------------------------------------------------------------------------
    00564
    00565
    00572 size_t THDF5_File::GetDatasetElementCount(const char * DatasetName){
    00573
    00574     hsize_t dims[3] = {0,0,0};
    00575
    00576      herr_t status = H5LTget_dataset_info(HDF5_FileId,DatasetName,dims,NULL,NULL);
    00577      if (status < 0) {
    00578         char ErrorMessage[256];
    00579         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotReadFrom,DatasetName);
    00580
    00581         throw ios::failure(ErrorMessage);
    00582      }
    00583
    00584      return dims[0] * dims[1] * dims[2];
    00585  }// end of GetDatasetElementCount
    00586  //-----------------------------------------------------------------------------
    00587
    00588
    00589
    00590
    00597 void THDF5_File::WriteMatrixDataType(const char * DatasetName, const THDF5_MatrixDataType & MatrixDataType){
    00598
    00599    WriteStringAttribute(DatasetName, HDF5_MatrixDataTypeName, HDF5_MatrixDataTypeNames[MatrixDataType]);
    00600
    00601 }// end of WriteMatrixDataType
    00602 //------------------------------------------------------------------------------
    00603
    00604
    00611 void THDF5_File::WriteMatrixDomainType(const char * DatasetName, const THDF5_MatrixDomainType & MatrixDomainType){
    00612
    00613     WriteStringAttribute(DatasetName, HDF5_MatrixDomainTypeName, HDF5_MatrixDomainTypeNames [MatrixDomainType]);
    00614
    00615 }// end of WriteMatrixDomainType
    00616 //------------------------------------------------------------------------------
    00617
    00618
    00626 THDF5_File::THDF5_MatrixDataType THDF5_File::ReadMatrixDataType(const char * DatasetName){
    00627
    00628     string ParamValue;
    00629
    00630     ParamValue = ReadStringAttribute(DatasetName, HDF5_MatrixDataTypeName);
    00631
    00632     if (ParamValue == HDF5_MatrixDataTypeNames[0]) return (THDF5_MatrixDataType) 0;
    00633     if (ParamValue == HDF5_MatrixDataTypeNames[1]) return (THDF5_MatrixDataType) 1;
    00634
    00635     char ErrorMessage[256];
    00636     sprintf(ErrorMessage,HDF5_ERR_FMT_BadAttributeValue,DatasetName, HDF5_MatrixDataTypeName,ParamValue.c_str());
    00637     throw ios::failure(ErrorMessage);
    00638
    00639     return (THDF5_MatrixDataType) 0;
    00640
    00641 }// end of ReadMatrixDataType
    00642 //------------------------------------------------------------------------------
    00643
    00644
    00652 THDF5_File::THDF5_MatrixDomainType THDF5_File::ReadMatrixDomainType(const char * DatasetName){
    00653
    00654     string ParamValue;
    00655
    00656     ParamValue = ReadStringAttribute(DatasetName, HDF5_MatrixDomainTypeName);
    00657
    00658     if (ParamValue == HDF5_MatrixDomainTypeNames[0]) return (THDF5_MatrixDomainType) 0;
    00659     if (ParamValue == HDF5_MatrixDomainTypeNames[1]) return (THDF5_MatrixDomainType) 1;
    00660
    00661
    00662     char ErrorMessage[256];
    00663     sprintf(ErrorMessage,HDF5_ERR_FMT_BadAttributeValue,DatasetName, HDF5_MatrixDomainTypeName,ParamValue.c_str());
    00664     throw ios::failure(ErrorMessage);
    00665
    00666
    00667     return (THDF5_MatrixDomainType) 0;
    00668
    00669 }// end of ReadMatrixDomainType
    00670 //------------------------------------------------------------------------------
    00671
    00672
    00681 inline void THDF5_File::WriteStringAttribute(const char * DatasetName, const char * AttributeName, const string & Value){
    00682
    00683     herr_t status = H5LTset_attribute_string(HDF5_FileId, DatasetName, AttributeName, Value.c_str());
    00684
    00685     if (status < 0) {
    00686         char ErrorMessage[256];
    00687         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotWriteToAttribute,AttributeName, DatasetName);
    00688
    00689         throw ios::failure(ErrorMessage);
    00690      }
    00691
    00692 }// end of WriteIntAttribute
    00693 //------------------------------------------------------------------------------
    00694
    00695
    00696
    00705 inline  string THDF5_File::ReadStringAttribute(const char * DatasetName, const char * AttributeName){
    00706
    00707     char Value[256] = "";
    00708     herr_t status = H5LTget_attribute_string (HDF5_FileId, DatasetName, AttributeName, Value);
    00709
    00710     if (status < 0) {
    00711         char ErrorMessage[256];
    00712         sprintf(ErrorMessage,HDF5_ERR_FMT_CouldNotReadFromAttribute,AttributeName, DatasetName);
    00713
    00714         throw ios::failure(ErrorMessage);
    00715     }
    00716
    00717     return Value;
    00718
    00719 }// end of ReadIntAttribute
    00720 //------------------------------------------------------------------------------
    00721
    00722
    00723 //----------------------------------------------------------------------------//
    00724 //----------------------------    THDF5_File    ------------------------------//
    00725 //----------------------------    Protected     ------------------------------//
    00726 //----------------------------------------------------------------------------//
    00727
    00728
    00729
    00730
    00731
    00732
    00733
    00734
    00735 //----------------------------------------------------------------------------//
    00736 //------------------------    THDF5_File_Header ------------------------------//
    00737 //-----------------------------    Public     --------------------------------//
    00738 //----------------------------------------------------------------------------//
    00739
    00743 THDF5_FileHeader::THDF5_FileHeader(){
    00744
    00745     HDF5_FileHeaderValues.clear();
    00746     PopulateHeaderFileMap();
    00747
    00748 }// end of constructor
    00749 //------------------------------------------------------------------------------
    00750
    00751
    00756 THDF5_FileHeader::THDF5_FileHeader(const THDF5_FileHeader & other){
    00757     HDF5_FileHeaderValues = other.HDF5_FileHeaderValues;
    00758     HDF5_FileHeaderNames  = other.HDF5_FileHeaderNames;
    00759
    00760 }// end of copy constructor
    00761 //------------------------------------------------------------------------------
    00762
    00763
    00768 THDF5_FileHeader::~THDF5_FileHeader(){
    00769     HDF5_FileHeaderValues.clear();
    00770     HDF5_FileHeaderNames.clear();
    00771
    00772 }// end of destructor
    00773 //------------------------------------------------------------------------------
    00774
    00775
    00776
    00781 void THDF5_FileHeader::ReadHeaderFromInputFile(THDF5_File & InputFile){
    00782
    00783     // read file type
    00784     HDF5_FileHeaderValues[hdf5_fhi_file_type] = InputFile.ReadStringAttribute("/",HDF5_FileHeaderNames[hdf5_fhi_file_type].c_str());
    00785
    00786     if (GetFileType() == hdf5_ft_input) {
    00787         HDF5_FileHeaderValues[hdf5_fhi_created_by]       = InputFile.ReadStringAttribute("/",HDF5_FileHeaderNames[hdf5_fhi_created_by].c_str());
    00788         HDF5_FileHeaderValues[hdf5_fhi_creation_date]    = InputFile.ReadStringAttribute("/",HDF5_FileHeaderNames[hdf5_fhi_creation_date].c_str());
    00789         HDF5_FileHeaderValues[hdf5_fhi_file_description] = InputFile.ReadStringAttribute("/",HDF5_FileHeaderNames[hdf5_fhi_file_description].c_str());
    00790         HDF5_FileHeaderValues[hdf5_fhi_major_version]    = InputFile.ReadStringAttribute("/",HDF5_FileHeaderNames[hdf5_fhi_major_version].c_str());
    00791         HDF5_FileHeaderValues[hdf5_fhi_minor_version]    = InputFile.ReadStringAttribute("/",HDF5_FileHeaderNames[hdf5_fhi_minor_version].c_str());
    00792     }
    00793
    00794
    00795 }// end of ReadHeaderFromInputFile
    00796 //------------------------------------------------------------------------------
    00797
    00802 void THDF5_FileHeader::WriteHeaderToOutputFile (THDF5_File & OutputFile){
    00803
    00804     for (map<THDF5_FileHeaderItems, string>::iterator it = HDF5_FileHeaderNames.begin();
    00805          it != HDF5_FileHeaderNames.end(); it++) {
    00806
    00807         OutputFile.WriteStringAttribute("/",it->second.c_str(), HDF5_FileHeaderValues[it->first]);
    00808     }
    00809
    00810 }// end of WriteHeaderToOutputFile
    00811 //------------------------------------------------------------------------------
    00812
    00813
    00818 THDF5_FileHeader::THDF5_FileType  THDF5_FileHeader::GetFileType(){
    00819
    00820     for (int i = hdf5_ft_input; i < hdf5_ft_unknown ; i++){
    00821       if (HDF5_FileHeaderValues[hdf5_fhi_file_type] == HDF5_FileTypesNames[static_cast<THDF5_FileType >(i)]) return static_cast<THDF5_FileType >(i);
    00822     }
    00823
    00824     return THDF5_FileHeader::hdf5_ft_unknown;
    00825
    00826 }// end of GetFileType
    00827 //------------------------------------------------------------------------------
    00828
    00833 void THDF5_FileHeader::SetFileType(const THDF5_FileHeader::THDF5_FileType FileType){
    00834
    00835     HDF5_FileHeaderValues[hdf5_fhi_file_type] = HDF5_FileTypesNames[FileType];
    00836
    00837 }// end of SetFileType
    00838 //------------------------------------------------------------------------------
    00839
    00840
    00845 void THDF5_FileHeader::SetActualCreationTime(){
    00846
    00847     struct tm *current;
    00848     time_t now;
    00849     time(&now);
    00850     current = localtime(&now);
    00851
    00852     char DateString[20];
    00853
    00854     sprintf(DateString, "%02i/%02i/%02i, %02i:%02i:%02i",
    00855                         current->tm_mday, current->tm_mon+1, current->tm_year-100,
    00856                         current->tm_hour, current->tm_min, current->tm_sec);
    00857
    00858     HDF5_FileHeaderValues[hdf5_fhi_creation_date] = DateString;
    00859
    00860 }// end of SetCreationTime
    00861 //------------------------------------------------------------------------------
    00862
    00867 void THDF5_FileHeader::SetHostName(){
    00868
    00869     char   HostName[256];
    00870     gethostname(HostName, 256);
    00871
    00872     HDF5_FileHeaderValues[hdf5_fhi_host_name] = HostName;
    00873
    00874
    00875 }// end of SetHostName
    00876 //------------------------------------------------------------------------------
    00877
    00878
    00883 void THDF5_FileHeader::SetMemoryConsumption(size_t TotalMemory){
    00884
    00885     char Text[20] = "";
    00886     sprintf(Text, "%ld MB",TotalMemory);
    00887
    00888
    00889     HDF5_FileHeaderValues[hdf5_fhi_total_memory_consumption]     = Text;
    00890
    00891     sprintf(Text, "%ld MB",TotalMemory / TParameters::GetInstance()->GetNumberOfThreads());
    00892     HDF5_FileHeaderValues[hdf5_fhi_peak_core_memory_consumption] = Text;
    00893
    00894 }// end of SetMemoryConsumption
    00895 //------------------------------------------------------------------------------
    00896
    00897
    00906 void THDF5_FileHeader::SetExecutionTimes(const double TotalTime, const double LoadTime,
    00907                            const double PreProcessingTime, const double SimulationTime,
    00908                            const double PostprocessingTime){
    00909
    00910     char Text [30] = "";
    00911
    00912     sprintf(Text,"%8.2fs", TotalTime);
    00913     HDF5_FileHeaderValues[hdf5_fhi_total_execution_time] = Text;
    00914
    00915     sprintf(Text,"%8.2fs", LoadTime);
    00916     HDF5_FileHeaderValues[hdf5_fhi_data_load_time] = Text;
    00917
    00918     sprintf(Text,"%8.2fs", PreProcessingTime);
    00919     HDF5_FileHeaderValues[hdf5_fhi_preprocessing_time] = Text;
    00920
    00921
    00922     sprintf(Text,"%8.2fs", SimulationTime);
    00923     HDF5_FileHeaderValues[hdf5_fhi_simulation_time] = Text;
    00924
    00925     sprintf(Text,"%8.2fs", PostprocessingTime);
    00926     HDF5_FileHeaderValues[hdf5_fhi_postprocessing_time] = Text;
    00927
    00928
    00929 }// end of SetExecutionTimes
    00930 //------------------------------------------------------------------------------
    00931
    00932
    00933
    00938 void THDF5_FileHeader::SetNumberOfCores(){
    00939     char Text[12] = "";
    00940     sprintf(Text, "%d",TParameters::GetInstance()->GetNumberOfThreads());
    00941
    00942     HDF5_FileHeaderValues[hdf5_fhi_number_of_cores] = Text;
    00943
    00944 }// end of SetNumberOfCores
    00945 //------------------------------------------------------------------------------
    00946
    00947 //----------------------------------------------------------------------------//
    00948 //------------------------    THDF5_File_Header ------------------------------//
    00949 //---------------------------    Protected     --------------------------------//
    00950 //----------------------------------------------------------------------------//
    00951
    00952
    00953
    00954
    00955
    00956
    00961 void THDF5_FileHeader::PopulateHeaderFileMap(){
    00962
    00963     HDF5_FileHeaderNames.clear();
    00964
    00965     HDF5_FileHeaderNames[hdf5_fhi_created_by]                   = "created_by";
    00966     HDF5_FileHeaderNames[hdf5_fhi_creation_date]                = "creation_date";
    00967     HDF5_FileHeaderNames[hdf5_fhi_file_description]             = "file_description";
    00968     HDF5_FileHeaderNames[hdf5_fhi_major_version]                = "major_version";
    00969     HDF5_FileHeaderNames[hdf5_fhi_minor_version]                = "minor_version";
    00970     HDF5_FileHeaderNames[hdf5_fhi_file_type]                    = "file_type";
    00971
    00972     HDF5_FileHeaderNames[hdf5_fhi_host_name]                    = "host_names";
    00973     HDF5_FileHeaderNames[hdf5_fhi_number_of_cores]              = "number_of_cpu_cores" ;
    00974     HDF5_FileHeaderNames[hdf5_fhi_total_memory_consumption]     = "total_memory_in_use";
    00975     HDF5_FileHeaderNames[hdf5_fhi_peak_core_memory_consumption] = "peak_core_memory_in_use";
    00976
    00977     HDF5_FileHeaderNames[hdf5_fhi_total_execution_time]         = "total_execution_time";
    00978     HDF5_FileHeaderNames[hdf5_fhi_data_load_time]               = "data_loading_phase_execution_time";
    00979     HDF5_FileHeaderNames[hdf5_fhi_preprocessing_time]           = "pre-processing_phase_execution_time";
    00980     HDF5_FileHeaderNames[hdf5_fhi_simulation_time]              = "simulation_phase_execution_time";
    00981     HDF5_FileHeaderNames[hdf5_fhi_postprocessing_time]          = "post-processing_phase_execution_time";
    00982
    00983 }// end of PopulateHeaderFileMap
    00984 //------------------------------------------------------------------------------

All Classes Files Functions Variables Typedefs Enumerations