Index: trunk/SophyaPI/PIext/basexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/basexecut.cc	(revision 2302)
+++ trunk/SophyaPI/PIext/basexecut.cc	(revision 2305)
@@ -14,4 +14,5 @@
 #include "nobjmgr.h"
 #include "servnobjm.h"
+#include "nomgadapter.h"
 #include "piyfxdrw.h"
 
@@ -528,5 +529,152 @@
     }
   }
-
+// ----- Vecteur/NTuple <> Lignes/variables interpreteur
+// Creation de vecteur depuis le contenu de la ligne
+else if (kw == "line2vec") {  
+  if (tokens.size() < 2) { 
+    cout << "Usage: line2vec vecname v0 v1 v2 ... " << endl; return(0); 
+    }
+  int vsz = tokens.size()-1;
+  Vector* v = new Vector(vsz);
+  for(int kkv=0; kkv<vsz; kkv++)  (*v)(kkv) = atof(tokens[kkv+1].c_str());
+  mObjMgr->AddObj(v, tokens[0]);
+  }
+// Remplissage de NTuple depuis la ligne
+else if (kw == "line2nt") {
+  if (tokens.size() < 2) { 
+    cout << "Usage: line2nt ntname col0 col1 ..." << endl; return(0); 
+  }
+  AnyDataObj* obj;
+  obj = mObjMgr->GetObj(tokens[0]);
+  if(obj == NULL) {
+    cerr << "line2nt Error , No such object " << tokens[0] << endl; 
+    return(0);
+  }
+  NTuple* nt = dynamic_cast<NTuple *>(obj);
+  if(nt == NULL) {
+    cerr << "line2nt Error " << tokens[0] << " not an NTuple ! " << endl;
+    return(0);
+  }
+  if (nt->NbColumns() < 1) {
+    cerr << "line2nt Error: NbColumns  < 1" << endl;
+    return(0);
+  }
+  r_4* xnt = new r_4[ nt->NbColumns() ];
+  int kkx; 
+  for(kkx=0; kkx<nt->NbColumns(); kkx++) { 
+    if (kkx < tokens.size()-1)  xnt[kkx] = atof(tokens[kkx+1].c_str());
+    else xnt[kkx] = 0.;
+  }
+  nt->Fill(xnt);
+  delete[] xnt;
+}  
+// Contenu du vecteur vers variable interpreteur
+#define MAXNWORDSO2V 32768
+else if (kw == "vec2var") {  
+  if (tokens.size() < 2) { 
+    cout << "Usage: vec2var vecname varname [loop_param start:end:step] " << endl; return(0); 
+    }
+  AnyDataObj* obj;
+  obj = mObjMgr->GetObj(tokens[0]);
+  if(obj == NULL) {
+    cerr << "vec2var Error , No such object " << tokens[0] << endl; 
+    return(0);
+  }
+  Vector* v = dynamic_cast<Vector *>(obj);
+  if(v == NULL) {
+    cerr << "vec2var Error " << tokens[0] << " not a Vector ! " << endl;
+    return(0);
+  }
+  int kks = 0;
+  int kke = v->NElts();
+  int kkp = 1;
+  if (tokens.size() > 2) Services2NObjMgr::DecodeLoopParameters(tokens[2], kks, kke, kkp);
+  if (kks < 0)  kks = 0;
+  if (kke > v->NElts()) kke = v->NElts();
+  if (kkp < 1) kkp = 1;
+  int nelt = (kke-kks-1)/kkp;
+  if (nelt > MAXNWORDSO2V) {
+    nelt = MAXNWORDSO2V;
+    cout << "vec2var Warning:  Only " << nelt 
+	 << " elements  will be converted to string" << endl;
+    kke = kks+nelt*kkp;
+  }
+  string v2str;
+  char buff[64];
+  for(int kkv=kks; kkv<kke; kkv+=kkp) {
+    sprintf(buff, "%lg ", (*v)(kkv));
+    v2str += buff;
+  }
+  
+  mObjMgr->SetVar(tokens[1], v2str);
+}
+// Une ligne du NTuple/NTupleInterface -> variable interpreteur
+else if ((kw == "ntline2var") || (kw == "ntcol2var")) {  
+  if (tokens.size() < 3) {
+    cout << "Usage: ntline/col2var objname line_number varname" << endl; 
+    return(0); 
+  }
+  NObjMgrAdapter* oa = mObjMgr->GetObjAdapter(tokens[0]);
+  if(oa == NULL) {
+    cerr << "ntline/col2var Error , No such object " << tokens[0] << endl; 
+    return(0);
+  }
+  bool adel = false;
+  NTupleInterface* nti = oa->GetNTupleInterface(adel);
+  if(nti == NULL) {
+    cerr << "ntline/col2var Error: objet" << tokens[0] << " has no NTupleInterface" << endl; 
+    return(0);
+  }
+
+  if (nti->NbColumns() < 1 || nti->NbLines() < 1) {
+    cerr << "ntline/col2var Error: NbColumns or NbLines < 1" << endl;
+    return(0);
+  }
+  string v2str;
+  char buff[64];
+  if (kw == "ntline2var") {
+    int numline = atoi(tokens[1].c_str());
+    if ( (numline >= nti->NbLines()) || (numline < 0) )  {
+      cerr << "ntline2var Error: numline" << tokens[1] << " out of bounds" << endl; 
+      return(0);
+    }
+    r_8* dline = nti->GetLineD(numline);
+    for(int kkv=0; kkv<nti->NbColumns(); kkv++) {
+      sprintf(buff, "%lg ", dline[kkv]);
+      v2str += buff;
+    }
+  }
+  else {
+    int numcol = atoi(tokens[1].c_str());
+    if ( (numcol >= nti->NbColumns()) || (numcol < 0) )  {
+      cerr << "ntcol2var Error: numcol" << tokens[1] << " out of bounds" << endl; 
+      return(0);
+    }
+    int kks = 0;
+    int kke = nti->NbLines();
+    int kkp = 1;
+    if (tokens.size() > 3) Services2NObjMgr::DecodeLoopParameters(tokens[3], kks, kke, kkp);
+    if (kks < 0)  kks = 0;
+    if (kke > nti->NbLines()) kke = nti->NbLines();
+    if (kkp < 1) kkp = 1;
+    int nelt = (kke-kks-1)/kkp;
+    if (nelt > MAXNWORDSO2V) {
+      nelt = MAXNWORDSO2V;
+      cout << "ntcol2var Warning: Only " << nelt
+	   << " lines " << " will be converted to string" << endl;
+      kke = kks+nelt*kkp;
+    }
+    r_8* dline;
+    for(int kkl=kks; kkl<kke; kkl+=kkp) {
+      dline = nti->GetLineD(kkl);
+      sprintf(buff, "%lg ", dline[numcol]);
+      v2str += buff;
+    }
+  }
+  mObjMgr->SetVar(tokens[2], v2str);
+  if (adel) delete nti;
+}
+
+// -------------------------------------------------------
 // Copie d'objets
 else if ( (kw == "copy") || (kw == "cp") ) {
@@ -1378,5 +1526,5 @@
 kw = "newvec";
 usage = "Creates (and optionaly fills) a vector \n Usage: newvec name size [f(i) [dopt] ] ";
-usage += "\n  Related commands: newmtx";  
+usage += "\n  Related commands: newmtx line2vec";  
 mpiac->RegisterCommand(kw, usage, this, "Objects");
 kw = "newmtx";
@@ -1384,4 +1532,29 @@
 usage +="  Usage: newmtx name sizeX(Col) sizeY(Lines) [f(i,j) [dopt] ] ";
 usage += "\n  Related commands: newvec";  
+mpiac->RegisterCommand(kw, usage, this, "Objects");
+kw = "line2vec";
+usage = "Creates a vector from the line \n";
+usage += "  Usage: line2vec vecname v0 v1 v2 ... \n";
+usage += "  Related commands: newvec line2nt";  
+mpiac->RegisterCommand(kw, usage, this, "Objects");
+kw = "line2nt";
+usage = "Fills (append) an NTuple from the line content \n";
+usage += "  Usage: line2nt ntname col0 col1 ... \n";
+usage += "  Related commands: newnt line2vec ntline2var ntcol2var";  
+mpiac->RegisterCommand(kw, usage, this, "Objects");
+kw = "vec2var";
+usage = "Vector content to an interpreter variable varname = 'v0 v1 v2 ...' \n";
+usage += "  Usage: line2vec vecname varname [LoopParam start:end[:step] ]\n";
+usage += "  Related commands: line2vec ntline2var";  
+mpiac->RegisterCommand(kw, usage, this, "Objects");
+kw = "ntline2var";
+usage = "Object NTupleInterface line to an interpreter variable \n";
+usage += "  Usage: ntline2var objname line_number varname \n";
+usage += "  Related commands: vec2var ntcol2var";  
+mpiac->RegisterCommand(kw, usage, this, "Objects");
+kw = "ntcol2var";
+usage = "Object NTupleInterface column to an interpreter variable \n";
+usage += "  Usage: ntline2var objname column_number varname [LoopParam start:end[:step] ] \n";
+usage += "  Related commands: vec2var ntline2var";  
 mpiac->RegisterCommand(kw, usage, this, "Objects");
 
Index: trunk/SophyaPI/PIext/piacmd.cc
===================================================================
--- trunk/SophyaPI/PIext/piacmd.cc	(revision 2302)
+++ trunk/SophyaPI/PIext/piacmd.cc	(revision 2305)
@@ -417,10 +417,10 @@
 cmdhgrp["All"] = 0;
 cmdgrpid = 1;
-cmdhgrp["Commands"] = 1;
+cmdhgrp["PIACmd"] = 1;
 helpwin = new PIAHelpWind(app, this);
 helpwin->AddHelpGroup("All", 0);
-helpwin->AddHelpGroup("Commands", 1);
-
-string kw = "piacmd";
+helpwin->AddHelpGroup("PIACmd", 1);
+
+string kw = "Interpreter";
 string usage;
 usage = ">>> (piacmd) Interpreter's keywords : \n";
@@ -430,4 +430,6 @@
 usage += "  > unset varname          # clear variable definition \n";
 usage += "  > rpneval varname RPNExpression # Reverse Polish Notation evaluation \n";
+usage += "  > varname = 'string string ...' # To set a variable, $varname  \n";
+usage += "  > varname = RPNExpression # RPN evaluation / result -> varname \n";
 usage += "  > echo string            # output string \n";
 usage += "  > echo2file filename string # Append the string to the specified file \n";
@@ -453,5 +455,29 @@
 usage += "  > helpwindow           # Displays help window \n";
 usage += "  > timingon  timingoff traceon  traceoff \n";
-string grp = "Commands";
+string grp = "PIACmd";
+RegisterHelp(kw, usage, grp);
+
+kw = "RPNEvaluator";
+usage = " Reverse Polish Notation (HP calculator like) expression evaluation \n";
+usage += "  >> Stack: \n";
+usage += "     ... (4) (3) z=(2) y=(1) x=(0)=Stack.Top() \n";
+usage += "  >> Examples:  \n";
+usage += "  - sin(PI/6): pi 6 / sin \n";
+usage += "  - 1*2*...*5: 1 2 3 4 5 product \n";
+usage += "  - x = $x $y * \n";
+usage += "  >>> Stack operations : \n";
+usage += "      print x<>y pop push (duplicate x) \n";
+usage += "  >>> Constants (Cst pushed to stack): \n";
+usage += "      pi e \n";
+usage += "  >>> Arithmetic operators (x,y) --> x@y \n";
+usage += "      + - * / % ( (int)y % (int)x )\n";
+usage += "  >>> F(X): x --> F(x) \n";
+usage += "      chs sqrt sq log log10 exp  \n"; 
+usage += "      fabs  floor ceil nint trunc  \n"; 
+usage += "      cos sin tan acos asin atan deg2rad rad2deg \n"; 
+usage += "  >>> F(X,Y): (x,y) --> F(x,y) \n";
+usage += "      pow atan2 \n"; 
+usage += "  >>> Stack sum/product/mean/sigma/sigma^2 \n";
+usage += "      sum product mean sigma sigma2 sigmean (y->sigma x->mean) \n"; 
 RegisterHelp(kw, usage, grp);
 
@@ -459,5 +485,5 @@
 usage  = "> shell  command_string  # Execute  shell command\n";
 usage += "> cshell command_string  # Execute cshell command\n";
-usage += "---Exemples:\n";
+usage += "---Examples:\n";
 usage += "  > shell ls\n";
 usage += "  > cshell echo '$LD_LIBRARY_PATH'; map2cl -h; ls\n";
@@ -858,6 +884,9 @@
 
 rcs = SubstituteVars(s, s2);
-if (rcs) return(rcs);
-
+if (rcs) { 
+  cerr << "PIACmd::Interpret()/syntax error in SubstituteVars() \n"
+       << "line: " << s << endl;
+  return(rcs);
+}
 // >>>> Separating keyword and tokens 
 vector<string> tokens;
@@ -885,5 +914,5 @@
   int rct = EvaluateTest(tokens, s, restst);
   if (rct) {
-    cerr << "PIACmd::Interpret() if syntax Error ! " << endl;
+    cerr << "PIACmd::Interpret() if syntax Error ! " << "line: " << s << endl;
     return(1);
   }
@@ -900,5 +929,5 @@
   int rcev = EvalRPNExpr(tokens, s);
   if (rcev) {
-    cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << endl;
+    cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << "line: " << s << endl;
     return(1);
   }
@@ -913,5 +942,5 @@
   }
   else {
-    cerr << "PIACmd::Interpret() No script name in defscript" << endl;
+    cerr << "PIACmd::Interpret() No script name in defscript" << "line: " << s << endl;
     return(1);
   }
