[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();
|
---|
[2155] | 21 | void skymapmodule_init();
|
---|
| 22 | void skymapmodule_end();
|
---|
[1506] | 23 | void fitsbtadapter_init();
|
---|
| 24 | void fitsbtadapter_end();
|
---|
[1524] | 25 | void W2PSModule_init();
|
---|
| 26 | void W2PSModule_end();
|
---|
[722] | 27 | }
|
---|
| 28 |
|
---|
[1440] | 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 | */
|
---|
[722] | 35 |
|
---|
[1440] | 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
|
---|
[2105] | 48 | SOPHYA Version 1.3 Revision 70 (V_Jun2002) -- Jul 16 2002 15:45:53 cxx
|
---|
[1440] | 49 |
|
---|
[2105] | 50 | piapp: Interactive data analysis and visualisation program
|
---|
| 51 | Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin]
|
---|
| 52 | [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
|
---|
[1440] | 53 | -nored : NoRedirect StdOut/StdErr
|
---|
| 54 | -nosig : Don't catch SigFPE, SigSEGV
|
---|
| 55 | -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
|
---|
[2105] | 56 | -hidezswin : Hide Zoom/Stat/ColMap window
|
---|
[1440] | 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"
|
---|
[1972] | 73 | << " Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin] \n"
|
---|
[1440] | 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"
|
---|
[1972] | 78 | << " -hidezswin : Hide Zoom/Stat/ColMap window \n"
|
---|
[1440] | 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 |
|
---|
[722] | 87 | /* ================================ MAIN() ================================= */
|
---|
| 88 |
|
---|
| 89 | int main(int narg, char *arg[])
|
---|
| 90 | {
|
---|
| 91 | int ofa;
|
---|
[1972] | 92 | bool fgfpe, fgsegv, fgred, fghidezsw, fgexec;
|
---|
[722] | 93 |
|
---|
| 94 | SkyTInitiator skyinit;
|
---|
| 95 |
|
---|
| 96 | InitTim();
|
---|
| 97 |
|
---|
| 98 |
|
---|
[1440] | 99 | if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
| 100 |
|
---|
[722] | 101 | ofa = 1;
|
---|
| 102 | fgred = fgfpe = fgsegv = true;
|
---|
[1972] | 103 | fghidezsw = false;
|
---|
[722] | 104 | fgexec = false;
|
---|
[1440] | 105 | bool fgtmp = false;
|
---|
| 106 | string tmpdir;
|
---|
[722] | 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;
|
---|
[1972] | 116 | else if (strcmp(arg[ka],"-hidezswin") == 0) fghidezsw=true;
|
---|
[722] | 117 | else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
|
---|
[1440] | 118 | else if (strcmp(arg[ka],"-tmpdir") == 0) {
|
---|
| 119 | if (ka == narg-1) Usage(true);
|
---|
| 120 | fgtmp = true; ka++;
|
---|
| 121 | tmpdir = arg[ka];
|
---|
| 122 | }
|
---|
[722] | 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 |
|
---|
[1440] | 133 |
|
---|
[722] | 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 |
|
---|
[2105] | 139 | char* vcmds=NULL;
|
---|
| 140 | string vcmd;
|
---|
[1440] | 141 | if (fgtmp) {
|
---|
| 142 | if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/'; // Necessaire pour SetSwapPath
|
---|
[2105] | 143 | vcmd = "TMPDIR=" + tmpdir;
|
---|
[1440] | 144 | vcmds = new char[vcmd.length()+1];
|
---|
| 145 | strcpy(vcmds, vcmd.c_str());
|
---|
| 146 | putenv(vcmds);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[2105] | 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
|
---|
[1440] | 171 | // cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
|
---|
| 172 |
|
---|
[722] | 173 | PIStdImgApp * app = new PIStdImgApp(narg, arg);
|
---|
[1440] | 174 | // cout << " DBG-2 " << app->ObjMgr()->GetTmpDir() << endl;
|
---|
[2105] | 175 | cout << " NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
|
---|
| 176 | app->ObjMgr()->SetTmpDir(tmpdir);
|
---|
| 177 | XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
|
---|
[722] | 178 |
|
---|
[1440] | 179 |
|
---|
[2105] | 180 |
|
---|
[722] | 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 |
|
---|
[1972] | 186 | // if Hide Zoom/Stat Win
|
---|
| 187 | if (fghidezsw) app->StatZoomWindowSetVisible(false);
|
---|
| 188 |
|
---|
[722] | 189 | // S'il y a un fichier de commande a executer
|
---|
[2189] | 190 | // if (fgexec) app->CmdInterpreter()->Interpret(exfc);
|
---|
| 191 | if (fgexec) app->SubmitCommand(exfc);
|
---|
[722] | 192 |
|
---|
| 193 | // On charge le module sopiamodule
|
---|
| 194 | sopiamodule_init();
|
---|
[2155] | 195 | // On charge le module skymapmodule
|
---|
| 196 | skymapmodule_init();
|
---|
[1506] | 197 | // On charge le module de lecture ligne a ligne des Fits BINARY/ASCII tables
|
---|
| 198 | fitsbtadapter_init();
|
---|
[1524] | 199 | // On charge le module des commandes de creation de fichier postscript
|
---|
| 200 | W2PSModule_init();
|
---|
[722] | 201 |
|
---|
| 202 | // S'il y a besoin de faire le fichier Help
|
---|
| 203 | if (fgtexh) {
|
---|
| 204 | string thf = "piahelp.tex";
|
---|
[2261] | 205 | app->CmdInterpreter()->HelptoLaTeX(thf);
|
---|
[722] | 206 | printf("piapp : Help file piahelp.tex created --> exit(0) \n");
|
---|
| 207 | delete app;
|
---|
| 208 | exit(0);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | int rc = 0;
|
---|
| 212 | bool cont = true;
|
---|
[2093] | 213 | char rep; // ans[32]
|
---|
[722] | 214 | int excnt = 0;
|
---|
| 215 | while(cont) {
|
---|
| 216 | rc = 0; cont = false;
|
---|
| 217 | app->SetReady();
|
---|
| 218 | if (fgred) app->RedirectStdOutErr(true);
|
---|
| 219 | try {
|
---|
[2093] | 220 | app->Run();
|
---|
| 221 | }
|
---|
[722] | 222 | catch(PThrowable exc) { // Catching SOPHYA exceptions
|
---|
| 223 | app->Stop();
|
---|
| 224 | app->RedirectStdOutErr(false);
|
---|
| 225 | //BUG ? fait planter OSF-cxx fflush(stdout);
|
---|
| 226 | cout << endl; cerr << endl;
|
---|
| 227 | cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl;
|
---|
| 228 | cout << ++excnt << "- continue <CR>, Close Windows, "
|
---|
| 229 | << " continue C<CR> Stop program S<CR> ? " << endl;
|
---|
[2093] | 230 | rep = getchar(); // was: gets(ans);
|
---|
| 231 | rep = toupper(rep);
|
---|
[722] | 232 | if (rep == 'S') {
|
---|
| 233 | cout << " !!!! Stopping piapp !!!! " << endl;
|
---|
| 234 | rc = 78;
|
---|
| 235 | cont = false;
|
---|
| 236 | }
|
---|
| 237 | else {
|
---|
| 238 | if (rep == 'C') {
|
---|
| 239 | cout << "piapp/main() Closing all windows ... " << endl;
|
---|
| 240 | app->CloseAllWindows();
|
---|
| 241 | }
|
---|
| 242 | cout << " *** piapp - Continuing event loop *** " << endl;
|
---|
| 243 | cont = true;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | catch(...) { // Catching all other exceptions
|
---|
| 247 | app->Stop();
|
---|
| 248 | app->RedirectStdOutErr(false);
|
---|
| 249 | cout << endl; cerr << endl;
|
---|
| 250 | cout << "\n piapp/main() exception catched ! " << endl;
|
---|
| 251 | cout << ++excnt << "- continue <CR>, Close Windows, "
|
---|
| 252 | << " continue C<CR> Stop program S<CR> ? " << endl;
|
---|
[2093] | 253 | rep = getchar(); // gets(ans);
|
---|
| 254 | rep = toupper(rep);
|
---|
[722] | 255 | if (rep == 'S') {
|
---|
| 256 | cout << " !!!! Stopping piapp !!!! " << endl;
|
---|
| 257 | rc = 78;
|
---|
| 258 | cont = false;
|
---|
| 259 | }
|
---|
| 260 | else {
|
---|
| 261 | if (rep == 'C') {
|
---|
| 262 | cout << "piapp/main() Closing all windows ... " << endl;
|
---|
| 263 | app->CloseAllWindows();
|
---|
| 264 | }
|
---|
| 265 | cout << " *** piapp - Continuing event loop *** " << endl;
|
---|
| 266 | cont = true;
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
[2105] | 270 | cout << "\n ------------------------------------------------ \n"
|
---|
| 271 | << " piapp: Cleaning up ... " << endl;
|
---|
[722] | 272 |
|
---|
| 273 | app->RedirectStdOutErr(false);
|
---|
[1506] | 274 | // On de-charge le module sopiamodule et fitsbtadapter
|
---|
[722] | 275 | sopiamodule_end();
|
---|
[2155] | 276 | skymapmodule_end();
|
---|
[1506] | 277 | fitsbtadapter_end();
|
---|
[1524] | 278 | W2PSModule_end();
|
---|
[1506] | 279 |
|
---|
[722] | 280 | delete app;
|
---|
[1440] | 281 | if (fgtmp) delete[] vcmds;
|
---|
[722] | 282 |
|
---|
[2105] | 283 | vcmd = "rm -rf ";
|
---|
| 284 | vcmd += tmpdir;
|
---|
| 285 | cout << " --piapp: Removing Tmp Directory: " << tmpdir << endl;
|
---|
| 286 | rcc = system(vcmd.c_str());
|
---|
| 287 | if (rcc != 0) {
|
---|
| 288 | cout << " --piapp: Error deleting TmpDir " << vcmd << endl;
|
---|
| 289 | return(9);
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | cout << "------------------------------------------------ \n"
|
---|
[722] | 293 | << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
|
---|
| 294 | << "------------------------------------------------ " << endl;
|
---|
| 295 | return(rc);
|
---|
| 296 | }
|
---|
| 297 |
|
---|