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
|
---|
17 | extern "C" {
|
---|
18 | void sopiamodule_init();
|
---|
19 | void sopiamodule_end();
|
---|
20 | void fitsbtadapter_init();
|
---|
21 | void fitsbtadapter_end();
|
---|
22 | }
|
---|
23 |
|
---|
24 | /*!
|
---|
25 | \defgroup ProgPI ProgPI module
|
---|
26 | This module contains programs for interactive data analysis and
|
---|
27 | visualisation, based on SOPHYA class libray and PI (GUI framework)
|
---|
28 | and PIext (Interactive data analysis framework).
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*!
|
---|
32 | \ingroup ProgPI
|
---|
33 | \file piapp.cc
|
---|
34 | \brief \b (s)piapp: Starts the piapp interactive data analysis program.
|
---|
35 |
|
---|
36 | The current version of the program has a single execution thread. This
|
---|
37 | creates few limitations (GUI can not be used when computing is being
|
---|
38 | done, ...). Also the command file executed during start-up (-exec)
|
---|
39 | cannot contain display (graphic) commands.
|
---|
40 |
|
---|
41 | \verbatim
|
---|
42 | csh> spiapp -h
|
---|
43 | SOPHYA Version 1.1 Revision 0 (V_Fev2001) -- Mar 9 2001 15:45:31 cxx
|
---|
44 |
|
---|
45 | piapp: Interactive data analysis and visualisation program
|
---|
46 | Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv]
|
---|
47 | [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
|
---|
48 | -nored : NoRedirect StdOut/StdErr
|
---|
49 | -nosig : Don't catch SigFPE, SigSEGV
|
---|
50 | -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
|
---|
51 | -tmpdir TmpDirectory: defines TMDIR for temporary files
|
---|
52 | -help2tex: Create a LaTeX help file (piahelp.tex)
|
---|
53 | -exec file [args] : Execute command file
|
---|
54 |
|
---|
55 | \endverbatim
|
---|
56 |
|
---|
57 | */
|
---|
58 |
|
---|
59 | void Usage(bool fgerr)
|
---|
60 | {
|
---|
61 | if (fgerr) {
|
---|
62 | cout << " piapp : Argument Error ! piapp -h for Usage" << endl;
|
---|
63 | exit(1);
|
---|
64 | }
|
---|
65 | else {
|
---|
66 | cout << "\n piapp: Interactive data analysis and visualisation program \n"
|
---|
67 | << " Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] \n"
|
---|
68 | << " [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]] \n"
|
---|
69 | << " -nored : NoRedirect StdOut/StdErr \n"
|
---|
70 | << " -nosig : Don't catch SigFPE, SigSEGV \n"
|
---|
71 | << " -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV \n"
|
---|
72 | << " -tmpdir TmpDirectory: defines TMDIR for temporary files \n"
|
---|
73 | << " -help2tex: Create a LaTeX help file (piahelp.tex)\n"
|
---|
74 | << " -exec file [args] : Execute command file \n"
|
---|
75 | << endl;
|
---|
76 | exit(0);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | /* ================================ MAIN() ================================= */
|
---|
81 |
|
---|
82 | int main(int narg, char *arg[])
|
---|
83 | {
|
---|
84 | int ofa;
|
---|
85 | int fgfpe, fgsegv, fgred, fgexec;
|
---|
86 |
|
---|
87 | SkyTInitiator skyinit;
|
---|
88 |
|
---|
89 | InitTim();
|
---|
90 |
|
---|
91 |
|
---|
92 | if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
93 |
|
---|
94 | ofa = 1;
|
---|
95 | fgred = fgfpe = fgsegv = true;
|
---|
96 | fgexec = false;
|
---|
97 | bool fgtmp = false;
|
---|
98 | string tmpdir;
|
---|
99 | string exfc;
|
---|
100 | // Pour fabriquer le help
|
---|
101 | bool fgtexh = false;
|
---|
102 | int ka;
|
---|
103 | for(ka=1; ka<narg; ka++) {
|
---|
104 | if (strcmp(arg[ka],"-nored") == 0) fgred=false;
|
---|
105 | else if (strcmp(arg[ka],"-nosig") == 0) fgfpe=fgsegv=false;
|
---|
106 | else if (strcmp(arg[ka],"-nosigfpe") == 0) fgfpe=false;
|
---|
107 | else if (strcmp(arg[ka],"-nosigsegv") == 0) fgsegv=false;
|
---|
108 | else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
|
---|
109 | else if (strcmp(arg[ka],"-tmpdir") == 0) {
|
---|
110 | if (ka == narg-1) Usage(true);
|
---|
111 | fgtmp = true; ka++;
|
---|
112 | tmpdir = arg[ka];
|
---|
113 | }
|
---|
114 | else if (strcmp(arg[ka],"-exec") == 0) {
|
---|
115 | if (ka < narg-1) {
|
---|
116 | fgexec = true;
|
---|
117 | exfc = "exec";
|
---|
118 | for(int kaa=ka+1; kaa<narg; kaa++) { exfc += ' '; exfc += arg[kaa]; }
|
---|
119 | }
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
|
---|
126 | else printf(">>>>> Starting piapp <<<<< \n");
|
---|
127 | printf("Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
|
---|
128 | (double)PI_VERSIONNUMBER, (double)skyinit.Version());
|
---|
129 |
|
---|
130 | char *vcmds;
|
---|
131 | if (fgtmp) {
|
---|
132 | if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/'; // Necessaire pour SetSwapPath
|
---|
133 | string vcmd = "TMPDIR=" + tmpdir;
|
---|
134 | vcmds = new char[vcmd.length()+1];
|
---|
135 | strcpy(vcmds, vcmd.c_str());
|
---|
136 | putenv(vcmds);
|
---|
137 | }
|
---|
138 |
|
---|
139 | // cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
|
---|
140 |
|
---|
141 | PIStdImgApp * app = new PIStdImgApp(narg, arg);
|
---|
142 | // cout << " DBG-2 " << app->ObjMgr()->GetTmpDir() << endl;
|
---|
143 | if (fgtmp) { // Changement de tmpdir
|
---|
144 | cout << " NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
|
---|
145 | app->ObjMgr()->SetTmpDir(tmpdir);
|
---|
146 | XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | // Gestion de redirection stdout/err et Signaux
|
---|
151 | if (fgred) app->RedirectStdOutErr(true);
|
---|
152 | else app->RedirectStdOutErr(false);
|
---|
153 | app->CatchSignals(fgfpe, fgsegv);
|
---|
154 |
|
---|
155 | // S'il y a un fichier de commande a executer
|
---|
156 | if (fgexec) app->CmdInterpreter()->Interpret(exfc);
|
---|
157 |
|
---|
158 | // On charge le module sopiamodule
|
---|
159 | sopiamodule_init();
|
---|
160 | // On charge le module de lecture ligne a ligne des Fits BINARY/ASCII tables
|
---|
161 | fitsbtadapter_init();
|
---|
162 |
|
---|
163 | // S'il y a besoin de faire le fichier Help
|
---|
164 | if (fgtexh) {
|
---|
165 | string thf = "piahelp.tex";
|
---|
166 | app->CmdInterpreter()->HelptoLaTex(thf);
|
---|
167 | printf("piapp : Help file piahelp.tex created --> exit(0) \n");
|
---|
168 | delete app;
|
---|
169 | exit(0);
|
---|
170 | }
|
---|
171 |
|
---|
172 | int rc = 0;
|
---|
173 | bool cont = true;
|
---|
174 | char ans[32],rep;
|
---|
175 | int excnt = 0;
|
---|
176 | while(cont) {
|
---|
177 | rc = 0; cont = false;
|
---|
178 | app->SetReady();
|
---|
179 | if (fgred) app->RedirectStdOutErr(true);
|
---|
180 | try {
|
---|
181 | app->Run();
|
---|
182 | }
|
---|
183 | catch(PThrowable exc) { // Catching SOPHYA exceptions
|
---|
184 | app->Stop();
|
---|
185 | app->RedirectStdOutErr(false);
|
---|
186 | //BUG ? fait planter OSF-cxx fflush(stdout);
|
---|
187 | cout << endl; cerr << endl;
|
---|
188 | cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl;
|
---|
189 | cout << ++excnt << "- continue <CR>, Close Windows, "
|
---|
190 | << " continue C<CR> Stop program S<CR> ? " << endl;
|
---|
191 | gets(ans);
|
---|
192 | rep = toupper(ans[0]);
|
---|
193 | if (rep == 'S') {
|
---|
194 | cout << " !!!! Stopping piapp !!!! " << endl;
|
---|
195 | rc = 78;
|
---|
196 | cont = false;
|
---|
197 | }
|
---|
198 | else {
|
---|
199 | if (rep == 'C') {
|
---|
200 | cout << "piapp/main() Closing all windows ... " << endl;
|
---|
201 | app->CloseAllWindows();
|
---|
202 | }
|
---|
203 | cout << " *** piapp - Continuing event loop *** " << endl;
|
---|
204 | cont = true;
|
---|
205 | }
|
---|
206 | }
|
---|
207 | catch(...) { // Catching all other exceptions
|
---|
208 | app->Stop();
|
---|
209 | app->RedirectStdOutErr(false);
|
---|
210 | cout << endl; cerr << endl;
|
---|
211 | cout << "\n piapp/main() exception catched ! " << endl;
|
---|
212 | cout << ++excnt << "- continue <CR>, Close Windows, "
|
---|
213 | << " continue C<CR> Stop program S<CR> ? " << endl;
|
---|
214 | gets(ans);
|
---|
215 | rep = toupper(ans[0]);
|
---|
216 | if (rep == 'S') {
|
---|
217 | cout << " !!!! Stopping piapp !!!! " << endl;
|
---|
218 | rc = 78;
|
---|
219 | cont = false;
|
---|
220 | }
|
---|
221 | else {
|
---|
222 | if (rep == 'C') {
|
---|
223 | cout << "piapp/main() Closing all windows ... " << endl;
|
---|
224 | app->CloseAllWindows();
|
---|
225 | }
|
---|
226 | cout << " *** piapp - Continuing event loop *** " << endl;
|
---|
227 | cont = true;
|
---|
228 | }
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | app->RedirectStdOutErr(false);
|
---|
233 | // On de-charge le module sopiamodule et fitsbtadapter
|
---|
234 | sopiamodule_end();
|
---|
235 | fitsbtadapter_end();
|
---|
236 |
|
---|
237 | delete app;
|
---|
238 | if (fgtmp) delete[] vcmds;
|
---|
239 |
|
---|
240 | cout << "\n------------------------------------------------ \n"
|
---|
241 | << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
|
---|
242 | << "------------------------------------------------ " << endl;
|
---|
243 | return(rc);
|
---|
244 | }
|
---|
245 |
|
---|