Index: trunk/SophyaProg/Tests/piapp.cc
===================================================================
--- trunk/SophyaProg/Tests/piapp.cc	(revision 491)
+++ trunk/SophyaProg/Tests/piapp.cc	(revision 499)
@@ -1,18 +1,13 @@
 #include <stdlib.h>
 #include <stdio.h>
-#ifdef OSF1
-#include <dlfcn.h>
-#else
-#define C_NO_SHLIBS
-#endif
 
-#include <string>
-#include "psighand.h"
-#include "dynccd.h"
+#include "pistdimgapp.h"
+#include "piacmd.h"
+#include "piversion.h"
+#include "piaversion.h"
 
 #include "timing.h"
-#include "piinit.h"
+#include "outilsinit.h"
 
-#include "pistdimgapp.h"
 
 
@@ -23,7 +18,7 @@
 {
 int ofa;
-int fgsig, fgred;
+int fgfpe, fgsegv, fgred, fgexec;
 
-PeidaInteractiveInitiator piinit;
+PeidaInit();
    
 InitTim();
@@ -35,5 +30,10 @@
     {
     puts("\n piapp: Programme d'analyse interactive ");
-    puts("Usage: piapp [-nored] [-nosig]");
+    puts("Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-help2tex] [-exec file [args]]");
+    puts("  -nored : NoRedirect StdOut/StdErr");
+    puts("  -nosig : Don't catch SigFPE, SigSEGV");
+    puts("  -nosigfpe -nosigsegv: Don't catch SigFPE / SigSEGV");
+    puts("  -help2tex: Create a LaTeX help file (piahelp.tex)");
+    puts("  -exec file [args] : Execute command file \n");
     exit(0);
     }
@@ -41,15 +41,49 @@
 
 ofa = 1;
-fgred = fgsig = true;
-if (  (narg > 1) && (strcmp(arg[1],"-nored") == 0) )  { fgred=false;  ofa = 2; }
-if (  (narg > 1) && (strcmp(arg[1],"-nosig") == 0) )  { fgsig=false;  ofa = 2; }
-if (  (narg > 2) && (strcmp(arg[2],"-nored") == 0) )  { fgred=false;  ofa = 3; }
-if (  (narg > 2) && (strcmp(arg[2],"-nosig") == 0) )  { fgsig=false;  ofa = 3; }
+fgred = fgfpe = fgsegv = true;
+fgexec = false;
+string exfc;
+// Pour fabriquer le help
+bool fgtexh = false;
+int ka;
+for(ka=1; ka<narg; ka++) {
+  if (strcmp(arg[ka],"-nored") == 0)   fgred=false; 
+  else if (strcmp(arg[ka],"-nosig") == 0)   fgfpe=fgsegv=false; 
+  else if (strcmp(arg[ka],"-nosigfpe") == 0)   fgfpe=false; 
+  else if (strcmp(arg[ka],"-nosigsegv") == 0)   fgsegv=false; 
+  else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
+  else if (strcmp(arg[ka],"-exec") == 0) {
+    if (ka < narg-1) {
+      fgexec = true;
+      exfc = "exec";
+      for(int kaa=ka+1; kaa<narg; kaa++)  { exfc += ' ';  exfc +=  arg[kaa]; }
+      }
+    break;
+    }
+  }
 
+if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str()); 
+else printf(">>>>> Starting piapp <<<<< \n");
+printf("Version: piapp=%g  PI=%g  PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER, 
+              (double)PI_VERSIONNUMBER, (float)PeidaVersion());
 
-PIStdImgApp * app = new PIStdImgApp(narg-ofa, arg+ofa);
-if (!fgred) app->RedirectStdOutErr(false);
-else app->RedirectStdOutErr(true);
-if (fgsig)  app->CatchSignals(true);
+PIStdImgApp * app = new PIStdImgApp(narg, arg);
+
+// Gestion de redirection stdout/err et Signaux
+if (fgred) app->RedirectStdOutErr(true);
+else app->RedirectStdOutErr(false);
+app->CatchSignals(fgfpe, fgsegv);
+
+// S'il y a un fichier de commande a executer
+if (fgexec) app->CmdInterpreter()->Interpret(exfc);
+
+// S'il y a besoin de faire le fichier Help
+if (fgtexh) { 
+  string thf = "piahelp.tex";
+  app->CmdInterpreter()->HelptoLaTex(thf);
+  printf("piapp : Help file piahelp.tex created --> exit(0) \n"); 
+  delete app;
+  exit(0);
+}
 
 int rc = 0;
