From e74176481c4d210532ddb2210a6015c02e478939 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (laptop)" <j.wuttke@fz-juelich.de>
Date: Mon, 25 Jan 2010 10:13:57 +0100
Subject: [PATCH] corr+acc plot; mehrere dy-Korrekturen; ody+ noch in Bau

---
 pub/src/dualplot.cpp | 30 +++++++++--------
 pub/src/dualplot.h   | 11 ++++---
 pub/src/edif.cpp     | 25 ++++++++-------
 pub/src/frida2.cpp   |  2 ++
 pub/src/manip.cpp    |  6 ++--
 pub/src/opr.cpp      | 76 ++++++++++++++++++++++++++++++++++++++++++++
 pub/src/opr.h        |  1 +
 7 files changed, 119 insertions(+), 32 deletions(-)

diff --git a/pub/src/dualplot.cpp b/pub/src/dualplot.cpp
index 435a8ccd..f122221f 100644
--- a/pub/src/dualplot.cpp
+++ b/pub/src/dualplot.cpp
@@ -383,11 +383,11 @@ void CPlot::plotFrame()
 
 //! Plot one scan.
 
-void CPlot::plotScan( bool as_line, int style_no,
-                      const vector<double>& xp,
-                      const vector<double>& yp, const vector<double>& dyp,
-                      const vector<double>& z,
-                      string xco, string yco, string info
+void CPlot::addScan( bool as_line, int style_no,
+                     const vector<double>& xp,
+                     const vector<double>& yp, const vector<double>& dyp,
+                     const vector<double>& z,
+                     string xco, string yco, string info
     )
 {
     // Checks:
@@ -427,13 +427,6 @@ void CPlot::plotScan( bool as_line, int style_no,
         return;
     }
 
-    // Live display:
-    string cmd = "plot " + 
-        str( format( "[%12.8g:%12.8g] [%12.8g:%12.8g] " )
-                     % X.inf % X.sup % Y.inf % Y.sup ) +
-        gp_fnames;
-    gp_write( cmd );
-
     // Postscript copy:
     snprintf( outlin, CPLOT_LINSIZ, "\n%3u [", ++ps_snum );
     ps_accu.push_back( outlin );
@@ -463,6 +456,17 @@ void CPlot::plotScan( bool as_line, int style_no,
     }
 }
 
+//! Live display as prepared by addScan.
+
+void CPlot::showScans()
+{
+    string cmd = "plot " + 
+        str( format( "[%12.8g:%12.8g] [%12.8g:%12.8g] " )
+                     % X.inf % X.sup % Y.inf % Y.sup ) +
+        gp_fnames;
+    gp_write( cmd );
+}
+
 //! Add documentation lines to postscript output.
 
 void CPlot::plotDoclines( const vector<string>& lDoc )
@@ -561,7 +565,7 @@ string CPlot::info() const
 void CPlot::gp_write( string in )
 {
     string out = in + "\n";
-    // printf( "DEBUG GNUPLOT '%s'\n", out.c_str() );
+    printf( "DEBUG GNUPLOT '%s'\n", out.c_str() );
     if( write( gp_fifo, out.c_str(), out.size() ) <= 0 )
         throw string( "could not write to gp_fifo" );
 }
diff --git a/pub/src/dualplot.h b/pub/src/dualplot.h
index c54242ae..02ab5977 100644
--- a/pub/src/dualplot.h
+++ b/pub/src/dualplot.h
@@ -40,11 +40,12 @@ class CPlot {
 
     void clearFrame();
     void plotFrame();
-    void plotScan( bool as_line, int style_no,
-                   const vector<double>& xp,
-                   const vector<double>& yp, const vector<double>& dyp,
-                   const vector<double>& z,
-                   string xco, string yco, string info );
+    void addScan( bool as_line, int style_no,
+                  const vector<double>& xp,
+                  const vector<double>& yp, const vector<double>& dyp,
+                  const vector<double>& z,
+                  string xco, string yco, string info );
+    void showScans();
     void plotDoclines( const vector<string>& lDoc );
     void writePostscript( bool full_outfile );
     void setAux( string cmd );
diff --git a/pub/src/edif.cpp b/pub/src/edif.cpp
index 258cccc6..c4607ad5 100644
--- a/pub/src/edif.cpp
+++ b/pub/src/edif.cpp
@@ -1115,10 +1115,10 @@ void NEdif::Plot( CPlot *plot, bool add )
                         printf( "  %u points > ymax\n", nyh );
                     continue;
                 } else {
-                    plot->plotScan( false, pstyle++,
-                                    xp, yp, dyp, *(e->Z(j)),
-                                    e->P()->xco.str(), e->P()->yco.str(),
-                                    "data file " + strg(k) + " scan "+strg(j) );
+                    plot->addScan( false, pstyle++,
+                                   xp, yp, dyp, *(e->Z(j)),
+                                   e->P()->xco.str(), e->P()->yco.str(),
+                                   "data file " + strg(k) + " scan "+strg(j) );
                 }
             } else if ( fc && fc->kconv!=-1 ) {
                 // plot only at x points of convolutand
@@ -1146,7 +1146,7 @@ void NEdif::Plot( CPlot *plot, bool add )
                     cout << "curve k="<<strg(k)<<", j="<<strg(j)<<" is empty\n";
                     return;
                 }
