From 4c165d6124e5e94039daf137ebae07ce5775d222 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de> Date: Wed, 15 Mar 2017 17:49:59 +0100 Subject: [PATCH] print x/y/hSetCoord --- pub/lib/special.cpp | 21 ++++++++++++++++++++- pub/trivia/vector_ops.hpp | 17 ++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pub/lib/special.cpp b/pub/lib/special.cpp index 70b37084..4b8cb2cc 100644 --- a/pub/lib/special.cpp +++ b/pub/lib/special.cpp @@ -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"; } diff --git a/pub/trivia/vector_ops.hpp b/pub/trivia/vector_ops.hpp index 894f6b4b..22edd3e4 100644 --- a/pub/trivia/vector_ops.hpp +++ b/pub/trivia/vector_ops.hpp @@ -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) { -- GitLab