@@ -59,7 +93,7 @@
   app->SetReady();
   if (fgred) app->RedirectStdOutErr(true);
-  TRY {
+  try {
   app->Run();
-  }  CATCH(merr) {
+  }  catch ( PException exc ) {
      char ans[32],rep;
      app->Stop();
@@ -68,15 +102,24 @@
      cout << endl; 
      cerr << endl;
-     printf("PIStdImg/main() Exception catched ! = %ld (%s) \n", (long)merr, PeidaExc(merr));
-     printf(" exit <CR> , continue c<CR> , close-windows, continue k<cr> ? ");  gets(ans);
-     rc = merr;
+     cerr << "PIStdImg/main() Exception catched ! " << exc.Msg() << endl;
+     cerr << " continue <CR> , Stop program S<CR> ? " << endl;  gets(ans);
+     rc = 9;
      rep = toupper(ans[0]);  
-     if ((rep != 'C')||(rep != 'K'))  cont = false;
-     else { cont = true; if (rep == 'K') app->CloseAllWindows(); }
+     if (rep == 'S')  { 
+       printf(" !!!! Stopping piapp !!!! \n"); 
+       cont = false;
+       }
+     else { 
+       printf(" *** piapp - Continuing event loop *** \n");
+       cont = true;
+       }
+//     else { cont = true; if (rep == 'K') app->CloseAllWindows(); }
   } ENDTRY;
 }
 
 app->RedirectStdOutErr(false);  
+// On de-charge le module erospiamodule
 delete app;
+
 printf("piapp : Exiting .... Rc= %d \n", rc); 
 exit(rc);
