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

Last change on this file since 2093 was 2093, checked in by cmv, 23 years ago

gets()->getchar() + gestion wranings cmv 15/7/02

File size: 7.4 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] [-hidezswin] \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 << " -hidezswin : Hide Zoom/Stat/ColMap window \n"
75 << " -tmpdir TmpDirectory: defines TMDIR for temporary files \n"
76 << " -help2tex: Create a LaTeX help file (piahelp.tex)\n"
77 << " -exec file [args] : Execute command file \n"
78 << endl;
79 exit(0);
80 }
81}
82
83/* ================================ MAIN() ================================= */
84
85int main(int narg, char *arg[])
86{
87int ofa;
88bool fgfpe, fgsegv, fgred, fghidezsw, fgexec;
89
90SkyTInitiator skyinit;
91
92InitTim();
93
94
95if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
96
97ofa = 1;
98fgred = fgfpe = fgsegv = true;
99fghidezsw = false;
100fgexec = false;
101bool fgtmp = false;
102string tmpdir;
103string exfc;
104// Pour fabriquer le help
105bool fgtexh = false;
106int ka;
107for(ka=1; ka<narg; ka++) {
108 if (strcmp(arg[ka],"-nored") == 0) fgred=false;
109 else if (strcmp(arg[ka],"-nosig") == 0) fgfpe=fgsegv=false;
110 else if (strcmp(arg[ka],"-nosigfpe") == 0) fgfpe=false;
111 else if (strcmp(arg[ka],"-nosigsegv") == 0) fgsegv=false;
112 else if (strcmp(arg[ka],"-hidezswin") == 0) fghidezsw=true;
113 else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
114 else if (strcmp(arg[ka],"-tmpdir") == 0) {
115 if (ka == narg-1) Usage(true);
116 fgtmp = true; ka++;
117 tmpdir = arg[ka];
118 }
119 else if (strcmp(arg[ka],"-exec") == 0) {
120 if (ka < narg-1) {
121 fgexec = true;
122 exfc = "exec";
123 for(int kaa=ka+1; kaa<narg; kaa++) { exfc += ' '; exfc += arg[kaa]; }
124 }
125 break;
126 }
127 }
128
129
130if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
131else printf(">>>>> Starting piapp <<<<< \n");
132printf("Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
133 (double)PI_VERSIONNUMBER, (double)skyinit.Version());
134
135char *vcmds=NULL;
136if (fgtmp) {
137 if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/'; // Necessaire pour SetSwapPath
138 string vcmd = "TMPDIR=" + tmpdir;
139 vcmds = new char[vcmd.length()+1];
140 strcpy(vcmds, vcmd.c_str());
141 putenv(vcmds);
142}
143
144// cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
145
146PIStdImgApp * app = new PIStdImgApp(narg, arg);
147// cout << " DBG-2 " << app->ObjMgr()->GetTmpDir() << endl;
148if (fgtmp) { // Changement de tmpdir
149 cout << " NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
150 app->ObjMgr()->SetTmpDir(tmpdir);
151 XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
152}
153
154
155// Gestion de redirection stdout/err et Signaux
156if (fgred) app->RedirectStdOutErr(true);
157else app->RedirectStdOutErr(false);
158app->CatchSignals(fgfpe, fgsegv);
159
160// if Hide Zoom/Stat Win
161if (fghidezsw) app->StatZoomWindowSetVisible(false);
162
163// S'il y a un fichier de commande a executer
164if (fgexec) app->CmdInterpreter()->Interpret(exfc);
165
166// On charge le module sopiamodule
167sopiamodule_init();
168// On charge le module de lecture ligne a ligne des Fits BINARY/ASCII tables
169fitsbtadapter_init();
170// On charge le module des commandes de creation de fichier postscript
171W2PSModule_init();
172
173// S'il y a besoin de faire le fichier Help
174if (fgtexh) {
175 string thf = "piahelp.tex";
176 app->CmdInterpreter()->HelptoLaTex(thf);
177 printf("piapp : Help file piahelp.tex created --> exit(0) \n");
178 delete app;
179 exit(0);
180}
181
182int rc = 0;
183bool cont = true;
184char rep; // ans[32]
185int excnt = 0;
186while(cont) {
187 rc = 0; cont = false;
188 app->SetReady();
189 if (fgred) app->RedirectStdOutErr(true);
190 try {
191 app->Run();
192 }
193 catch(PThrowable exc) { // Catching SOPHYA exceptions
194 app->Stop();
195 app->RedirectStdOutErr(false);
196 //BUG ? fait planter OSF-cxx fflush(stdout);
197 cout << endl; cerr << endl;
198 cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl;
199 cout << ++excnt << "- continue <CR>, Close Windows, "
200 << " continue C<CR> Stop program S<CR> ? " << endl;
201 rep = getchar(); // was: gets(ans);
202 rep = toupper(rep);
203 if (rep == 'S') {
204 cout << " !!!! Stopping piapp !!!! " << endl;
205 rc = 78;
206 cont = false;
207 }
208 else {
209 if (rep == 'C') {
210 cout << "piapp/main() Closing all windows ... " << endl;
211 app->CloseAllWindows();
212 }
213 cout << " *** piapp - Continuing event loop *** " << endl;
214 cont = true;
215 }
216 }
217 catch(...) { // Catching all other exceptions
218 app->Stop();
219 app->RedirectStdOutErr(false);
220 cout << endl; cerr << endl;
221 cout << "\n piapp/main() exception catched ! " << endl;
222 cout << ++excnt << "- continue <CR>, Close Windows, "
223 << " continue C<CR> Stop program S<CR> ? " << endl;
224 rep = getchar(); // gets(ans);
225 rep = toupper(rep);
226 if (rep == 'S') {
227 cout << " !!!! Stopping piapp !!!! " << endl;
228 rc = 78;
229 cont = false;
230 }
231 else {
232 if (rep == 'C') {
233 cout << "piapp/main() Closing all windows ... " << endl;
234 app->CloseAllWindows();
235 }
236 cout << " *** piapp - Continuing event loop *** " << endl;
237 cont = true;
238 }
239 }
240}
241
242app->RedirectStdOutErr(false);
243// On de-charge le module sopiamodule et fitsbtadapter
244sopiamodule_end();
245fitsbtadapter_end();
246W2PSModule_end();
247
248delete app;
249if (fgtmp) delete[] vcmds;
250
251cout << "\n------------------------------------------------ \n"
252 << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
253 << "------------------------------------------------ " << endl;
254return(rc);
255}
256
Note: See TracBrowser for help on using the repository browser.