[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
|
---|
| 40 | \brief \b (s)piapp: Starts the piapp interactive data analysis program.
|
---|
| 41 |
|
---|
| 42 | The current version of the program has a single execution thread. This
|
---|
| 43 | creates few limitations (GUI can not be used when computing is being
|
---|
| 44 | done, ...). Also the command file executed during start-up (-exec)
|
---|
| 45 | cannot contain display (graphic) commands.
|
---|
| 46 |
|
---|
| 47 | \verbatim
|
---|
| 48 | csh> spiapp -h
|
---|
[2105] | 49 | SOPHYA Version 1.3 Revision 70 (V_Jun2002) -- Jul 16 2002 15:45:53 cxx
|
---|
[1440] | 50 |
|
---|
[2105] | 51 | piapp: Interactive data analysis and visualisation program
|
---|
| 52 | Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin]
|
---|
| 53 | [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
|
---|
[1440] | 54 | -nored : NoRedirect StdOut/StdErr
|
---|
| 55 | -nosig : Don't catch SigFPE, SigSEGV
|
---|
| 56 | -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
|
---|
[2105] | 57 | -hidezswin : Hide Zoom/Stat/ColMap window
|
---|
[1440] | 58 | -tmpdir TmpDirectory: defines TMDIR for temporary files
|
---|
| 59 | -help2tex: Create a LaTeX help file (piahelp.tex)
|
---|
| 60 | -exec file [args] : Execute command file
|
---|
| 61 |
|
---|
| 62 | \endverbatim
|
---|
| 63 |
|
---|
| 64 | */
|
---|
| 65 |
|
---|
[2418] | 66 | int Usage(bool fgerr)
|
---|
[1440] | 67 | {
|
---|
| 68 | if (fgerr) {
|
---|
| 69 | cout << " piapp : Argument Error ! piapp -h for Usage" << endl;
|
---|
[2418] | 70 | return 1;
|
---|
[1440] | 71 | }
|
---|
| 72 | else {
|
---|
| 73 | cout << "\n piapp: Interactive data analysis and visualisation program \n"
|
---|
[1972] | 74 | << " Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin] \n"
|
---|
[1440] | 75 | << " [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]] \n"
|
---|
| 76 | << " -nored : NoRedirect StdOut/StdErr \n"
|
---|
| 77 | << " -nosig : Don't catch SigFPE, SigSEGV \n"
|
---|
| 78 | << " -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV \n"
|
---|
[1972] | 79 | << " -hidezswin : Hide Zoom/Stat/ColMap window \n"
|
---|
[1440] | 80 | << " -tmpdir TmpDirectory: defines TMDIR for temporary files \n"
|
---|
| 81 | << " -help2tex: Create a LaTeX help file (piahelp.tex)\n"
|
---|
| 82 | << " -exec file [args] : Execute command file \n"
|
---|
| 83 | << endl;
|
---|
[2418] | 84 | return 0;
|
---|
[1440] | 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[722] | 88 | /* ================================ MAIN() ================================= */
|
---|
| 89 |
|
---|
| 90 | int main(int narg, char *arg[])
|
---|
| 91 | {
|
---|
| 92 | int ofa;
|
---|
[1972] | 93 | bool fgfpe, fgsegv, fgred, fghidezsw, fgexec;
|
---|
[722] | 94 |
|
---|
| 95 | SkyTInitiator skyinit;
|
---|
| 96 |
|
---|
| 97 | InitTim();
|
---|
| 98 |
|
---|
[2418] | 99 | if(narg>1)
|
---|
| 100 | for(int jh=1;jh<narg;jh++) if(strcmp(arg[jh],"-h") == 0) return Usage(false);
|
---|
[722] | 101 |
|
---|
| 102 | ofa = 1;
|
---|
| 103 | fgred = fgfpe = fgsegv = true;
|
---|
[1972] | 104 | fghidezsw = false;
|
---|
[722] | 105 | fgexec = false;
|
---|
[1440] | 106 | bool fgtmp = false;
|
---|
| 107 | string tmpdir;
|
---|
[722] | 108 | string exfc;
|
---|
| 109 | // Pour fabriquer le help
|
---|
| 110 | bool fgtexh = false;
|
---|
| 111 | int ka;
|
---|
| 112 | for(ka=1; ka<narg; ka++) {
|
---|
| 113 | if (strcmp(arg[ka],"-nored") == 0) fgred=false;
|
---|
| 114 | else if (strcmp(arg[ka],"-nosig") == 0) fgfpe=fgsegv=false;
|
---|
| 115 | else if (strcmp(arg[ka],"-nosigfpe") == 0) fgfpe=false;
|
---|
| 116 | else if (strcmp(arg[ka],"-nosigsegv") == 0) fgsegv=false;
|
---|
[1972] | 117 | else if (strcmp(arg[ka],"-hidezswin") == 0) fghidezsw=true;
|
---|
[722] | 118 | else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
|
---|
[1440] | 119 | else if (strcmp(arg[ka],"-tmpdir") == 0) {
|
---|
[2418] | 120 | if (ka == narg-1) return Usage(true);
|
---|
[1440] | 121 | fgtmp = true; ka++;
|
---|
| 122 | tmpdir = arg[ka];
|
---|
| 123 | }
|
---|
[722] | 124 | else if (strcmp(arg[ka],"-exec") == 0) {
|
---|
| 125 | if (ka < narg-1) {
|
---|
| 126 | fgexec = true;
|
---|
| 127 | exfc = "exec";
|
---|
| 128 | for(int kaa=ka+1; kaa<narg; kaa++) { exfc += ' '; exfc += arg[kaa]; }
|
---|
| 129 | }
|
---|
| 130 | break;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[1440] | 134 |
|
---|
[722] | 135 | if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
|
---|
| 136 | else printf(">>>>> Starting piapp <<<<< \n");
|
---|
| 137 | printf("Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
|
---|
| 138 | (double)PI_VERSIONNUMBER, (double)skyinit.Version());
|
---|
| 139 |
|
---|
[2105] | 140 | char* vcmds=NULL;
|
---|
| 141 | string vcmd;
|
---|
[1440] | 142 | if (fgtmp) {
|
---|
| 143 | if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/'; // Necessaire pour SetSwapPath
|
---|
[2105] | 144 | vcmd = "TMPDIR=" + tmpdir;
|
---|
[1440] | 145 | vcmds = new char[vcmd.length()+1];
|
---|
| 146 | strcpy(vcmds, vcmd.c_str());
|
---|
| 147 | putenv(vcmds);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[2105] | 150 | char* tmpde = getenv("TMPDIR");
|
---|
| 151 | char tmpdname[32];
|
---|
| 152 | if (tmpde == NULL) tmpde = "./";
|
---|
| 153 | if (tmpde[strlen(tmpde)-1] != '/')
|
---|
| 154 | strcpy(tmpdname, "/PIATmp_XXXXXX");
|
---|
| 155 | else
|
---|
| 156 | strcpy(tmpdname, "PIATmp_XXXXXX");
|
---|
| 157 | mktemp(tmpdname);
|
---|
| 158 | tmpdir = tmpde;
|
---|
| 159 | tmpdir += tmpdname;
|
---|
| 160 | tmpdir += '/';
|
---|
| 161 | vcmd = "mkdir ";
|
---|
| 162 | vcmd += tmpde;
|
---|
| 163 | vcmd += tmpdname;
|
---|
| 164 | cout << " --piapp: Creating Tmp Directory: " << tmpdir << endl;
|
---|
| 165 | int rcc = system(vcmd.c_str());
|
---|
| 166 | if (rcc != 0) {
|
---|
| 167 | cout << " --piapp: Error creating TmpDir " << vcmd << " ---> exit !" << endl;
|
---|
| 168 | return(9);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | // On cree un repertoire temporaire
|
---|
[1440] | 172 | // cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
|
---|
| 173 |
|
---|
[722] | 174 | PIStdImgApp * app = new PIStdImgApp(narg, arg);
|
---|
[1440] | 175 | // cout << " DBG-2 " << app->ObjMgr()->GetTmpDir() << endl;
|
---|
[2105] | 176 | cout << " NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
|
---|
| 177 | app->ObjMgr()->SetTmpDir(tmpdir);
|
---|
| 178 | XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
|
---|
[722] | 179 |
|
---|
[1440] | 180 |
|
---|
[2105] | 181 |
|
---|
[722] | 182 | // Gestion de redirection stdout/err et Signaux
|
---|
| 183 | if (fgred) app->RedirectStdOutErr(true);
|
---|
| 184 | else app->RedirectStdOutErr(false);
|
---|
| 185 | app->CatchSignals(fgfpe, fgsegv);
|
---|
| 186 |
|
---|
[1972] | 187 | // if Hide Zoom/Stat Win
|
---|
| 188 | if (fghidezsw) app->StatZoomWindowSetVisible(false);
|
---|
| 189 |
|
---|
[722] | 190 | // S'il y a un fichier de commande a executer
|
---|
[2189] | 191 | // if (fgexec) app->CmdInterpreter()->Interpret(exfc);
|
---|
| 192 | if (fgexec) app->SubmitCommand(exfc);
|
---|
[722] | 193 |
|
---|
| 194 | // On charge le module sopiamodule
|
---|
| 195 | sopiamodule_init();
|
---|
[2155] | 196 | // On charge le module skymapmodule
|
---|
| 197 | skymapmodule_init();
|
---|
[1506] | 198 | // On charge le module de lecture ligne a ligne des Fits BINARY/ASCII tables
|
---|
| 199 | fitsbtadapter_init();
|
---|
[1524] | 200 | // On charge le module des commandes de creation de fichier postscript
|
---|
| 201 | W2PSModule_init();
|
---|
[722] | 202 |
|
---|
| 203 | // S'il y a besoin de faire le fichier Help
|
---|
| 204 | if (fgtexh) {
|
---|
| 205 | string thf = "piahelp.tex";
|
---|
[2261] | 206 | app->CmdInterpreter()->HelptoLaTeX(thf);
|
---|
[722] | 207 | printf("piapp : Help file piahelp.tex created --> exit(0) \n");
|
---|
| 208 | delete app;
|
---|
| 209 | exit(0);
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | int rc = 0;
|
---|
| 213 | bool cont = true;
|
---|
[2093] | 214 | char rep; // ans[32]
|
---|
[722] | 215 | int excnt = 0;
|
---|
| 216 | while(cont) {
|
---|
| 217 | rc = 0; cont = false;
|
---|
| 218 | app->SetReady();
|
---|
| 219 | if (fgred) app->RedirectStdOutErr(true);
|
---|
| 220 | try {
|
---|
[2093] | 221 | app->Run();
|
---|
| 222 | }
|
---|
[722] | 223 | catch(PThrowable exc) { // Catching SOPHYA exceptions
|
---|
| 224 | app->Stop();
|
---|
| 225 | app->RedirectStdOutErr(false);
|
---|
| 226 | //BUG ? fait planter OSF-cxx fflush(stdout);
|
---|
| 227 | cout << endl; cerr << endl;
|
---|
| 228 | cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl;
|
---|
| 229 | cout << ++excnt << "- continue <CR>, Close Windows, "
|
---|
| 230 | << " continue C<CR> Stop program S<CR> ? " << endl;
|
---|
[2093] | 231 | rep = getchar(); // was: gets(ans);
|
---|
| 232 | rep = toupper(rep);
|
---|
[722] | 233 | if (rep == 'S') {
|
---|
| 234 | cout << " !!!! Stopping piapp !!!! " << endl;
|
---|
| 235 | rc = 78;
|
---|
| 236 | cont = false;
|
---|
| 237 | }
|
---|
| 238 | else {
|
---|
| 239 | if (rep == 'C') {
|
---|
| 240 | cout << "piapp/main() Closing all windows ... " << endl;
|
---|
| 241 | app->CloseAllWindows();
|
---|
| 242 | }
|
---|
| 243 | cout << " *** piapp - Continuing event loop *** " << endl;
|
---|
| 244 | cont = true;
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | catch(...) { // Catching all other exceptions
|
---|
| 248 | app->Stop();
|
---|
| 249 | app->RedirectStdOutErr(false);
|
---|
| 250 | cout << endl; cerr << endl;
|
---|
| 251 | cout << "\n piapp/main() exception catched ! " << endl;
|
---|
| 252 | cout << ++excnt << "- continue <CR>, Close Windows, "
|
---|
| 253 | << " continue C<CR> Stop program S<CR> ? " << endl;
|
---|
[2093] | 254 | rep = getchar(); // gets(ans);
|
---|
| 255 | rep = toupper(rep);
|
---|
[722] | 256 | if (rep == 'S') {
|
---|
| 257 | cout << " !!!! Stopping piapp !!!! " << endl;
|
---|
| 258 | rc = 78;
|
---|
| 259 | cont = false;
|
---|
| 260 | }
|
---|
| 261 | else {
|
---|
| 262 | if (rep == 'C') {
|
---|
| 263 | cout << "piapp/main() Closing all windows ... " << endl;
|
---|
| 264 | app->CloseAllWindows();
|
---|
| 265 | }
|
---|
| 266 | cout << " *** piapp - Continuing event loop *** " << endl;
|
---|
| 267 | cont = true;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
[2105] | 271 | cout << "\n ------------------------------------------------ \n"
|
---|
| 272 | << " piapp: Cleaning up ... " << endl;
|
---|
[722] | 273 |
|
---|
| 274 | app->RedirectStdOutErr(false);
|
---|
[1506] | 275 | // On de-charge le module sopiamodule et fitsbtadapter
|
---|
[722] | 276 | sopiamodule_end();
|
---|
[2155] | 277 | skymapmodule_end();
|
---|
[1506] | 278 | fitsbtadapter_end();
|
---|
[1524] | 279 | W2PSModule_end();
|
---|
[1506] | 280 |
|
---|
[722] | 281 | delete app;
|
---|
[1440] | 282 | if (fgtmp) delete[] vcmds;
|
---|
[722] | 283 |
|
---|
[2105] | 284 | vcmd = "rm -rf ";
|
---|
| 285 | vcmd += tmpdir;
|
---|
| 286 | cout << " --piapp: Removing Tmp Directory: " << tmpdir << endl;
|
---|
| 287 | rcc = system(vcmd.c_str());
|
---|
| 288 | if (rcc != 0) {
|
---|
| 289 | cout << " --piapp: Error deleting TmpDir " << vcmd << endl;
|
---|
| 290 | return(9);
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | cout << "------------------------------------------------ \n"
|
---|
[722] | 294 | << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
|
---|
| 295 | << "------------------------------------------------ " << endl;
|
---|
| 296 | return(rc);
|
---|
| 297 | }
|
---|
| 298 |
|
---|