From 701edc85a769d177b16cd7b55ca93fe85b310375 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (home)" <j.wuttke@fz-juelich.de>
Date: Sun, 30 May 2010 20:03:50 +0200
Subject: [PATCH] simplify parameter fixation (now bool, not list)

---
 TODO               |  7 ++--
 pub/CHANGELOG      |  3 ++
 pub/src/axis.cpp   | 81 ++++++++++++++++++++++++++++++++++------------
 pub/src/axis.h     |  2 +-
 pub/src/curve.cpp  | 27 ++++++++--------
 pub/src/frida2.cpp |  6 ++--
 pub/src/olf.h      |  1 -
 pub/src/zentry.h   |  1 +
 8 files changed, 85 insertions(+), 43 deletions(-)

diff --git a/TODO b/TODO
index eb166e51..729c1300 100644
--- a/TODO
+++ b/TODO
@@ -9,13 +9,14 @@
 
 == TO CHECK ==
 
-== WISHLIST: TODO ==
-
-- user interface
   - dialog generics
     - restore ask callback help for lists (prompt for list, not for string)
     - restore help on "?" (e.g. expression help for 'md')
     - default for plot range
+
+== WISHLIST: TODO ==
+
+- user interface
   - 'hf' add explanation (formulae)
   - 'gp!' <filename> ?
   - 'op' to give expressions for all parameters
diff --git a/pub/CHANGELOG b/pub/CHANGELOG
index 53e195e8..bfa34387 100644
--- a/pub/CHANGELOG
+++ b/pub/CHANGELOG
@@ -4,8 +4,11 @@ Release
   - 'dd' now shows doc lines, 'ed' allows to edit them via vi
 - improved behavior:
   - reduce noise in lDoc (no 'cf'; basic merge in 'mfj')
+  - 'gx', 'gy': restore defaults
 - internal changes:
   - eliminate remnants of SPHERES/XML read in
+  - eliminate myask template
+  - simplify parameter fixation (now bool, not list)
 - bugfixes:
   - repaired 'ry' after 100511 introduction of shared_ptr
 
diff --git a/pub/src/axis.cpp b/pub/src/axis.cpp
index ccb9607b..4ed748cc 100644
--- a/pub/src/axis.cpp
+++ b/pub/src/axis.cpp
@@ -13,6 +13,8 @@
 #include <fcntl.h>
 #include <boost/format.hpp>
 
+#include <readln.h>
+
 #include "mystd.h"
 #include "axis.h"
 
@@ -55,28 +57,65 @@ void CAxis::setLog( bool _log )
 
 //! Parse string to set bounds.
 
