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

Last change on this file since 1524 was 1524, checked in by ansari, 24 years ago

Ajout du module W2PSModule, MAJ Makefile , Reza 13/6/2001

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