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