-                plot->plotScan( true, cstyle++, xo, yo, novec, *(e->Z(j)),
+                plot->addScan( true, cstyle++, xo, yo, novec, *(e->Z(j)),
                                 e->P()->xco.str(), e->P()->yco.str(),
                                 "curve file "+strg(k)+" scan "+strg(j) );
             } else if ( fc ) {
@@ -1163,7 +1163,7 @@ void NEdif::Plot( CPlot *plot, bool add )
                         yp.push_back( yc[i] );
                     }
                 }
-                plot->plotScan( true, cstyle++, xp, yp, novec, *(e->Z(j)),
+                plot->addScan( true, cstyle++, xp, yp, novec, *(e->Z(j)),
                                 e->P()->xco.str(), e->P()->yco.str(),
                                 "curve file "+strg(k)+" scan "+strg(j) );
             } else if ( false ) {
@@ -1204,12 +1204,12 @@ void NEdif::Plot( CPlot *plot, bool add )
                         pos = 1-1e-8;
                 }
                 for( int iS=0; iS<SS.size(); ++iS ){
-                    plot->plotScan( true, cstyle,
-                                    SS[iS].x, SS[iS].y, SS[iS].dy,
-                                    *(e->Z(j)),
-                                    e->P()->xco.str(), e->P()->yco.str(),
-                                    "curve file "+strg(k)+" scan "+strg(j)+
-                                    " segment "+strg(iS) );
+                    plot->addScan( true, cstyle,
+                                   SS[iS].x, SS[iS].y, SS[iS].dy,
+                                   *(e->Z(j)),
+                                   e->P()->xco.str(), e->P()->yco.str(),
+                                   "curve file "+strg(k)+" scan "+strg(j)+
+                                   " segment "+strg(iS) );
                 }
                 cstyle++;
             } else
@@ -1219,4 +1219,5 @@ void NEdif::Plot( CPlot *plot, bool add )
         if( fc )
             plot->plotDoclines( fc->pInfo() );
     }
+    plot->showScans();
 }
