| [722] | 1 | #include <stdlib.h>
 | 
|---|
 | 2 | #include <stdio.h>
 | 
|---|
| [2112] | 3 | #include <unistd.h>
 | 
|---|
| [2322] | 4 | #include <iostream>
 | 
|---|
| [722] | 5 | 
 | 
|---|
| [2615] | 6 | #include "sopnamsp.h"
 | 
|---|
| [722] | 7 | #include "pistdimgapp.h"
 | 
|---|
 | 8 | #include "piacmd.h"
 | 
|---|
 | 9 | #include "piversion.h"
 | 
|---|
 | 10 | #include "piaversion.h"
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | #include "timing.h"
 | 
|---|
 | 13 | #include "skyinit.h"
 | 
|---|
 | 14 | 
 | 
|---|
| [1440] | 15 | #include "xntuple.h" // Pour faire le SetTmpDir()
 | 
|---|
| [722] | 16 | 
 | 
|---|
| [1440] | 17 | 
 | 
|---|
| [722] | 18 | // ---- Pour charger automatiquement le module sopiamodule 
 | 
|---|
 | 19 | extern "C" {
 | 
|---|
 | 20 | void sopiamodule_init();
 | 
|---|
 | 21 | void sopiamodule_end();
 | 
|---|
| [2155] | 22 | void skymapmodule_init();
 | 
|---|
 | 23 | void skymapmodule_end();
 | 
|---|
| [1506] | 24 | void fitsbtadapter_init();
 | 
|---|
 | 25 | void fitsbtadapter_end();
 | 
|---|
| [1524] | 26 | void W2PSModule_init();
 | 
|---|
 | 27 | void W2PSModule_end();
 | 
|---|
| [722] | 28 | }
 | 
|---|
 | 29 | 
 | 
|---|
| [1440] | 30 | /*!
 | 
|---|
 | 31 |   \defgroup ProgPI ProgPI module
 | 
|---|
 | 32 |   This module contains programs for interactive data analysis and
 | 
|---|
 | 33 |   visualisation, based on SOPHYA class libray and PI (GUI framework)
 | 
|---|
 | 34 |   and PIext (Interactive data analysis framework).
 | 
|---|
 | 35 | */
 | 
|---|
| [722] | 36 | 
 | 
|---|
| [1440] | 37 | /*!
 | 
|---|
 | 38 |   \ingroup ProgPI
 | 
|---|
 | 39 |   \file piapp.cc
 | 
|---|
| [2810] | 40 |   \brief \b piapp: Starts the piapp interactive data analysis program.
 | 
|---|
| [1440] | 41 | 
 | 
|---|
| [2810] | 42 |   This interactive analysis program uses the SOPHYA libray, the PI GUI 
 | 
|---|
 | 43 |   library. It has multiple execution threads and a  c-shell inspired 
 | 
|---|
 | 44 |   command execution interpreter. See the piapp user manual for more
 | 
|---|
 | 45 |   information.
 | 
|---|
 | 46 |   The SOPHYA piapp executable is called \b spiapp.
 | 
|---|
| [1440] | 47 | 
 | 
|---|
 | 48 |   \verbatim
 | 
|---|
 | 49 |   csh> spiapp -h
 | 
|---|
| [2810] | 50 |  SophyaInitiator::SophyaInitiator() BaseTools Init
 | 
|---|
 | 51 |  PIOPersist::Initialize() Starting Sophya Persistence management service 
 | 
|---|
 | 52 | SOPHYA Version  1.9 Revision 0 (V_Mai2005) -- Jun  9 2005 22:01:01 
 | 
|---|
 | 53 | gcc 3.3-fast 20030304 (Apple Computer, Inc. build 1614)
 | 
|---|
| [1440] | 54 | 
 | 
|---|
| [2810] | 55 |  piapp: Interactive data analysis and visualisation program 
 | 
|---|
 | 56 |  Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin] 
 | 
|---|
 | 57 |               [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]] 
 | 
|---|
 | 58 |   -nored : NoRedirect StdOut/StdErr 
 | 
|---|
 | 59 |   -nosig : Don't catch SigFPE, SigSEGV 
 | 
|---|
 | 60 |   -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV 
 | 
|---|
 | 61 |   -hidezswin : Hide Zoom/Stat/ColMap window 
 | 
|---|
 | 62 |   -tmpdir TmpDirectory: defines TMDIR for temporary files 
 | 
|---|
 | 63 |   -help2tex: Create a LaTeX help file (piahelp.tex)
 | 
|---|
 | 64 |   -exec file [args] : Execute command file 
 | 
|---|
| [1440] | 65 |   
 | 
|---|
 | 66 |   \endverbatim
 | 
|---|
 | 67 |  
 | 
|---|
 | 68 | */
 | 
