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

Last change on this file since 1451 was 1440, checked in by ansari, 25 years ago

documentation piapp.cc pour doxygen - Reza 14/3/2001

File size: 6.7 KB
Line 
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
13#include "xntuple.h" // Pour faire le SetTmpDir()
14
15
16// ---- Pour charger automatiquement le module sopiamodule
17extern "C" {
18void sopiamodule_init();
19void sopiamodule_end();
20}
21
22/*!
23 \defgroup ProgPI ProgPI module
24 This module contains programs for interactive data analysis and
25 visualisation, based on SOPHYA class libray and PI (GUI framework)
26 and PIext (Interactive data analysis framework).
27*/
28
29/*!
30 \ingroup ProgPI
31 \file piapp.cc
32 \brief \b (s)piapp: Starts the piapp interactive data analysis program.
33
34 The current version of the program has a single execution thread. This
35 creates few limitations (GUI can not be used when computing is being
36 done, ...). Also the command file executed during start-up (-exec)
37 cannot contain display (graphic) commands.
38
39 \verbatim
40 csh> spiapp -h
41 SOPHYA Version 1.1 Revision 0 (V_Fev2001) -- Mar 9 2001 15:45:31 cxx
42
43 piapp: Interactive data analysis and visualisation program
44 Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv]
45 [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
46 -nored : NoRedirect StdOut/StdErr
47 -nosig : Don't catch SigFPE, SigSEGV
48 -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
49 -tmpdir TmpDirectory: defines TMDIR for temporary files
50 -help2tex: Create a LaTeX help file (piahelp.tex)
51 -exec file [args] : Execute command file
52
53 \endverbatim
54
55*/
56
57void Usage(bool fgerr)
58{
59 if (fgerr) {
60 cout << " piapp : Argument Error ! piapp -h for Usage" << endl;
61 exit(1);
62 }
63 else {
64 cout << "\n piapp: Interactive data analysis and visualisation program \n"
65 << " Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] \n"
66 << " [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]] \n"
67 << " -nored : NoRedirect StdOut/StdErr \n"
68 << " -nosig : Don't catch SigFPE, SigSEGV \n"
69 << " -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV \n"
70 << " -tmpdir TmpDirectory: defines TMDIR for temporary files \n"
71 << " -help2tex: Create a LaTeX help file (piahelp.tex)\n"
72 << " -exec file [args] : Execute command file \n"
73 << endl;
74 exit(0);
75 }
76}
77
78/* ================================ MAIN() ================================= */
79
80int main(int narg, char *arg[])
81{
82int ofa;
83int fgfpe, fgsegv, fgred, fgexec;
84
85SkyTInitiator skyinit;
86
87InitTim();
88
89
90if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
91
92ofa = 1;
93fgred = fgfpe = fgsegv = true;
94fgexec = false;
95bool fgtmp = false;
96string tmpdir;
97string exfc;
98// Pour fabriquer le help
99bool fgtexh = false;
100int ka;
101for(ka=1; ka<narg; ka++) {
102 if (strcmp(arg[ka],"-nored") == 0) fgred=false;
103 else if (strcmp(arg[ka],"-nosig") == 0) fgfpe=fgsegv=false;
104 else if (strcmp(arg[ka],"-nosigfpe") == 0) fgfpe=false;
105 else if (strcmp(arg[ka],"-nosigsegv") == 0) fgsegv=false;
106 else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
107 else if (strcmp(arg[ka],"-tmpdir") == 0) {
108 if (ka == narg-1) Usage(true);
109 fgtmp = true; ka++;
110 tmpdir = arg[ka];
111 }
112 else if (strcmp(arg[ka],"-exec") == 0) {
113 if (ka < narg-1) {
114 fgexec = true;
115 exfc = "exec";
116 for(int kaa=ka+1; kaa<narg; kaa++) { exfc += ' '; exfc += arg[kaa]; }
117 }
118 break;
119 }
120 }
121
122
123if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
124else printf(">>>>> Starting piapp <<<<< \n");
125printf("Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
126 (double)PI_VERSIONNUMBER, (double)skyinit.Version());
127
128char *vcmds;
129if (fgtmp) {
130 if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/'; // Necessaire pour SetSwapPath
131 string vcmd = "TMPDIR=" + tmpdir;
132 vcmds = new char[vcmd.length()+1];
133 strcpy(vcmds, vcmd.c_str());
134 putenv(vcmds);
135}
136
137// cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
138
139PIStdImgApp * app = new PIStdImgApp(narg, arg);
140// cout << " DBG-2 " << app->ObjMgr()->GetTmpDir() << endl;
141if (fgtmp) { // Changement de tmpdir
142 cout << " NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
143 app->ObjMgr()->SetTmpDir(tmpdir);
144 XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
145}
146
147
148// Gestion de redirection stdout/err et Signaux
149if (fgred) app->RedirectStdOutErr(true);
150else app->RedirectStdOutErr(false);
151app->CatchSignals(fgfpe, fgsegv);
152
153// S'il y a un fichier de commande a executer
154if (fgexec) app->CmdInterpreter()->Interpret(exfc);
155
156// On charge le module sopiamodule
157sopiamodule_init();
158
159// S'il y a besoin de faire le fichier Help
160if (fgtexh) {
161 string thf = "piahelp.tex";
162 app->CmdInterpreter()->HelptoLaTex(thf);
163 printf("piapp : Help file piahelp.tex created --> exit(0) \n");
164 delete app;
165 exit(0);
166}
167
168int rc = 0;
169bool cont = true;
170char ans[32],rep;
171int excnt = 0;
172while(cont) {
173 rc = 0; cont = false;
174 app->SetReady();
175 if (fgred) app->RedirectStdOutErr(true);
176 try {
177 app->Run();
178 }
179 catch(PThrowable exc) { // Catching SOPHYA exceptions
180 app->Stop();
181 app->RedirectStdOutErr(false);
182 //BUG ? fait planter OSF-cxx fflush(stdout);
183 cout << endl; cerr << endl;
184 cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl;
185 cout << ++excnt << "- continue <CR>, Close Windows, "
186 << " continue C<CR> Stop program S<CR> ? " << endl;
187 gets(ans);
188 rep = toupper(ans[0]);
189 if (rep == 'S') {
190 cout << " !!!! Stopping piapp !!!! " << endl;
191 rc = 78;
192 cont = false;
193 }
194 else {
195 if (rep == 'C') {
196 cout << "piapp/main() Closing all windows ... " << endl;
197 app->CloseAllWindows();
198 }
199 cout << " *** piapp - Continuing event loop *** " << endl;
200 cont = true;
201 }
202 }
203 catch(...) { // Catching all other exceptions
204 app->Stop();
205 app->RedirectStdOutErr(false);
206 cout << endl; cerr << endl;
207 cout << "\n piapp/main() exception catched ! " << endl;
208 cout << ++excnt << "- continue <CR>, Close Windows, "
209 << " continue C<CR> Stop program S<CR> ? " << endl;
210 gets(ans);
211 rep = toupper(ans[0]);
212 if (rep == 'S') {
213 cout << " !!!! Stopping piapp !!!! " << endl;
214 rc = 78;
215 cont = false;
216 }
217 else {
218 if (rep == 'C') {
219 cout << "piapp/main() Closing all windows ... " << endl;
220 app->CloseAllWindows();
221 }
222 cout << " *** piapp - Continuing event loop *** " << endl;
223 cont = true;
224 }
225 }
226}
227
228app->RedirectStdOutErr(false);
229// On de-charge le module sopiamodule
230sopiamodule_end();
231delete app;
232if (fgtmp) delete[] vcmds;
233
234cout << "\n------------------------------------------------ \n"
235 << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
236 << "------------------------------------------------ " << endl;
237return(rc);
238}
239
Note: See TracBrowser for help on using the repository browser.