From f9f7b37638a42f9ff8b920618d35e5b3de970523 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (laptop)" <j.wuttke@fz-juelich.de>
Date: Fri, 9 Oct 2009 13:48:14 +0200
Subject: [PATCH] corr: intercept out-of-range points; implement 'force'

---
 pub/src/dualplot.cpp |  8 +++++++-
 pub/src/dualplot.h   |  2 +-
 pub/src/edif.cpp     | 36 ++++++++++++++++++++++++++----------
 pub/src/frida2.cpp   |  1 +
 4 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/pub/src/dualplot.cpp b/pub/src/dualplot.cpp
index 3789a0cf..b0cfcd99 100644
--- a/pub/src/dualplot.cpp
+++ b/pub/src/dualplot.cpp
@@ -379,8 +379,14 @@ void CPlot::Line( const bool as_line, const int style_no,
     FILE *gp_fd;
     if (!(gp_fd = fopen(gp_fnam, "w")))
         throw string("cannot save gnuplot data to ") + gp_fnam;
-    for (uint i=0; i<np; i++)
+    for (uint i=0; i<np; i++){
+        // invalid points should be intercepted outside Line(..)
+        if( xp[i]<X.R.inf || xp[i]>X.R.sup )
+            throw "Plot::Line: x["+strg(i)+"]="+strg(xp[i])+" out of range";
+        if( yp[i]<Y.R.inf || yp[i]>Y.R.sup )
+            throw "Plot::Line: y["+strg(i)+"]="+strg(yp[i])+" out of range";
         fprintf(gp_fd, "%16.8g %16.8g\n", xp[i], yp[i]);
+    }
     fclose(gp_fd);
 	
     // Live display:
diff --git a/pub/src/dualplot.h b/pub/src/dualplot.h
index 140157e4..79058e31 100644
--- a/pub/src/dualplot.h
+++ b/pub/src/dualplot.h
@@ -27,7 +27,7 @@ class CAxis {
     bool   log;
     bool   force;
 
-    CAxis( bool _log ) : log(_log) {};
+    CAxis( bool _log ) : log(_log), force(false) {};
 
     void Ask( const string& quest );
     void SetLog( const bool _log );
diff --git a/pub/src/edif.cpp b/pub/src/edif.cpp
index 321aa40b..2945c7ce 100644
--- a/pub/src/edif.cpp
+++ b/pub/src/edif.cpp
@@ -1114,21 +1114,37 @@ void NEdif::Plot( CPlot *plot, bool add )
                 size_t np=0, nxl=0, nxh=0, nyl=0, nyh=0;
                 vector<double> xp, yp;
                 for ( size_t i=0; i<n; i++ ) {
-                    if( !plot->X.force && !plot->X.R.contained(s->x[i]) ) {
-                        if (s->x[i]<=plot->X.R.inf) nxl++;
-                        if (s->x[i]>=plot->X.R.sup) nxh++;
-                        continue;
+                    double x = s->x[i];
+                    if( !plot->X.R.contained(x) ) {
+                        if ( x<=plot->X.R.inf ){
+                            x = plot->X.R.inf;
+                            nxl++;
+                        }
+                        if ( x>=plot->X.R.sup ){
+                            x = plot->X.R.sup;
+                            nxh++;
+                        }
+                        if ( !plot->X.force )
+                            continue;
                     }
-                    if( !plot->Y.force && !plot->Y.R.contained(s->y[i]) ) {
-                        if (s->y[i]<=plot->Y.R.inf) nyl++;
-                        if (s->y[i]>=plot->Y.R.sup) nyh++;
-                        continue;
+                    double y = s->y[i];
+                    if( !plot->Y.R.contained(y) ) {
+                        if ( y<=plot->Y.R.inf ){
+                            y = plot->Y.R.inf;
+                            nyl++;
+                        }
+                        if ( y>=plot->Y.R.sup ){
+                            y = plot->Y.R.sup;
+                            nyh++;
+                        }
+                        if ( !plot->Y.force )
+                            continue;
                     }
                     if( np==plot->maxpoints && np<n ) {
                         printf("reached maxpoints at %g\n", s->x[i]);
                     }
-                    xp.push_back( s->x[i] );
-                    yp.push_back( s->y[i] );
+                    xp.push_back( x );
+                    yp.push_back( y );
                     np = xp.size();
                     if( np > plot->maxpoints ) // continue in large steps
                         i += plot->maxpoints;
diff --git a/pub/src/frida2.cpp b/pub/src/frida2.cpp
index bd071f79..cf9ecce7 100644
--- a/pub/src/frida2.cpp
+++ b/pub/src/frida2.cpp
@@ -263,6 +263,7 @@ int main()
                     "  gp   plot to complete .ps file\n"
                     "  gf   plot to short .psX file\n"
                     "  gl   list of plot windows\n"
+                    "  g<n> switch to plot window <n>\n"
                     "  gd   dialog (within gnuplot)\n"
                     "  p    plot\n"
                     "  pp   plot with new autoranges\n"
-- 
GitLab