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

Last change on this file since 2945 was 2945, checked in by ansari, 19 years ago

1/ Ajout classe de lecture sur stdin (terminal) avec thread separe pour
piapp - incluant la possibilite d'utilisation de la librairie GNU readline
(fichiers piacmdrdr.cc piacmdrdr.h + fichier makfile specifique makefile_wgrdl

pour compil+link avec GNU readline)

2/ MAJ Makefile et modif programme principal piapp.cc avec flag -small
et activation thread de lecture sur terminal

Reza , 26/04/2006

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