1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-09-20 05:25:37 +01:00

Merge pull request #2 from mspraggs/master

Fixed a couple of HDF5 bugs
This commit is contained in:
Antonin Portelli 2015-10-07 18:44:55 +01:00
commit e31b8f0dcb
2 changed files with 21 additions and 3 deletions

View File

@ -63,7 +63,7 @@ void Hdf5File::save(const DMat &m, const string &name)
DataSpace dataSpace(2, dim), attrSpace(1, &attrDim); DataSpace dataSpace(2, dim), attrSpace(1, &attrDim);
group = h5File_->createGroup(name.c_str()); group = h5File_->createGroup(name.c_str() + nameOffset(name));
attr = group.createAttribute("type", PredType::NATIVE_SHORT, attrSpace); attr = group.createAttribute("type", PredType::NATIVE_SHORT, attrSpace);
attr.write(PredType::NATIVE_SHORT, &dMatType); attr.write(PredType::NATIVE_SHORT, &dMatType);
dataset = group.createDataSet("data", PredType::NATIVE_DOUBLE, dataSpace); dataset = group.createDataSet("data", PredType::NATIVE_DOUBLE, dataSpace);
@ -82,7 +82,7 @@ void Hdf5File::save(const DMatSample &sample, const string &name)
const long int nSample = sample.size(); const long int nSample = sample.size();
string datasetName; string datasetName;
group = h5File_->createGroup(name.c_str()); group = h5File_->createGroup(name.c_str() + nameOffset(name));
attr = group.createAttribute("type", PredType::NATIVE_SHORT, attrSpace); attr = group.createAttribute("type", PredType::NATIVE_SHORT, attrSpace);
attr.write(PredType::NATIVE_SHORT, &dMatSampleType); attr.write(PredType::NATIVE_SHORT, &dMatSampleType);
attr = group.createAttribute("nSample", PredType::NATIVE_LONG, attrSpace); attr = group.createAttribute("nSample", PredType::NATIVE_LONG, attrSpace);
@ -105,7 +105,7 @@ void Hdf5File::save(const RandGenState &state, const string &name)
hsize_t attrDim = 1; hsize_t attrDim = 1;
DataSpace dataSpace(1, &dim), attrSpace(1, &attrDim); DataSpace dataSpace(1, &dim), attrSpace(1, &attrDim);
group = h5File_->createGroup(name.c_str()); group = h5File_->createGroup(name.c_str() + nameOffset(name));
attr = group.createAttribute("type", PredType::NATIVE_SHORT, attrSpace); attr = group.createAttribute("type", PredType::NATIVE_SHORT, attrSpace);
attr.write(PredType::NATIVE_SHORT, &rgStateType); attr.write(PredType::NATIVE_SHORT, &rgStateType);
dataset = group.createDataSet("data", PredType::NATIVE_DOUBLE, dataSpace); dataset = group.createDataSet("data", PredType::NATIVE_DOUBLE, dataSpace);
@ -185,6 +185,7 @@ string Hdf5File::getFirstGroupName(void)
}; };
char groupName[maxGroupNameSize]; char groupName[maxGroupNameSize];
groupName[0] = 0; // Need to make sure it's null-terminated
h5File_->iterateElems("/", nullptr, firstGroupName, groupName); h5File_->iterateElems("/", nullptr, firstGroupName, groupName);
res = groupName; res = groupName;
@ -313,3 +314,18 @@ string Hdf5File::load(const string &name)
return ""; return "";
} }
} }
size_t Hdf5File::nameOffset(const string& name)
{
size_t ret = 0;
string badChars = "/";
for (auto c : badChars) {
size_t pos = name.rfind(c);
if (pos != string::npos and pos > ret) {
ret = pos;
}
}
return ret;
}

View File

@ -62,6 +62,8 @@ private:
void load(DMat &m, const H5NS::DataSet &d); void load(DMat &m, const H5NS::DataSet &d);
void load(DMatSample &s, const H5NS::DataSet &d); void load(DMatSample &s, const H5NS::DataSet &d);
void load(RandGenState &state, const H5NS::DataSet &d); void load(RandGenState &state, const H5NS::DataSet &d);
static size_t nameOffset(const std::string& name);
private: private:
// file name // file name
std::unique_ptr<H5NS::H5File> h5File_{nullptr}; std::unique_ptr<H5NS::H5File> h5File_{nullptr};