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

Last change on this file since 2735 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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