From d16545c77638f36052a52ea0949ddccead557e10 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Thu, 29 Apr 2010 19:26:45 +0200 Subject: [PATCH] dump time information to hdf5 file --- FDTD/processfields.cpp | 7 ++++++- FDTD/processfields.h | 2 +- FDTD/processfields_td.cpp | 8 ++++---- matlab/ReadHDF5FieldData.m | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/FDTD/processfields.cpp b/FDTD/processfields.cpp index c35043e..dae9c38 100644 --- a/FDTD/processfields.cpp +++ b/FDTD/processfields.cpp @@ -307,7 +307,7 @@ bool ProcessFields::DumpMultiScalarArray2VTK(ofstream &file, string names[], FDT return true; } -bool ProcessFields::DumpVectorArray2HDF5(string filename, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines) +bool ProcessFields::DumpVectorArray2HDF5(string filename, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines, float time) { const H5std_string FILE_NAME(filename); const H5std_string DATASET_NAME( name ); @@ -329,6 +329,11 @@ bool ProcessFields::DumpVectorArray2HDF5(string filename, string name, FDTD_FLOA // datatype.setOrder( H5T_ORDER_LE ); H5::DataSet dataset = group.createDataSet( DATASET_NAME, datatype, dataspace ); + hsize_t t_dimsf[] = {1}; + H5::DataSpace t_dataspace( 1, t_dimsf ); + H5::Attribute attr = dataset.createAttribute("time",H5::PredType::NATIVE_FLOAT,t_dataspace); + attr.write( H5::PredType::NATIVE_FLOAT , &time); + // I have not the slightest idea why this array-copy action is necessary... but it's the only way hdf5 does what it is supposed to do anyway!! // at least it is save in case FDTD_FLOAT was defined as double... // why does hdf5 write the dimensions backwards??? or matlab??? diff --git a/FDTD/processfields.h b/FDTD/processfields.h index ab164f1..5aef9c9 100644 --- a/FDTD/processfields.h +++ b/FDTD/processfields.h @@ -57,7 +57,7 @@ public: static bool DumpScalarArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12); static bool DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12); - static bool DumpVectorArray2HDF5(string filename, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines); + static bool DumpVectorArray2HDF5(string filename, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines, float time=0); double CalcTotalEnergy() const; diff --git a/FDTD/processfields_td.cpp b/FDTD/processfields_td.cpp index b818070..40359ef 100644 --- a/FDTD/processfields_td.cpp +++ b/FDTD/processfields_td.cpp @@ -84,7 +84,7 @@ void ProcessFieldsTD::DumpCellInterpol(string filename) { stringstream ss; ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->GetNumberOfTimesteps(); - DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),E_T,numDLines); + DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),E_T,numDLines,Eng->GetNumberOfTimesteps()*Op->GetTimestep()); } else cerr << "ProcessFieldsTD::DumpCellInterpol: unknown File-Type" << endl; @@ -148,7 +148,7 @@ void ProcessFieldsTD::DumpCellInterpol(string filename) { stringstream ss; ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->GetNumberOfTimesteps(); - DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),H_T,numDLines); + DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),H_T,numDLines,(0.5+Eng->GetNumberOfTimesteps())*Op->GetTimestep()); } else cerr << "ProcessFieldsTD::DumpCellInterpol: unknown File-Type" << endl; @@ -198,7 +198,7 @@ void ProcessFieldsTD::DumpNoInterpol(string filename) { stringstream ss; ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->GetNumberOfTimesteps(); - DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),E_T,numLines); + DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),E_T,numLines,Eng->GetNumberOfTimesteps()*Op->GetTimestep()); } else cerr << "ProcessFieldsTD::DumpCellInterpol: unknown File-Type" << endl; @@ -244,7 +244,7 @@ void ProcessFieldsTD::DumpNoInterpol(string filename) { stringstream ss; ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->GetNumberOfTimesteps(); - DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),H_T,numLines); + DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),H_T,numLines,(0.5+Eng->GetNumberOfTimesteps())*Op->GetTimestep()); } else cerr << "ProcessFieldsTD::DumpCellInterpol: unknown File-Type" << endl; diff --git a/matlab/ReadHDF5FieldData.m b/matlab/ReadHDF5FieldData.m index 83471a6..dfa1304 100644 --- a/matlab/ReadHDF5FieldData.m +++ b/matlab/ReadHDF5FieldData.m @@ -15,11 +15,12 @@ for n=1:numel(info.GroupHierarchy.Groups) if strcmp(info.GroupHierarchy.Groups(n).Name,'/FieldData') for m=1:numel(info.GroupHierarchy.Groups(n).Datasets) names{m} = info.GroupHierarchy.Groups(n).Datasets(m).Name; + hdf_fielddata.time(m) = double(info.GroupHierarchy.Groups(n).Datasets(m).Attributes.Value); end end end hdf_fielddata.names = names; for n=1:numel(names) - hdf_fielddata.values{n} = hdf5read(file,names{n}); + hdf_fielddata.values{n} = double(hdf5read(file,names{n})); end \ No newline at end of file