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