From 71c9bb7a5c892a1a7c5dbe12a0dc082cc00602f7 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Thu, 1 Jul 2021 12:13:38 +0000 Subject: [PATCH] fix/optimize floating point precision for file output/info output/json output --- lib/imc_channel.hpp | 54 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/lib/imc_channel.hpp b/lib/imc_channel.hpp index f7cca7a..227f274 100644 --- a/lib/imc_channel.hpp +++ b/lib/imc_channel.hpp @@ -6,6 +6,7 @@ #include #include "imc_datatype.hpp" #include "imc_conversion.hpp" +#include //---------------------------------------------------------------------------// @@ -87,27 +88,49 @@ namespace imc } }; + // adjust stream object + void customize_stream(std::ostream& stout, int prec, bool fixed) + { + if ( fixed ) + { + stout< - std::string joinvec(std::vector
myvec, unsigned long int limit = 10) + std::string joinvec(std::vector
myvec, unsigned long int limit = 10, int prec = 10, bool fixed = true) { - // include entire list for limit = - 1 + // include entire list for limit = 0 limit = (limit == 0) ? myvec.size() : limit; std::stringstream ss; ss<<"["; if ( myvec.size() <= limit ) { - for ( dt el: myvec ) ss<at(chnenv_.CDuuid_).get_parameter(prms[5]); // TODO // xname_ = std::string("time"); + + // find appropriate precision for "xdata_" by means of "xstepwidth_" + xprec_ = (xstepwidth_ > 0 ) ? ceil(fabs(log10(xstepwidth_))) : 10; } // extract associated CP data @@ -363,8 +390,8 @@ namespace imc <(ydata_)<<"\n" - <(xdata_)<<"\n"; + <(ydata_,10,9,true)<<"\n" + <(xdata_,10,xprec_,true)<<"\n"; // <(ydata_,0) - <<",\"xdata\":"<(xdata_,0); + ss<<",\"ydata\":"<(ydata_,0,9,true) + <<",\"xdata\":"<(xdata_,0,xprec_,true); } // ss<<"\",\"aff. blocks\":\""<