1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-09-20 05:25:37 +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
commit 707496b245
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);
std::unique_ptr<File> file = open(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 + "'");
}
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);
std::unique_ptr<File> file = open(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 + "'");
}
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);
std::unique_ptr<File> file = open(fileName, mode);
std::string realName = (name.empty()) ? fileName : name;
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 + "'");
}
file->save(data, realName);
}
template <typename FileType>

View File

@ -15,11 +15,16 @@ endif
endif
bin_PROGRAMS = \
latan_create_rg_state \
latan_make_fake_sample\
latan_sample_combine \
latan_sample_read \
latan_resample
latan_create_rg_state_SOURCES = create_rg_state.cpp
latan_create_rg_state_CXXFLAGS = $(COM_CXXFLAGS)
latan_create_rg_state_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_make_fake_sample_SOURCES = make_fake_sample.cpp
latan_make_fake_sample_CXXFLAGS = $(COM_CXXFLAGS)
latan_make_fake_sample_LDFLAGS = -L../lib/.libs -lLatAnalyze

44
utils/create_rg_state.cpp Normal file
View File

@ -0,0 +1,44 @@
/*
* create_rg_state.cpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2015 Antonin Portelli
*
* LatAnalyze 3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze 3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/RandGen.hpp>
using namespace Latan;
using namespace std;
int main(int argc, char *argv[])
{
string outFilename;
if (argc != 2)
{
cerr << "usage: " << argv[0] << " <output file>" << endl;
return EXIT_FAILURE;
}
outFilename = argv[1];
RandGen gen;
Io::save(gen.getState(), outFilename);
return EXIT_SUCCESS;
}

View File

@ -34,7 +34,7 @@ using namespace Latan;
static void usage(const string &cmdName)
{
cerr << "usage: " << cmdName;
cerr << " [-n <nsample> -b <bin size> -r <state> -o <output dir>]";
cerr << " [-n <nsample> -b <bin size> -r <state> -o <output dir> -f {h5|sample}]";
cerr << " <data list> <name list>";
cerr << endl;
exit(EXIT_FAILURE);
@ -45,11 +45,12 @@ int main(int argc, char *argv[])
// argument parsing ////////////////////////////////////////////////////////
int c;
string manFileName, nameFileName, stateFileName, cmdName, outDirName = ".";
string ext = "h5";
Index binSize = 1, nSample = DEF_NSAMPLE;
opterr = 0;
cmdName = basename(argv[0]);
while ((c = getopt(argc, argv, "b:n:r:o:")) != -1)
while ((c = getopt(argc, argv, "b:n:r:o:f:")) != -1)
{
switch (c)
{
@ -65,6 +66,9 @@ int main(int argc, char *argv[])
case 'r':
stateFileName = optarg;
break;
case 'f':
ext = optarg;
break;
case '?':
cerr << "error parsing option -" << char(optopt) << endl;
usage(cmdName);
@ -92,11 +96,12 @@ int main(int argc, char *argv[])
cout << "================================================" << endl;
cout << "Data resampler" << endl;
cout << "------------------------------------------------" << endl;
cout << " #file= " << dataFileName.size() << endl;
cout << " #name= " << name.size() << endl;
cout << " bin size= " << binSize << endl;
cout << " #sample= " << nSample << endl;
cout << "output dir: " << outDirName << endl;
cout << " #file= " << dataFileName.size() << endl;
cout << " #name= " << name.size() << endl;
cout << " bin size= " << binSize << endl;
cout << " #sample= " << nSample << endl;
cout << " output dir: " << outDirName << endl;
cout << "output format: " << ext << endl;
cout << "------------------------------------------------" << endl;
// data loading ////////////////////////////////////////////////////////////
@ -109,30 +114,13 @@ int main(int argc, char *argv[])
}
for (unsigned int i = 0; i < dataFileName.size(); ++i)
{
std::unique_ptr<File> dataFile;
std::unique_ptr<File> dataFile = Io::open(dataFileName[i]);
if (extension(dataFileName[i]) == "dat")
{
dataFile.reset(new AsciiFile);
}
else if (extension(dataFileName[i]) == "h5")
{
dataFile.reset(new Hdf5File);
}
else
{
cerr << "error: '" << dataFileName[i];
cerr << "' has an unknown extension" << endl;
return EXIT_FAILURE;
}
cout << '\r' << ProgressBar(i + 1, dataFileName.size());
dataFile->open(dataFileName[i], AsciiFile::Mode::read);
for (const string &n: name)
{
data[n][i] = dataFile->read<DMat>(n);
}
dataFile->close();
}
cout << endl;
@ -148,7 +136,7 @@ int main(int argc, char *argv[])
}
for (unsigned int i = 0; i < name.size(); ++i)
{
const string outFileName = name[i] + "_" + manFileName + ".sample";
const string outFileName = name[i] + "_" + manFileName + "." + ext;
cout << '\r' << ProgressBar(i + 1, name.size());
data[name[i]].bin(binSize);