From a2b1739154a4429dee1a225698fe4fdc6c5a08f3 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (home)" <j.wuttke@fz-juelich.de>
Date: Wed, 9 Sep 2009 11:56:08 +0200
Subject: [PATCH] new ft option: ftc, to choose y from columns

---
 pub/src/edif.cpp   | 45 ++++++++++++++++++++++++++++++++++++---------
 pub/src/frida2.cpp |  3 ++-
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/pub/src/edif.cpp b/pub/src/edif.cpp
index 39ec4042..acaa702e 100644
--- a/pub/src/edif.cpp
+++ b/pub/src/edif.cpp
@@ -752,9 +752,11 @@ void NEdif::ReadTab( string qualif )
     if( qualif.find_first_not_of("hvsm")!=string::npos )
         throw string( "ReadTab: invalid qualifier" );
     char dir = qualif[0];
-    if( !( dir=='h' || dir=='v' ) )
+    if( !( dir=='h' || dir=='v' || dir=='c' ) )
         throw string( "ReadTab: missing qualifier h or v" );
     bool horizontal = dir=='h';
+    bool choosecol = dir=='c';
+    static int iycol=0;
     bool fromscript = qualif.find('s')!=string::npos;
     bool multiblock = qualif.find('m')!=string::npos;
 
@@ -772,6 +774,13 @@ void NEdif::ReadTab( string qualif )
         if( mystd::glob_file_list( fnames, "", "", &inFiles )<=0 )
             throw "files " + fnames + " not found";
     }
+
+    if( choosecol ){
+        printf( "at present, x:=i\n" );
+        iycol = iask( "Read y from column", iycol );
+        if( iycol<0 ) return;
+    }
+    
     FILE *fd;
     string fdir, fshort, fext;
     NOlm::SelNew();
@@ -787,11 +796,20 @@ void NEdif::ReadTab( string qualif )
             mystd::fname_divide( inFiles[iF], &fdir, &fshort, &fext);
             olf.lDoc.push_back( "ft"+qualif+" " + inFiles[iF] );
             olf.name = fshort;
+            if( choosecol ){
+                olf.lDoc.push_back( "y from column " + strg(iycol) );
+                olf.name += "_" + strg(iycol);
+            }
         }
 
         // ** file-level settings **
-        olf.xco = CCoord("x", "");
-        olf.yco = CCoord("y", "");
+        if( choosecol ){
+            olf.xco = CCoord("i", "");
+            olf.yco = CCoord("y"+strg(iycol), "");
+        } else {
+            olf.xco = CCoord("x", "");
+            olf.yco = CCoord("y", "");
+        }
 
         // *** read input ***
         string lin, s1, s2;
@@ -873,12 +891,21 @@ void NEdif::ReadTab( string qualif )
                     S.push_back( (double)i, dat[i] );
                 olf.VS.push_back(S);
             } else { // vertical
-                if( dat.size()!=2 )
-                    throw "line "+strg(n_in)+" (line "+strg(nline)+
-                        " in block "+strg(nblock)+") ["+lin+
-                        "] contains "+strg(dat.size())+" values; "+
-                        "at present, exactly 2 are required";
-                S.push_back( dat[0], dat[1] );
+                if( choosecol ){
+                    if( iycol>=dat.size() )
+                        throw "line "+strg(n_in)+" (line "+strg(nline)+
+                            " in block "+strg(nblock)+") ["+lin+
+                            "] contains only "+strg(dat.size())+" values; "+
+                            "cannot read y from col "+strg(iycol);
+                    S.push_back( (double)nline, dat[iycol] );
+                } else {
+                    if( dat.size()!=2 )
+                        throw "line "+strg(n_in)+" (line "+strg(nline)+
+                            " in block "+strg(nblock)+") ["+lin+
+                            "] contains "+strg(dat.size())+" values; "+
+                            "at present, exactly 2 are required";
+                    S.push_back( dat[0], dat[1] );
+                }
             }
             
         } // end of file input loop
diff --git a/pub/src/frida2.cpp b/pub/src/frida2.cpp
index 459247ba..106d1ac5 100644
--- a/pub/src/frida2.cpp
+++ b/pub/src/frida2.cpp
@@ -217,9 +217,10 @@ int main()
                     "  fdel delete\n"
                     "  fm   make\n"
                     "  fr   read in\n"
-                    "  ft(h|v)[m][s]  read tab\n"
+                    "  ft(h|v|c)[m][s]  read tab\n"
                     "       h horizontal (only y values, one line per scan)\n"
                     "       v vertical (one x-y pair per line)\n"
+                    "       c choose vertical columns\n"
                     "       m multi-block (blocks begin with z line)\n"
                     "       s from script\n";
             } else if (cmd == "fl") {
-- 
GitLab