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

Last change on this file since 1506 was 1506, checked in by cmv, 24 years ago

intro module fitsbtadapter cmv 22/5/01

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