From f20a36863c77f42bab1e5643317bd1c59b3bc292 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Mon, 30 Jul 2012 11:11:41 +0200 Subject: [PATCH] hdf5: some fixes and minor improvements for hdf5 reader & writer --- tools/hdf5_file_reader.cpp | 14 ++++++++++++-- tools/hdf5_file_writer.cpp | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/hdf5_file_reader.cpp b/tools/hdf5_file_reader.cpp index 097a89c..bfb0117 100644 --- a/tools/hdf5_file_reader.cpp +++ b/tools/hdf5_file_reader.cpp @@ -102,6 +102,8 @@ bool HDF5_File_Reader::ReadDataSet(string ds_name, hsize_t &nDim, hsize_t* &dims cerr << "HDF5_File_Reader::ReadDataSet: error reading data" << endl; H5Dclose(dataset); H5Fclose(hdf5_file); + delete[] data; + data=NULL; return false; } H5Dclose(dataset); @@ -152,6 +154,7 @@ bool HDF5_File_Reader::ReadMesh(float** lines, unsigned int* numLines, int &mesh { cerr << "HDF5_File_Reader::ReadMesh: mesh dimension error" << endl; delete[] dims; + delete[] data; H5Fclose(hdf5_file); return false; } @@ -175,7 +178,7 @@ unsigned int HDF5_File_Reader::GetNumTimeSteps() return false; } - if (H5Lexists(hdf5_file, "/FieldData/TD", H5P_DEFAULT)<0) + if (H5Lexists(hdf5_file, "/FieldData/TD", H5P_DEFAULT)<=0) { H5Fclose(hdf5_file); return 0; @@ -282,7 +285,7 @@ float**** HDF5_File_Reader::GetTDVectorData(size_t idx, float &time, unsigned in } time = 0; - if (H5Lexists(hdf5_file, "/FieldData/TD", H5P_DEFAULT)<0) + if (H5Lexists(hdf5_file, "/FieldData/TD", H5P_DEFAULT)<=0) { cerr << "HDF5_File_Reader::GetTDVectorData: can't open ""/FieldData/TD""" << endl; H5Fclose(hdf5_file); @@ -404,6 +407,13 @@ complex**** HDF5_File_Reader::GetFDVectorData(size_t idx, float &frequenc bool HDF5_File_Reader::CalcFDVectorData(vector &frequencies, vector****> &FD_data, unsigned int data_size[4]) { FD_data.clear(); + + if (GetNumTimeSteps()<=0) + { + cerr << "HDF5_File_Reader::CalcFDVectorData: error, no TD data found..." << endl; + return false; + } + float time; //read first TD data float**** field = this->GetTDVectorData(0,time,data_size); diff --git a/tools/hdf5_file_writer.cpp b/tools/hdf5_file_writer.cpp index 6e73dcf..6c7761f 100644 --- a/tools/hdf5_file_writer.cpp +++ b/tools/hdf5_file_writer.cpp @@ -393,7 +393,7 @@ bool HDF5_File_Writer::WriteAtrribute(std::string locName, std::string attr_name bool HDF5_File_Writer::WriteAtrribute(std::string locName, std::string attr_name, vector values) { - float val[values.size()]; + double val[values.size()]; for (size_t n=0;n