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

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

module skymap cmv 4/8/2002

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