@@ -993,4 +1022,5 @@
 string vn, vv;
 while (p < l) {
+  iarr = -1;
   q = s.find('$',p);
   if (q > l) break;
@@ -1281,4 +1311,8 @@
       rpnstack.top() = y/x;
     }
+    else if (args[k] == "%") { 
+      if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
+      rpnstack.top() = (int)y % (int)x;
+    }
     // Les constantes : e , pi
     else if (args[k] == "e") {
@@ -1313,4 +1347,16 @@
       rpnstack.top() = atan(x);
     }
+    else if (args[k] == "chs") {
+      if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
+      rpnstack.top() = -x;
+    }
+    else if (args[k] == "sqrt") {
+      if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
+      rpnstack.top() = sqrt(x);
+    }
+    else if (args[k] == "sq") {  // x^2 
+      if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
+      rpnstack.top() = x*x;
+    }
     else if (args[k] == "log") {
       if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
@@ -1329,7 +1375,19 @@
       rpnstack.top() = fabs(x);
     }
-    else if (args[k] == "chs") {
+    else if (args[k] == "floor") {
       if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
-      rpnstack.top() = -x;
+      rpnstack.top() = floor(x);
+    }
+    else if (args[k] == "ceil") {
+      if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
+      rpnstack.top() = ceil(x);
+    }
+    else if (args[k] == "nint") {
+      if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
+      rpnstack.top() = nint(x);
+    }
+    else if (args[k] == "trunc") {
+      if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
+      rpnstack.top() = trunc(x);
     }
     else if (args[k] == "deg2rad") {
@@ -1351,5 +1409,5 @@
     }
     // Fonction a N arguments  - Somme, produit, etc ...
-    else if ((args[k] == "sum") || (args[k] == "mean") || 
+    else if ((args[k] == "sum") || (args[k] == "mean") || (args[k] == "sigmean") || 
 	     (args[k] == "sigma") || (args[k] == "sigma2") ) {
       double sx, sx2;
@@ -1363,7 +1421,8 @@
 	}
 	double fnn = nn;
-	if (args[k] == "mean")  rpnstack.push(sx/fnn);
-	else if (args[k] == "sigma2") rpnstack.push(sx2/fnn-(x*x/(fnn*fnn)));
-	else rpnstack.push(sqrt(sx2/fnn-(x*x/(fnn*fnn))));
+	if ((args[k] == "sigma") || (args[k] == "sigmean")) 
+	  rpnstack.push(sqrt(sx2/fnn-(x*x/(fnn*fnn))));
+	else if ((args[k] == "mean") || (args[k] == "sigmean"))  rpnstack.push(sx/fnn);
+	else rpnstack.push(sx2/fnn-(x*x/(fnn*fnn)));
       }
     }
@@ -1385,4 +1444,11 @@
       if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
       rpnstack.top() = x;  rpnstack.push(y);
+    }
+    else if (args[k] == "pop") {
+      rpnstack.pop();
+    }
+    else if (args[k] == "push") {
+      if (rpnstack.empty()) rpnstack.push(0.);
+      else rpnstack.push(rpnstack.top());
     }
     // On met un nombre sur le stack 
