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

Last change on this file since 2921 was 2810, checked in by ansari, 20 years ago

correction petite erreur sans importance (m4<>m1) , Reza 20/06/2005

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