|---|
 | 69 | 
 | 
|---|
| [2418] | 70 | int Usage(bool fgerr)
 | 
|---|
| [1440] | 71 | {
 | 
|---|
 | 72 |   if (fgerr) { 
 | 
|---|
 | 73 |     cout << " piapp : Argument Error ! piapp -h for Usage" << endl; 
 | 
|---|
| [2418] | 74 |     return 1;
 | 
|---|
| [1440] | 75 |   }
 | 
|---|
 | 76 |   else {
 | 
|---|
 | 77 |     cout << "\n piapp: Interactive data analysis and visualisation program \n"
 | 
|---|
| [1972] | 78 |          << " Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin] \n"
 | 
|---|
| [1440] | 79 |          << "              [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]] \n"
 | 
|---|
 | 80 |          << "  -nored : NoRedirect StdOut/StdErr \n"
 | 
|---|
 | 81 |          << "  -nosig : Don't catch SigFPE, SigSEGV \n"
 | 
|---|
 | 82 |          << "  -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV \n"
 | 
|---|
| [1972] | 83 |          << "  -hidezswin : Hide Zoom/Stat/ColMap window \n"
 | 
|---|
| [1440] | 84 |          << "  -tmpdir TmpDirectory: defines TMDIR for temporary files \n"
 | 
|---|
 | 85 |          << "  -help2tex: Create a LaTeX help file (piahelp.tex)\n"
 | 
|---|
 | 86 |          << "  -exec file [args] : Execute command file \n"
 | 
|---|
 | 87 |          << endl;
 | 
|---|
| [2418] | 88 |     return 0;
 | 
|---|
| [1440] | 89 |   }
 | 
|---|
 | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|
| [722] | 92 | /*  ================================ MAIN() =================================  */
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | int main(int narg, char *arg[])
 | 
|---|
 | 95 | {
 | 
|---|
 | 96 | int ofa;
 | 
|---|
| [1972] | 97 | bool fgfpe, fgsegv, fgred, fghidezsw, fgexec;
 | 
|---|
| [722] | 98 | 
 | 
|---|
 | 99 | SkyTInitiator skyinit;
 | 
|---|
 | 100 |    
 | 
|---|
 | 101 | InitTim();
 | 
|---|
 | 102 | 
 | 
|---|
| [2418] | 103 | if(narg>1) 
 | 
|---|
 | 104 |   for(int jh=1;jh<narg;jh++) if(strcmp(arg[jh],"-h") == 0) return Usage(false);
 | 
|---|
| [722] | 105 | 
 | 
|---|
 | 106 | ofa = 1;
 | 
|---|
 | 107 | fgred = fgfpe = fgsegv = true;
 | 
|---|
| [1972] | 108 | fghidezsw = false;
 | 
|---|
| [722] | 109 | fgexec = false;
 | 
|---|
| [1440] | 110 | bool fgtmp = false;
 | 
|---|
 | 111 | string tmpdir;
 | 
|---|
| [722] | 112 | string exfc;
 | 
|---|
 | 113 | // Pour fabriquer le help
 | 
|---|
 | 114 | bool fgtexh = false;
 | 
|---|
 | 115 | int ka;
 | 
|---|
 | 116 | for(ka=1; ka<narg; ka++) {
 | 
|---|
 | 117 |   if (strcmp(arg[ka],"-nored") == 0)   fgred=false; 
 | 
|---|
 | 118 |   else if (strcmp(arg[ka],"-nosig") == 0)   fgfpe=fgsegv=false; 
 | 
|---|
 | 119 |   else if (strcmp(arg[ka],"-nosigfpe") == 0)   fgfpe=false; 
 | 
|---|
 | 120 |   else if (strcmp(arg[ka],"-nosigsegv") == 0)   fgsegv=false; 
 | 
|---|
| [1972] | 121 |   else if (strcmp(arg[ka],"-hidezswin") == 0)   fghidezsw=true; 
 | 
|---|
| [722] | 122 |   else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
 | 
|---|
| [1440] | 123 |   else if (strcmp(arg[ka],"-tmpdir") == 0) {
 | 
|---|
| [2418] | 124 |     if (ka == narg-1) return Usage(true);
 | 
|---|
| [1440] | 125 |     fgtmp = true;  ka++;
 | 
|---|
 | 126 |     tmpdir = arg[ka];    
 | 
|---|
 | 127 |   }
 | 
|---|
| [722] | 128 |   else if (strcmp(arg[ka],"-exec") == 0) {
 | 
|---|
 | 129 |     if (ka < narg-1) {
 | 
|---|
 | 130 |       fgexec = true;
 | 
|---|
 | 131 |       exfc = "exec";
 | 
|---|
 | 132 |       for(int kaa=ka+1; kaa<narg; kaa++)  { exfc += ' ';  exfc +=  arg[kaa]; }
 | 
|---|
 | 133 |       }
 | 
|---|
 | 134 |     break;
 | 
|---|
 | 135 |     }
 | 
|---|
 | 136 |   }
 | 
|---|
 | 137 | 
 | 
|---|
| [1440] | 138 |  
 | 
|---|
| [722] | 139 | if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str()); 
 | 
|---|
 | 140 | else printf(">>>>> Starting piapp <<<<< \n");
 | 
|---|
 | 141 | printf("Version: piapp=%g  PI=%g  SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER, 
 | 
|---|
 | 142 |               (double)PI_VERSIONNUMBER, (double)skyinit.Version());
 | 
|---|
 | 143 | 
 | 
|---|
| [2105] | 144 | char* vcmds=NULL;
 | 
|---|
 | 145 | string vcmd;
 | 
|---|
| [1440] | 146 | if (fgtmp) {
 | 
|---|
 | 147 |   if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/';  // Necessaire pour SetSwapPath
 | 
|---|
| [2105] | 148 |   vcmd = "TMPDIR=" + tmpdir;
 | 
|---|
| [1440] | 149 |   vcmds = new char[vcmd.length()+1];
 | 
|---|
 | 150 |   strcpy(vcmds, vcmd.c_str());
 | 
|---|
 | 151 |   putenv(vcmds);
 | 
|---|
 | 152 | }
 | 
|---|
 | 153 | 
 | 
|---|
| [2105] | 154 | char* tmpde = getenv("TMPDIR");
 | 
|---|
 | 155 | char  tmpdname[32];
 | 
|---|
 | 156 | if (tmpde == NULL) tmpde = "./";
 | 
|---|
 | 157 | if (tmpde[strlen(tmpde)-1] != '/')
 | 
|---|
 | 158 |   strcpy(tmpdname, "/PIATmp_XXXXXX"); 
 | 
|---|
 | 159 | else 
 | 
|---|
 | 160 |   strcpy(tmpdname, "PIATmp_XXXXXX"); 
 | 
|---|
 | 161 | mktemp(tmpdname);
 | 
|---|
 | 162 | tmpdir = tmpde;
 | 
|---|
 | 163 | tmpdir += tmpdname;
 | 
|---|
 | 164 | tmpdir += '/';
 | 
|---|
 | 165 | vcmd = "mkdir ";
 | 
|---|
 | 166 | vcmd += tmpde;
 | 
|---|
 | 167 | vcmd += tmpdname;
 | 
|---|
 | 168 | cout << " --piapp: Creating Tmp Directory: " << tmpdir << endl;
 | 
|---|
 | 169 | int rcc = system(vcmd.c_str());
 | 
|---|
 | 170 | if (rcc != 0) {
 | 
|---|
 | 171 |   cout << " --piapp: Error creating TmpDir " << vcmd << " ---> exit !" << endl;
 | 
|---|
 | 172 |   return(9);
 | 
|---|
 | 173 | }
 | 
|---|
 | 174 | 
 | 
|---|
 | 175 | // On cree un repertoire temporaire 
 | 
|---|
| [1440] | 176 | // cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
 | 
|---|
 | 177 | 
 | 
|---|
| [722] | 178 | PIStdImgApp * app = new PIStdImgApp(narg, arg);
 | 
|---|
| [1440] | 179 | // cout << " DBG-2 " <<  app->ObjMgr()->GetTmpDir() << endl;
 | 
|---|
| [2105] | 180 | cout << "  NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
 | 
|---|
 | 181 | app->ObjMgr()->SetTmpDir(tmpdir);
 | 
|---|
 | 182 | XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
 | 
|---|
| [722] | 183 | 
 | 
|---|
| [1440] | 184 | 
 | 
|---|
| [2105] | 185 | 
 | 
|---|
| [722] | 186 | // Gestion de redirection stdout/err et Signaux
 | 
|---|
 | 187 | if (fgred) app->RedirectStdOutErr(true);
 | 
|---|
 | 188 | else app->RedirectStdOutErr(false);
 | 
|---|
 | 189 | app->CatchSignals(fgfpe, fgsegv);
 | 
|---|
 | 190 | 
 | 
|---|
| [1972] | 191 | // if Hide Zoom/Stat Win
 | 
|---|
 | 192 | if (fghidezsw)  app->StatZoomWindowSetVisible(false);
 | 
|---|
 | 193 | 
 | 
|---|
| [722] | 194 | // S'il y a un fichier de commande a executer
 | 
|---|
| [2189] | 195 | // if (fgexec) app->CmdInterpreter()->Interpret(exfc);
 | 
|---|
 | 196 | if (fgexec) app->SubmitCommand(exfc);
 | 
|---|
| [722] | 197 | 
 | 
|---|
 | 198 | // On charge le module sopiamodule
 | 
|---|
 | 199 | sopiamodule_init();
 | 
|---|
| [2155] | 200 | // On charge le module skymapmodule
 | 
|---|
 | 201 | skymapmodule_init();
 | 
|---|
| [1506] | 202 | // On charge le module de lecture ligne a ligne des Fits BINARY/ASCII tables
 | 
|---|
 | 203 | fitsbtadapter_init();
 | 
|---|
| [1524] | 204 | // On charge le module des commandes de creation de fichier postscript
 | 
|---|
 | 205 | W2PSModule_init();
 | 
|---|
| [722] | 206 | 
 | 
|---|
 | 207 | // S'il y a besoin de faire le fichier Help
 | 
|---|
 | 208 | if (fgtexh) { 
 | 
|---|
 | 209 |   string thf = "piahelp.tex";
 | 
|---|
| [2261] | 210 |   app->CmdInterpreter()->HelptoLaTeX(thf);
 | 
|---|
| [722] | 211 |   printf("piapp : Help file piahelp.tex created --> exit(0) \n"); 
 | 
|---|
 | 212 |   delete app;
 | 
|---|
 | 213 |   exit(0);
 | 
|---|
 | 214 | }
 | 
|---|
 | 215 | 
 | 
|---|
 | 216 | int rc = 0;
 | 
|---|
 | 217 | bool cont = true;
 | 
|---|
| [2093] | 218 | char rep; // ans[32]
 | 
|---|
| [722] | 219 | int excnt = 0;
 | 
|---|
 | 220 | while(cont) {
 | 
|---|
 | 221 |   rc = 0;   cont = false;
 | 
|---|
 | 222 |   app->SetReady();
 | 
|---|
 | 223 |   if (fgred) app->RedirectStdOutErr(true);
 | 
|---|
 | 224 |   try {
 | 
|---|
| [2093] | 225 |     app->Run();
 | 
|---|
 | 226 |   }
 | 
|---|
| [722] | 227 |   catch(PThrowable exc) {  // Catching SOPHYA exceptions 
 | 
|---|
 | 228 |     app->Stop();
 | 
|---|
 | 229 |     app->RedirectStdOutErr(false);  
 | 
|---|
 | 230 |     //BUG ? fait planter OSF-cxx     fflush(stdout); 
 | 
|---|
 | 231 |     cout << endl;      cerr << endl;
 | 
|---|
 | 232 |     cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl;
 | 
|---|
 | 233 |     cout << ++excnt << "- continue <CR>, Close Windows, "
 | 
|---|
 | 234 |          << " continue C<CR> Stop program S<CR> ? " << endl; 
 | 
|---|
| [2093] | 235 |     rep = getchar();  // was: gets(ans);
 | 
|---|
 | 236 |     rep = toupper(rep);  
 | 
|---|
| [722] | 237 |     if (rep == 'S')  { 
 | 
|---|
 | 238 |       cout << " !!!! Stopping piapp !!!! " << endl;
 | 
|---|
 | 239 |       rc = 78;
 | 
|---|
 | 240 |       cont = false;
 | 
|---|
 | 241 |     }
 | 
|---|
 | 242 |     else { 
 | 
|---|
 | 243 |       if (rep == 'C') {
 | 
|---|
 | 244 |         cout << "piapp/main() Closing all windows ... " << endl;
 | 
|---|
 | 245 |         app->CloseAllWindows();
 | 
|---|
 | 246 |       }
 | 
|---|
 | 247 |       cout << " *** piapp - Continuing event loop *** " << endl;
 | 
|---|
 | 248 |       cont = true;
 | 
|---|
 | 249 |     }
 | 
|---|
 | 250 |   }
 | 
|---|
 | 251 |   catch(...) { // Catching all other exceptions 
 | 
|---|
 | 252 |     app->Stop();
 | 
|---|
 | 253 |     app->RedirectStdOutErr(false);  
 | 
|---|
 | 254 |     cout << endl;      cerr << endl;
 | 
|---|
 | 255 |     cout << "\n piapp/main() exception catched ! " << endl;
 | 
|---|
 | 256 |     cout << ++excnt << "- continue <CR>, Close Windows, "
 | 
|---|
 | 257 |          << " continue C<CR> Stop program S<CR> ? " << endl; 
 | 
|---|
| [2093] | 258 |     rep = getchar(); // gets(ans);
 | 
|---|
 | 259 |     rep = toupper(rep);  
 | 
|---|
| [722] | 260 |     if (rep == 'S')  { 
 | 
|---|
 | 261 |       cout << " !!!! Stopping piapp !!!! " << endl;
 | 
|---|
 | 262 |       rc = 78;
 | 
|---|
 | 263 |       cont = false;
 | 
|---|
 | 264 |     }
 | 
|---|
 | 265 |     else { 
 | 
|---|
 | 266 |       if (rep == 'C') {
 | 
|---|
 | 267 |         cout << "piapp/main() Closing all windows ... " << endl;
 | 
|---|
 | 268 |         app->CloseAllWindows();
 | 
|---|
 | 269 |       }
 | 
|---|
 | 270 |       cout << " *** piapp - Continuing event loop *** " << endl;
 | 
|---|
 | 271 |       cont = true;
 | 
|---|
 | 272 |     }
 | 
|---|
 | 273 |   }
 | 
|---|
 | 274 | }
 | 
|---|
| [2105] | 275 | cout << "\n ------------------------------------------------ \n"
 | 
|---|
 | 276 |      << " piapp: Cleaning up ... " << endl;
 | 
|---|
| [722] | 277 | 
 | 
|---|
 | 278 | app->RedirectStdOutErr(false);  
 | 
|---|
| [1506] | 279 | // On de-charge le module sopiamodule et fitsbtadapter
 | 
|---|
| [722] | 280 | sopiamodule_end();
 | 
|---|
| [2155] | 281 | skymapmodule_end();
 | 
|---|
| [1506] | 282 | fitsbtadapter_end();
 | 
|---|
| [1524] | 283 | W2PSModule_end();
 | 
|---|
| [1506] | 284 | 
 | 
|---|
| [722] | 285 | delete app;
 | 
|---|
| [1440] | 286 | if (fgtmp) delete[] vcmds;
 | 
|---|
| [722] | 287 | 
 | 
|---|
| [2105] | 288 | vcmd = "rm -rf ";
 | 
|---|
 | 289 | vcmd += tmpdir;
 | 
|---|
 | 290 | cout << " --piapp: Removing Tmp Directory: " << tmpdir << endl;
 | 
|---|
 | 291 | rcc = system(vcmd.c_str());
 | 
|---|
 | 292 | if (rcc != 0) {
 | 
|---|
 | 293 |   cout << " --piapp: Error deleting TmpDir " << vcmd << endl;
 | 
|---|
 | 294 |   return(9);
 | 
|---|
 | 295 | }
 | 
|---|
 | 296 | 
 | 
|---|
 | 297 | cout << "------------------------------------------------ \n"
 | 
|---|
| [722] | 298 |      << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
 | 
|---|
 | 299 |      << "------------------------------------------------ " << endl; 
 | 
|---|
 | 300 | return(rc);
 | 
|---|
 | 301 | }
 | 
|---|
 | 302 | 
 | 
|---|