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