-void CAxis::set_from_string( string in )
+void CAxis::ask_and_set( const string& quest )
 {
-    if ( in=="*" ) {
-        setAuto();
-        return;
-    }
-    string s1, s2;
-    mystd::string_extract_word( in, &s1, &s2 );
-    if ( !mystd::any2dbl(s1,&inf) )
-        throw string( "invalid lower bound, expecting real number" );
-    if ( !mystd::any2dbl(s2,&sup) )
-        throw string( "invalid upper bound, expecting real number" );
-    // check new range
-    if ( logflag && inf<=0 && inf!=-INFINITY ) {
-        setAuto();
-        throw string( "log scale requires range above 0" );
-    }
-    if (!logflag && ( ( inf!=-INFINITY && inf<-3e38 ) ||
-                      ( sup!=+INFINITY && sup>+3e38 ) ) ) {
-        setAuto();
-        throw string( "lin scale exceeds typical PS implementation range "
-                      "(abs<3e38)" );
+    string prompt = quest + " [" + str() + "] ?";
+
+    for( ;; ) {
+        double inf_in, sup_in;
+        string resp1 = NRead::readwd(prompt);
+        if        ( resp1 == "\\q" ) {
+            throw "user escape to main menu";
+        } else if ( resp1 == "" ) {
+            return; // don't change current value
+        } else if ( resp1 == "*" ) {
+            setAuto();
+            return;
+        } else if ( resp1 == "\\EOL" ) {
+            inf_in = inf;
+        } else if( mystd::any2dbl(resp1,&inf_in) ) {
+            ; // ok
+        } else {
+            cout << "required input: plot axis range\n"
+                "examples:\n"
+                "    0.1 1000    two floating-point numbers\n"
+                "    \\   1000    let lower bond unchanged\n"
+                "    0.1  \\      let upper bound unchanged\n"
+                "    *           redetermine bounds from data\n"
+                "just press ENTER to let present range unchanged [" 
+                 << str() << "]\n";
+            continue;
+        if ( logflag && inf_in<=0 ) {
+            cout << "log axis requires lower bound>0\n";
+            continue;
+        }
+        string resp2 = NRead::readwd(
+            ".. and upper limit [" + strg(sup) + "] ?" );
+        if        ( resp2 == "\\q" ) {
+            throw "user escape to main menu";
+        } else if ( resp2 == "" || resp2 == "\\EOL" ) {
+            sup_in = sup;
+        } else if( mystd::any2dbl(resp2,&sup_in) ) {
+            ; // ok
+        } else {
+            cout << "invalid upper bound; use '?' for help\n";
+            continue;
+        }
+        if( sup_in<=inf_in ){
+            cout << "invalid input, does not fulfill lower<upper\n";
+            continue;
+        }
+        if( logflag && (sup_in>200 || inf_in<-200) ){
+            cout << "log range currently restricted to -200..200\n";
+            continue;
+        }
+        if( !logflag && (sup_in>3e38 || inf_in<-3e38) ){
+            cout << "lin range currently restricted to -3e38..3e38\n";
+            continue;
+        }
+        inf = inf_in;
+        sup = sup_in;
+        }
     }
 }
 
diff --git a/pub/src/axis.h b/pub/src/axis.h
index b3b608ac..a19c3767 100644
--- a/pub/src/axis.h
+++ b/pub/src/axis.h
@@ -12,7 +12,7 @@ class CAxis {
     void setAuto();
     void setLimits( string axnam, double _inf, double _sup );
     void setRoundedLimits( string axnam, double _inf, double _sup );
-    void set_from_string( string text );
+    void ask_and_set( const string& quest );
 
     string str() const;
     string info() const;
diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp
index df3c3b31..dded8889 100644
--- a/pub/src/curve.cpp
+++ b/pub/src/curve.cpp
@@ -66,7 +66,6 @@ void NCurveFile::setFunction( POlc f, const string& expr )
     f->T = T;
     for( uint ip=0; ip<T->npar(); ip++ ){
         f->PCo.push_back( CCoord("p" + strg(ip), "") );
-        f->Fixed.push_back( CList() );
     }
     f->weighing = COlc::_ERR;
     f->cv_intmod = NCurveFile::numint_cvmode;
@@ -99,6 +98,7 @@ void NCurveFile::CreateFitcurve()
             PCurve sout( new CCurve );
             sout->z = fd->VS(j)->z;
             sout->P = P;
+            sout->fixed.resize( fout->nPar(), false );
             fout->V.push_back( sout );
         }
         NOlm::OloAdd( fout );
@@ -145,13 +145,12 @@ void NCurveFile::ChangeExpr()
         fc->lDoc.push_back( "ccm " + expr );
         uint nParNew = fc->T->npar();
         fc->PCo.resize(nParNew);
-        fc->Fixed.resize(nParNew);
         for( uint ip=nParOld; ip<nParNew; ip++ ){
             fc->PCo[ip] = CCoord("p" + strg(ip), "");
-            fc->Fixed[ip] = CList();
         }
         for (uint j=0; j<fc->nJ(); j++) {
             fc->VC(j)->P.resize( nParNew );
+            fc->VC(j)->fixed.resize( nParNew, false );
             for( uint ip=nParOld; ip<nParNew; ip++ )
                 fc->VC(j)->P[ip] = 1.0;
         }
@@ -246,7 +245,7 @@ vector<string> COlc::pInfo() const
         }
         for ( uint ip=0; ip<nPar(); ip++ ) {
             snprintf( wrd, PINFO_WRD_SIZ, "%c%-12.7g ",
-                      Fixed[ip].contains(j) ? 'x':' ', VC(j)->P[ip] );
+                      VC(j)->fixed[ip] ? 'x' : ' ', VC(j)->P[ip] );
             lin += wrd;
         }
         ret.push_back( lin );
