1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 |
|
---|
5 | #include <iostream.h>
|
---|
6 | #include <string>
|
---|
7 | #include <vector>
|
---|
8 | #include <map>
|
---|
9 | #if defined(__KCC__)
|
---|
10 | using std::string ;
|
---|
11 | #include <vector.h>
|
---|
12 | #include <map.h>
|
---|
13 | #endif
|
---|
14 |
|
---|
15 | #include "ctimer.h"
|
---|
16 |
|
---|
17 | #include "nobjmgr.h"
|
---|
18 | #include "piacmd.h"
|
---|
19 | #include "pistdimgapp.h"
|
---|
20 |
|
---|
21 | #include "histos.h"
|
---|
22 | #include "histos2.h"
|
---|
23 | #include "hisprof.h"
|
---|
24 | #include "ntuple.h"
|
---|
25 | #include "generaldata.h"
|
---|
26 |
|
---|
27 |
|
---|
28 | // Pour le decoupage des commandes en lignes
|
---|
29 | typedef vector<string> cmdtok;
|
---|
30 |
|
---|
31 | // Fonction pour faire le Fit de PSF sur image
|
---|
32 | static int FitPSFImg(cmdtok& tokens);
|
---|
33 | static int Photom_Ouv(cmdtok& tokens);
|
---|
34 |
|
---|
35 |
|
---|
36 | /* --Methode-- */
|
---|
37 | PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
|
---|
38 | {
|
---|
39 | if (omg) { mOmg= false; mObjMgr = omg; }
|
---|
40 | else { mObjMgr = new NamedObjMgr; mOmg = true; }
|
---|
41 | mImgApp = app;
|
---|
42 | system("cp history.pic hisold.pic");
|
---|
43 | hist.open("history.pic");
|
---|
44 | trace = false; timing = false;
|
---|
45 | gltimer = NULL;
|
---|
46 | dynlink = NULL;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /* --Methode-- */
|
---|
50 | PIACmd::~PIACmd()
|
---|
51 | {
|
---|
52 | if (mOmg) delete mObjMgr;
|
---|
53 | hist.close();
|
---|
54 | if (gltimer) { delete gltimer; gltimer = NULL; }
|
---|
55 | }
|
---|
56 |
|
---|
57 | /* --Methode-- */
|
---|
58 | int PIACmd::Exec(string& file)
|
---|
59 | {
|
---|
60 | char line_buff[512];
|
---|
61 | FILE *fip;
|
---|
62 |
|
---|
63 | if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
|
---|
64 | cerr << "PIACmd::Exec() Error opening file " << file << endl;
|
---|
65 | hist << "##! PIACmd::Exec() Error opening file " << file << endl;
|
---|
66 | return(0);
|
---|
67 | }
|
---|
68 |
|
---|
69 | hist << "### Executing commands from " << file << endl;
|
---|
70 | if (trace) {
|
---|
71 | mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta);
|
---|
72 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
73 | mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta);
|
---|
74 | }
|
---|
75 |
|
---|
76 | while (fgets(line_buff,511,fip) != NULL)
|
---|
77 | {
|
---|
78 | if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta);
|
---|
79 | line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */
|
---|
80 | string line(line_buff);
|
---|
81 | Do(line);
|
---|
82 | }
|
---|
83 | hist << "### End of Exec( " << file << " ) " << endl;
|
---|
84 | if (trace) {
|
---|
85 | mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta);
|
---|
86 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
87 | mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
|
---|
88 | }
|
---|
89 |
|
---|
90 | return(0);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /* --Methode-- */
|
---|
94 | int PIACmd::Do(string& s)
|
---|
95 | {
|
---|
96 |
|
---|
97 | cmdtok tokens;
|
---|
98 | if (s.length() < 1) return(0);
|
---|
99 |
|
---|
100 | hist << s << endl; // On enregistre les commandes
|
---|
101 |
|
---|
102 | if (s[0] == '#') {
|
---|
103 | cout << "PIACmd::Do() Comment-Line:" << s << endl;
|
---|
104 | return(0);
|
---|
105 | }
|
---|
106 | string toks,kw;
|
---|
107 | size_t p = s.find_first_not_of(" ");
|
---|
108 | s = s.substr(p);
|
---|
109 | p = 0;
|
---|
110 | size_t q = s.find_first_of(" ");
|
---|
111 | size_t l = s.length();
|
---|
112 |
|
---|
113 | if (q < l)
|
---|
114 | { kw = s.substr(p,q-p); toks = s.substr(q, l-q); }
|
---|
115 | else { kw = s.substr(p,l-p); toks = ""; }
|
---|
116 |
|
---|
117 | q = 0;
|
---|
118 | while (q < l) {
|
---|
119 | p = toks.find_first_not_of(" ",q+1); // au debut d'un token
|
---|
120 | if (p>=l) break;
|
---|
121 | q = toks.find_first_of(" ",p); // la fin du token;
|
---|
122 | string token = toks.substr(p,q-p);
|
---|
123 | tokens.push_back(token);
|
---|
124 | }
|
---|
125 |
|
---|
126 | for(int k=0; k<tokens.size(); k++) { // On remplace les $varname par la valeur de la variable
|
---|
127 | if ((tokens[k])[0] != '$') continue;
|
---|
128 | CmdVarList::iterator it = mVars.find(tokens[k].substr(1));
|
---|
129 | if (it != mVars.end()) tokens[k] = (*it).second;
|
---|
130 | }
|
---|
131 |
|
---|
132 | // cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl;
|
---|
133 | // for(int ii=0; ii<tokens.size(); ii++)
|
---|
134 | // cout << "arg[ " << ii << " ] : " << tokens[ii] << endl;
|
---|
135 |
|
---|
136 | // >>>>>>>>>>> Commande d'interpreteur
|
---|
137 | if (kw == "help") {
|
---|
138 | cout << "\n PIACmd::Do() ----- Help : Liste des commandes ------------ \n";
|
---|
139 | cout << "help shelp exec set listvars traceon traceoff \n";
|
---|
140 | cout << "timingon timingoff shell \n";
|
---|
141 | cout << "link call zone grwin gratt stacknext \n" ;
|
---|
142 | cout << "openppf saveall listobjs openfits savefits \n";
|
---|
143 | cout << "print rename del delobjs \n";
|
---|
144 | cout << "newh1d newh2d newprof newgfd func func2d \n" ;
|
---|
145 | cout << "disp surf nt2d nt3d gfd2d gfd3d \n" ;
|
---|
146 | cout << "plot2d plot3d projh1d projh2d projprof \n";
|
---|
147 | cout << "fillvec fillnt fillgd1 fillgd2 fft fit fitpsf aper\n";
|
---|
148 | cout << "*** Commande sans args -> liste d'arguments\n";
|
---|
149 | cout << "*** dopt: DisplayOption = next/same/win/stack,color,... \n";
|
---|
150 | cout << "*** $varname remplace par la valeur de la variable varname\n" << endl;
|
---|
151 | }
|
---|
152 |
|
---|
153 | else if (kw == "shelp" ) {
|
---|
154 | cout << "\n PIACmd::Do() ------------- SHelp ------------ " << endl;
|
---|
155 | cout << "exec filename -- set varname string -- clr varname -- listvars \n";
|
---|
156 | cout << "traceon/off -- timingon/off -- shell cmdline\n";
|
---|
157 | cout << "link fnameso f1 [f2 f3] -- call userf [arg1 arg2 ...]\n";
|
---|
158 | cout << "zone nx ny -- newwin nx ny -- gratt attributes_list -- stacknext \n";
|
---|
159 | cout << "openppf file -- saveall file -- listobjs \n";
|
---|
160 | cout << "openfits file -- savefits nomobj file \n";
|
---|
161 | cout << "print nomobj -- rename nomobj nomnew -- del nomobj -- delobjs pattern (*,?) \n";
|
---|
162 | cout << "newh1d nomh xmin xmax nbin -- newh2d nomh xmin xmax nbinx ymin ymax nbiny\n";
|
---|
163 | cout << "newprof nomh xmin xmax nbin [ymin ymax] \n";
|
---|
164 | cout << "newgfd nomgfd nvar nalloc [errx(0/1)]\n";
|
---|
165 | cout << "func expfunc xmin xmax npt opt\n";
|
---|
166 | cout << "func2d expfunc xmin xmax nptx ymin ymax npty opt\n";
|
---|
167 | cout << "disp nomobj opt -- surf nomobj opt\n";
|
---|
168 | cout << "nt2d nomobj varx vary errx erry opt\n";
|
---|
169 | cout << "nt3d nomobj varx vary varz errx erry errz dopt\n";
|
---|
170 | cout << "gfd2d nomobj numvarx erreur=(x y xy) opt\n";
|
---|
171 | cout << "gfd3d nomobj numvarx numvary erreur=(x y z xy xz yz xyz) opt\n";
|
---|
172 | cout << "plot2d nomobj expx expy [experrx experry] expcut dopt\n";
|
---|
173 | cout << "plot3d nomobj expx expy expz expcut dopt\n";
|
---|
174 | cout << "projh1d nomobj expx expwt expcut nomh1 dopt\n";
|
---|
175 | cout << "projh2d nomobj expx expy expwt expcut nomh2 dopt\n";
|
---|
176 | cout << "projprof nomobj expx expy expwt expcut nomprof dopt\n";
|
---|
177 | cout << "fillnt nomobj expx expy expz expt expcut nomnt dopt\n";
|
---|
178 | cout << "fillvec nomobj expx expcut nomvec dopt\n";
|
---|
179 | cout << "fillgd1 nomobj expx expy experry expcut nomgfd\n";
|
---|
180 | cout << "fillgd2 nomobj expx expy expz experrz expcut nomgfd\n";
|
---|
181 | cout << "fft nomobj dopt\n";
|
---|
182 | cout << "fit nomobj func [p:p1,.,pn s:s1,.,sn m:m1,.,mn M:M1,.,Mn I:i1,i2 o:... o:...]\n";
|
---|
183 | cout << "fitpsf psf_typ [options_fit]\n";
|
---|
184 | cout << "aper fond_typ [options_calcul]\n";
|
---|
185 | }
|
---|
186 |
|
---|
187 | else if (kw == "set") {
|
---|
188 | if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: set varname string" << endl; return(0); }
|
---|
189 | mVars[tokens[0]] = tokens[1];
|
---|
190 | }
|
---|
191 | else if (kw == "clr") {
|
---|
192 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: clr varname" << endl; return(0); }
|
---|
193 | CmdVarList::iterator it = mVars.find(tokens[0]);
|
---|
194 | if (it != mVars.end()) mVars.erase(it);
|
---|
195 | else cerr << "PIACmd::Do() Pas de variable de nom " << tokens[0] << endl;
|
---|
196 | }
|
---|
197 | else if (kw == "listvars") {
|
---|
198 | cout << "PIACmd::Do() Variable List , VarName = Value \n";
|
---|
199 | CmdVarList::iterator it;
|
---|
200 | for(it = mVars.begin(); it != mVars.end(); it++)
|
---|
201 | cout << (*it).first << " = " << (*it).second << "\n";
|
---|
202 | cout << endl;
|
---|
203 | }
|
---|
204 | else if (kw == "traceon") { cout << "PIACmd::Do() -> Trace ON mode " << endl; trace = true; }
|
---|
205 | else if (kw == "traceoff") { cout << "PIACmd::Do() -> Trace OFF mode " << endl; trace = false; }
|
---|
206 | else if (kw == "timingon") {
|
---|
207 | cout << "PIACmd::Do() -> Timing ON mode " << endl;
|
---|
208 | if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true; }
|
---|
209 | else if (kw == "timingoff") {
|
---|
210 | cout << "PIACmd::Do() -> Timing OFF mode " << endl;
|
---|
211 | if (gltimer) delete gltimer; gltimer = NULL; timing = false; }
|
---|
212 | else if (kw == "exec") {
|
---|
213 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: exec filename" << endl; return(0); }
|
---|
214 | Exec(tokens[0]);
|
---|
215 | }
|
---|
216 | else if (kw == "shell") {
|
---|
217 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: shell cmdline" << endl; return(0); }
|
---|
218 | system(toks.c_str());
|
---|
219 | }
|
---|
220 |
|
---|
221 | // >>>>>>>>>>> Fenetre graphique , changement d'attributs graphiques
|
---|
222 | else if (kw == "zone") {
|
---|
223 | if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: zone nx ny" << endl; return(0); }
|
---|
224 | int nx, ny;
|
---|
225 | nx = ny = 1;
|
---|
226 | nx = atoi(tokens[0].c_str()); ny = atoi(tokens[1].c_str());
|
---|
227 | mObjMgr->SetGraphicWinZone(nx, ny, false);
|
---|
228 | }
|
---|
229 | else if (kw == "newwin") {
|
---|
230 | if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: newwin nx ny" << endl; return(0); }
|
---|
231 | int nx, ny;
|
---|
232 | nx = ny = 1;
|
---|
233 | nx = atoi(tokens[0].c_str()); ny = atoi(tokens[1].c_str());
|
---|
234 | mObjMgr->SetGraphicWinZone(nx, ny, true);
|
---|
235 | }
|
---|
236 | else if (kw == "gratt") {
|
---|
237 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: gratt attributes_list (att=def->defaut)" << endl; return(0); }
|
---|
238 | mObjMgr->SetGraphicAttributes(tokens[0]);
|
---|
239 | }
|
---|
240 | else if (kw == "stacknext") mImgApp->StackWinNext();
|
---|
241 |
|
---|
242 | // >>>>>>>>>>> Link dynamique de fonctions C++
|
---|
243 | else if (kw == "link" ) {
|
---|
244 | if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: link fnameso f1 [f2 f3]" << endl; return(0); }
|
---|
245 | string sph = "";
|
---|
246 | for(int gg=0; gg<5; gg++) tokens.push_back(sph);
|
---|
247 | int rc = LinkUserFuncs(tokens[0], tokens[1], tokens[2], tokens[3]);
|
---|
248 | if (rc == 0) cout << "PIAcmd::Do(): Link from " << tokens[0] << " OK " << endl;
|
---|
249 | }
|
---|
250 | else if (kw == "call" ) {
|
---|
251 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: call userf [arg1 arg2 ...]" << endl; return(0); }
|
---|
252 | UsFmap::iterator it = usfmap.find(tokens[0]);
|
---|
253 | if (it == usfmap.end()) {
|
---|
254 | cerr << "PIAcmd::Do() No User Function " << tokens[0] << endl;
|
---|
255 | return(0);
|
---|
256 | }
|
---|
257 | cout << "PIAcmd::Do() Call " << tokens[0] << "( ... )" << endl;
|
---|
258 | // on est oblige de faire un cast etant donne qu'on
|
---|
259 | // utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++)
|
---|
260 | DlUserProcFunction fuf = (DlUserProcFunction)(*it).second;
|
---|
261 | TRY {
|
---|
262 | tokens.erase(tokens.begin());
|
---|
263 | fuf(tokens);
|
---|
264 | } CATCH(merr) {
|
---|
265 | fflush(stdout);
|
---|
266 | cout << endl;
|
---|
267 | cerr << endl;
|
---|
268 | string es = PeidaExc(merr);
|
---|
269 | cerr << "PIACmd::Do() Call UserFunc Exception :" << merr << es;
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | // >>>>>>>>>>> lecture/ecriture des objets, gestion des objets
|
---|
274 | else if (kw == "openfits" ) {
|
---|
275 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: openfits file " << endl; return(0); }
|
---|
276 | else mObjMgr->ReadFits(tokens[0]);
|
---|
277 | }
|
---|
278 | else if (kw == "savefits" ) {
|
---|
279 | if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: savefits nomobj filename " << endl; return(0); }
|
---|
280 | else mObjMgr->SaveFits(tokens[0], tokens[1]);
|
---|
281 | }
|
---|
282 | else if (kw == "openppf" ) {
|
---|
283 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: openppf file " << endl; return(0); }
|
---|
284 | mObjMgr->ReadAll(tokens[0]);
|
---|
285 | }
|
---|
286 | else if (kw == "saveall" ) {
|
---|
287 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: saveall file " << endl; return(0); }
|
---|
288 | mObjMgr->SaveAll(tokens[0]);
|
---|
289 | }
|
---|
290 | else if (kw == "print" ) {
|
---|
291 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: print nomobj " << endl; return(0); }
|
---|
292 | mObjMgr->PrintObj(tokens[0]);
|
---|
293 | }
|
---|
294 | else if (kw == "rename" ) {
|
---|
295 | if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: rename nomobj nomnew" << endl; return(0); }
|
---|
296 | mObjMgr->RenameObj(tokens[0], tokens[1]);
|
---|
297 | }
|
---|
298 | else if (kw == "del" ) {
|
---|
299 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: del nomobj " << endl; return(0); }
|
---|
300 | mObjMgr->DelObj(tokens[0]);
|
---|
301 | }
|
---|
302 | else if (kw == "delobjs" ) {
|
---|
303 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: delobjs nomobjpattern (*,?) " << endl; return(0); }
|
---|
304 | mObjMgr->DelObjects(tokens[0]);
|
---|
305 | }
|
---|
306 | else if (kw == "listobjs") mObjMgr->ListObjs();
|
---|
307 |
|
---|
308 | // >>>>>>>>>>> Creation d'histos 1D-2D
|
---|
309 | else if (kw == "newh1d") {
|
---|
310 | if (tokens.size() < 4) { cout << "PIACmd::Do() Usage: newh1d nom xmin xmax nbin" << endl; return(0); }
|
---|
311 | int nbx;
|
---|
312 | float xmin, xmax;
|
---|
313 | nbx = 100;
|
---|
314 | xmin = 0.; xmax = 1.;
|
---|
315 | nbx = atoi(tokens[3].c_str());
|
---|
316 | xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
|
---|
317 | Histo* h = new Histo(xmin, xmax, nbx);
|
---|
318 | mObjMgr->AddObj(h, tokens[0]);
|
---|
319 | }
|
---|
320 | else if (kw == "newh2d") {
|
---|
321 | if (tokens.size() < 7) {
|
---|
322 | cout << "PIACmd::Do() Usage:newh2d nomh xmin xmax nbinx ymin ymax nbiny" << endl;
|
---|
323 | return(0);
|
---|
324 | }
|
---|
325 | int nbx, nby;
|
---|
326 | float xmin, xmax;
|
---|
327 | float ymin, ymax;
|
---|
328 | nbx = nby = 50;
|
---|
329 | xmin = 0.; xmax = 1.;
|
---|
330 | ymin = 0.; ymax = 1.;
|
---|
331 | nbx = atoi(tokens[3].c_str());
|
---|
332 | nby = atoi(tokens[6].c_str());
|
---|
333 | xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
|
---|
334 | ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str());
|
---|
335 | Histo2D* h = new Histo2D(xmin, xmax, nbx, ymin, ymax, nby);
|
---|
336 | mObjMgr->AddObj(h, tokens[0]);
|
---|
337 | }
|
---|
338 | else if (kw == "newprof") {
|
---|
339 | if (tokens.size() < 4)
|
---|
340 | { cout << "PIACmd::Do() Usage: newprof nom xmin xmax nbin [ymin ymax]" << endl; return(0); }
|
---|
341 | int nbx;
|
---|
342 | float xmin, xmax, ymin = 1., ymax = -1.;
|
---|
343 | if(tokens.size() > 5)
|
---|
344 | {ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str());}
|
---|
345 | nbx = 100;
|
---|
346 | xmin = 0.; xmax = 1.;
|
---|
347 | nbx = atoi(tokens[3].c_str());
|
---|
348 | xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
|
---|
349 | HProf* h = new HProf(xmin, xmax, nbx, ymin, ymax);
|
---|
350 | mObjMgr->AddObj(h, tokens[0]);
|
---|
351 | }
|
---|
352 | else if (kw == "newgfd") {
|
---|
353 | if (tokens.size() < 3)
|
---|
354 | { cout << "PIACmd::Do() Usage: newgfd nvar nalloc [errx(0/1)]" << endl; return(0); }
|
---|
355 | int nvar, nalloc, errx=0;
|
---|
356 | if (tokens.size() > 3)
|
---|
357 | { errx = atoi(tokens[3].c_str()); if(errx>0) errx=1; else errx = 0;}
|
---|
358 | nvar = atoi(tokens[1].c_str()); nalloc = atoi(tokens[2].c_str());
|
---|
359 | if(nvar>0 && nalloc>0) {
|
---|
360 | GeneralFitData* gfd = new GeneralFitData(nvar,nalloc,errx);
|
---|
361 | mObjMgr->AddObj(gfd, tokens[0]);
|
---|
362 | }
|
---|
363 | }
|
---|
364 |
|
---|
365 | // >>>>>>>>>>> Affichage des objets
|
---|
366 | else if ( (kw == "disp") || (kw == "surf") ) {
|
---|
367 | if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: disp nomobj opt" << endl; return(0); }
|
---|
368 | string opt = "n";
|
---|
369 | if (tokens.size() > 1) opt = tokens[1];
|
---|
370 | if (kw == "disp") mObjMgr->DisplayObj(tokens[0], opt);
|
---|
371 | else if (kw == "surf") mObjMgr->DisplaySurf3D(tokens[0], opt);
|
---|
372 | }
|
---|
373 |
|
---|
374 | else if (kw == "nt2d") {
|
---|
375 | if (tokens.size() < 5) { cout << "PIACmd::Do() Usage: nt2d nomobj varx vary errx erry opt" << endl; return(0); }
|
---|
376 | string opt = "n";
|
---|
377 | if (tokens.size() > 5) opt = tokens[5];
|
---|
378 | string ph = "";
|
---|
379 | mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], ph, tokens[3], tokens[4], ph, opt);
|
---|
380 | }
|
---|
381 | else if (kw == "nt3d") {
|
---|
382 | if (tokens.size() < 7) { cout << "PIACmd::Do() Usage: nt3d nomobj varx vary varz errx erry errz opt" << endl; return(0); }
|
---|
383 | string opt = "n";
|
---|
384 | if (tokens.size() > 7) opt = tokens[7];
|
---|
385 | mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6], opt);
|
---|
386 | }
|
---|
387 |
|
---|
388 | else if (kw == "gfd2d") {
|
---|
389 | if(tokens.size()<2)
|
---|
390 | {cout<<"PIACmd::Do() Usage: gfd2d nomobj numvarx erreur=(x y xy) opt"<<endl;
|
---|
391 | return(0);}
|
---|
392 | string numvary = "";
|
---|
393 | string err = "";
|
---|
394 | string opt = "n";
|
---|
395 | if(tokens.size()>2) err = tokens[2];
|
---|
396 | if(tokens.size()>3) opt = tokens[3];
|
---|
397 | mObjMgr->DisplayGFD(tokens[0],tokens[1],numvary,err,opt);
|
---|
398 | }
|
---|
399 | else if (kw == "gfd3d") {
|
---|
400 | if(tokens.size()<3)
|
---|
401 | {cout<<"PIACmd::Do() Usage: gfd3d nomobj numvarx numvary erreur=(x y z xy xz yz xyz) opt"<<endl;
|
---|
402 | return(0);}
|
---|
403 | string err = "";
|
---|
404 | string opt = "n";
|
---|
405 | if(tokens.size()>3) err = tokens[3];
|
---|
406 | if(tokens.size()>4) opt = tokens[4];
|
---|
407 | mObjMgr->DisplayGFD(tokens[0],tokens[1],tokens[2],err,opt);
|
---|
408 | }
|
---|
409 |
|
---|
410 | // >>>>>>>>>>> Trace de fonctions
|
---|
411 | else if ( (kw == "func") ) {
|
---|
412 | if (tokens.size() < 4) { cout << "PIACmd::Do() Usage: func expr xmin xmax npt opt" << endl; return(0); }
|
---|
413 | string opt = "n";
|
---|
414 | if (tokens.size() > 4) opt = tokens[4];
|
---|
415 | int np;
|
---|
416 | float xmin, xmax;
|
---|
417 | np = 100;
|
---|
418 | xmin = 0.; xmax = 1.;
|
---|
419 | np = atoi(tokens[3].c_str());
|
---|
420 | xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
|
---|
421 | mObjMgr->PlotFunc(tokens[0], xmin, xmax, np, opt);
|
---|
422 | }
|
---|
423 | else if ( (kw == "func2d") ) {
|
---|
424 | if (tokens.size() < 7) {
|
---|
425 | cout << "PIACmd::Do() Usage: func2d expr xmin xmax nptx ymin ymax npty opt" << endl;
|
---|
426 | return(0);
|
---|
427 | }
|
---|
428 | int npx, npy;
|
---|
429 | float xmin, xmax;
|
---|
430 | float ymin, ymax;
|
---|
431 | npx = npy = 50;
|
---|
432 | xmin = 0.; xmax = 1.;
|
---|
433 | ymin = 0.; ymax = 1.;
|
---|
434 | npx = atoi(tokens[3].c_str());
|
---|
435 | npy = atoi(tokens[6].c_str());
|
---|
436 | xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str());
|
---|
437 | ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str());
|
---|
438 | string opt = "n";
|
---|
439 | if (tokens.size() > 7) opt = tokens[7];
|
---|
440 | mObjMgr->PlotFunc2D(tokens[0], xmin, xmax, ymin, ymax, npx, npy, opt);
|
---|
441 | }
|
---|
442 |
|
---|
443 | // >>>>>>>>>>> Trace d'expressions de N_Tuple, StarList, etc ...
|
---|
444 | else if (kw == "plot2d" ) {
|
---|
445 | if (tokens.size() < 4) {
|
---|
446 | cout << "PIACmd::Do() Usage: plot2d nomobj expx expy [experrx experry] expcut opt" << endl;
|
---|
447 | return(0);
|
---|
448 | }
|
---|
449 | string errx = ""; string erry = ""; string ecut = "1";
|
---|
450 | string opt = "n";
|
---|
451 | if (tokens.size() < 6) { // Plot sans les erreurs
|
---|
452 | ecut = tokens[3];
|
---|
453 | if (tokens.size() > 4) opt = tokens[4];
|
---|
454 | }
|
---|
455 | else { // Plot avec les erreurs
|
---|
456 | errx = tokens[3]; erry = tokens[4]; ecut = tokens[5];
|
---|
457 | if (tokens.size() > 6) opt = tokens[6];
|
---|
458 | }
|
---|
459 | mObjMgr->DisplayPoints2D(tokens[0],tokens[1],tokens[2],errx,erry,ecut,opt);
|
---|
460 | }
|
---|
461 |
|
---|
462 | else if (kw == "plot3d" ) {
|
---|
463 | if (tokens.size() < 5) {
|
---|
464 | cout << "PIACmd::Do() Usage: plot3d nomobj expx expy expz expcut opt" << endl;
|
---|
465 | return(0);
|
---|
466 | }
|
---|
467 | string opt = "n";
|
---|
468 | if (tokens.size() > 5) opt = tokens[5];
|
---|
469 | mObjMgr->DisplayPoints3D(tokens[0],tokens[1],tokens[2],tokens[3], tokens[4], opt);
|
---|
470 | }
|
---|
471 |
|
---|
472 | else if (kw == "projh1d" ) {
|
---|
473 | if (tokens.size() < 5) {
|
---|
474 | cout << "PIACmd::Do() Usage: projh1d nomobj expx expwt expcut nomh1 opt" << endl;
|
---|
475 | return(0);
|
---|
476 | }
|
---|
477 | string opt = "n";
|
---|
478 | if (tokens.size() > 5) opt = tokens[5];
|
---|
479 | mObjMgr->ProjectH1(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], opt);
|
---|
480 | }
|
---|
481 |
|
---|
482 | else if (kw == "projh2d" ) {
|
---|
483 | if (tokens.size() < 6) {
|
---|
484 | cout << "PIACmd::Do() Usage: projh2 nomobj expx expy expwt expcut nomh2 opt" << endl;
|
---|
485 | return(0);
|
---|
486 | }
|
---|
487 | string opt = "n";
|
---|
488 | if (tokens.size() > 6) opt = tokens[6];
|
---|
489 |
|
---|
490 | mObjMgr->ProjectH2(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt);
|
---|
491 | }
|
---|
492 |
|
---|
493 | else if (kw == "projprof" ) {
|
---|
494 | if (tokens.size() < 6) {
|
---|
495 | cout << "PIACmd::Do() Usage: projprof nomobj expx expy expwt expcut nomprof opt" << endl;
|
---|
496 | return(0);
|
---|
497 | }
|
---|
498 | string opt = "n";
|
---|
499 | if (tokens.size() > 6) opt = tokens[6];
|
---|
500 |
|
---|
501 | mObjMgr->ProjectHProf(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt);
|
---|
502 | }
|
---|
503 |
|
---|
504 | else if (kw == "fillnt" ) {
|
---|
505 | if (tokens.size() < 7) {
|
---|
506 | cout << "PIACmd::Do() Usage: fillnt nomobj expx expy expz expt expcut nomnt" << endl;
|
---|
507 | return(0);
|
---|
508 | }
|
---|
509 | mObjMgr->FillNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6] );
|
---|
510 | }
|
---|
511 |
|
---|
512 | else if (kw == "fillvec" ) {
|
---|
513 | if (tokens.size() < 4) {
|
---|
514 | cout << "PIACmd::Do() Usage: fillvec nomobj expx expcut nomvec opt" << endl;
|
---|
515 | return(0);
|
---|
516 | }
|
---|
517 | string opt = "n";
|
---|
518 | if (tokens.size() > 4) opt = tokens[4];
|
---|
519 | mObjMgr->FillVect(tokens[0],tokens[1],tokens[2], tokens[3], opt);
|
---|
520 | }
|
---|
521 |
|
---|
522 | else if (kw == "fillgd1" ) {
|
---|
523 | if (tokens.size() < 5) {
|
---|
524 | cout << "PIACmd::Do() Usage: fillgd1 nomobj expx expy experry expcut nomgfd" << endl;
|
---|
525 | return(0);
|
---|
526 | }
|
---|
527 | string nomgfd = "";
|
---|
528 | if (tokens.size() > 5) nomgfd = tokens[5];
|
---|
529 | string expy = "";
|
---|
530 | mObjMgr->FillGFD(tokens[0],tokens[1], expy, tokens[2], tokens[3], tokens[4],nomgfd);
|
---|
531 | }
|
---|
532 |
|
---|
533 | else if (kw == "fillgd2" ) {
|
---|
534 | if (tokens.size() < 6) {
|
---|
535 | cout << "PIACmd::Do() Usage: fillgd2 nomobj expx expy expz experrz expcut nomgfd" << endl;
|
---|
536 | return(0);
|
---|
537 | }
|
---|
538 | string nomgfd = "";
|
---|
539 | if (tokens.size() > 6) nomgfd = tokens[6];
|
---|
540 | mObjMgr->FillGFD(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5],nomgfd);
|
---|
541 | }
|
---|
542 |
|
---|
543 | // Calcul TF
|
---|
544 | else if (kw == "fft" ) {
|
---|
545 | if (tokens.size() < 1) {
|
---|
546 | cout << "PIACmd::Do() Usage: fft nomobj opt" << endl;
|
---|
547 | return(0);
|
---|
548 | }
|
---|
549 | string opt = "n";
|
---|
550 | if (tokens.size() > 1) opt = tokens[1];
|
---|
551 | mObjMgr->FFT(tokens[0], opt);
|
---|
552 | }
|
---|
553 |
|
---|
554 | // Fit 1D sur objets 1D. Egalement Fit 2D sur objets 2D.
|
---|
555 | else if (kw == "fit") {
|
---|
556 | if (tokens.size() < 2) {
|
---|
557 | cout <<"PIACmd::Do() Usage:fit nomobj func \n"
|
---|
558 | <<" [p:p1,...,pn s:s1,...,sn m:m1,...,mn M:M1,...,Mn o:... o:...]\n";
|
---|
559 | return(0);
|
---|
560 | }
|
---|
561 | string p=""; string s=""; string m=""; string M=""; string O="";
|
---|
562 | if (tokens.size()>2)
|
---|
563 | for(int ip=2;ip<tokens.size();ip++) {
|
---|
564 | if(tokens[ip].length()<=2) continue;
|
---|
565 | const char *c = tokens[ip].c_str();
|
---|
566 | if(c[1]!=':') continue;
|
---|
567 | if(c[0]=='p') p=c+2;
|
---|
568 | else if(c[0]=='s') s=c+2;
|
---|
569 | else if(c[0]=='m') m=c+2;
|
---|
570 | else if(c[0]=='M') M=c+2;
|
---|
571 | else if(c[0]=='o') {O += ","; O += c+2;}
|
---|
572 | }
|
---|
573 | mObjMgr->Fit12D(tokens[0],tokens[1],p,s,m,M,O);
|
---|
574 | }
|
---|
575 |
|
---|
576 | #ifndef SANS_StarReco
|
---|
577 | // FITPSF sur image
|
---|
578 | else if (kw == "fitpsf" ) {
|
---|
579 | if (tokens.size() < 1) {
|
---|
580 | cout << "PIACmd::Do() Usage: fitpsf psf_typ [options_fit]" << endl;
|
---|
581 | return(0);
|
---|
582 | }
|
---|
583 | FitPSFImg(tokens);
|
---|
584 | }
|
---|
585 |
|
---|
586 | // Photometrie d'ouvertue sur image
|
---|
587 | else if (kw == "aper" ) {
|
---|
588 | if (tokens.size() < 1) {
|
---|
589 | cout << "PIACmd::Do() Usage: aper fond_typ [opt_calcul opt_disp]" << endl;
|
---|
590 | return(0);
|
---|
591 | }
|
---|
592 | Photom_Ouv(tokens);
|
---|
593 | }
|
---|
594 | #endif
|
---|
595 |
|
---|
596 | else {
|
---|
597 | cerr << "PIACmd::Do() Erreur - Commande " << kw << " inconuue ! " << endl;
|
---|
598 | return(-1);
|
---|
599 | }
|
---|
600 | if (timing) gltimer->Split();
|
---|
601 |
|
---|
602 | return(0);
|
---|
603 | }
|
---|
604 |
|
---|
605 |
|
---|
606 |
|
---|
607 | /* --Methode-- */
|
---|
608 | int PIACmd::LinkUserFuncs(string& fnameso, string& func1, string& func2, string& func3)
|
---|
609 | // string& func4, string& func5)
|
---|
610 | {
|
---|
611 | string cmd;
|
---|
612 | int rc;
|
---|
613 |
|
---|
614 | if (dynlink) delete dynlink; dynlink = NULL;
|
---|
615 | usfmap.clear();
|
---|
616 |
|
---|
617 | dynlink = new PDynLinkMgr(fnameso, true);
|
---|
618 | if (dynlink == NULL) {
|
---|
619 | string sn = fnameso;
|
---|
620 | cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur ouverture SO " << sn << endl;
|
---|
621 | return(2);
|
---|
622 | }
|
---|
623 |
|
---|
624 | int nok=0;
|
---|
625 | // on utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++)
|
---|
626 | // DlUserProcFunction f = NULL;
|
---|
627 | DlFunction f = NULL;
|
---|
628 | if ((func1.length() < 1) || (func1 == "-") || (func1 == ".") ) goto fin;
|
---|
629 | // f = (DlUserProcFunction) dlsym(dlhandle, func1.c_str());
|
---|
630 | f = dynlink->GetFunction(func1);
|
---|
631 | if (f) { nok++; usfmap[func1] = f; }
|
---|
632 | else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func1 << endl;
|
---|
633 |
|
---|
634 | if ((func2.length() < 1) || (func2 == "-") || (func2 == ".") ) goto fin;
|
---|
635 | // f = (DlUserProcFunction) dlsym(dlhandle, func2.c_str());
|
---|
636 | f = dynlink->GetFunction(func2);
|
---|
637 | if (f) { nok++; usfmap[func2] = f; }
|
---|
638 | else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func2 << endl;
|
---|
639 |
|
---|
640 | if ((func3.length() < 1) || (func3 == "-") || (func3 == ".") ) goto fin;
|
---|
641 | // f = (DlUserProcFunction) dlsym(dlhandle, func3.c_str());
|
---|
642 | f = dynlink->GetFunction(func3);
|
---|
643 | if (f) { nok++; usfmap[func3] = f; }
|
---|
644 | else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func3 << endl;
|
---|
645 |
|
---|
646 | /* Pb compile g++ 2.7.2
|
---|
647 | if ((func4.length() < 1) || (func4 == "-") || (func4 == ".") ) goto fin;
|
---|
648 | // f = (DlUserProcFunction) dlsym(dlhandle, func4.c_str());
|
---|
649 | f = dynlink->GetFunction(func4);
|
---|
650 | if (f) { nok++; usfmap[func4] = f; }
|
---|
651 | else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func4 << endl;
|
---|
652 |
|
---|
653 | if ((func5.length() < 1) || (func5 == "-") || (func5 == ".") ) goto fin;
|
---|
654 | // f = (DlUserProcFunction) dlsym(dlhandle, func5.c_str());
|
---|
655 | f = dynlink->GetFunction(func5);
|
---|
656 | if (f) { nok++; usfmap[func5] = f; }
|
---|
657 | else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func5 << endl;
|
---|
658 | */
|
---|
659 | fin:
|
---|
660 | if (nok < 1) { if (dynlink) delete dynlink; dynlink = NULL; return(3); }
|
---|
661 | else return(0);
|
---|
662 | }
|
---|
663 |
|
---|
664 | /////////////////////////////////////////////////////////////////////////
|
---|
665 | /////////////////////////////////////////////////////////////////////////
|
---|
666 | /////////////////////////////// Fonctions ///////////////////////////////
|
---|
667 | /////////////////////////////////////////////////////////////////////////
|
---|
668 | /////////////////////////////////////////////////////////////////////////
|
---|
669 | #ifndef SANS_StarReco
|
---|
670 | #include "psf.h"
|
---|
671 | #include "dynccd.h"
|
---|
672 | #include "pimgadapter.h"
|
---|
673 | #include "nbmath.h"
|
---|
674 | #include "nbtri.h"
|
---|
675 |
|
---|
676 | /* Nouvelle-Fonction rz + cmv 15/10/98 */
|
---|
677 | int FitPSFImg(cmdtok& tokens)
|
---|
678 | // Fit de PSF sur une Image.
|
---|
679 | //| tokens[0] = Type de PSF ()
|
---|
680 | //| : G = fit gaussienne+fond (volume)
|
---|
681 | //| : Gi = fit gaussienne+fond integree (volume)
|
---|
682 | //| : d = fit DL de gaussienne+fond (volume)
|
---|
683 | //| : di = fit DL de gaussienne+fond integree (volume)
|
---|
684 | //| : D = fit DL de gaussienne+fond avec coeff variable p6 (volume)
|
---|
685 | //| : Di = fit DL de gaussienne+fond integree avec coeff variable p6 (volume)
|
---|
686 | //| : M = fit Moffat+fond (expos=p6) (volume)
|
---|
687 | //| : Mi = fit Moffat+fond integree (expos=p6) (volume)
|
---|
688 | //| tokens[1] = options pour le fit ex: l1.0,G2.,R7.,m10.,M65000.,P3.,f,n,r,i,w10/450
|
---|
689 | //| : r = ecriture de l'image des residus (def=non)
|
---|
690 | //| : f = ecriture de l'image de de la PSF fitee (def=non)
|
---|
691 | //| : i = ecriture du pave initial selectionne pour le fit (def=non)
|
---|
692 | //| : n = ecriture de l'image du bruit (def=non)
|
---|
693 | //| : Gaa.bbb = gain en e-/ADU (def=1)
|
---|
694 | //| : Raa.bbb = readout noise en e- (def=0)
|
---|
695 | //| : maa.bbb = limite basse dynamique en ADU (def=-9.e19)
|
---|
696 | //| : Maa.bbb = limite haute dynamique en ADU (def=9.e19)
|
---|
697 | //| : Paa.bbb = valeur du parametre supplementaire pour
|
---|
698 | //| : la.a = print a=FitPSFImg, b=PSF.Fit PSF.IniFit
|
---|
699 | //| : wa/b = "a" est le facteur de zoom de la fenetre de representation
|
---|
700 | //| des resultats (def=6) et b sa taille maximale (def=500).
|
---|
701 | //| Return: 0 si Ok, <0 sinon.
|
---|
702 | {
|
---|
703 | // Decodage des arguments
|
---|
704 | if(tokens.size()<1) return(-1);
|
---|
705 | int typ_psf=PSF::psfGaussienne;
|
---|
706 | bool wres=false, wpsf=false, wpav=false, wnois=false;
|
---|
707 | float gain=1., readout=0., pixmin=-9.e19, pixmax=9.e19;
|
---|
708 | int zoom=6, wmax=500;
|
---|
709 | float par6=-1.;
|
---|
710 | int lp=1, lpg=0;
|
---|
711 | string dummy,dum;
|
---|
712 |
|
---|
713 | if(tokens.size()>=2) {
|
---|
714 | dummy = "," + tokens[1]+ ",";
|
---|
715 | if(strstr(dummy.c_str(),",r,")) wres=true;
|
---|
716 | if(strstr(dummy.c_str(),",f,")) wpsf=true;
|
---|
717 | if(strstr(dummy.c_str(),",i")) wpav=true;
|
---|
718 | if(strstr(dummy.c_str(),",n")) wnois=true;
|
---|
719 | if(strstr(dummy.c_str(),",G")) {
|
---|
720 | size_t p = dummy.find(",G"); size_t q = dummy.find_first_of(',',p+1);
|
---|
721 | dum = dummy.substr(p,q-p);
|
---|
722 | if(dum.length()>2) sscanf(dum.c_str(),",G%f",&gain);
|
---|
723 | }
|
---|
724 | if(strstr(dummy.c_str(),",P")) {
|
---|
725 | size_t p = dummy.find(",P"); size_t q = dummy.find_first_of(',',p+1);
|
---|
726 | dum = dummy.substr(p,q-p);
|
---|
727 | if(dum.length()>2) sscanf(dum.c_str(),",P%f",&par6);
|
---|
728 | }
|
---|
729 | if(strstr(dummy.c_str(),",R")) {
|
---|
730 | size_t p = dummy.find(",R"); size_t q = dummy.find_first_of(',',p+1);
|
---|
731 | dum = dummy.substr(p,q-p);
|
---|
732 | if(dum.length()>2) sscanf(dum.c_str(),",R%f",&readout);
|
---|
733 | }
|
---|
734 | if(strstr(dummy.c_str(),",m")) {
|
---|
735 | size_t p = dummy.find(",m"); size_t q = dummy.find_first_of(',',p+1);
|
---|
736 | dum = dummy.substr(p,q-p);
|
---|
737 | if(dum.length()>2) sscanf(dum.c_str(),",m%f",&pixmin);
|
---|
738 | }
|
---|
739 | if(strstr(dummy.c_str(),",M")) {
|
---|
740 | size_t p = dummy.find(",M"); size_t q = dummy.find_first_of(',',p+1);
|
---|
741 | dum = dummy.substr(p,q-p);
|
---|
742 | if(dum.length()>2) sscanf(dum.c_str(),",M%f",&pixmax);
|
---|
743 | }
|
---|
744 | if(strstr(dummy.c_str(),",l")) { // niveau de print
|
---|
745 | size_t p = dummy.find(",l"); size_t q = dummy.find_first_of(',',p+1);
|
---|
746 | dum = dummy.substr(p,q-p);
|
---|
747 | float ab;
|
---|
748 | if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
|
---|
749 | if(ab<0) ab = 0.;
|
---|
750 | lp = (int) ab; lpg = (int) 10.*(ab-lp);
|
---|
751 | }
|
---|
752 | if(strstr(dummy.c_str(),",w")) { // niveau de print
|
---|
753 | size_t p = dummy.find(",w"); size_t q = dummy.find_first_of(',',p+1);
|
---|
754 | dum = dummy.substr(p,q-p);
|
---|
755 | if(dum.length()>2) sscanf(dum.c_str(),",w%d/%d",&zoom,&wmax);
|
---|
756 | }
|
---|
757 | }
|
---|
758 |
|
---|
759 | dummy = "," + tokens[0]+ ",";
|
---|
760 | if(strstr(dummy.c_str(),",G,")) typ_psf=PSF::psfGaussienne;
|
---|
761 | else if(strstr(dummy.c_str(),",Gi,")) typ_psf=PSF::psfGaussInteg;
|
---|
762 | else if(strstr(dummy.c_str(),",d,") ) typ_psf=PSF::psfDelGaussienne;
|
---|
763 | else if(strstr(dummy.c_str(),",di,")) typ_psf=PSF::psfDelGaussinteg;
|
---|
764 | else if(strstr(dummy.c_str(),",D,") ) {typ_psf=PSF::psfDel1Gaussienne; if(par6<=0.) par6=1.;}
|
---|
765 | else if(strstr(dummy.c_str(),",Di,")) {typ_psf=PSF::psfDel1GaussInteg; if(par6<=0.) par6=1.;}
|
---|
766 | else if(strstr(dummy.c_str(),",M,") ) {typ_psf=PSF::psfMoffat; if(par6<=1.) par6=2.5;}
|
---|
767 | else if(strstr(dummy.c_str(),",Mi,")) {typ_psf=PSF::psfMoffInteg; if(par6<=1.) par6=2.5;}
|
---|
768 |
|
---|
769 | if(gain<=0.) gain=1.; if(readout<0.) readout=0.;
|
---|
770 | if(zoom<1) zoom=1; if(zoom>10) zoom=10; // Il semble que le zoom soit limite a 10 !!!
|
---|
771 | if(wmax>500) wmax=500;
|
---|
772 | if(lp<0) lp=1; if(lpg<0) lpg=0;
|
---|
773 |
|
---|
774 | // Wigdet,piimage et image courants
|
---|
775 | NamedObjMgr omg;
|
---|
776 | PIStdImgApp* app = omg.GetImgApp();
|
---|
777 | if(app == NULL)
|
---|
778 | {cout<<"Pas de PIStdImgApp*"<<endl; return(-2);}
|
---|
779 | PIBaseWdg* curw= app->CurrentBaseWdg() ;
|
---|
780 | if(curw == NULL)
|
---|
781 | {cout<<"Pas de PIBaseWdg*"<<endl; return(-3);}
|
---|
782 | if(curw->kind() != PIImage::ClassId)
|
---|
783 | {cout<<"Current window not an Image"<<endl; return(-4);}
|
---|
784 | PIImage* curpimg = (PIImage*)curw;
|
---|
785 | if(curpimg == NULL)
|
---|
786 | {cout<<"Pas de PIImage*"<<endl; return(-5);}
|
---|
787 | P2DArrayAdapter* img = curpimg->Image();
|
---|
788 | if(img == NULL)
|
---|
789 | {cout<<"Pas de Image*"<<endl; return(-6);}
|
---|
790 | string nom = "fitpsf_";
|
---|
791 |
|
---|
792 | // Definition du pave courant sur la piimage
|
---|
793 | int dx = curpimg->XSzPave(), dy = curpimg->YSzPave();
|
---|
794 | int x0 = curpimg->XPave()-dx/2, y0 = curpimg->YPave()-dy/2;
|
---|
795 | if(x0<0) x0 = 0; if(y0<0) y0 = 0;
|
---|
796 | int x1 = x0+dx, y1 = y0+dy;
|
---|
797 | if(x1>img->XSize()) x1=img->XSize(); if(y1>img->YSize()) y1=img->YSize();
|
---|
798 | dx = x1-x0; dy = y1-y0;
|
---|
799 | int dxy = (dx>dy)?dx:dy;
|
---|
800 | ImageR4* pav = new ImageR4(dx, dy);
|
---|
801 | {for(int j=0;j<dy;j++) for(int i=0;i<dx;i++) (*pav)(i,j)=(*img)(i+x0,j+y0);}
|
---|
802 |
|
---|
803 | // Bruit sur le pave
|
---|
804 | DynCCD mdynccd(kPhotonNoise,pixmin,pixmax,gain,readout);
|
---|
805 | ImageR4 *nois = NoiseImage(pav, &mdynccd);
|
---|
806 |
|
---|
807 | // Print
|
---|
808 | int w=2*zoom*dxy+25; if(w>wmax){w=wmax;zoom=(wmax-25)/(2*dxy);if(zoom<1)zoom=1;}
|
---|
809 | if(lp>1)
|
---|
810 | {cout<<"FitPSFImg: fun="<<tokens[0]<<","<<typ_psf
|
---|
811 | <<" Write res="<<wres<<" psf="<<wpsf<<" pav="<<wpav<<" nois="<<wnois
|
---|
812 | <<" Par6="<<par6<<" lp="<<lp<<","<<lpg<<endl;
|
---|
813 | mdynccd.Print();
|
---|
814 | cout<<"... dx,y="<<dxy<<" zoom="<<zoom<<" w="<<w<<endl;}
|
---|
815 |
|
---|
816 | // PSF et Fit
|
---|
817 | PSF mypsf(typ_psf,100.0);
|
---|
818 | int npar = mypsf.NParm();
|
---|
819 | PSFStar mypsfstar(&mypsf);
|
---|
820 | if(npar>7) mypsfstar.Parm(6)=(double)par6; // Cas moffat et Dl gauss avec coeff var.
|
---|
821 | int rc = mypsfstar.IniFit(*pav,*nois,lpg);
|
---|
822 | if(rc != 0)
|
---|
823 | {cout<<"PIDemoApp::FitPSFImg(), Echec IniFit (rc="<<rc<<")"<<endl;
|
---|
824 | delete nois; delete pav; return(-10); }
|
---|
825 | rc = mypsfstar.Fit(*pav,*nois,lpg);
|
---|
826 | if(rc != 0)
|
---|
827 | {cout<<"PIDemoApp::FitPSFImg(), Echec Fit (rc="<<rc<<")"<<endl;
|
---|
828 | delete nois; delete pav; return(-11); }
|
---|
829 | if(lp) mypsfstar.Print(2);
|
---|
830 | float smax,axisrat,tiltdeg;
|
---|
831 | rc = paramga((float) mypsfstar.SigX(),(float) mypsfstar.SigY()
|
---|
832 | ,(float) mypsfstar.Rho(),&smax,&axisrat,&tiltdeg);
|
---|
833 | if(rc==0 && lp)
|
---|
834 | printf("... sa=%g sb=%g (%g) teta=%g\n",smax,smax*axisrat,axisrat,tiltdeg);
|
---|
835 | else printf("Erreur paramga \n");
|
---|
836 |
|
---|
837 | // Creation des pave resultats
|
---|
838 | ImageR4* res = new ImageR4(dx, dy);
|
---|
839 | ImageR4* psf = new ImageR4(dx, dy);
|
---|
840 | CopieImage(*res,*pav); *res -= mypsfstar;
|
---|
841 | *psf = 0.; *psf += mypsfstar;
|
---|
842 |
|
---|
843 | // Si on demande d'ecrire au moins un des resultats (pav,nois,res,psf) => menage!
|
---|
844 | bool delobj = (wpav||wnois||wres||wpsf)?true:false;
|
---|
845 |
|
---|
846 | // Display des resultats, fenetre 2x2 {{pav,nois},{res,psf}}
|
---|
847 | app->CreateGraphWin(2,2,w,w); app->SetZoomAtt(zoom);
|
---|
848 | dummy = nom+"pav"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum);
|
---|
849 | if(wpav) {
|
---|
850 | // Si on veut garder l'objet
|
---|
851 | omg.AddObj(pav,dummy);
|
---|
852 | omg.DisplayObj(omg.LastObjName());
|
---|
853 | } else {
|
---|
854 | // "true" pour tuer (delete) de l'objet ImageR4 lors de la destruction de PIImage
|
---|
855 | app->DispImage(new ImageAdapter<r_4>(pav,true),dummy,Disp_Next);
|
---|
856 | }
|
---|
857 | dummy = nom+"nois"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum);
|
---|
858 | if(wnois) {
|
---|
859 | omg.AddObj(nois,dummy);
|
---|
860 | omg.DisplayObj(omg.LastObjName());
|
---|
861 | } else {
|
---|
862 | app->DispImage(new ImageAdapter<r_4>(nois,true),dummy,Disp_Next);
|
---|
863 | }
|
---|
864 | dummy = nom+"res"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum);
|
---|
865 | if(wres) {
|
---|
866 | omg.AddObj(res,dummy);
|
---|
867 | omg.DisplayObj(omg.LastObjName());
|
---|
868 | } else {
|
---|
869 | app->DispImage(new ImageAdapter<r_4>(res,true),dummy,Disp_Next);
|
---|
870 | }
|
---|
871 | dummy = nom+"psf"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum);
|
---|
872 | if(wpsf) {
|
---|
873 | omg.AddObj(psf,dummy);
|
---|
874 | omg.DisplayObj(omg.LastObjName());
|
---|
875 | } else {
|
---|
876 | app->DispImage(new ImageAdapter<r_4>(psf,true),dummy,Disp_Next);
|
---|
877 | }
|
---|
878 |
|
---|
879 | return(0);
|
---|
880 | }
|
---|
881 |
|
---|
882 | /* Nouvelle-Fonction cmv 16/10/98 */
|
---|
883 | int Photom_Ouv(cmdtok& tokens)
|
---|
884 | // Photometrie d'ouverture sur une Image.
|
---|
885 | //| tokens[0] = Type de calcul du fond et du flux.
|
---|
886 | //| : b = fond calcule sur les pixels du bord du pave.
|
---|
887 | //| : a = fond sur les pixels autres que ceux servant au calcul du flux.
|
---|
888 | //| : faa.bbb = fond fixe a aa.bbb
|
---|
889 | //| defaut : "b"
|
---|
890 | //| tokens[1] = options pour le fit ex: l1
|
---|
891 | //| : ra = "a" rayon minimal de scan (def=0)
|
---|
892 | //| : ga = "a" taille de la fenetre glissante pour les extrapolations (def=4)
|
---|
893 | //| : la = "a" niveau de print
|
---|
894 | //| : c = la surface pour la photometrie est un carre (defaut=cercle)
|
---|
895 | //| : C = recentrage du pave sur le pixel le + brillant (defaut=non)
|
---|
896 | //| tokens[2] = options graphiques
|
---|
897 | //| Return: 0 si Ok, <0 sinon.
|
---|
898 | {
|
---|
899 | // Decodage des arguments
|
---|
900 | if(tokens.size()<1) return(-1);
|
---|
901 | int typ_fond=1, rmin=0, rmax, npt_gliss=4, lp=0;
|
---|
902 | float fondimpos=0., fondbord=0., fondautre;
|
---|
903 | bool cercle=true, centre=false;
|
---|
904 | string opt="";
|
---|
905 | string dummy; string dum;
|
---|
906 |
|
---|
907 | if(tokens.size()>=3) opt = tokens[2];
|
---|
908 | if(tokens.size()>=2) {
|
---|
909 | dummy = "," + tokens[1]+ ",";
|
---|
910 | if(strstr(dummy.c_str(),",r")) {
|
---|
911 | size_t p = dummy.find(",r"); size_t q = dummy.find_first_of(',',p+1);
|
---|
912 | dum = dummy.substr(p,q-p);
|
---|
913 | if(dum.length()>2) sscanf(dum.c_str(),",r%d",&rmin);
|
---|
914 | }
|
---|
915 | if(strstr(dummy.c_str(),",g")) {
|
---|
916 | size_t p = dummy.find(",g"); size_t q = dummy.find_first_of(',',p+1);
|
---|
917 | dum = dummy.substr(p,q-p);
|
---|
918 | if(dum.length()>2) sscanf(dum.c_str(),",g%d",&npt_gliss);
|
---|
919 | }
|
---|
920 | if(strstr(dummy.c_str(),",l")) {
|
---|
921 | size_t p = dummy.find(",l"); size_t q = dummy.find_first_of(',',p+1);
|
---|
922 | dum = dummy.substr(p,q-p);
|
---|
923 | if(dum.length()>2) sscanf(dum.c_str(),",l%d",&lp);
|
---|
924 | }
|
---|
925 | if(strstr(dummy.c_str(),",c")) cercle = false;
|
---|
926 | if(strstr(dummy.c_str(),",C")) centre = true;
|
---|
927 | }
|
---|
928 |
|
---|
929 | dummy = "," + tokens[0]+ ",";
|
---|
930 | if(strstr(dummy.c_str(),",b,")) typ_fond=1;
|
---|
931 | else if(strstr(dummy.c_str(),",a,")) typ_fond=2;
|
---|
932 | else if(strstr(dummy.c_str(),",f")) {
|
---|
933 | typ_fond=3;
|
---|
934 | size_t p = dummy.find(",f"); size_t q = dummy.find_first_of(',',p+1);
|
---|
935 | dum = dummy.substr(p,q-p);
|
---|
936 | if(dum.length()>2) sscanf(dum.c_str(),",f%f",&fondimpos);
|
---|
937 | }
|
---|
938 |
|
---|
939 | if(rmin<0) rmin=0; if(npt_gliss<=0) npt_gliss=4; if(lp<0) lp=1;
|
---|
940 |
|
---|
941 | // Wigdet,piimage et image courants
|
---|
942 | NamedObjMgr omg;
|
---|
943 | PIStdImgApp* app = omg.GetImgApp();
|
---|
944 | if(app == NULL)
|
---|
945 | {cout<<"Pas de PIStdImgApp*"<<endl; return(-2);}
|
---|
946 | PIBaseWdg* curw= app->CurrentBaseWdg() ;
|
---|
947 | if(curw == NULL)
|
---|
948 | {cout<<"Pas de PIBaseWdg*"<<endl; return(-3);}
|
---|
949 | if(curw->kind() != PIImage::ClassId)
|
---|
950 | {cout<<"Current window not an Image"<<endl; return(-4);}
|
---|
951 | PIImage* curpimg = (PIImage*)curw;
|
---|
952 | if(curpimg == NULL)
|
---|
953 | {cout<<"Pas de PIImage*"<<endl; return(-5);}
|
---|
954 | P2DArrayAdapter* img = curpimg->Image();
|
---|
955 | if(img == NULL)
|
---|
956 | {cout<<"Pas de Image*"<<endl; return(-6);}
|
---|
957 | string nom = "ouver_";
|
---|
958 |
|
---|
959 | // Definition du pave courant sur la piimage
|
---|
960 | int xc = curpimg->XPave(), yc = curpimg->YPave();
|
---|
961 | int dx = curpimg->XSzPave(), dy = curpimg->YSzPave();
|
---|
962 | int dxym = (dx<dy)?dx:dy; if(dxym%2==0) dxym++; rmax = dxym/2;
|
---|
963 | if(dxym<3||dxym>img->XSize()||dxym>img->YSize())
|
---|
964 | {cout<<"Pave trop petit/grand: "<<dxym<<endl; return(-10);}
|
---|
965 | if(rmin>=rmax)
|
---|
966 | {cout<<"rayon mini="<<rmin<<">= rmax="<<rmax<<endl; return(-11);}
|
---|
967 | if(centre) { // Recentrage autour du pixel le + brillant?
|
---|
968 | int xcnew=-1, ycnew=-1; float pxnew=-1.e20,pxold=-1.e20,px;
|
---|
969 | for(int j=yc-rmax;j<=yc+rmax;j++) {
|
---|
970 | if(j<0 || j>=img->YSize()) continue;
|
---|
971 | for(int i=xc-rmax;i<=xc+rmax;i++) {
|
---|
972 | if(i<0 || i>=img->XSize()) continue;
|
---|
973 | px = (*img)(i,j);
|
---|
974 | if(i==xc && j==yc) pxold = px;
|
---|
975 | if((xcnew==-1 && ycnew==-1) || px>=pxnew) {xcnew=i; ycnew=j; pxnew=px;}
|
---|
976 | // cout<<"xcnew,ycnew,pxnew="<<xcnew<<" "<<ycnew<<" "<<pxnew<<endl;
|
---|
977 | } }
|
---|
978 | if(lp>1) cout<<"Re-centrage(x,y,px): old=("<<xc<<","<<yc<<","<<pxold<<")"
|
---|
979 | <<" -> new=("<<xcnew<<","<<ycnew<<","<<pxnew<<")"<<endl;
|
---|
980 | if(xcnew!=-1 && ycnew!=-1 && pxnew>pxold) {xc=xcnew; yc=ycnew;}
|
---|
981 | }
|
---|
982 | int x0=xc-rmax, y0=yc-rmax, x1=xc+rmax, y1=yc+rmax;
|
---|
983 | if(x0<0||y0<0||x1>=img->XSize()||y1>=img->YSize())
|
---|
984 | {cout<<"Pave hors image"<<endl; return(-12);}
|
---|
985 | int ic = rmax, jc = rmax;
|
---|
986 | ImageR4* pav = new ImageR4(dxym, dxym);
|
---|
987 | {for(int j=-rmax;j<=rmax;j++) for(int i=-rmax;i<=rmax;i++)
|
---|
988 | (*pav)(ic+i,jc+j)=(*img)(xc+i,yc+j);}
|
---|
989 |
|
---|
990 | // Print
|
---|
991 | if(lp>1)
|
---|
992 | cout<<"photom_ouv[cercle="<<cercle<<",typ="<<typ_fond<<"]: pav["
|
---|
993 | <<dx<<","<<dy<<","<<dxym
|
---|
994 | <<"] xc,yc=["<<xc<<","<<yc<<"] ic,jc="<<ic<<","<<jc<<endl
|
---|
995 | <<" (fond="<<fondimpos<<") pxmil="<<(*pav)(ic,ic)
|
---|
996 | <<" -> Rph de "<<rmin<<" a "<<rmax<<endl;
|
---|
997 |
|
---|
998 | // Ouverture des buffers et objets necessaires
|
---|
999 | float *p = new float[dxym*dxym];
|
---|
1000 | r_4 xnt[4];
|
---|
1001 | NTuple *ntfl=NULL, *ntex=NULL;
|
---|
1002 | {char* name[4]={"npx","flux","fond","mag"}; ntfl = new NTuple(4,name);}
|
---|
1003 | {char* name[3]={"k","a","f0"}; ntex = new NTuple(3,name);}
|
---|
1004 |
|
---|
1005 | // Calcul du fond sur les pixels du bord du pave
|
---|
1006 | {
|
---|
1007 | int nf = 0;
|
---|
1008 | for(int i=0;i<dxym;i++) {p[nf]=(*pav)(i,0); nf++; p[nf]=(*pav)(i,dxym-1); nf++;}
|
---|
1009 | for(int j=1;j<dxym-1;j++) {p[nf]=(*pav)(0,j); nf++; p[nf]=(*pav)(dxym-1,j); nf++;}
|
---|
1010 | qsort(p,(size_t) nf,sizeof(float),qSort_Float);
|
---|
1011 | fondbord = (p[nf/2]+p[(nf-1)/2])/2.;
|
---|
1012 | if(lp>0) cout<<"Fond_Bord: "<<fondbord<<" (avec 1 px au bord="<<nf<<")"<<endl;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | // Photometrie d'ouverture variable.
|
---|
1016 | int rfin = -1;
|
---|
1017 | for(int r=rmin;r<=rmax;r++) {
|
---|
1018 | double sum=0.; int ns=0, nf=0;
|
---|
1019 | for(int i=0;i<dxym;i++) for(int j=0;j<dxym;j++) {
|
---|
1020 | double ray2 = (i-ic)*(i-ic)+(j-jc)*(j-jc)-0.1;
|
---|
1021 | if( (cercle && ray2<=r*r) ||
|
---|
1022 | (!cercle && ic-r<=i && i<=ic+r && jc-r<=j && j<=jc+r) )
|
---|
1023 | {sum += (*pav)(i,j); ns++;}
|
---|
1024 | else {p[nf] = (*pav)(i,j); nf++;}
|
---|
1025 | }
|
---|
1026 | if(typ_fond==2) {
|
---|
1027 | if(nf<2) continue;
|
---|
1028 | qsort(p,(size_t) nf,sizeof(float),qSort_Float);
|
---|
1029 | fondautre = (p[nf/2]+p[(nf-1)/2])/2.;
|
---|
1030 | }
|
---|
1031 | double fond=-1.e19;
|
---|
1032 | if(typ_fond==3) fond=fondimpos; else if(typ_fond==2) fond=fondautre; else fond=fondbord;
|
---|
1033 | rfin = r;
|
---|
1034 | xnt[0] = ns;
|
---|
1035 | xnt[1] = sum-fond*ns;
|
---|
1036 | xnt[2] = fond;
|
---|
1037 | xnt[3] = (xnt[1]>0.)? -2.5*log10((double)xnt[1]): -99.;
|
---|
1038 | if(lp>0)
|
---|
1039 | cout<<"Ouv[r="<<r<<",ns="<<xnt[0]<<",nf="<<nf<<"]: fd="<<xnt[2]
|
---|
1040 | <<" fl="<<xnt[1]<<" mag="<<xnt[3]<<endl;
|
---|
1041 | ntfl->Fill(xnt);
|
---|
1042 | }
|
---|
1043 | delete [] p;
|
---|
1044 | int nr = ntfl->NEntry();
|
---|
1045 | if(lp>1) cout<<"Nombre de calculs de flux: "<<nr<<endl;
|
---|
1046 | if(nr<=0)
|
---|
1047 | {cout<<"Pas de flux calcules"<<endl; delete pav; delete ntfl; delete ntex; return(-13);}
|
---|
1048 |
|
---|
1049 | cout<<"Ouv[rouv="<<rfin<<",npix="<<xnt[0]<<"]: fond="<<xnt[2]
|
---|
1050 | <<" flux="<<xnt[1]<<" mag="<<xnt[3]<<endl;
|
---|
1051 |
|
---|
1052 | // Extrapolation: F_mes = F_vrai + npxflux*(Fd_vrai-Fd_mes)
|
---|
1053 | // On fit F_mes=f(npxflux) sur une fenetre glissante de npt_gliss pts.
|
---|
1054 | bool ex = false;
|
---|
1055 | if(nr>=npt_gliss) {
|
---|
1056 | ex = true;
|
---|
1057 | double *npix = new double[nr], *flux = new double[nr], *err = new double[nr];
|
---|
1058 | for(int i=0;i<nr;i++) { ntfl->GetVec(i,xnt); npix[i]=xnt[0]; flux[i]=xnt[1]; err[i]=1.;}
|
---|
1059 | double a,b; int n;
|
---|
1060 | for(int k=0;k<=nr-npt_gliss;k++) {
|
---|
1061 | n = npt_gliss; FitLin(&npix[k],&flux[k],&err[k],&n,&b,&a);
|
---|
1062 | xnt[0]=k; xnt[1]=a; xnt[2]=b; ntex->Fill(xnt);
|
---|
1063 | if(lp>1)
|
---|
1064 | cout<<"Fit["<<k<<","<<k+npt_gliss-1<<"] f0="<<xnt[2]<<" pente="<<xnt[1]<<endl;
|
---|
1065 | }
|
---|
1066 | delete [] npix; delete [] flux; delete [] err;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | // Display des resultats, fenetre 2x2 {{flux%ns,fond%ns},{f0,pente}}
|
---|
1070 | if(ex) app->CreateGraphWin(2,2); else app->CreateGraphWin(1,2);
|
---|
1071 | dummy = nom+"*"; omg.DelObjects(dummy);
|
---|
1072 |
|
---|
1073 | dummy=nom+"pav"; omg.AddObj(pav,dummy);
|
---|
1074 |
|
---|
1075 | string xd=""; string yd=""; string zd,exd,eyd,ezd;
|
---|
1076 | dummy=nom+"flux"; omg.AddObj(ntfl,dummy);
|
---|
1077 | xd="npx"; yd="flux";
|
---|
1078 | omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt);
|
---|
1079 | if(typ_fond==2)
|
---|
1080 | {xd="npx"; yd="fond"; omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt);}
|
---|
1081 | if(ex) {
|
---|
1082 | dummy=nom+"fit"; omg.AddObj(ntex,dummy);
|
---|
1083 | if(typ_fond!=2)
|
---|
1084 | {xd="a"; yd="f0"; omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt);}
|
---|
1085 | xd = "k"; yd = "f0";
|
---|
1086 | omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt);
|
---|
1087 | xd = "k"; yd = "a";
|
---|
1088 | omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt);
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | return(0);
|
---|
1092 | }
|
---|
1093 | #endif
|
---|