mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 08:55:37 +00:00
Merge branch 'master' of github.com:aportelli/LatAnalyze3
This commit is contained in:
commit
707496b245
@ -124,8 +124,8 @@ void Hdf5File::save(const RandGenState &state, const string &name)
|
|||||||
group = h5File_->createGroup(name.c_str() + nameOffset(name));
|
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_INT, dataSpace);
|
||||||
dataset.write(state.data(), PredType::NATIVE_DOUBLE);
|
dataset.write(state.data(), PredType::NATIVE_INT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read first name ////////////////////////////////////////////////////////////
|
// read first name ////////////////////////////////////////////////////////////
|
||||||
@ -262,7 +262,7 @@ void Hdf5File::load(RandGenState &state, const DataSet &d)
|
|||||||
dataspace.getSimpleExtentDims(dim);
|
dataspace.getSimpleExtentDims(dim);
|
||||||
if (dim[0] != RLXG_STATE_SIZE)
|
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);
|
d.read(state.data(), PredType::NATIVE_INT);
|
||||||
}
|
}
|
||||||
|
15
lib/Io.cpp
15
lib/Io.cpp
@ -25,20 +25,9 @@ using namespace Latan;
|
|||||||
|
|
||||||
string Io::getFirstName(const string &fileName)
|
string Io::getFirstName(const string &fileName)
|
||||||
{
|
{
|
||||||
string ext = extension(fileName);
|
std::unique_ptr<File> file = open(fileName);
|
||||||
|
|
||||||
if (ext == "h5")
|
return file->getFirstName();
|
||||||
{
|
|
||||||
return getFirstName<Hdf5File>(fileName);
|
|
||||||
}
|
|
||||||
else if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
|
|
||||||
{
|
|
||||||
return getFirstName<AsciiFile>(fileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Io, "unknown file extension '" + ext + "'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<File> Io::open(const std::string &fileName, const unsigned int mode)
|
unique_ptr<File> Io::open(const std::string &fileName, const unsigned int mode)
|
||||||
|
33
lib/Io.hpp
33
lib/Io.hpp
@ -48,7 +48,7 @@ public:
|
|||||||
static std::string getFirstName(const std::string &fileName);
|
static std::string getFirstName(const std::string &fileName);
|
||||||
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,
|
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 /////////////////////////////////////////////////////
|
// template implementation /////////////////////////////////////////////////////
|
||||||
@ -63,20 +63,9 @@ IoT Io::load(const std::string &fileName, const std::string &name)
|
|||||||
template <typename IoT>
|
template <typename IoT>
|
||||||
IoT Io::load(const std::string &fileName, const std::string &name)
|
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 file->read<IoT>(name);
|
||||||
{
|
|
||||||
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 + "'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename IoT, typename FileType>
|
template <typename IoT, typename FileType>
|
||||||
@ -93,20 +82,10 @@ template <typename IoT>
|
|||||||
void Io::save(const IoT &data, const std::string &fileName,
|
void Io::save(const IoT &data, const std::string &fileName,
|
||||||
const unsigned int mode, const std::string &name)
|
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")
|
file->save(data, realName);
|
||||||
{
|
|
||||||
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 + "'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FileType>
|
template <typename FileType>
|
||||||
|
@ -15,11 +15,16 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
bin_PROGRAMS = \
|
bin_PROGRAMS = \
|
||||||
|
latan_create_rg_state \
|
||||||
latan_make_fake_sample\
|
latan_make_fake_sample\
|
||||||
latan_sample_combine \
|
latan_sample_combine \
|
||||||
latan_sample_read \
|
latan_sample_read \
|
||||||
latan_resample
|
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_SOURCES = make_fake_sample.cpp
|
||||||
latan_make_fake_sample_CXXFLAGS = $(COM_CXXFLAGS)
|
latan_make_fake_sample_CXXFLAGS = $(COM_CXXFLAGS)
|
||||||
latan_make_fake_sample_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
latan_make_fake_sample_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||||
|
44
utils/create_rg_state.cpp
Normal file
44
utils/create_rg_state.cpp
Normal 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;
|
||||||
|
}
|
@ -34,7 +34,7 @@ using namespace Latan;
|
|||||||
static void usage(const string &cmdName)
|
static void usage(const string &cmdName)
|
||||||
{
|
{
|
||||||
cerr << "usage: " << 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 << " <data list> <name list>";
|
||||||
cerr << endl;
|
cerr << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -45,11 +45,12 @@ int main(int argc, char *argv[])
|
|||||||
// argument parsing ////////////////////////////////////////////////////////
|
// argument parsing ////////////////////////////////////////////////////////
|
||||||
int c;
|
int c;
|
||||||
string manFileName, nameFileName, stateFileName, cmdName, outDirName = ".";
|
string manFileName, nameFileName, stateFileName, cmdName, outDirName = ".";
|
||||||
|
string ext = "h5";
|
||||||
Index binSize = 1, nSample = DEF_NSAMPLE;
|
Index binSize = 1, nSample = DEF_NSAMPLE;
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
cmdName = basename(argv[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)
|
switch (c)
|
||||||
{
|
{
|
||||||
@ -65,6 +66,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'r':
|
case 'r':
|
||||||
stateFileName = optarg;
|
stateFileName = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
ext = optarg;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
cerr << "error parsing option -" << char(optopt) << endl;
|
cerr << "error parsing option -" << char(optopt) << endl;
|
||||||
usage(cmdName);
|
usage(cmdName);
|
||||||
@ -97,6 +101,7 @@ int main(int argc, char *argv[])
|
|||||||
cout << " bin size= " << binSize << endl;
|
cout << " bin size= " << binSize << endl;
|
||||||
cout << " #sample= " << nSample << endl;
|
cout << " #sample= " << nSample << endl;
|
||||||
cout << " output dir: " << outDirName << endl;
|
cout << " output dir: " << outDirName << endl;
|
||||||
|
cout << "output format: " << ext << endl;
|
||||||
cout << "------------------------------------------------" << endl;
|
cout << "------------------------------------------------" << endl;
|
||||||
|
|
||||||
// data loading ////////////////////////////////////////////////////////////
|
// data loading ////////////////////////////////////////////////////////////
|
||||||
@ -109,30 +114,13 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < dataFileName.size(); ++i)
|
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());
|
cout << '\r' << ProgressBar(i + 1, dataFileName.size());
|
||||||
dataFile->open(dataFileName[i], AsciiFile::Mode::read);
|
|
||||||
for (const string &n: name)
|
for (const string &n: name)
|
||||||
{
|
{
|
||||||
data[n][i] = dataFile->read<DMat>(n);
|
data[n][i] = dataFile->read<DMat>(n);
|
||||||
}
|
}
|
||||||
dataFile->close();
|
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
@ -148,7 +136,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < name.size(); ++i)
|
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());
|
cout << '\r' << ProgressBar(i + 1, name.size());
|
||||||
data[name[i]].bin(binSize);
|
data[name[i]].bin(binSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user