Index: trunk/SophyaProg/Tests/tobjio.cc
===================================================================
--- trunk/SophyaProg/Tests/tobjio.cc	(revision 499)
+++ trunk/SophyaProg/Tests/tobjio.cc	(revision 499)
@@ -0,0 +1,165 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "math.h"
+#include <iostream.h>
+#include <string>
+#include "nobjmgr.h"
+
+// Pour le test 
+#include "cvector.h"
+#include "matrix.h"
+#include "histos.h"
+#include "histos2.h"
+#include "ntuple.h"
+
+
+#include "fmath.h"
+#include "nbrandom.h"
+
+
+int main(int narg, char* arg[])
+{
+
+  POutPersist so("tobjio.ppf");
+
+  cout << "Test Creation / PPersist Save NTuple, Histo, ..." << endl;
+  NTuple *nt;
+  float xnt[4];
+  char *ntn[4] = {"x","y","ex","ey"};
+  int nent,i;
+  nent = 1000;
+  nt = new NTuple(2,ntn);  // Creation NTuple (AVEC new )
+  for(i=0; i<nent; i++) {
+    xnt[0] = i*50./nent; xnt[1] = 0.2*xnt[0]*xnt[0]+(NorRand()*xnt[0]/3.);
+    nt->Fill(xnt);
+  }
+
+  string nom = "nt21";
+  ObjFileIO<NTuple> oiont(*nt);
+  oiont.Write(so, nom);
+  cout << "Writing " << nom << endl;
+
+  string nx, ny, nz;
+  string ex,ey,ez;
+  nx = "x";  ny = "y";
+  nent = 20;
+  nt = new NTuple(4,ntn);  // Creation NTuple (AVEC new )
+  for(i=0; i<nent; i++) {
+    xnt[0] = i*50./nent; xnt[1] = 0.2*xnt[0]*xnt[0]+(NorRand()*xnt[0]/3.);
+    xnt[2] = sqrt((double) xnt[0]); xnt[3] = xnt[0]*2;
+    nt->Fill(xnt);
+  }
+  nom = "nt22";
+  ObjFileIO<NTuple> oiont2(*nt);
+  oiont2.Write(so, nom);
+  cout << "Writing " << nom << endl;
+
+  {  //  Objet Histo-2D
+  float x,y,w;
+  int i,j;
+  Histo2D* h = new Histo2D(-10.,10.,25,-10.,10.,25);
+  for(i=0; i<25; i++) for(j=0; j<25; j++) {
+    h->BinCenter(i,j,x,y);
+    w = 100.*exp(-0.5*(x*x/9. + y*y/9.));
+    h->Add(x,y,w);
+    w = 50.*exp(-0.5*((x+10.)*(x+10.)/9. + (y+10.)*(y+10.)/9.));
+    h->Add(x,y,w);
+    }
+  nom = "h2d";
+  ObjFileIO<Histo2D> oioh(*h);
+  oioh.Write(so, nom);
+  cout << "Writing " << nom << endl;
+  }
+
+  {
+  Histo *h;
+  float x;
+
+
+  h = new Histo(0., 200., 100);  // Creation histo (AVEC new )
+  for(i=0; i<100; i++)  // Remplissage d'histo
+    { x = (2*i+1.);  h->Add(x, x*(200.-x)); }
+  nom = "h1d";
+  ObjFileIO<Histo> oioh(*h);
+  oioh.Write(so, nom);
+  cout << "Writing " << nom << endl;
+  
+  }
+
+  {   // Vecteurs 
+  Vector* vpx, *vpy;
+  vpx = new Vector(20);  vpy = new Vector(20);
+  int i;   double x;
+  for(i=0; i<20; i++) { x = 8.*i/20;  (*vpx)(i) = x;  (*vpy)(i) = 3*cos(x)+2*sin(x); }
+  nom = "vx1";
+  vpx->Write(so, nom);
+  cout << "Writing " << nom << endl;
+  nom = "vy1";
+  vpy->Write(so, nom);
+  cout << "Writing " << nom << endl;
+  vpx = new Vector(30);  
+  for(i=0; i<30; i++) { x = 8.*i/30+0.1;  (*vpx)(i) = sin(2.*x)/(2.*x); }
+  nom = "vx2";
+  vpx->Write(so, nom);
+  cout << "Writing " << nom << endl;
+  }
+
+      
+  {       // NTuple 3D
+  float xnt[6];
+  double ang;
+  char *ntn[6] = {"x","y","z","ex","ey","ez"};
+  int nent,i;
+      
+  NTuple* nt = new NTuple(6,ntn);  // Creation NTuple (AVEC new )
+  nent = 3000;
+  for(i=0; i<nent; i++) {
+  ang = 5.*6.28*(double)i/(double)nent;
+  xnt[0] = cos(ang)*1.5+NorRand()*0.1; xnt[1] = sin(ang)*1.5+NorRand()*0.1;
+  xnt[2] = ang/8.+NorRand()*0.05;   xnt[3] = xnt[4] = xnt[5] = 0.;
+  nt->Fill(xnt);
+  }
+
+  nom = "nt31";
+  ObjFileIO<NTuple> oiont(*nt);
+  oiont.Write(so, nom);
+  cout << "Writing " << nom << endl;
+  
+  nt = new NTuple(6,ntn);  // Creation NTuple (AVEC new )
+  nent = 100;
+  for(i=0; i<nent; i++) {
+    ang = 5.*6.28*(double)i/(double)nent;
+    xnt[0] = cos(-ang)*1+NorRand()*0.0; xnt[1] = sin(-ang)*1.+NorRand()*0.0;
+    xnt[2] = ang/8.+NorRand()*0.0;   xnt[3] = 0.1; xnt[4] = 0.15;  xnt[5] = 0.07;
+    nt->Fill(xnt);
+    }
+  nom = "nt32";
+  ObjFileIO<NTuple> oiont2(*nt);
+  oiont2.Write(so, nom);
+  cout << "Writing " << nom << endl;
+  }
+
+  {    // Matrices 
+  Matrix* mtx = new Matrix(50, 50);
+  int i,j;
+  double xp,yp,rp;
+  for(i=0; i<50; i++)
+     for(j=0; j<50; j++) { 
+     xp = i-15;   yp = j-25;
+     rp = (xp*xp)/16.+(yp*yp)/16.;
+     (*mtx)(j,i) = 11.*exp(-rp);
+     xp = i-35;   yp = j-15;
+     rp = (xp*xp)/9.+(yp*yp)/9.;
+     (*mtx)(j,i) += 3.*exp(-rp);
+     xp = i-45;   yp = j-40;
+     rp = (xp*xp)/10.+(yp*yp)/20.;
+     (*mtx)(j,i) += 6.*exp(-rp);
+     }
+  nom = "mtx1";
+  mtx->Write(so, nom);
+  cout << "Writing " << nom << endl;
+  }
+
+  cout << " End --- exit .... " << endl;
+}
+