diff --git a/pub/src/frida2.cpp b/pub/src/frida2.cpp
index 4e938cc5..6fda68a1 100644
--- a/pub/src/frida2.cpp
+++ b/pub/src/frida2.cpp
@@ -448,6 +448,8 @@ int main()
 
             } else if (cmd == "oz+") {
                 NOperate::NewZ();
+            } else if (cmd == "ody+") {
+                NOperate::NewDY();
             } else if (cmd[0]=='o' && strchr("xyz", cmd[1])) {
                 NOperate::Pointwise(cmd.substr(1));
             } else if (cmd.substr(0,2) == "op") {
diff --git a/pub/src/manip.cpp b/pub/src/manip.cpp
index 0fcbee24..5febd4ef 100644
--- a/pub/src/manip.cpp
+++ b/pub/src/manip.cpp
@@ -94,10 +94,11 @@ void NManip::PtsSelect( string del_or_ret )
             Sout = *Sin;
             Sout.x.clear();
             Sout.y.clear();
+            Sout.dy.clear();
             pLis.evaluate( 0, Sin->size()-1 );
             for (uint i=0; i<Sin->size(); i++) {
                 if ( sel_del ^ pLis.contains(i) )
-                    Sout.push_xy(Sin->x[i], Sin->y[i]);
+                    Sout.push_xyd(Sin->x[i], Sin->y[i], Sin->dy[i]);
             }
             if (Sout.size())
                 fout.VS.push_back(Sout);
@@ -253,7 +254,8 @@ void NManip::PtsSort()
             vector<double> xout(n);
             for (i=0; i<n; ++i) {
                 xout[i] = Sin->x[P[i]];
-                Sout.y[i] = Sin->y[P[i]];
+                Sout.y[i]  = Sin->y[P[i]];
+                Sout.dy[i] = Sin->dy[P[i]];
             }
             Sout.x = xout;
             fout.VS.push_back(Sout);
diff --git a/pub/src/opr.cpp b/pub/src/opr.cpp
index 77978744..56709a3e 100644
--- a/pub/src/opr.cpp
+++ b/pub/src/opr.cpp
@@ -236,6 +236,82 @@ void NOperate::Pointwise( string llabel )
 }
 
 
+//! Set error bar.
+
+void NOperate::NewDY() 
+{
+    throw string( "not yet implemented" );
+    string expr = sask("Function ?");
+    if (expr=="") return;
+    PTree T;
+    user_xaxparse( expr.c_str(), &T );
+ 
+    NOlm::IterateEle iter;
+    if (!NOlm::overwrite) NOlm::SelNew();
+    CEle *ein;
+    COlo *fout;
+    vector<double> vout;
+    double dout;
+    uint n;
+    while( (ein=iter()) ){
+        uint k = iter.SelNo();
+        if (NOlm::overwrite) {
+            fout = ein->P();
+        } else {
+            if( ein->isD() )
+                fout = (COlo*) new COld( *((COld*) ein->P()) );
+            else
+                fout = (COlo*) new COlc( *((COlc*) ein->P()) );
+        }
+        fout->lDoc.push_back( "o" + lref.ref_info() + " " + expr);
+        
+        if      (lref.var==CRef::_X) 
+            T->coord(&(fout->xco), k);
+        else if (lref.var==CRef::_Y) 
+            T->coord(&(fout->yco), k);
+        else if (lref.var==CRef::_Z) {
+            if( lref.num>= fout->ZCo.size() ){
+                delete fout;
+                throw string( "no such z coordinate to operate onto" );
+            }
+            T->coord(&(fout->ZCo[lref.num]), k);
+        }
+
+        for( uint j=0; j<ein->nScan(); j++ ){
+            
+            if (lref.pointwise()) {
+                if( !ein->isD() ){
+                    delete fout;
+                    throw string( "no pointwise operation on curve" );
+                }
+                n = ((COld*)(ein->D()))->VS[j].size();
+                vout.resize(n);
+                T->tree_vec_val( &vout, k, j );
+                if (lref.var==CRef::_X)
+                    ((COld*)fout)->VS[j].x = vout;
+                else
+                    ((COld*)fout)->VS[j].y = vout;
+            } else if (lref.var==CRef::_Z) {
+                T->tree_point_val( &dout, k, j );
+                if( ein->isD() )
+                    ((COld*)fout)->VS[j].z[lref.num] = dout;
+                else
+                    ((COlc*)fout)->VC[j].z[lref.num] = dout;
+            } else {
+                delete fout;
+                throw string( "PROGRAM ERROR/ invalid oxy" );
+            }
+			
+        }
+        if( !(NOlm::overwrite) ){
+            NOlm::OloAdd( fout );
+            delete fout;
+        }
+        
+    }
+}
+
+
 //! Add new z coordinate, and set values according to arithmetic expression.
 
 void NOperate::NewZ() 
diff --git a/pub/src/opr.h b/pub/src/opr.h
index 0a2a2757..f35e7d67 100644
--- a/pub/src/opr.h
+++ b/pub/src/opr.h
@@ -2,6 +2,7 @@ namespace NOperate {
     void Show( string subcmd );
     void Select(bool askdelete);
     void NewZ();
+    void NewDY();
     void Pointwise(string llabel);
     void IntXY();
     void Integral();
-- 
GitLab