@@ -308,12 +307,14 @@ void NCurveFile::SetFixed()
         while( (f=fiter()) ) {
             if( ip>=f->nPar() )
                 throw string( "invalid parameter number" );
-            if      ( tokens[2] == "+" )
-                f->Fixed[ip] = CList( 0, f->nJ()-1 );
-            else if ( tokens[2] == "-" )
-                f->Fixed[ip] = CList( );
-            else if ( tokens[2] == "=" )
-                f->Fixed[ip] = CList( tokens[3], 0, f->nJ()-1 );
+            for( uint j=0; j<f->nJ(); ++j ){
+                if ( f->ProtectedSpecs.contains(j) )
+                    continue;
+                if      ( tokens[2] == "+" )
+                    f->VC(j)->fixed[ip] = true;
+                else if ( tokens[2] == "-" )
+                    f->VC(j)->fixed[ip] = false;
+            }
         }
     }
 }
@@ -463,7 +464,7 @@ void globalEvaluate( const double* par, int m_dat, const void *data,
         
         uint ip = 0;
         for( uint i=0; i<fc->nPar(); ++i )
-            if ( !(fc->Fixed[i].contains( mydata->j )) )
+            if ( !(fc->VC(mydata->j)->fixed[i]) )
                 c->P[i] = par[ip++];
         
         const PSpec s = fd->VS(mydata->j);
@@ -651,14 +652,14 @@ void NCurveFile::Fit( bool _allow_slow_conv )
             // determine number of free parameters
             uint npfree = 0;
             for ( uint ip=0; ip<np; ++ip )
-                if( !fc->Fixed[ip].contains(j) )
+                if( !fc->VC(j)->fixed[ip] )
                     ++npfree;
             if (npfree<=0)
                 continue;
             Par.resize(npfree);
             uint ipf=0;
             for ( uint ip=0; ip<np; ip++ ) {
-                if ( !fc->Fixed[ip].contains(j) )
+                if ( !fc->VC(j)->fixed[ip] )
                     Par[ipf++] = C->P[ip];
             }
                                         
diff --git a/pub/src/frida2.cpp b/pub/src/frida2.cpp
index c1c81077..548770e3 100644
--- a/pub/src/frida2.cpp
+++ b/pub/src/frida2.cpp
@@ -336,11 +336,9 @@ int main()
                     ;
 
             } else if ( cmd == "gx" ) {
-                string range = sask( "Set x range" );
-                Plots[iPlot]->X.set_from_string( range );
+                Plots[iPlot]->X.ask_and_set( "Plot x range" );
             } else if ( cmd == "gy" ) {
-                string range = sask( "Set y range" );
-                Plots[iPlot]->Y.set_from_string( range );
+                Plots[iPlot]->Y.ask_and_set( "Plot y range" );
             } else if ( cmd == "ga" ) {
                 Plots[iPlot]->X.setAuto();
                 Plots[iPlot]->Y.setAuto();
diff --git a/pub/src/olf.h b/pub/src/olf.h
index 6a04e1f4..522d57f1 100644
--- a/pub/src/olf.h
+++ b/pub/src/olf.h
@@ -82,7 +82,6 @@ class COlc : public COlo {
 
     // online state records:
     PTree T;
-    vector<CList>  Fixed;
     enum TWgt { _LIN, _LOG, _ERR } weighing;
     uint           kd; // internal number of data file to be fitted
     uint           kconv;
diff --git a/pub/src/zentry.h b/pub/src/zentry.h
index 3d408879..7f6d9b84 100644
--- a/pub/src/zentry.h
+++ b/pub/src/zentry.h
@@ -20,6 +20,7 @@ class CCurve: public CZentry {
  public:
     static const int mQuality = 3;
     vector<double> P;
+    vector<bool>   fixed;
     double Quality[mQuality];
     
     void clear( void );
-- 
GitLab