1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-09-20 05:25:37 +01:00
LatAnalyze/utils/plot.cpp

83 lines
2.9 KiB
C++
Raw Normal View History

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;
bool parsed;
string plotFileName, outFileName, xName, yName, title;
double xLow, xHigh, spacing;
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", "");
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", "");
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);
if (!parsed or (opt.getArgs().size() < 1) or opt.gotOption("help"))
{
cerr << "usage: " << argv[0] << " <options> <.h5 file> " << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
plotFileName = opt.getArgs()[0];
xName = opt.optionValue("x");
xLow = opt.optionValue<double>("l");
2019-02-04 10:58:28 +00:00
yName = opt.optionValue("y");
spacing = opt.optionValue<double>("s");
2019-02-04 10:58:28 +00:00
title = opt.optionValue("t");
outFileName = opt.optionValue<string>("o");
// load file /////////////////////////////////////////////////////////
DMatSample tmp;
Index nt;
2019-02-04 10:58:28 +00:00
tmp = Io::load<DMatSample>(plotFileName);
nt = tmp[central].rows();
tmp = tmp.block(0, 0, nt, 1);
// plots ///////////////////////////////////////////////////////////////////
Plot p;
DVec tAxis;
xHigh= xLow+spacing*(nt-1);
tAxis.setLinSpaced(nt, xLow, xHigh);
2019-02-04 10:58:28 +00:00
p << Label(xName, Axis::x);
p << Label(yName, Axis::y);
p << PlotRange(Axis::x, xLow, xHigh);
2019-02-04 10:58:28 +00:00
p << Color("rgb 'red'") << PlotData(tAxis, tmp);
p << Caption(title);
p.display();
// output //////////////////////////////////////////////////////////////////
if (!outFileName.empty())
{
Io::save(tmp, outFileName);
cout << "File saved as: " << outFileName << endl;
}
return EXIT_SUCCESS;
}