Index: trunk/SophyaPI/ProgPI/piapp.cc
===================================================================
--- trunk/SophyaPI/ProgPI/piapp.cc	(revision 1374)
+++ trunk/SophyaPI/ProgPI/piapp.cc	(revision 1440)
@@ -11,4 +11,6 @@
 #include "skyinit.h"
 
+#include "xntuple.h" // Pour faire le SetTmpDir()
+
 
 // ---- Pour charger automatiquement le module sopiamodule 
@@ -18,4 +20,59 @@
 }
 
+/*!
+  \defgroup ProgPI ProgPI module
+  This module contains programs for interactive data analysis and
+  visualisation, based on SOPHYA class libray and PI (GUI framework)
+  and PIext (Interactive data analysis framework).
+*/
+
+/*!
+  \ingroup ProgPI
+  \file piapp.cc
+  \brief \b (s)piapp: Starts the piapp interactive data analysis program.
+
+  The current version of the program has a single execution thread. This
+  creates few limitations (GUI can not be used when computing is being
+  done, ...). Also the command file executed during start-up (-exec)
+  cannot contain display (graphic) commands.
+
+  \verbatim
+  csh> spiapp -h
+  SOPHYA Version  1.1 Revision 0 (V_Fev2001) -- Mar  9 2001 15:45:31 cxx
+
+  piapp: Interactive data analysis and visualisation program
+  Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv]
+               [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
+    -nored : NoRedirect StdOut/StdErr
+    -nosig : Don't catch SigFPE, SigSEGV
+    -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
+    -tmpdir TmpDirectory: defines TMDIR for temporary files
+    -help2tex: Create a LaTeX help file (piahelp.tex)
+    -exec file [args] : Execute command file
+  
+  \endverbatim
+ 
+*/
+
+void Usage(bool fgerr)
+{
+  if (fgerr) { 
+    cout << " piapp : Argument Error ! piapp -h for Usage" << endl; 
+    exit(1);
+  }
+  else {
+    cout << "\n piapp: Interactive data analysis and visualisation program \n"
+	 << " Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] \n"
+	 << "              [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]] \n"
+	 << "  -nored : NoRedirect StdOut/StdErr \n"
+	 << "  -nosig : Don't catch SigFPE, SigSEGV \n"
+         << "  -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV \n"
+	 << "  -tmpdir TmpDirectory: defines TMDIR for temporary files \n"
+	 << "  -help2tex: Create a LaTeX help file (piahelp.tex)\n"
+	 << "  -exec file [args] : Execute command file \n"
+	 << endl;
+    exit(0);
+  }
+}
 
 /*  ================================ MAIN() =================================  */
@@ -30,23 +87,12 @@
 InitTim();
 
-ofa = 1;   
-if (narg > 1)
-  {
-  if (strcmp(arg[1],"-h") == 0) 
-    {
-    puts("\n piapp: Programme d'analyse interactive ");
-    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);
-    }
-  }
+
+if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
 
 ofa = 1;
 fgred = fgfpe = fgsegv = true;
 fgexec = false;
+bool fgtmp = false;
+string tmpdir;
 string exfc;
 // Pour fabriquer le help
@@ -59,4 +105,9 @@
   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],"-tmpdir") == 0) {
+    if (ka == narg-1) Usage(true);
+    fgtmp = true;  ka++;
+    tmpdir = arg[ka];    
+  }
   else if (strcmp(arg[ka],"-exec") == 0) {
     if (ka < narg-1) {
@@ -69,4 +120,5 @@
   }
 
+ 
 if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str()); 
 else printf(">>>>> Starting piapp <<<<< \n");
@@ -74,5 +126,23 @@
               (double)PI_VERSIONNUMBER, (double)skyinit.Version());
 
+char *vcmds;
+if (fgtmp) {
+  if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/';  // Necessaire pour SetSwapPath
+  string vcmd = "TMPDIR=" + tmpdir;
+  vcmds = new char[vcmd.length()+1];
+  strcpy(vcmds, vcmd.c_str());
+  putenv(vcmds);
+}
+
+// cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
+
 PIStdImgApp * app = new PIStdImgApp(narg, arg);
+// cout << " DBG-2 " <<  app->ObjMgr()->GetTmpDir() << endl;
+if (fgtmp) {  // Changement de tmpdir 
+  cout << "  NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
+  app->ObjMgr()->SetTmpDir(tmpdir);
+  XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
+}
+
 
 // Gestion de redirection stdout/err et Signaux
@@ -160,4 +230,5 @@
 sopiamodule_end();
 delete app;
+if (fgtmp) delete[] vcmds;
 
 cout << "\n------------------------------------------------ \n"
