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