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