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
|
---|
20 | extern "C" {
|
---|
21 | void sopiamodule_init();
|
---|
22 | void sopiamodule_end();
|
---|
23 | void skymapmodule_init();
|
---|
24 | void skymapmodule_end();
|
---|
25 | void fitsbtadapter_init();
|
---|
26 | void fitsbtadapter_end();
|
---|
27 | void W2PSModule_init();
|
---|
28 | void 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
|
---|
52 | SOPHYA 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 |
|
---|
70 | int 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 |
|
---|
95 | int main(int narg, char *arg[])
|
---|
96 | {
|
---|
97 | int ofa;
|
---|
98 | bool fgfpe, fgsegv, fgred, fghidezsw, fgexec, fgsmall;
|
---|
99 |
|
---|
100 | SkyTInitiator skyinit;
|
---|
101 |
|
---|
102 | InitTim();
|
---|
103 |
|
---|
104 | if(narg>1)
|
---|
105 | for(int jh=1;jh<narg;jh++) if(strcmp(arg[jh],"-h") == 0) return Usage(false);
|
---|
106 |
|
---|
107 | ofa = 1;
|
---|
108 | fgred = fgfpe = fgsegv = true;
|
---|
109 | fghidezsw = false;
|
---|
110 | fgexec = false;
|
---|
111 | bool fgtmp = false;
|
---|
112 | fgsmall = false;
|
---|
113 | string tmpdir;
|
---|
114 | string exfc;
|
---|
115 | // Pour fabriquer le help
|
---|
116 | bool fgtexh = false;
|
---|
117 | int ka;
|
---|
118 | for(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 |
|
---|
142 | if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
|
---|
143 | else printf(">>>>> Starting piapp <<<<< \n");
|
---|
144 | printf("Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
|
---|
145 | (double)PI_VERSIONNUMBER, (double)skyinit.Version());
|
---|
146 |
|
---|
147 | char* vcmds=NULL;
|
---|
148 | string vcmd;
|
---|
149 | if (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 |
|
---|
157 | char* tmpde = getenv("TMPDIR");
|
---|
158 | char tmpdname[32];
|
---|
159 | if (tmpde == NULL) tmpde = "./";
|
---|
160 | if (tmpde[strlen(tmpde)-1] != '/')
|
---|
161 | strcpy(tmpdname, "/PIATmp_XXXXXX");
|
---|
162 | else
|
---|
163 | strcpy(tmpdname, "PIATmp_XXXXXX");
|
---|
164 | mktemp(tmpdname);
|
---|
165 | tmpdir = tmpde;
|
---|
166 | tmpdir += tmpdname;
|
---|
167 | tmpdir += '/';
|
---|
168 | vcmd = "mkdir ";
|
---|
169 | vcmd += tmpde;
|
---|
170 | vcmd += tmpdname;
|
---|
171 | cout << " --piapp: Creating Tmp Directory: " << tmpdir << endl;
|
---|
172 | int rcc = system(vcmd.c_str());
|
---|
173 | if (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 |
|
---|
181 | PIStdImgApp * app = new PIStdImgApp(fgsmall, narg, arg);
|
---|
182 | // cout << " DBG-2 " << app->ObjMgr()->GetTmpDir() << endl;
|
---|
183 | cout << " NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
|
---|
184 | app->ObjMgr()->SetTmpDir(tmpdir);
|
---|
185 | XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
|
---|
186 |
|
---|
187 |
|
---|
188 |
|
---|
189 | // Gestion de redirection stdout/err et Signaux
|
---|
190 | if (fgred) app->RedirectStdOutErr(true);
|
---|
191 | else app->RedirectStdOutErr(false);
|
---|
192 | app->CatchSignals(fgfpe, fgsegv);
|
---|
193 |
|
---|
194 | // if Hide Zoom/Stat Win
|
---|
195 | if (fghidezsw) app->StatZoomWindowSetVisible(false);
|
---|
196 |
|
---|
197 | // S'il y a un fichier de commande a executer
|
---|
198 | // if (fgexec) app->CmdInterpreter()->Interpret(exfc);
|
---|
199 | if (fgexec) app->SubmitCommand(exfc);
|
---|
200 |
|
---|
201 | // On charge le module sopiamodule
|
---|
202 | sopiamodule_init();
|
---|
203 | // On charge le module skymapmodule
|
---|
204 | skymapmodule_init();
|
---|
205 | // On charge le module de lecture ligne a ligne des Fits BINARY/ASCII tables
|
---|
206 | fitsbtadapter_init();
|
---|
207 | // On charge le module des commandes de creation de fichier postscript
|
---|
208 | W2PSModule_init();
|
---|
209 |
|
---|
210 | // S'il y a besoin de faire le fichier Help
|
---|
211 | if (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)
|
---|
220 | PIACmdReader cmdrdr(app);
|
---|
221 | cmdrdr.start();
|
---|
222 |
|
---|
223 | int rc = 0;
|
---|
224 | bool cont = true;
|
---|
225 | char rep; // ans[32]
|
---|
226 | int excnt = 0;
|
---|
227 | while(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 | }
|
---|
282 | cout << "\n ------------------------------------------------ \n"
|
---|
283 | << " piapp: Cleaning up ... " << endl;
|
---|
284 |
|
---|
285 | app->RedirectStdOutErr(false);
|
---|
286 | cmdrdr.cancel();
|
---|
287 |
|
---|
288 | // On de-charge le module sopiamodule et fitsbtadapter
|
---|
289 | sopiamodule_end();
|
---|
290 | skymapmodule_end();
|
---|
291 | fitsbtadapter_end();
|
---|
292 | W2PSModule_end();
|
---|
293 |
|
---|
294 | delete app;
|
---|
295 | if (fgtmp) delete[] vcmds;
|
---|
296 |
|
---|
297 | vcmd = "rm -rf ";
|
---|
298 | vcmd += tmpdir;
|
---|
299 | cout << " --piapp: Removing Tmp Directory: " << tmpdir << endl;
|
---|
300 | rcc = system(vcmd.c_str());
|
---|
301 | if (rcc != 0) {
|
---|
302 | cout << " --piapp: Error deleting TmpDir " << vcmd << endl;
|
---|
303 | return(9);
|
---|
304 | }
|
---|
305 |
|
---|
306 | cout << "------------------------------------------------ \n"
|
---|
307 | << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
|
---|
308 | << "------------------------------------------------ " << endl;
|
---|
309 | return(rc);
|
---|
310 | }
|
---|
311 |
|
---|