added: readstring function to the HDF5 reader

git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@1024 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
akva 2011-06-01 13:30:40 +00:00 committed by Knut Morten Okstad
parent 2205096b27
commit 48cf338752
2 changed files with 20 additions and 0 deletions

View File

@ -108,6 +108,25 @@ void HDF5Writer::readArray(int group, const std::string& name,
#endif #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, void HDF5Writer::writeArray(int group, const std::string& name,
int len, const void* data, int type) int len, const void* data, int type)
{ {

View File

@ -26,6 +26,7 @@ public:
bool readField(int level, const std::string& name, bool readField(int level, const std::string& name,
Vector& vec, SIMbase* sim, int components); Vector& vec, SIMbase* sim, int components);
void readString(const std::string& name, std::string& out);
protected: protected:
void writeArray(int group, const std::string& name, void writeArray(int group, const std::string& name,