1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-20 16:26:54 +01:00

Merge branch 'master' of github.com:aportelli/LatAnalyze3

This commit is contained in:
Matt Spraggs
2015-11-19 14:14:44 +00:00
6 changed files with 78 additions and 73 deletions

View File

@ -124,8 +124,8 @@ void Hdf5File::save(const RandGenState &state, const string &name)
group = h5File_->createGroup(name.c_str() + nameOffset(name));
attr = group.createAttribute("type", PredType::NATIVE_SHORT, attrSpace);
attr.write(PredType::NATIVE_SHORT, &rgStateType);
dataset = group.createDataSet("data", PredType::NATIVE_DOUBLE, dataSpace);
dataset.write(state.data(), PredType::NATIVE_DOUBLE);
dataset = group.createDataSet("data", PredType::NATIVE_INT, dataSpace);
dataset.write(state.data(), PredType::NATIVE_INT);
}
// read first name ////////////////////////////////////////////////////////////
@ -262,7 +262,7 @@ void Hdf5File::load(RandGenState &state, const DataSet &d)
dataspace.getSimpleExtentDims(dim);
if (dim[0] != RLXG_STATE_SIZE)
{
// error here
LATAN_ERROR(Io, "random generator state has a wrong length");
}
d.read(state.data(), PredType::NATIVE_INT);
}

View File

@ -25,20 +25,9 @@ using namespace Latan;
string Io::getFirstName(const string &fileName)
{
string ext = extension(fileName);
if (ext == "h5")
{
return getFirstName<Hdf5File>(fileName);
}
else if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
{
return getFirstName<AsciiFile>(fileName);
}
else
{
LATAN_ERROR(Io, "unknown file extension '" + ext + "'");
}
std::unique_ptr<File> file = open(fileName);
return file->getFirstName();
}
unique_ptr<File> Io::open(const std::string &fileName, const unsigned int mode)

View File

@ -48,7 +48,7 @@ public:
static std::string getFirstName(const std::string &fileName);
static std::string getFirstName(const std::string &fileName);
static std::unique_ptr<File> open(const std::string &fileName,
const unsigned int mode = File::Mode::write);
const unsigned int mode = File::Mode::read);
};
// template implementation /////////////////////////////////////////////////////
@ -63,27 +63,16 @@ IoT Io::load(const std::string &fileName, const std::string &name)
template <typename IoT>
IoT Io::load(const std::string &fileName, const std::string &name)
{
std::string ext = extension(fileName);
if (ext == "h5")
{
return load<IoT, Hdf5File>(fileName, name);
}
else if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
{
return load<IoT, AsciiFile>(fileName, name);
}
else
{
LATAN_ERROR(Io, "unknown file extension '" + ext + "'");
}
std::unique_ptr<File> file = open(fileName);
return file->read<IoT>(name);
}
template <typename IoT, typename FileType>
void Io::save(const IoT &data, const std::string &fileName,
const unsigned int mode, const std::string &name)
{
FileType file(fileName, mode);
FileType file(fileName, mode);
std::string realName = (name.empty()) ? fileName : name;
file.save(data, realName);
@ -93,20 +82,10 @@ template <typename IoT>
void Io::save(const IoT &data, const std::string &fileName,
const unsigned int mode, const std::string &name)
{
std::string ext = extension(fileName);
if (ext == "h5")
{
save<IoT, Hdf5File>(data, fileName, mode, name);
}
else if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
{
save<IoT, AsciiFile>(data, fileName, mode, name);
}
else
{
LATAN_ERROR(Io, "unknown file extension '" + ext + "'");
}
std::unique_ptr<File> file = open(fileName, mode);
std::string realName = (name.empty()) ? fileName : name;
file->save(data, realName);
}
template <typename FileType>