From 64c0bfe3c4f409fc4bb36fdc827a0cb94952ceda Mon Sep 17 00:00:00 2001 From: JWu <j.wuttke@fz-juelich.de> Date: Mon, 4 Feb 2013 15:10:50 +0100 Subject: [PATCH] new property plot_to_grid of curve files --- pub/src/commands.cpp | 4 +++- pub/src/curve.cpp | 4 ++++ pub/src/olf.h | 4 +++- pub/src/plot.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/pub/src/commands.cpp b/pub/src/commands.cpp index 42b1a4ba..2b23e46e 100644 --- a/pub/src/commands.cpp +++ b/pub/src/commands.cpp @@ -121,6 +121,8 @@ bool fridaCommand( string cmd ) " cwc weighing: constant\n" " cwl weighing: logarithmic\n" " cwv weighing: reciprocal variance (default)\n" + " cg+ use plot grid from data reference file\n" + " cg- back to default grid\n" "Fit tuning parameters:\n" " cs? show parameters\n" " csf set gradient step factor\n" @@ -163,7 +165,7 @@ bool fridaCommand( string cmd ) NCurveFile::SetFixed( true ); } else if (cmd == "cu") { NCurveFile::SetFixed( false ); - } else if (cmd.substr(0,2) == "cw") { + } else if (cmd.substr(0,2) == "cw" || cmd.substr(0,2) == "cg") { NCurveFile::SetProperties( cmd.substr(1) ); } else if (cmd == "c_cd") { diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp index 141049d5..e2f158aa 100644 --- a/pub/src/curve.cpp +++ b/pub/src/curve.cpp @@ -673,6 +673,10 @@ void NCurveFile::SetProperties( string which ) fc->weighing = COlc::_LOG; else if (which=="wv") fc->weighing = COlc::_ERR; + else if (which=="g+") + fc->plot_to_grid = true; + else if (which=="g-") + fc->plot_to_grid = false; else throw "unknown property"; } diff --git a/pub/src/olf.h b/pub/src/olf.h index b66b4871..d1cb7c5b 100644 --- a/pub/src/olf.h +++ b/pub/src/olf.h @@ -92,10 +92,12 @@ class COlc : public COlo { uint kd; ///< Index of data file to be fitted. uint kconv; ///< Index of resolution file to convolve with. enum TWgt { _LIN, _LOG, _ERR } weighing; ///< Weight mode for fitting. + bool plot_to_grid; ///< Use grid from file 'kd' ? string range_expr; ///< Restricts points to be fitted (input expression). PNode range_T; ///< Restricts points to be fitted (parsed tree). - COlc() : kconv(-1), weighing( _ERR ), range_expr("") {}; + COlc() : + kconv(-1), weighing( _ERR ), plot_to_grid( false ), range_expr("") {}; // Trivially duplicated functions: PCurve VC( uint j ) const; diff --git a/pub/src/plot.cpp b/pub/src/plot.cpp index 8806fdd4..c6d23349 100644 --- a/pub/src/plot.cpp +++ b/pub/src/plot.cpp @@ -211,6 +211,32 @@ int plot_curve_convolved( CPlot* plot, POlc fc, uint k, uint j, int cstyle ) return xo.size(); } +//! Plot scan j of curve file fc, using grid from file kd. + +int plot_curve_to_grid( CPlot* plot, POlc fc, uint k, uint j, int cstyle ) +{ + if( fc->kd==-1 ) + throw "data reference not set, incompatible with cg+"; + POld fd = NOlm::mem_get_D(fc->kd); + if( !fd ) + throw "data reference not found"; + if( j>=fd->nJ() ) + throw "number of spectra does not match"; + vector<double> *xc = &(fd->VS(j)->x); + vector<double> novec, yc, xp, yp; + fc->curve_val_vec( &yc, *xc, k, j ); + for ( uint i=0; i<xc->size(); ++i ) { + if ( plot->X.contains((*xc)[i]) && plot->Y.contains(yc[i]) ) { + xp.push_back( (*xc)[i] ); + yp.push_back( yc[i] ); + } + } + plot->addSpec( true, true, cstyle, xp, yp, novec, fc->V[j]->z, + fc->xco.str_std(), fc->yco.str_std(), + "curve file "+S(k)+" spectrum "+S(j) ); + return xp.size(); +} + //! Plot scan j of non-convolved curve file fc on equidistant grid; //! return number of points plotted. @@ -469,6 +495,9 @@ void NPlot::Plot( class CPlot *plot, bool add, const string& mode ) if ( fc->kconv!=-1 ) { if ( !plot_curve_convolved( plot, fc, k, j, cstyle ) ) continue; + } else if ( fc->plot_to_grid ) { + if ( !plot_curve_to_grid( plot, fc, k, j, cstyle ) ) + continue; } else if ( !plot->refine ) { if ( !plot_curve_equidist( plot, fc, k, j, cstyle ) ) continue; -- GitLab