Skip to content
Snippets Groups Projects
Commit 4c165d61 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

print x/y/hSetCoord

parent c77ca108
No related branches found
No related tags found
No related merge requests found
......@@ -126,13 +126,32 @@ void NSpecial::export_p2d(bool allow_overwrite)
throw "file " + outfnam + " exists, use flag ! to overwrite";
std::ofstream ofs;
ofs.open(outfnam, std::ofstream::out);
// determine and print bin limits
vector<double> zval = f->zvec(0)->to_rvec();
vector<double> zlim = triv::histogram_limits(zval);
vector<double> xlim = triv::histogram_limits(f->VS(0)->x);
double xinf = xlim.front();
double xsup = xlim.back();
double yinf, ysup;
triv::getMinMax(f->VS(0)->y, yinf, ysup);
for (size_t j=1; j<m; ++j) {
xlim = triv::histogram_limits(f->VS(j)->x);
xinf = std::min(xinf, xlim.front());
xsup = std::max(xsup, xlim.back());
double yyinf, yysup;
triv::getMinMax(f->VS(j)->y, yyinf, yysup);
yinf = std::min(yinf, yyinf);
ysup = std::max(ysup, yysup);
}
ofs << ( format("0 %13.7g %13.7g xSetCoord\n") % xinf % xsup );
ofs << ( format("0 %13.7g %13.7g ySetCoord\n") % zlim.front() % zlim.back() );
ofs << ( format("0 %13.7g %13.7g hSetCoord\n") % yinf % ysup );
// print bins
for (size_t j=0; j<m; ++j) {
const CSpec* s = f->VS(j);
vector<double> xlim = triv::histogram_limits(s->x);
for (size_t i=0; i<s->size(); ++i)
ofs << ( format("%13.7g wx %13.7g wx %13.7g wz %13.7g wz %13.7g wy p2d\n")
ofs << ( format("%13.7g wx %13.7g wx %13.7g wy %13.7g wy %13.7g wh p2d\n")
% xlim[i] % xlim[i+1] % zlim[j] % zlim[j+1] % s->y[i] );
ofs << "\n";
}
......
......@@ -10,10 +10,10 @@
#include <vector>
#include <functional>
#include <algorithm>
namespace triv
{
void insert_in_sorted(std::vector<double>* V, double val);
void make_unique(std::vector<double>* V, double tolabs = 1e-100, double tolrel = 1e-10);
bool is_ascending(const std::vector<double>& V);
......@@ -24,6 +24,7 @@ namespace triv
void increment_indices(std::vector<int>& v, int incr, int siz);
std::string indices_to_s(const std::vector<int>& v);
template <class T> void getMinMax(const std::vector<T>& v, T& minval, T&maxval);
template <class T> bool contains(const std::vector<T>& v, const T e);
template <class T, class Pred> std::vector<T> merge_sorted(
const std::vector<T>& a, const std::vector<T>& b, Pred a_before_b);
......@@ -31,6 +32,20 @@ namespace triv
//**************************************************************************************************
// Template implementation
//**************************************************************************************************
template <class T>
void getMinMax(const std::vector<T>& v, T& minval, T&maxval)
{
if (v.size()==0)
throw "BUG: attempt to determine min and max of empty vector";
minval = v.front();
maxval = v.front();
for (auto t = v.begin()+1; t<v.end(); ++t) {
minval = std::min(minval, *t);
maxval = std::max(maxval, *t);
}
}
template <class T>
bool contains(const std::vector<T>& v, const T e)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment