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