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 |
|
---|
29 | extern "C" {
|
---|
30 | void sopiamodule_init();
|
---|
31 | void sopiamodule_end();
|
---|
32 | }
|
---|
33 |
|
---|
34 | void SophyaFFT_forw(string& nom, string& nomout, string dopt);
|
---|
35 | void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8=false);
|
---|
36 | // void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt);
|
---|
37 | void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec=false);
|
---|
38 |
|
---|
39 | class sopiamoduleExecutor : public CmdExecutor {
|
---|
40 | public:
|
---|
41 | sopiamoduleExecutor();
|
---|
42 | virtual ~sopiamoduleExecutor();
|
---|
43 | virtual int Execute(string& keyw, vector<string>& args, string& toks);
|
---|
44 | };
|
---|
45 |
|
---|
46 | // Classe pour trace de grille en projection spherique Mollweide
|
---|
47 | class MollweideGridDrawer : public PIDrawer {
|
---|
48 | public:
|
---|
49 | MollweideGridDrawer(int np, int nm, int nx, int ny);
|
---|
50 | MollweideGridDrawer(int np, int nm, double x_larg=0., double x_0=0.,
|
---|
51 | double y_larg=0., double y_0=0.);
|
---|
52 | virtual ~MollweideGridDrawer();
|
---|
53 | virtual void Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
|
---|
54 | virtual void UpdateLimits();
|
---|
55 |
|
---|
56 | protected:
|
---|
57 | double xlarg, x0;
|
---|
58 | double ylarg, y0;
|
---|
59 | int nbparall, nbmerid;
|
---|
60 | int nbpt;
|
---|
61 | bool fgrevtheta;
|
---|
62 | };
|
---|
63 |
|
---|
64 | /* --Methode-- */
|
---|
65 | MollweideGridDrawer::MollweideGridDrawer(int np, int nm, int nx, int ny)
|
---|
66 | {
|
---|
67 | x0 = (double)nx/2.;
|
---|
68 | y0 = (double)ny/2.;
|
---|
69 | xlarg = nx;
|
---|
70 | ylarg = ny;
|
---|
71 | nbparall = np;
|
---|
72 | nbmerid = nm;
|
---|
73 | nbpt = ny/5;
|
---|
74 | if ((nbpt % 20) == 0) nbpt++;
|
---|
75 | fgrevtheta = true;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* --Methode-- */
|
---|
79 | MollweideGridDrawer::MollweideGridDrawer(int np, int nm, double x_larg, double x_0,
|
---|
80 | double y_larg, double y_0)
|
---|
81 | {
|
---|
82 | if (x_larg > 0.) {
|
---|
83 | xlarg = x_larg; x0 = x_0;
|
---|
84 | }
|
---|
85 | else {
|
---|
86 | xlarg = M_PI*2.; x0 = M_PI;
|
---|
87 | }
|
---|
88 | if (y_larg > 0.) {
|
---|
89 | ylarg = y_larg; y0 = y_0;
|
---|
90 | }
|
---|
91 | else {
|
---|
92 | ylarg = M_PI; y0 = 0.;
|
---|
93 | }
|
---|
94 | nbparall = np;
|
---|
95 | nbmerid = nm;
|
---|
96 | nbpt = 101;
|
---|
97 | fgrevtheta = false;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /* --Methode-- */
|
---|
101 | MollweideGridDrawer::~MollweideGridDrawer()
|
---|
102 | {
|
---|
103 | }
|
---|
104 |
|
---|
105 | /* --Methode-- */
|
---|
106 | void MollweideGridDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
107 | {
|
---|
108 | PIGrCoord * xxl = new PIGrCoord[nbpt];
|
---|
109 | PIGrCoord * xxr = new PIGrCoord[nbpt];
|
---|
110 | PIGrCoord * yy = new PIGrCoord[nbpt];
|
---|
111 |
|
---|
112 | char buff[64];
|
---|
113 |
|
---|
114 | // Trace des paralleles
|
---|
115 | g->DrawLine(xmin, y0, xmax, y0);
|
---|
116 | g->DrawString(x0+xlarg/100, y0+ylarg/100, "0");
|
---|
117 |
|
---|
118 | // PIGrCoord asc, PIGrCoord desc;
|
---|
119 | int i,k;
|
---|
120 |
|
---|
121 | int nkp = (nbparall-1)/2;
|
---|
122 | if (nkp > 0) {
|
---|
123 | double dy = 0.5*ylarg/(double)(nkp+1);
|
---|
124 | double dtd = 90./(double)(nkp+1);
|
---|
125 | for(k=1; k<=nkp; k++) {
|
---|
126 | double fx = sin(acos(2.*(double)k*dy/ylarg))*0.5;
|
---|
127 | double yc = k*dy+y0;
|
---|
128 | g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
|
---|
129 | double ctd = (fgrevtheta) ? -dtd*k : dtd*k;
|
---|
130 | sprintf(buff, "%5.1f", ctd);
|
---|
131 | g->DrawString(x0, yc, buff);
|
---|
132 | g->DrawString(x0-0.3*xlarg, yc, buff);
|
---|
133 | g->DrawString(x0+0.25*xlarg, yc, buff);
|
---|
134 | yc = -k*dy+y0;
|
---|
135 | g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
|
---|
136 | sprintf(buff, "%5.1f", -ctd);
|
---|
137 | g->DrawString(x0, yc, buff);
|
---|
138 | g->DrawString(x0-0.3*xlarg, yc, buff);
|
---|
139 | g->DrawString(x0+0.25*xlarg, yc, buff);
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | // Trace des meridiennes
|
---|
144 | g->DrawLine(x0, ymin, x0, ymax);
|
---|
145 |
|
---|
146 | int nkm = (nbmerid-1)/2;
|
---|
147 | if (nkm < 1) nkm = 1;
|
---|
148 | double dphi = M_PI/nkm;
|
---|
149 | double dpd = 180./(double)(nkm);
|
---|
150 | double dy = ylarg/(nbpt-1);
|
---|
151 | for(k=0; k<nkm; k++) {
|
---|
152 | double phi0 = k*dphi;
|
---|
153 | double dphimil = fabs(phi0-M_PI);
|
---|
154 | if (dphimil < 1.e-6) continue;
|
---|
155 | for(i=0; i<nbpt; i++) {
|
---|
156 | double yc = (double)i*dy+y0-0.5*ylarg;
|
---|
157 | double fx = (2.*fabs(yc-y0)/ylarg <= 1.) ?
|
---|
158 | sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5 : 0.;
|
---|
159 | yy[i] = yc;
|
---|
160 | xxl[i] = x0-fx*xlarg;
|
---|
161 | xxr[i] = x0+fx*xlarg;
|
---|
162 | }
|
---|
163 |
|
---|
164 | g->DrawPolygon(xxl, yy, nbpt, false);
|
---|
165 | g->DrawPolygon(xxr, yy, nbpt, false);
|
---|
166 |
|
---|
167 | if (k == 0) continue;
|
---|
168 | for(i=-1; i<=1; i++) {
|
---|
169 | double yc = 0.20*i*ylarg+y0;
|
---|
170 | double fx = sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5;
|
---|
171 | double xc = x0-fx*xlarg;
|
---|
172 | sprintf(buff, "%4.1f", dpd*k);
|
---|
173 | g->DrawString(xc, yc, buff);
|
---|
174 | xc = x0+fx*xlarg;
|
---|
175 | sprintf(buff, "%4.1f", 360.-dpd*k);
|
---|
176 | g->DrawString(xc, yc, buff);
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | delete [] xxl;
|
---|
181 | delete [] xxr;
|
---|
182 | delete [] yy;
|
---|
183 | }
|
---|
184 |
|
---|
185 | /* --Methode-- */
|
---|
186 | void MollweideGridDrawer::UpdateLimits()
|
---|
187 | {
|
---|
188 | SetLimits(x0-xlarg/2., x0+xlarg/2., y0-ylarg/2., y0+ylarg/2.);
|
---|
189 | }
|
---|
190 |
|
---|
191 | /* --Methode-- */
|
---|
192 | sopiamoduleExecutor::sopiamoduleExecutor()
|
---|
193 | {
|
---|
194 |
|
---|
195 | PIACmd * mpiac;
|
---|
196 | NamedObjMgr omg;
|
---|
197 | mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
198 |
|
---|
199 | string kw,usage;
|
---|
200 | // ------------- Help group FFT
|
---|
201 | string hgrp = "FFT";
|
---|
202 |
|
---|
203 | kw = "fftforw";
|
---|
204 | usage = "FFT on a vector -> computes forward Fourier transform";
|
---|
205 | usage += "\n Usage: fftforw vecSig vecSpec [graphic_att] ";
|
---|
206 | usage += "\n vecSpec = FFTForward(vecSig) ";
|
---|
207 | usage += "\n vecSig: Input data vector of type r_8 or complex<r_8> ";
|
---|
208 | usage += "\n vecSpec: Output data vector of type complex<r_8> ";
|
---|
209 | usage += "\n See also : fftback fftfilter fftfuncfilter ";
|
---|
210 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
211 |
|
---|
212 | kw = "fftback";
|
---|
213 | usage = "FFT on a vector -> computes backward Fourier transform ";
|
---|
214 | usage += "\n Usage: fftback vecSpec vecSig [graphic_att] [C/Z] ";
|
---|
215 | usage += "\n vecSig = FFTBackward(vecSpec) ";
|
---|
216 | usage += "\n vecSpec: Input data vector of type complex<r_8> ";
|
---|
217 | usage += "\n vecSig: Output Data vector of type r_8 (default) ";
|
---|
218 | usage += "\n or complex<r_8> if C/Z specified or ";
|
---|
219 | usage += "\n vecSpec computed by fftforw on a complex vector";
|
---|
220 | usage += "\n See also : fftforw fftfilter fftfuncfilter ";
|
---|
221 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
222 |
|
---|
223 | kw = "fftfilter";
|
---|
224 | usage = "Filter (multiply) vecSpec (vector complex<r_8>) by Filter (vector<r_8>)";
|
---|
225 | usage += "\n Usage: fftfilter vecSpec FilterVec vecFiltSpec [graphic_att] ";
|
---|
226 | usage += "\n vecFiltSpec(i) = vecSpec(i) * complex(FilterVec(i),0) ";
|
---|
227 | usage += "\n See also : fftforw fftbackw fftfuncfilter ";
|
---|
228 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
229 |
|
---|
230 | kw = "fftfuncfilter";
|
---|
231 | usage = "Filter (multiply) vecSpec (vector complex<r_8>) by FilterFunc(i) ";
|
---|
232 | usage += "\n Usage: fftfilter vecSpec FilterFunc vecFiltSpec [graphic_att] ";
|
---|
233 | usage += "\n vecFiltSpec(i) = vecSpec(i) * complex(FilterFunc(i),0) ";
|
---|
234 | usage += "\n See also : fftforw fftbackw fftfilter ";
|
---|
235 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
236 |
|
---|
237 | //--------------------------
|
---|
238 | hgrp = "SophyaCmd";
|
---|
239 |
|
---|
240 | kw = "mollgridsph";
|
---|
241 | usage = "Creates a spherical coordinate grid in Molleweide projection ";
|
---|
242 | usage += "\n Usage: mollgridsph NameSphericalMap [Nb_Parallel Nb_Meridien graphic_att] ";
|
---|
243 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
244 |
|
---|
245 | kw = "mollgrid";
|
---|
246 | usage = "Creates a spherical coordinate grid in Molleweide projection ";
|
---|
247 | usage += "\n Usage: mollgrid [Nb_Parallel Nb_Meridien graphic_att] ";
|
---|
248 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
249 |
|
---|
250 | kw = "setprjmoldefval";
|
---|
251 | usage = "Set default value for Molleweide projection of spherical maps (outside maps)";
|
---|
252 | usage += "\n Usage: setprjmoldefval OutOfMapValue ";
|
---|
253 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
254 |
|
---|
255 | }
|
---|
256 |
|
---|
257 | /* --Methode-- */
|
---|
258 | sopiamoduleExecutor::~sopiamoduleExecutor()
|
---|
259 | {
|
---|
260 | }
|
---|
261 |
|
---|
262 | /* --Methode-- */
|
---|
263 | int sopiamoduleExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
264 | {
|
---|
265 |
|
---|
266 | if (kw == "powerspec" || kw == "fftforw") {
|
---|
267 | if (tokens.size() < 2) {
|
---|
268 | cout << "Usage: fftforw vecSig vecSpec [graphic_att] " << endl;
|
---|
269 | return(0);
|
---|
270 | }
|
---|
271 | if (tokens.size() < 3) tokens.push_back((string)"");
|
---|
272 | SophyaFFT_forw(tokens[0], tokens[1], tokens[2]);
|
---|
273 | }
|
---|
274 | else if (kw == "fftback") {
|
---|
275 | if (tokens.size() < 2) {
|
---|
276 | cout << "Usage: fftback vecSpec vecSig [graphic_att] [C/Z]" << endl;
|
---|
277 | return(0);
|
---|
278 | }
|
---|
279 | bool forcez8 = false;
|
---|
280 | if (tokens.size() > 3) {
|
---|
281 | char fcz8 = tolower(tokens[3][0]);
|
---|
282 | if ( (fcz8 == 'c') || (fcz8 == 'z') ) forcez8 = true;
|
---|
283 | }
|
---|
284 | if (tokens.size() < 3) tokens.push_back((string)"");
|
---|
285 | SophyaFFT_back(tokens[0], tokens[1], tokens[2], forcez8);
|
---|
286 | }
|
---|
287 | else if ( (kw == "fftfilter") || (kw == "fftfuncfilter") ) {
|
---|
288 | if (tokens.size() < 3) {
|
---|
289 | cout << "Usage: fftfilter/fftfuncfilter vecSpec Filter vecFiltSpec [graphic_att]" << endl;
|
---|
290 | return(0);
|
---|
291 | }
|
---|
292 | if (tokens.size() < 4) tokens.push_back((string)"");
|
---|
293 | bool fgvec = false;
|
---|
294 | if (kw == "fftfilter") fgvec = true;
|
---|
295 | SophyaFFT_filter(tokens[0], tokens[1], tokens[2], tokens[3], fgvec);
|
---|
296 | }
|
---|
297 |
|
---|
298 | else if (kw == "prjmoldefval") {
|
---|
299 | if (tokens.size() < 1) {
|
---|
300 | cout << "Usage: prjmoldefval OutOfMapValue" << endl;
|
---|
301 | return(0);
|
---|
302 | }
|
---|
303 | Set_Project_Mol_DefVal(atof(tokens[0].c_str()) );
|
---|
304 | }
|
---|
305 |
|
---|
306 | else if ( (kw == "mollgridsph") || (kw == "mollgrid") ) {
|
---|
307 | NamedObjMgr omg;
|
---|
308 | MollweideGridDrawer * mollgrid = NULL;
|
---|
309 | string dopt="";
|
---|
310 | if (kw == "mollgridsph") {
|
---|
311 | if (tokens.size() < 1) {
|
---|
312 | cout << "Usage: mollgridsph NameSphericalMap [Nb_Parallel Nb_Meridien graphic_att]"
|
---|
313 | << endl;
|
---|
314 | return(0);
|
---|
315 | }
|
---|
316 | int np = 5;
|
---|
317 | int nm = 5;
|
---|
318 | dopt = "same,thinline";
|
---|
319 | if (tokens.size() > 1) np = atoi(tokens[1].c_str());
|
---|
320 | if (tokens.size() > 2) nm = atoi(tokens[2].c_str());
|
---|
321 | if (tokens.size() > 3) dopt = tokens[3];
|
---|
322 | NObjMgrAdapter* obja = omg.GetObjAdapter(tokens[0]);
|
---|
323 | if (obja == NULL) {
|
---|
324 | cout << "mollgridsph Error , No object with name " << tokens[0] << endl;
|
---|
325 | return(0);
|
---|
326 | }
|
---|
327 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
328 | if (arr == NULL) {
|
---|
329 | cout << "mollgridsph Error , object has non 2DArrayAdapter - Not a spherical map "
|
---|
330 | << endl;
|
---|
331 | return(0);
|
---|
332 | }
|
---|
333 | int nx = arr->XSize();
|
---|
334 | int ny = arr->YSize();
|
---|
335 | delete arr;
|
---|
336 | mollgrid = new MollweideGridDrawer(np, nm, nx, ny);
|
---|
337 | cout << " mollgridsph: Creating MollweideGridDrawer() for object" << tokens[0] << endl;
|
---|
338 | }
|
---|
339 | else if (kw == "mollgrid") {
|
---|
340 | int np = 5;
|
---|
341 | int nm = 5;
|
---|
342 | if (tokens.size() > 0) np = atoi(tokens[0].c_str());
|
---|
343 | if (tokens.size() > 1) nm = atoi(tokens[1].c_str());
|
---|
344 | if (tokens.size() > 2) dopt = tokens[2];
|
---|
345 | mollgrid = new MollweideGridDrawer(np, nm);
|
---|
346 | cout << " mollgrid: Creating MollweideGridDrawer(" << np << "," << nm << ")" << endl;
|
---|
347 | }
|
---|
348 |
|
---|
349 | if (mollgrid == NULL) {
|
---|
350 | cout << "mollgridsph Error/BUG !!! mollgrid = NULL " << endl;
|
---|
351 | return(0);
|
---|
352 | }
|
---|
353 |
|
---|
354 | int wrsid = 0;
|
---|
355 | //bool fgsr = true;
|
---|
356 |
|
---|
357 | string name = "mollgrid";
|
---|
358 | wrsid = omg.GetImgApp()->DispScDrawer(mollgrid, name, dopt);
|
---|
359 | }
|
---|
360 |
|
---|
361 | return(0);
|
---|
362 |
|
---|
363 | }
|
---|
364 |
|
---|
365 | static sopiamoduleExecutor * piaerex = NULL;
|
---|
366 | /* Nouvelle-Fonction */
|
---|
367 | void sopiamodule_init()
|
---|
368 | {
|
---|
369 | // Fonction d'initialisation du module
|
---|
370 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
|
---|
371 | if (piaerex) delete piaerex;
|
---|
372 | piaerex = new sopiamoduleExecutor;
|
---|
373 | }
|
---|
374 |
|
---|
375 | /* Nouvelle-Fonction */
|
---|
376 | void sopiamodule_end()
|
---|
377 | {
|
---|
378 | // Desactivation du module
|
---|
379 | if (piaerex) delete piaerex;
|
---|
380 | piaerex = NULL;
|
---|
381 | }
|
---|
382 |
|
---|
383 |
|
---|
384 | /* Nouvelle-Fonction */
|
---|
385 | void SophyaFFT_forw(string& nom, string& nomout, string dopt)
|
---|
386 | {
|
---|
387 | //Timer tm("powerspec");
|
---|
388 | NamedObjMgr omg;
|
---|
389 | AnyDataObj* obj=omg.GetObj(nom);
|
---|
390 | if (obj == NULL) {
|
---|
391 | cout<<"SophyaFFT_forw() Error , Pas d'objet de nom "<<nom<<endl;
|
---|
392 | return;
|
---|
393 | }
|
---|
394 |
|
---|
395 | TVector<r_8>* vin = dynamic_cast<TVector<r_8> *>(obj);
|
---|
396 | TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj);
|
---|
397 | if (vin == NULL && vinc == NULL) {
|
---|
398 | cout<<"SophyaFFT_forw() Error , Objet n'est pas un vecteur r_8 ou complex<r_8>"<<endl;
|
---|
399 | return;
|
---|
400 | }
|
---|
401 | TVector< complex<r_8> > * vout = new TVector< complex<r_8> > ;
|
---|
402 | FFTPackServer ffts;
|
---|
403 | if(vin!=NULL) {
|
---|
404 | cout<<"SophyaFFT_forw() - Computing FFT of TVector<r_8> of size "<<vin->NElts()<< endl;
|
---|
405 | ffts.FFTForward(*vin, *vout);
|
---|
406 | cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl;
|
---|
407 | vout->Info()["FFTTYPE"]="F:R8->Z8";
|
---|
408 | } else {
|
---|
409 | cout<<"SophyaFFT_forw() - Computing FFT of vector TVector<complex<r_8>> of size "<<vinc->NElts()<< endl;
|
---|
410 | ffts.FFTForward(*vinc, *vout);
|
---|
411 | cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl;
|
---|
412 | vout->Info()["FFTTYPE"] = "F:Z8->Z8";
|
---|
413 | }
|
---|
414 | // cout << " SophyaFFT - FFT done " << endl;
|
---|
415 | // tm.Split(" FFT done ");
|
---|
416 |
|
---|
417 | omg.AddObj(vout, nomout);
|
---|
418 | omg.DisplayObj(nomout, dopt);
|
---|
419 | return;
|
---|
420 |
|
---|
421 | }
|
---|
422 |
|
---|
423 |
|
---|
424 | /* Nouvelle-Fonction */
|
---|
425 | void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8)
|
---|
426 | {
|
---|
427 | //Timer tm("powerspec");
|
---|
428 | NamedObjMgr omg;
|
---|
429 | AnyDataObj* obj=omg.GetObj(nom);
|
---|
430 | if (obj == NULL) {
|
---|
431 | cout << "SophyaFFT_back() Error , Pas d'objet de nom " << nom << endl;
|
---|
432 | return;
|
---|
433 | }
|
---|
434 |
|
---|
435 | TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj);
|
---|
436 | if (vinc == NULL) {
|
---|
437 | cout << "SophyaFFT_back() Error , Objet n'est pas un vecteur complex<r_8>" << endl;
|
---|
438 | return;
|
---|
439 | }
|
---|
440 |
|
---|
441 | TVector< r_8 > * vout = NULL;
|
---|
442 | TVector< complex<r_8> > * voutc = NULL;
|
---|
443 |
|
---|
444 | if (forcez8 || (vinc->Info().GetS("FFTTYPE") == "F:Z8->Z8") ) {
|
---|
445 | voutc = new TVector< complex<r_8> >;
|
---|
446 | }
|
---|
447 | else {
|
---|
448 | vout = new TVector< r_8 >;
|
---|
449 | }
|
---|
450 |
|
---|
451 | FFTPackServer ffts;
|
---|
452 | cout << "SophyaFFT_back() - Computing Backward FFT of vector size " << vinc->NElts() << endl;
|
---|
453 | if(vout!=NULL) {
|
---|
454 | ffts.FFTBackward(*vinc, *vout);
|
---|
455 | cout<<"...Output TVector<r_8> of size: "<<vout->NElts()<<endl;
|
---|
456 | vout->Info()["FFTTYPE"]="B:Z8->R8";
|
---|
457 | omg.AddObj(vout, nomout);
|
---|
458 | } else {
|
---|
459 | ffts.FFTBackward(*vinc, *voutc);
|
---|
460 | cout<<"...Output TVector<complex<r_8>> of size: "<<voutc->NElts()<<endl;
|
---|
461 | voutc->Info()["FFTTYPE"]="B:Z8->Z8";
|
---|
462 | omg.AddObj(voutc, nomout);
|
---|
463 | }
|
---|
464 |
|
---|
465 | omg.DisplayObj(nomout, dopt);
|
---|
466 | return;
|
---|
467 | }
|
---|
468 |
|
---|
469 | /* Nouvelle-Fonction */
|
---|
470 | void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt)
|
---|
471 | {
|
---|
472 | NamedObjMgr omg;
|
---|
473 | AnyDataObj* obj=omg.GetObj(nomvec);
|
---|
474 | if(obj == NULL) {
|
---|
475 | cout<<"SophyaFFT_crefilter() Error , Pas d'objet de nom "<<nomvec<<endl;
|
---|
476 | return;
|
---|
477 | }
|
---|
478 |
|
---|
479 | TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj);
|
---|
480 | if(vfft == NULL) {
|
---|
481 | cout<<"SophyaFFT_crefilter() Error , Objet "<<nomvec<<" n'est pas un Tvector<complex<r_8>>"<< endl;
|
---|
482 | return;
|
---|
483 | }
|
---|
484 | sa_size_t n = vfft->Size();
|
---|
485 | if(n<=0) return;
|
---|
486 |
|
---|
487 | cout<<"Creating filter "<<nomfilter<<"("<<n<<") from vec "<<nomvec<<" with fun "<<func<<endl;
|
---|
488 | omg.GetServiceObj()->PlotFunc(func,nomfilter,0.,(double)n,n,dopt);
|
---|
489 | }
|
---|
490 |
|
---|
491 | /* Nouvelle-Fonction */
|
---|
492 | void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec)
|
---|
493 | {
|
---|
494 | NamedObjMgr omg;
|
---|
495 | AnyDataObj* obj=omg.GetObj(nom);
|
---|
496 | if(obj == NULL) {
|
---|
497 | cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nom<<endl;
|
---|
498 | return;
|
---|
499 | }
|
---|
500 | TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj);
|
---|
501 | if(vfft == NULL) {
|
---|
502 | cout<<"SophyaFFT_filter() Error , Objet "<<nom<<" n'est pas un Tvector<complex<r_8>>"<< endl;
|
---|
503 | return;
|
---|
504 | }
|
---|
505 | int n = vfft->Size();
|
---|
506 | if(n<=0) {
|
---|
507 | cout<<"SophyaFFT_filter() Error , vector size = 0 " << endl;
|
---|
508 | return;
|
---|
509 | }
|
---|
510 |
|
---|
511 | string nomfilter = "/autoc/fft_filter";
|
---|
512 | if (fgvec) {
|
---|
513 | nomfilter = filt;
|
---|
514 | cout<<"SophyaFFT_filter(): using vector " << filt << " for filtering spectrum ..." << endl;
|
---|
515 | }
|
---|
516 | else {
|
---|
517 | cout<<"SophyaFFT_filter(): Creating filter vector "<<nomfilter
|
---|
518 | <<" from function " << filt << endl;
|
---|
519 | string fcrdopt = "nodisp";
|
---|
520 | omg.GetServiceObj()->PlotFunc(filt, nomfilter, 0., (double)n, n, fcrdopt);
|
---|
521 | }
|
---|
522 | AnyDataObj* objfilter=omg.GetObj(nomfilter);
|
---|
523 | if(objfilter == NULL) {
|
---|
524 | cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nomfilter<<endl;
|
---|
525 | return;
|
---|
526 | }
|
---|
527 |
|
---|
528 | TVector<r_8>* vfilter = dynamic_cast<TVector<r_8>*>(objfilter);
|
---|
529 | if(vfft == NULL) {
|
---|
530 | cout<<"SophyaFFT_filter() Error , Objet "<<nomfilter<<" n'est pas un Tvector<r_8>"<<endl;
|
---|
531 | return;
|
---|
532 | }
|
---|
533 |
|
---|
534 | n = (vfilter->Size()<vfft->Size()) ? vfilter->Size(): vfft->Size();
|
---|
535 |
|
---|
536 | cout<<" SophyaFFT_filter(): filtering from 0 to "<<n<<endl;
|
---|
537 | TVector< complex<r_8> > * filtfft = new TVector< complex<r_8> >(*vfft, false);
|
---|
538 | for(int i=0;i<n;i++) (*filtfft)(i) *= (*vfilter)(i);
|
---|
539 |
|
---|
540 | cout<<"SophyaFFT_filter(): Adding obj: " << outvec << endl;
|
---|
541 | omg.AddObj(filtfft, outvec);
|
---|
542 | omg.DisplayObj(outvec, dopt);
|
---|
543 | return;
|
---|
544 | }
|
---|