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