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