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

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

Creation Tmpdir pour piapp par mktemp - Reza 17/7/2002

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