mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-11 03:20:46 +01:00
resampler: option to choose output format
This commit is contained in:
parent
a4999a53fd
commit
7ade4be54b
@ -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);
|
||||||
@ -92,11 +96,12 @@ int main(int argc, char *argv[])
|
|||||||
cout << "================================================" << endl;
|
cout << "================================================" << endl;
|
||||||
cout << "Data resampler" << endl;
|
cout << "Data resampler" << endl;
|
||||||
cout << "------------------------------------------------" << endl;
|
cout << "------------------------------------------------" << endl;
|
||||||
cout << " #file= " << dataFileName.size() << endl;
|
cout << " #file= " << dataFileName.size() << endl;
|
||||||
cout << " #name= " << name.size() << endl;
|
cout << " #name= " << name.size() << endl;
|
||||||
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…
x
Reference in New Issue
Block a user