source: Sophya/trunk/SophyaPI/ProgPI/sopiamodule.cc@ 3547

Last change on this file since 3547 was 3434, checked in by ansari, 18 years ago

Adaptation commande mollgrid aux nouvelles limites 0..360 degres, -90-90 degres , Reza 11/12/2007

File size: 19.4 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdio.h>
4#include <stdlib.h>
5#include <iostream>
6#include <ctype.h>
7#include <math.h>
8
9#include <typeinfo>
10
11#include <vector>
12#include <string>
13
14#include "piacmd.h"
15#include "nobjmgr.h"
16#include "pistdimgapp.h"
17#include "servnobjm.h"
18#include "tvector.h"
19#include "pitvmaad.h"
20#include "fftpserver.h"
21#include "bruit.h"
22#include "piscdrawwdg.h"
23#include "ctimer.h"
24
25#include "pidrawer.h"
26#include "nomgadapter.h"
27#include "nomskymapadapter.h"
28
29extern "C" {
30void sopiamodule_init();
31void sopiamodule_end();
32}
33
34// --- fonctions pour faire FFT
35void SophyaFFT_forw(string& nom, string& nomout, string dopt);
36void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8=false);
37// void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt);
38void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec=false);
39
40//--- fonctions pour trace d'ellipse d'erreur
41int diag_ellipse(double s1, double s2, double c,
42 double &a, double &b, double& tet, double& phi, int prt=0);
43
44void ellipse2vec(double a, double b, double tet, Vector& evx, Vector& evy,
45 double scale=1., int nbpoints=101);
46
47//--- Declaration du CmdExecutor du module
48class sopiamoduleExecutor : public CmdExecutor {
49public:
50 sopiamoduleExecutor();
51 virtual ~sopiamoduleExecutor();
52 virtual int Execute(string& keyw, vector<string>& args, string& toks);
53};
54
55//--- Classe pour trace de grille en projection spherique Mollweide
56class MollweideGridDrawer : public PIDrawer {
57public:
58 MollweideGridDrawer(int np, int nm, int nx, int ny);
59 MollweideGridDrawer(int np, int nm, double x_larg=0., double x_0=0.,
60 double y_larg=0., double y_0=0.);
61 virtual ~MollweideGridDrawer();
62 virtual void Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
63 virtual void UpdateLimits();
64
65protected:
66 double xlarg, x0;
67 double ylarg, y0;
68 int nbparall, nbmerid;
69 int nbpt;
70 bool fgrevtheta;
71};
72
73/* --Methode-- */
74MollweideGridDrawer::MollweideGridDrawer(int np, int nm, int nx, int ny)
75{
76 x0 = (double)nx/2.;
77 y0 = (double)ny/2.;
78 xlarg = nx;
79 ylarg = ny;
80 nbparall = np;
81 nbmerid = nm;
82 nbpt = ny/5;
83 if ((nbpt % 20) == 0) nbpt++;
84 fgrevtheta = true;
85}
86
87/* --Methode-- */
88MollweideGridDrawer::MollweideGridDrawer(int np, int nm, double x_larg, double x_0,
89 double y_larg, double y_0)
90{
91 if (x_larg > 0.) {
92 xlarg = x_larg; x0 = x_0;
93 }
94 else {
95 xlarg = M_PI*2.; x0 = M_PI;
96 }
97 if (y_larg > 0.) {
98 ylarg = y_larg; y0 = y_0;
99 }
100 else {
101 ylarg = M_PI; y0 = 0.;
102 }
103 nbparall = np;
104 nbmerid = nm;
105 nbpt = 101;
106 fgrevtheta = false;
107}
108
109/* --Methode-- */
110MollweideGridDrawer::~MollweideGridDrawer()
111{
112}
113
114/* --Methode-- */
115void MollweideGridDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
116{
117 PIGrCoord * xxl = new PIGrCoord[nbpt];
118 PIGrCoord * xxr = new PIGrCoord[nbpt];
119 PIGrCoord * yy = new PIGrCoord[nbpt];
120
121 char buff[64];
122
123 // Trace des paralleles
124 g->DrawLine(xmin, y0, xmax, y0);
125 g->DrawString(x0+xlarg/100, y0+ylarg/100, "0");
126
127 // PIGrCoord asc, PIGrCoord desc;
128 int i,k;
129
130 int nkp = (nbparall-1)/2;
131 if (nkp > 0) {
132 double dy = 0.5*ylarg/(double)(nkp+1);
133 double dtd = 90./(double)(nkp+1);
134 for(k=1; k<=nkp; k++) {
135 double fx = sin(acos(2.*(double)k*dy/ylarg))*0.5;
136 double yc = k*dy+y0;
137 g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
138 double ctd = (fgrevtheta) ? -dtd*k : dtd*k;
139 sprintf(buff, "%5.1f", ctd);
140 g->DrawString(x0, yc, buff);
141 g->DrawString(x0-0.3*xlarg, yc, buff);
142 g->DrawString(x0+0.25*xlarg, yc, buff);
143 yc = -k*dy+y0;
144 g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
145 sprintf(buff, "%5.1f", -ctd);
146 g->DrawString(x0, yc, buff);
147 g->DrawString(x0-0.3*xlarg, yc, buff);
148 g->DrawString(x0+0.25*xlarg, yc, buff);
149 }
150 }
151
152 // Trace des meridiennes
153 g->DrawLine(x0, ymin, x0, ymax);
154
155 int nkm = (nbmerid-1)/2;
156 if (nkm < 1) nkm = 1;
157 double dphi = M_PI/nkm;
158 double dpd = 180./(double)(nkm);
159 double dy = ylarg/(nbpt-1);
160 for(k=0; k<nkm; k++) {
161 double phi0 = k*dphi;
162 double dphimil = fabs(phi0-M_PI);
163 if (dphimil < 1.e-6) continue;
164 for(i=0; i<nbpt; i++) {
165 double yc = (double)i*dy+y0-0.5*ylarg;
166 double fx = (2.*fabs(yc-y0)/ylarg <= 1.) ?
167 sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5 : 0.;
168 yy[i] = yc;
169 xxl[i] = x0-fx*xlarg;
170 xxr[i] = x0+fx*xlarg;
171 }
172
173 g->DrawPolygon(xxl, yy, nbpt, false);
174 g->DrawPolygon(xxr, yy, nbpt, false);
175
176 if (k == 0) continue;
177 for(i=-1; i<=1; i++) {
178 double yc = 0.20*i*ylarg+y0;
179 double fx = sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5;
180 double xc = x0-fx*xlarg;
181 sprintf(buff, "%4.1f", dpd*k);
182 g->DrawString(xc, yc, buff);
183 xc = x0+fx*xlarg;
184 sprintf(buff, "%4.1f", 360.-dpd*k);
185 g->DrawString(xc, yc, buff);
186 }
187 }
188
189 delete [] xxl;
190 delete [] xxr;
191 delete [] yy;
192}
193
194/* --Methode-- */
195void MollweideGridDrawer::UpdateLimits()
196{
197 SetLimits(x0-xlarg/2., x0+xlarg/2., y0-ylarg/2., y0+ylarg/2.);
198}
199// Cette fonction calcule les parametres de l'ellipse des erreurs
200// a,b 1/2 grand, petit axe ; tet : Angle du grand axe / Ox
201// A partir de s1 = Sigma_1^2 , s2 = Sigma_2^2 , c = Covar_1_2 = Sigma_1 x Sigma_2 x Rho
202
203//---------------------------------------------------------------------------
204//--- Fonctions de trace d'ellipses d'erreur
205//---------------------------------------------------------------------------
206
207/* Nouvelle-Fonction */
208int diag_ellipse(double s1, double s2, double c,
209 double &a, double &b, double& tet, double& phi, int prt)
210{
211 int rc = 0;
212 // On calcule les valeurs propres de la matrice
213 // | s1 c |
214 // | c s2 |
215 a = b = 0.; // Demi axes de l'ellipse
216 tet = 0.; // Cos theta de l'angle de l'axe de l'ellipse
217 phi = 0.;
218 double det = (s1-s2)*(s1-s2) + 4*c*c;
219 if (det < 0.) {
220 if (prt > 0)
221 cout << "ERREUR : diag_ellipse, ERREUR det = " << det << " <0. s1="
222 << s1 << " s2=" << s2 << " c=" << c << endl;
223 return 99;
224 }
225 // les deux valeurs propres l1, l2
226 double l1 = 0.5*((s1+s2)+sqrt(det));
227 double l2 = 0.5*((s1+s2)-sqrt(det));
228 if (l1 < 0.) {
229 if (prt > 1)
230 cout << "diag_ellipse/Warning l1 < 0. -> a = -sqrt(l1)" << endl;
231 a = -sqrt(-l1);
232 rc += 2;
233 }
234 else a = sqrt(l1);
235 if (l2 < 0.) {
236 if (prt > 1)
237 cout << "diag_ellipse/Warning l2 < 0. -> b = -sqrt(l2)" << endl;
238 b = -sqrt(-l2);
239 rc += 4;
240 }
241 else b = sqrt(l2);
242
243 if (fabs(c) > 1.e-9) tet = atan2((l1-s1), c);
244 else {
245 if (prt > 2)
246 cout << "diag_ellipse/Warning c (Correlation) = 0. -> Tet=0 " << endl;
247 }
248 // Calcul de tan(2 phi)
249 double t2phi = 0.;
250 if (fabs(s1-s2) > 1.e-9) {
251 t2phi = 2.*c/(s1-s2);
252 phi = atan(t2phi)/2.;
253 }
254 else {
255 if (prt > 3)
256 cout << "diag_ellipse/Warning fabs(s1-s2)=" << fabs(s1-s2)
257 << " -> Phi=Pi/4 ... " << endl;
258 phi = 0.25*M_PI;
259 }
260 if (prt > 0)
261 cout << "diag_ellipse/Info: s1=" << s1 << " s2=" << s2
262 << " c=" << c << " ---> l1=" << l1 << " l2=" << l2
263 << "\n a= " << a << " b=" << b << " Theta= " << tet
264 << "( " << tet*2/M_PI << " xPi/2) Phi= " << phi
265 << "( " << phi*2/M_PI << " x Pi/2) " << endl;
266 return rc;
267}
268
269/* Nouvelle-Fonction */
270void ellipse2vec(double a, double b, double tet, Vector& evx, Vector& evy,
271 double scale, int nbpoints)
272{
273 a *= scale;
274 b *= scale;
275
276 int npt = nbpoints;
277 double pas = M_PI*2./(npt-1);
278 evx.SetSize(npt+1);
279 evy.SetSize(npt+1);
280 for(int i=0; i<=npt; i++) {
281 double t = i*pas;
282 double xr = a*cos(t);
283 double yr = b*sin(t);
284 double ar = atan2(yr, xr);
285 double r = sqrt(xr*xr+yr*yr);
286 evx(i) = r*cos(ar+tet);
287 evy(i) = r*sin(ar+tet);
288 }
289 return;
290}
291
292//---------------------------------------------------------------------------
293//--- Classe sopiamoduleExecutor
294//---------------------------------------------------------------------------
295/* --Methode-- */
296sopiamoduleExecutor::sopiamoduleExecutor()
297{
298
299PIACmd * mpiac;
300NamedObjMgr omg;
301mpiac = omg.GetImgApp()->CmdInterpreter();
302
303string kw,usage;
304// ------------- Help group FFT
305string hgrp = "FFT";
306
307kw = "fftforw";
308usage = "FFT on a vector -> computes forward Fourier transform";
309usage += "\n Usage: fftforw vecSig vecSpec [graphic_att] ";
310usage += "\n vecSpec = FFTForward(vecSig) ";
311usage += "\n vecSig: Input data vector of type r_8 or complex<r_8> ";
312usage += "\n vecSpec: Output data vector of type complex<r_8> ";
313usage += "\n See also : fftback fftfilter fftfuncfilter ";
314mpiac->RegisterCommand(kw, usage, this, hgrp);
315
316kw = "fftback";
317usage = "FFT on a vector -> computes backward Fourier transform ";
318usage += "\n Usage: fftback vecSpec vecSig [graphic_att] [C/Z] ";
319usage += "\n vecSig = FFTBackward(vecSpec) ";
320usage += "\n vecSpec: Input data vector of type complex<r_8> ";
321usage += "\n vecSig: Output Data vector of type r_8 (default) ";
322usage += "\n or complex<r_8> if C/Z specified or ";
323usage += "\n vecSpec computed by fftforw on a complex vector";
324usage += "\n See also : fftforw fftfilter fftfuncfilter ";
325mpiac->RegisterCommand(kw, usage, this, hgrp);
326
327kw = "fftfilter";
328usage = "Filter (multiply) vecSpec (vector complex<r_8>) by Filter (vector<r_8>)";
329usage += "\n Usage: fftfilter vecSpec FilterVec vecFiltSpec [graphic_att] ";
330usage += "\n vecFiltSpec(i) = vecSpec(i) * complex(FilterVec(i),0) ";
331usage += "\n See also : fftforw fftbackw fftfuncfilter ";
332mpiac->RegisterCommand(kw, usage, this, hgrp);
333
334kw = "fftfuncfilter";
335usage = "Filter (multiply) vecSpec (vector complex<r_8>) by FilterFunc(i) ";
336usage += "\n Usage: fftfilter vecSpec FilterFunc vecFiltSpec [graphic_att] ";
337usage += "\n vecFiltSpec(i) = vecSpec(i) * complex(FilterFunc(i),0) ";
338usage += "\n See also : fftforw fftbackw fftfilter ";
339mpiac->RegisterCommand(kw, usage, this, hgrp);
340
341//--------------------------
342hgrp = "SophyaCmd";
343
344kw = "mollgrid";
345usage = "Creates a spherical coordinate grid in Molleweide projection ";
346usage += "\n Usage: mollgrid [Nb_Parallel] [Nb_Meridien] [graphic_att] ";
347mpiac->RegisterCommand(kw, usage, this, hgrp);
348
349kw = "setprjmoldefval";
350usage = "Set default value for Molleweide projection of spherical maps (outside maps)";
351usage += "\n Usage: setprjmoldefval OutOfMapValue ";
352mpiac->RegisterCommand(kw, usage, this, hgrp);
353
354//--- Trace d'ellipse d'erreur
355hgrp = "SophyaCmd";
356kw = "errorellipse";
357usage = " Error ellipse plotter \n";
358usage += "Usage: errellipse [-fill] xc yc sx2 sy2 cov [scale=1] [gr_opt] [npt=128] \n";
359usage = " Adds an error ellipse, specified by its center (xc,yc) \n";
360usage += " and error matrix (covariance) parameters SigX^2,SigY^2,Covar \n" ;
361usage += " A global scaling parameters scale , graphic attributes and \n";
362usage += " nomber of points can optionnaly be specified\n";
363usage += " if the -fill flag specified, plots a filled ellipse \n" ;
364mpiac->RegisterCommand(kw, usage, this, hgrp);
365
366}
367
368/* --Methode-- */
369sopiamoduleExecutor::~sopiamoduleExecutor()
370{
371}
372
373/* --Methode-- */
374int sopiamoduleExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
375{
376
377if (kw == "powerspec" || kw == "fftforw") {
378 if (tokens.size() < 2) {
379 cout << "Usage: fftforw vecSig vecSpec [graphic_att] " << endl;
380 return(0);
381 }
382 if (tokens.size() < 3) tokens.push_back((string)"");
383 SophyaFFT_forw(tokens[0], tokens[1], tokens[2]);
384}
385else if (kw == "fftback") {
386 if (tokens.size() < 2) {
387 cout << "Usage: fftback vecSpec vecSig [graphic_att] [C/Z]" << endl;
388 return(0);
389 }
390 bool forcez8 = false;
391 if (tokens.size() > 3) {
392 char fcz8 = tolower(tokens[3][0]);
393 if ( (fcz8 == 'c') || (fcz8 == 'z') ) forcez8 = true;
394 }
395 if (tokens.size() < 3) tokens.push_back((string)"");
396 SophyaFFT_back(tokens[0], tokens[1], tokens[2], forcez8);
397}
398else if ( (kw == "fftfilter") || (kw == "fftfuncfilter") ) {
399 if (tokens.size() < 3) {
400 cout << "Usage: fftfilter/fftfuncfilter vecSpec Filter vecFiltSpec [graphic_att]" << endl;
401 return(0);
402 }
403 if (tokens.size() < 4) tokens.push_back((string)"");
404 bool fgvec = false;
405 if (kw == "fftfilter") fgvec = true;
406 SophyaFFT_filter(tokens[0], tokens[1], tokens[2], tokens[3], fgvec);
407}
408
409else if (kw == "prjmoldefval") {
410 if (tokens.size() < 1) {
411 cout << "Usage: prjmoldefval OutOfMapValue" << endl;
412 return(0);
413 }
414 Set_Project_Mol_DefVal(atof(tokens[0].c_str()) );
415}
416// Grille de coordonnees en projection molleweide
417else if (kw == "mollgrid") {
418 NamedObjMgr omg;
419 MollweideGridDrawer * mollgrid = NULL;
420 string dopt="";
421 int np = 5;
422 int nm = 5;
423 if (tokens.size() > 0) np = atoi(tokens[0].c_str());
424 if (tokens.size() > 1) nm = atoi(tokens[1].c_str());
425 if (tokens.size() > 2) dopt = tokens[2];
426 mollgrid = new MollweideGridDrawer(np, nm, 360., 180., 180., 0.);
427 cout << " mollgrid: Creating MollweideGridDrawer(" << np << "," << nm << ")" << endl;
428
429 if (mollgrid == NULL) {
430 cout << "mollgridsph Error/BUG !!! mollgrid = NULL " << endl;
431 return(0);
432 }
433
434 int wrsid = 0;
435 //bool fgsr = true;
436
437 string name = "mollgrid";
438 wrsid = omg.GetImgApp()->DispScDrawer(mollgrid, name, dopt);
439}
440// Trace d'ellipse d'erreur
441else if (kw == "errorellipse") {
442 if ((tokens.size()<5) || ((tokens.size()>0)&&(tokens[0]=="-fill")&&(tokens.size()<6))) {
443 cout << "Usage: errorellipse [-fill] xc yc sx2 sy2 cov [scale=1 gropt npt=128]" << endl;
444 return(1);
445 }
446 bool fgfill = false;
447 unsigned int offtok = 0;
448 if (tokens[0] == "-fill") {
449 offtok = 1; fgfill = true;
450 }
451 double xc = atof(tokens[0+offtok].c_str());
452 double yc = atof(tokens[1+offtok].c_str());
453 double sx = atof(tokens[2+offtok].c_str());
454 double sy = atof(tokens[3+offtok].c_str());
455 double cov = atof(tokens[4+offtok].c_str());
456 double scale = 1.;
457 if (tokens.size() > (5+offtok)) scale = atof(tokens[5+offtok].c_str());
458 string gropt;
459 if (tokens.size() > (6+offtok)) gropt = tokens[6+offtok];
460 int npt = 128;
461 if (tokens.size() > (7+offtok)) npt = atoi(tokens[7+offtok].c_str());
462
463 double a,b,tet,phi;
464 diag_ellipse(sx, sy, cov, a, b, tet, phi, 1);
465 Vector evx, evy;
466 ellipse2vec(a,b,tet,evx, evy, scale, npt+1);
467 vector<double> vx, vy;
468 for(int k=0; k<evx.Size(); k++) {
469 vx.push_back(evx(k)+xc);
470 vy.push_back(evy(k)+yc);
471 }
472 NamedObjMgr omg;
473 omg.GetImgApp()->AddPoly(vx, vy, gropt, fgfill, false);
474}
475
476return(0);
477
478}
479
480static sopiamoduleExecutor * piaerex = NULL;
481/* Nouvelle-Fonction */
482void sopiamodule_init()
483{
484// Fonction d'initialisation du module
485// Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
486if (piaerex) delete piaerex;
487piaerex = new sopiamoduleExecutor;
488}
489
490/* Nouvelle-Fonction */
491void sopiamodule_end()
492{
493// Desactivation du module
494if (piaerex) delete piaerex;
495piaerex = NULL;
496}
497
498
499/* Nouvelle-Fonction */
500void SophyaFFT_forw(string& nom, string& nomout, string dopt)
501{
502//Timer tm("powerspec");
503NamedObjMgr omg;
504AnyDataObj* obj=omg.GetObj(nom);
505if (obj == NULL) {
506 cout<<"SophyaFFT_forw() Error , Pas d'objet de nom "<<nom<<endl;
507 return;
508}
509
510TVector<r_8>* vin = dynamic_cast<TVector<r_8> *>(obj);
511TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj);
512if (vin == NULL && vinc == NULL) {
513 cout<<"SophyaFFT_forw() Error , Objet n'est pas un vecteur r_8 ou complex<r_8>"<<endl;
514 return;
515}
516TVector< complex<r_8> > * vout = new TVector< complex<r_8> > ;
517FFTPackServer ffts;
518if(vin!=NULL) {
519 cout<<"SophyaFFT_forw() - Computing FFT of TVector<r_8> of size "<<vin->NElts()<< endl;
520 ffts.FFTForward(*vin, *vout);
521 cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl;
522 vout->Info()["FFTTYPE"]="F:R8->Z8";
523} else {
524 cout<<"SophyaFFT_forw() - Computing FFT of vector TVector<complex<r_8>> of size "<<vinc->NElts()<< endl;
525 ffts.FFTForward(*vinc, *vout);
526 cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl;
527 vout->Info()["FFTTYPE"] = "F:Z8->Z8";
528}
529// cout << " SophyaFFT - FFT done " << endl;
530 // tm.Split(" FFT done ");
531
532omg.AddObj(vout, nomout);
533omg.DisplayObj(nomout, dopt);
534return;
535
536}
537
538
539/* Nouvelle-Fonction */
540void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8)
541{
542 //Timer tm("powerspec");
543NamedObjMgr omg;
544AnyDataObj* obj=omg.GetObj(nom);
545if (obj == NULL) {
546 cout << "SophyaFFT_back() Error , Pas d'objet de nom " << nom << endl;
547 return;
548}
549
550TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj);
551if (vinc == NULL) {
552 cout << "SophyaFFT_back() Error , Objet n'est pas un vecteur complex<r_8>" << endl;
553 return;
554 }
555
556TVector< r_8 > * vout = NULL;
557TVector< complex<r_8> > * voutc = NULL;
558
559if (forcez8 || (vinc->Info().GetS("FFTTYPE") == "F:Z8->Z8") ) {
560 voutc = new TVector< complex<r_8> >;
561}
562else {
563 vout = new TVector< r_8 >;
564}
565
566FFTPackServer ffts;
567cout << "SophyaFFT_back() - Computing Backward FFT of vector size " << vinc->NElts() << endl;
568if(vout!=NULL) {
569 ffts.FFTBackward(*vinc, *vout);
570 cout<<"...Output TVector<r_8> of size: "<<vout->NElts()<<endl;
571 vout->Info()["FFTTYPE"]="B:Z8->R8";
572 omg.AddObj(vout, nomout);
573} else {
574 ffts.FFTBackward(*vinc, *voutc);
575 cout<<"...Output TVector<complex<r_8>> of size: "<<voutc->NElts()<<endl;
576 voutc->Info()["FFTTYPE"]="B:Z8->Z8";
577 omg.AddObj(voutc, nomout);
578}
579
580omg.DisplayObj(nomout, dopt);
581return;
582}
583
584/* Nouvelle-Fonction */
585void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt)
586{
587NamedObjMgr omg;
588AnyDataObj* obj=omg.GetObj(nomvec);
589if(obj == NULL) {
590 cout<<"SophyaFFT_crefilter() Error , Pas d'objet de nom "<<nomvec<<endl;
591 return;
592}
593
594TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj);
595if(vfft == NULL) {
596 cout<<"SophyaFFT_crefilter() Error , Objet "<<nomvec<<" n'est pas un Tvector<complex<r_8>>"<< endl;
597 return;
598}
599sa_size_t n = vfft->Size();
600if(n<=0) return;
601
602cout<<"Creating filter "<<nomfilter<<"("<<n<<") from vec "<<nomvec<<" with fun "<<func<<endl;
603omg.GetServiceObj()->PlotFunc(func,nomfilter,0.,(double)n,n,dopt);
604}
605
606/* Nouvelle-Fonction */
607void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec)
608{
609NamedObjMgr omg;
610AnyDataObj* obj=omg.GetObj(nom);
611if(obj == NULL) {
612 cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nom<<endl;
613 return;
614}
615TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj);
616if(vfft == NULL) {
617 cout<<"SophyaFFT_filter() Error , Objet "<<nom<<" n'est pas un Tvector<complex<r_8>>"<< endl;
618 return;
619}
620int n = vfft->Size();
621if(n<=0) {
622 cout<<"SophyaFFT_filter() Error , vector size = 0 " << endl;
623 return;
624}
625
626string nomfilter = "/autoc/fft_filter";
627if (fgvec) {
628 nomfilter = filt;
629 cout<<"SophyaFFT_filter(): using vector " << filt << " for filtering spectrum ..." << endl;
630}
631else {
632 cout<<"SophyaFFT_filter(): Creating filter vector "<<nomfilter
633 <<" from function " << filt << endl;
634 string fcrdopt = "nodisp";
635 omg.GetServiceObj()->PlotFunc(filt, nomfilter, 0., (double)n, n, fcrdopt);
636}
637AnyDataObj* objfilter=omg.GetObj(nomfilter);
638if(objfilter == NULL) {
639 cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nomfilter<<endl;
640 return;
641}
642
643TVector<r_8>* vfilter = dynamic_cast<TVector<r_8>*>(objfilter);
644if(vfft == NULL) {
645 cout<<"SophyaFFT_filter() Error , Objet "<<nomfilter<<" n'est pas un Tvector<r_8>"<<endl;
646 return;
647}
648
649n = (vfilter->Size()<vfft->Size()) ? vfilter->Size(): vfft->Size();
650
651cout<<" SophyaFFT_filter(): filtering from 0 to "<<n<<endl;
652TVector< complex<r_8> > * filtfft = new TVector< complex<r_8> >(*vfft, false);
653for(int i=0;i<n;i++) (*filtfft)(i) *= (*vfilter)(i);
654
655cout<<"SophyaFFT_filter(): Adding obj: " << outvec << endl;
656omg.AddObj(filtfft, outvec);
657omg.DisplayObj(outvec, dopt);
658return;
659}
Note: See TracBrowser for help on using the repository browser.