source: Sophya/trunk/SophyaPI/ProgPI/piapp.cc@ 3551

Last change on this file since 3551 was 3410, checked in by ansari, 18 years ago

Correction Usage() -h + commentaires doxygen - Reza 26/11/2007

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