Index: trunk/SophyaPI/PIext/piacmd.cc
===================================================================
--- trunk/SophyaPI/PIext/piacmd.cc	(revision 2298)
+++ 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 
