From 48cf338752b57882cc07edefeb92ee847136e4a0 Mon Sep 17 00:00:00 2001 From: akva Date: Wed, 1 Jun 2011 13:30:40 +0000 Subject: [PATCH] added: readstring function to the HDF5 reader git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@1024 e10b68d5-8a6e-419e-a041-bce267b0401d --- src/Utility/HDF5Writer.C | 19 +++++++++++++++++++ src/Utility/HDF5Writer.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/Utility/HDF5Writer.C b/src/Utility/HDF5Writer.C index 2621b132..991ecc05 100644 --- a/src/Utility/HDF5Writer.C +++ b/src/Utility/HDF5Writer.C @@ -108,6 +108,25 @@ void HDF5Writer::readArray(int group, const std::string& name, #endif } +void HDF5Writer::readString(const std::string& name, std::string& out) +{ +#ifdef HAS_HDF5 + openFile(0); + hid_t set = H5Dopen2(m_file,name.c_str(),H5P_DEFAULT); + hsize_t siz = H5Dget_storage_size(set); + char* temp = new char[siz+1]; + out.resize(siz); + H5Dread(set,H5T_NATIVE_CHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,temp); + temp[siz] = '\0'; + out = temp; + delete[] temp; + H5Dclose(set); + closeFile(0); +#else + std::cout << "HDF5Writer: compiled without HDF5 support, no data read" << std::endl; +#endif +} + void HDF5Writer::writeArray(int group, const std::string& name, int len, const void* data, int type) { diff --git a/src/Utility/HDF5Writer.h b/src/Utility/HDF5Writer.h index f975ff74..b696455c 100644 --- a/src/Utility/HDF5Writer.h +++ b/src/Utility/HDF5Writer.h @@ -26,6 +26,7 @@ public: bool readField(int level, const std::string& name, Vector& vec, SIMbase* sim, int components); + void readString(const std::string& name, std::string& out); protected: void writeArray(int group, const std::string& name,