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