From aacbf33e6362aca6d5ad10a4bc1e8dadf3980f4d Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Fri, 17 Feb 2012 12:30:58 +0100 Subject: [PATCH] hdf5 writer: set and create current group --- tools/hdf5_file_writer.cpp | 19 +++++++++++++++++++ tools/hdf5_file_writer.h | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/hdf5_file_writer.cpp b/tools/hdf5_file_writer.cpp index 9c556ad..1043070 100644 --- a/tools/hdf5_file_writer.cpp +++ b/tools/hdf5_file_writer.cpp @@ -89,6 +89,25 @@ hid_t HDF5_File_Writer::OpenGroup(hid_t hdf5_file, string group) return grp; } +void HDF5_File_Writer::SetCurrentGroup(std::string group, bool createGrp) +{ + m_Group = group; + if (createGrp==false) + return; + + hid_t hdf5_file = H5Fopen( m_filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT ); + if (hdf5_file<0) + { + cerr << "HDF5_File_Writer::SetCurrentGroup: Error, opening the given file """ << m_filename << """ failed" << endl; + return; + } + hid_t hdf5_group = OpenGroup(hdf5_file, m_Group); + if (hdf5_group<0) + cerr << "HDF5_File_Writer::WriteData: Error opening group" << endl; + H5Gclose(hdf5_group); + H5Fclose(hdf5_file); +} + bool HDF5_File_Writer::WriteRectMesh(unsigned int const* numLines, double const* const* discLines, int MeshType, double scaling) { float* array[3]; diff --git a/tools/hdf5_file_writer.h b/tools/hdf5_file_writer.h index 4bae3d8..625224d 100644 --- a/tools/hdf5_file_writer.h +++ b/tools/hdf5_file_writer.h @@ -43,7 +43,7 @@ public: bool WriteAtrribute(std::string locName, std::string attr_name, float const* value, hsize_t size); bool WriteAtrribute(std::string locName, std::string attr_name, std::vector values); - void SetCurrentGroup(std::string group) {m_Group = group;} + void SetCurrentGroup(std::string group, bool createGrp=true); protected: std::string m_filename;