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