2019-02-04 10:58:28 +00:00
|
|
|
#include <LatCore/OptParser.hpp>
|
|
|
|
#include <LatAnalyze/CompiledModel.hpp>
|
|
|
|
#include <LatAnalyze/Io.hpp>
|
|
|
|
#include <LatAnalyze/MatSample.hpp>
|
|
|
|
#include <LatAnalyze/Math.hpp>
|
|
|
|
#include <LatAnalyze/MinuitMinimizer.hpp>
|
|
|
|
#include <LatAnalyze/NloptMinimizer.hpp>
|
|
|
|
#include <LatAnalyze/Plot.hpp>
|
|
|
|
#include <LatAnalyze/XYSampleData.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Latan;
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
// parse arguments /////////////////////////////////////////////////////////
|
|
|
|
OptParser opt;
|
2019-03-09 11:38:10 +00:00
|
|
|
bool parsed, imag;
|
2019-02-04 10:58:28 +00:00
|
|
|
string plotFileName, outFileName, xName, yName, title;
|
2019-02-20 19:56:14 +00:00
|
|
|
vector<string> inFileName;
|
2019-02-20 16:35:14 +00:00
|
|
|
double xLow, xHigh, spacing;
|
2019-02-20 19:56:14 +00:00
|
|
|
|
2019-03-09 11:38:10 +00:00
|
|
|
opt.addOption("i" , "imag" , OptParser::OptType::trigger, true,
|
|
|
|
"plot imaginary");
|
2019-02-04 10:58:28 +00:00
|
|
|
opt.addOption("o", "output", OptParser::OptType::value , true,
|
|
|
|
"output file", "");
|
|
|
|
opt.addOption("x", "xAxis", OptParser::OptType::value , true,
|
|
|
|
"x-axis name", "");
|
2019-02-20 16:35:14 +00:00
|
|
|
opt.addOption("l", "xLow", OptParser::OptType::value , true,
|
|
|
|
"x-axis lower bound", "0");
|
2019-02-04 10:58:28 +00:00
|
|
|
opt.addOption("y", "yAxis", OptParser::OptType::value , true,
|
|
|
|
"y-axis name", "");
|
2019-02-20 16:35:14 +00:00
|
|
|
opt.addOption("s", "spacing", OptParser::OptType::value , true,
|
|
|
|
"spacing between points", "1");
|
2019-02-04 10:58:28 +00:00
|
|
|
opt.addOption("t", "title", OptParser::OptType::value , true,
|
|
|
|
"plot title", "");
|
|
|
|
opt.addOption("", "help" , OptParser::OptType::trigger, true,
|
|
|
|
"show this help message and exit");
|
|
|
|
parsed = opt.parse(argc, argv);
|
2019-02-20 19:56:14 +00:00
|
|
|
if (!parsed or opt.gotOption("help") or opt.getArgs().size() != 1)
|
2019-02-04 10:58:28 +00:00
|
|
|
{
|
2019-02-20 19:56:14 +00:00
|
|
|
cerr << "usage: " << argv[0] << " <.h5/manifest file> <options> " << endl;
|
2019-02-04 10:58:28 +00:00
|
|
|
cerr << endl << "Possible options:" << endl << opt << endl;
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2019-02-20 19:56:14 +00:00
|
|
|
|
|
|
|
plotFileName = opt.getArgs().front();
|
2019-03-09 11:38:10 +00:00
|
|
|
imag = opt.gotOption("i");
|
2019-02-04 10:58:28 +00:00
|
|
|
xName = opt.optionValue("x");
|
2019-02-20 16:35:14 +00:00
|
|
|
xLow = opt.optionValue<double>("l");
|
2019-02-04 10:58:28 +00:00
|
|
|
yName = opt.optionValue("y");
|
2019-02-20 16:35:14 +00:00
|
|
|
spacing = opt.optionValue<double>("s");
|
2019-02-04 10:58:28 +00:00
|
|
|
title = opt.optionValue("t");
|
|
|
|
outFileName = opt.optionValue<string>("o");
|
2019-02-20 19:56:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
if(plotFileName.find(".h5") == string::npos)
|
|
|
|
{
|
|
|
|
inFileName = readManifest(plotFileName);
|
|
|
|
}
|
2019-02-04 10:58:28 +00:00
|
|
|
|
2019-02-20 19:56:14 +00:00
|
|
|
// load and plot file(s) /////////////////////////////////////////////////////////
|
2019-02-04 10:58:28 +00:00
|
|
|
DMatSample tmp;
|
|
|
|
Index nt;
|
|
|
|
Plot p;
|
|
|
|
DVec tAxis;
|
|
|
|
|
2019-02-20 19:56:14 +00:00
|
|
|
|
|
|
|
if(inFileName.size() == 0)
|
|
|
|
{
|
|
|
|
tmp = Io::load<DMatSample>(plotFileName);
|
|
|
|
nt = tmp[central].rows();
|
2019-03-09 11:38:10 +00:00
|
|
|
if(imag)
|
|
|
|
{
|
|
|
|
tmp = tmp.block(0, 1, nt, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = tmp.block(0, 0, nt, 1);
|
|
|
|
}
|
2019-02-20 19:56:14 +00:00
|
|
|
xHigh= xLow+spacing*(nt-1);
|
|
|
|
tAxis.setLinSpaced(nt, xLow, xHigh);
|
|
|
|
p << PlotData(tAxis, tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = Io::load<DMatSample>(inFileName[0]);
|
|
|
|
nt = tmp[central].rows();
|
|
|
|
xHigh= xLow+spacing*(nt-1);
|
|
|
|
tAxis.setLinSpaced(nt, xLow, xHigh);
|
|
|
|
|
|
|
|
for(unsigned long i = 0; i < inFileName.size(); i++)
|
|
|
|
{
|
|
|
|
plotFileName = inFileName[i];
|
|
|
|
tmp = Io::load<DMatSample>(plotFileName);
|
2019-03-09 11:38:10 +00:00
|
|
|
if(imag)
|
|
|
|
{
|
|
|
|
tmp = tmp.block(0, 1, nt, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-20 19:56:14 +00:00
|
|
|
tmp = tmp.block(0, 0, nt, 1);
|
2019-03-09 11:38:10 +00:00
|
|
|
}
|
2019-02-20 19:56:14 +00:00
|
|
|
p << PlotData(tAxis, tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-04 10:58:28 +00:00
|
|
|
p << Label(xName, Axis::x);
|
|
|
|
p << Label(yName, Axis::y);
|
2019-02-20 16:35:14 +00:00
|
|
|
p << PlotRange(Axis::x, xLow, xHigh);
|
2019-02-04 10:58:28 +00:00
|
|
|
p << Caption(title);
|
2019-02-20 19:56:14 +00:00
|
|
|
|
|
|
|
cout << "Displaying plot..." << endl;
|
2019-02-04 10:58:28 +00:00
|
|
|
p.display();
|
|
|
|
|
|
|
|
// output //////////////////////////////////////////////////////////////////
|
|
|
|
if (!outFileName.empty())
|
|
|
|
{
|
|
|
|
Io::save(tmp, outFileName);
|
|
|
|
cout << "File saved as: " << outFileName << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|