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

Last change on this file since 2112 was 2112, checked in by ansari, 23 years ago

include unistd.h pour compil sous MacOS-X , Reza 17/7/2002

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