1 | #include "sopnamsp.h"
|
---|
2 | #include "machdefs.h"
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include <iostream>
|
---|
6 | #include <math.h>
|
---|
7 |
|
---|
8 | #include <typeinfo>
|
---|
9 |
|
---|
10 | #include <vector>
|
---|
11 | #include <string>
|
---|
12 |
|
---|
13 | #include "piacmd.h"
|
---|
14 | #include "nobjmgr.h"
|
---|
15 | #include "pistdimgapp.h"
|
---|
16 | #include "servnobjm.h"
|
---|
17 | #include "tvector.h"
|
---|
18 | #include "pitvmaad.h"
|
---|
19 | #include "fftpserver.h"
|
---|
20 | #include "bruit.h"
|
---|
21 | #include "piscdrawwdg.h"
|
---|
22 | #include "ctimer.h"
|
---|
23 |
|
---|
24 | #include "pidrawer.h"
|
---|
25 | #include "nomgadapter.h"
|
---|
26 | #include "nomskymapadapter.h"
|
---|
27 |
|
---|
28 | extern "C" {
|
---|
29 | void sopiamodule_init();
|
---|
30 | void sopiamodule_end();
|
---|
31 | }
|
---|
32 |
|
---|
33 | void SophyaFFT(string& nom, string& nomout, string dopt);
|
---|
34 |
|
---|
35 | class sopiamoduleExecutor : public CmdExecutor {
|
---|
36 | public:
|
---|
37 | sopiamoduleExecutor();
|
---|
38 | virtual ~sopiamoduleExecutor();
|
---|
39 | virtual int Execute(string& keyw, vector<string>& args, string& toks);
|
---|
40 | };
|
---|
41 |
|
---|
42 | // Classe pour trace de grille en projection spherique Mollweide
|
---|
43 | class MollweideGridDrawer : public PIDrawer {
|
---|
44 | public:
|
---|
45 | MollweideGridDrawer(int np, int nm, int nx, int ny);
|
---|
46 | MollweideGridDrawer(int np, int nm, double x_larg=0., double x_0=0.,
|
---|
47 | double y_larg=0., double y_0=0.);
|
---|
48 | virtual ~MollweideGridDrawer();
|
---|
49 | virtual void Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
|
---|
50 | virtual void UpdateLimits();
|
---|
51 |
|
---|
52 | protected:
|
---|
53 | double xlarg, x0;
|
---|
54 | double ylarg, y0;
|
---|
55 | int nbparall, nbmerid;
|
---|
56 | int nbpt;
|
---|
57 | bool fgrevtheta;
|
---|
58 | };
|
---|
59 |
|
---|
60 | /* --Methode-- */
|
---|
61 | MollweideGridDrawer::MollweideGridDrawer(int np, int nm, int nx, int ny)
|
---|
62 | {
|
---|
63 | x0 = (double)nx/2.;
|
---|
64 | y0 = (double)ny/2.;
|
---|
65 | xlarg = nx;
|
---|
66 | ylarg = ny;
|
---|
67 | nbparall = np;
|
---|
68 | nbmerid = nm;
|
---|
69 | nbpt = ny/5;
|
---|
70 | if ((nbpt % 20) == 0) nbpt++;
|
---|
71 | fgrevtheta = true;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /* --Methode-- */
|
---|
75 | MollweideGridDrawer::MollweideGridDrawer(int np, int nm, double x_larg, double x_0,
|
---|
76 | double y_larg, double y_0)
|
---|
77 | {
|
---|
78 | if (x_larg > 0.) {
|
---|
79 | xlarg = x_larg; x0 = x_0;
|
---|
80 | }
|
---|
81 | else {
|
---|
82 | xlarg = M_PI*2.; x0 = M_PI;
|
---|
83 | }
|
---|
84 | if (y_larg > 0.) {
|
---|
85 | ylarg = y_larg; y0 = y_0;
|
---|
86 | }
|
---|
87 | else {
|
---|
88 | ylarg = M_PI; y0 = 0.;
|
---|
89 | }
|
---|
90 | nbparall = np;
|
---|
91 | nbmerid = nm;
|
---|
92 | nbpt = 101;
|
---|
93 | fgrevtheta = false;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /* --Methode-- */
|
---|
97 | MollweideGridDrawer::~MollweideGridDrawer()
|
---|
98 | {
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* --Methode-- */
|
---|
102 | void MollweideGridDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
103 | {
|
---|
104 | PIGrCoord * xxl = new PIGrCoord[nbpt];
|
---|
105 | PIGrCoord * xxr = new PIGrCoord[nbpt];
|
---|
106 | PIGrCoord * yy = new PIGrCoord[nbpt];
|
---|
107 |
|
---|
108 | char buff[64];
|
---|
109 |
|
---|
110 | // Trace des paralleles
|
---|
111 | g->DrawLine(xmin, y0, xmax, y0);
|
---|
112 | g->DrawString(x0+xlarg/100, y0+ylarg/100, "0");
|
---|
113 |
|
---|
114 | // PIGrCoord asc, PIGrCoord desc;
|
---|
115 | int i,k;
|
---|
116 |
|
---|
117 | int nkp = (nbparall-1)/2;
|
---|
118 | if (nkp > 0) {
|
---|
119 | double dy = 0.5*ylarg/(double)(nkp+1);
|
---|
120 | double dtd = 90./(double)(nkp+1);
|
---|
121 | for(k=1; k<=nkp; k++) {
|
---|
122 | double fx = sin(acos(2.*(double)k*dy/ylarg))*0.5;
|
---|
123 | double yc = k*dy+y0;
|
---|
124 | g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
|
---|
125 | double ctd = (fgrevtheta) ? -dtd*k : dtd*k;
|
---|
126 | sprintf(buff, "%5.1f", ctd);
|
---|
127 | g->DrawString(x0, yc, buff);
|
---|
128 | g->DrawString(x0-0.3*xlarg, yc, buff);
|
---|
129 | g->DrawString(x0+0.25*xlarg, yc, buff);
|
---|
130 | yc = -k*dy+y0;
|
---|
131 | g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
|
---|
132 | sprintf(buff, "%5.1f", -ctd);
|
---|
133 | g->DrawString(x0, yc, buff);
|
---|
134 | g->DrawString(x0-0.3*xlarg, yc, buff);
|
---|
135 | g->DrawString(x0+0.25*xlarg, yc, buff);
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | // Trace des meridiennes
|
---|
140 | g->DrawLine(x0, ymin, x0, ymax);
|
---|
141 |
|
---|
142 | int nkm = (nbmerid-1)/2;
|
---|
143 | if (nkm < 1) nkm = 1;
|
---|
144 | double dphi = M_PI/nkm;
|
---|
145 | double dpd = 180./(double)(nkm);
|
---|
146 | double dy = ylarg/(nbpt-1);
|
---|
147 | for(k=0; k<nkm; k++) {
|
---|
148 | double phi0 = k*dphi;
|
---|
149 | double dphimil = fabs(phi0-M_PI);
|
---|
150 | if (dphimil < 1.e-6) continue;
|
---|
151 | for(i=0; i<nbpt; i++) {
|
---|
152 | double yc = (double)i*dy+y0-0.5*ylarg;
|
---|
153 | double fx = (2.*fabs(yc-y0)/ylarg <= 1.) ?
|
---|
154 | sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5 : 0.;
|
---|
155 | yy[i] = yc;
|
---|
156 | xxl[i] = x0-fx*xlarg;
|
---|
157 | xxr[i] = x0+fx*xlarg;
|
---|
158 | }
|
---|
159 |
|
---|
160 | g->DrawPolygon(xxl, yy, nbpt, false);
|
---|
161 | g->DrawPolygon(xxr, yy, nbpt, false);
|
---|
162 |
|
---|
163 | if (k == 0) continue;
|
---|
164 | for(i=-1; i<=1; i++) {
|
---|
165 | double yc = 0.20*i*ylarg+y0;
|
---|
166 | double fx = sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5;
|
---|
167 | double xc = x0-fx*xlarg;
|
---|
168 | sprintf(buff, "%4.1f", dpd*k);
|
---|
169 | g->DrawString(xc, yc, buff);
|
---|
170 | xc = x0+fx*xlarg;
|
---|
171 | sprintf(buff, "%4.1f", 360.-dpd*k);
|
---|
172 | g->DrawString(xc, yc, buff);
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | delete [] xxl;
|
---|
177 | delete [] xxr;
|
---|
178 | delete [] yy;
|
---|
179 | }
|
---|
180 |
|
---|
181 | /* --Methode-- */
|
---|
182 | void MollweideGridDrawer::UpdateLimits()
|
---|
183 | {
|
---|
184 | SetLimits(x0-xlarg/2., x0+xlarg/2., y0-ylarg/2., y0+ylarg/2.);
|
---|
185 | }
|
---|
186 |
|
---|
187 | /* --Methode-- */
|
---|
188 | sopiamoduleExecutor::sopiamoduleExecutor()
|
---|
189 | {
|
---|
190 |
|
---|
191 | PIACmd * mpiac;
|
---|
192 | NamedObjMgr omg;
|
---|
193 | mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
194 |
|
---|
195 | string hgrp = "SophyaCmd";
|
---|
196 | string kw = "powerspec";
|
---|
197 | string usage = "FFT on a vector -> Plots power spectrum ";
|
---|
198 | usage += "\n Usage: fftp vecName vecFFT [graphic_att] ";
|
---|
199 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
200 | kw = "mollgridsph";
|
---|
201 | usage = "Creates a spherical coordinate grid in Molleweide projection ";
|
---|
202 | usage += "\n Usage: mollgridsph NameSphericalMap [Nb_Parallel Nb_Meridien graphic_att] ";
|
---|
203 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
204 | kw = "mollgrid";
|
---|
205 | usage = "Creates a spherical coordinate grid in Molleweide projection ";
|
---|
206 | usage += "\n Usage: mollgrid [Nb_Parallel Nb_Meridien graphic_att] ";
|
---|
207 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
208 | kw = "setprjmoldefval";
|
---|
209 | usage = "Set default value for Molleweide projection of spherical maps (outside maps)";
|
---|
210 | usage += "\n Usage: setprjmoldefval OutOfMapValue ";
|
---|
211 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
212 |
|
---|
213 | }
|
---|
214 |
|
---|
215 | /* --Methode-- */
|
---|
216 | sopiamoduleExecutor::~sopiamoduleExecutor()
|
---|
217 | {
|
---|
218 | }
|
---|
219 |
|
---|
220 | /* --Methode-- */
|
---|
221 | int sopiamoduleExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
222 | {
|
---|
223 |
|
---|
224 | if (kw == "powerspec") {
|
---|
225 | if (tokens.size() < 2) {
|
---|
226 | cout << "Usage: powerspec nameVec vecFFT [graphic_att]" << endl;
|
---|
227 | return(0);
|
---|
228 | }
|
---|
229 | if (tokens.size() < 3) tokens.push_back((string)"n");
|
---|
230 | SophyaFFT(tokens[0], tokens[1], tokens[2]);
|
---|
231 | }
|
---|
232 | else if (kw == "prjmoldefval") {
|
---|
233 | if (tokens.size() < 1) {
|
---|
234 | cout << "Usage: prjmoldefval OutOfMapValue" << endl;
|
---|
235 | return(0);
|
---|
236 | }
|
---|
237 | Set_Project_Mol_DefVal(atof(tokens[0].c_str()) );
|
---|
238 | }
|
---|
239 | else if ( (kw == "mollgridsph") || (kw == "mollgrid") ) {
|
---|
240 | NamedObjMgr omg;
|
---|
241 | MollweideGridDrawer * mollgrid = NULL;
|
---|
242 | string dopt="";
|
---|
243 | if (kw == "mollgridsph") {
|
---|
244 | if (tokens.size() < 1) {
|
---|
245 | cout << "Usage: mollgridsph NameSphericalMap [Nb_Parallel Nb_Meridien graphic_att]"
|
---|
246 | << endl;
|
---|
247 | return(0);
|
---|
248 | }
|
---|
249 | int np = 5;
|
---|
250 | int nm = 5;
|
---|
251 | dopt = "same,thinline";
|
---|
252 | if (tokens.size() > 1) np = atoi(tokens[1].c_str());
|
---|
253 | if (tokens.size() > 2) nm = atoi(tokens[2].c_str());
|
---|
254 | if (tokens.size() > 3) dopt = tokens[3];
|
---|
255 | NObjMgrAdapter* obja = omg.GetObjAdapter(tokens[0]);
|
---|
256 | if (obja == NULL) {
|
---|
257 | cout << "mollgridsph Error , No object with name " << tokens[0] << endl;
|
---|
258 | return(0);
|
---|
259 | }
|
---|
260 | P2DArrayAdapter* arr = obja->Get2DArray(dopt);
|
---|
261 | if (arr == NULL) {
|
---|
262 | cout << "mollgridsph Error , object has non 2DArrayAdapter - Not a spherical map "
|
---|
263 | << endl;
|
---|
264 | return(0);
|
---|
265 | }
|
---|
266 | int nx = arr->XSize();
|
---|
267 | int ny = arr->YSize();
|
---|
268 | delete arr;
|
---|
269 | mollgrid = new MollweideGridDrawer(np, nm, nx, ny);
|
---|
270 | cout << " mollgridsph: Creating MollweideGridDrawer() for object" << tokens[0] << endl;
|
---|
271 | }
|
---|
272 | else if (kw == "mollgrid") {
|
---|
273 | int np = 5;
|
---|
274 | int nm = 5;
|
---|
275 | if (tokens.size() > 0) np = atoi(tokens[0].c_str());
|
---|
276 | if (tokens.size() > 1) nm = atoi(tokens[1].c_str());
|
---|
277 | if (tokens.size() > 2) dopt = tokens[2];
|
---|
278 | mollgrid = new MollweideGridDrawer(np, nm);
|
---|
279 | cout << " mollgrid: Creating MollweideGridDrawer(" << np << "," << nm << ")" << endl;
|
---|
280 | }
|
---|
281 |
|
---|
282 | if (mollgrid == NULL) {
|
---|
283 | cout << "mollgridsph Error/BUG !!! mollgrid = NULL " << endl;
|
---|
284 | return(0);
|
---|
285 | }
|
---|
286 |
|
---|
287 | int wrsid = 0;
|
---|
288 | //bool fgsr = true;
|
---|
289 |
|
---|
290 | string name = "mollgrid";
|
---|
291 | wrsid = omg.GetImgApp()->DispScDrawer(mollgrid, name, dopt);
|
---|
292 | }
|
---|
293 |
|
---|
294 | return(0);
|
---|
295 |
|
---|
296 | }
|
---|
297 |
|
---|
298 | static sopiamoduleExecutor * piaerex = NULL;
|
---|
299 | /* Nouvelle-Fonction */
|
---|
300 | void sopiamodule_init()
|
---|
301 | {
|
---|
302 | // Fonction d'initialisation du module
|
---|
303 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
|
---|
304 | if (piaerex) delete piaerex;
|
---|
305 | piaerex = new sopiamoduleExecutor;
|
---|
306 | }
|
---|
307 |
|
---|
308 | /* Nouvelle-Fonction */
|
---|
309 | void sopiamodule_end()
|
---|
310 | {
|
---|
311 | // Desactivation du module
|
---|
312 | if (piaerex) delete piaerex;
|
---|
313 | piaerex = NULL;
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 | /* --Methode-- */
|
---|
318 | void SophyaFFT(string& nom, string& nomout, string dopt)
|
---|
319 | {
|
---|
320 | Timer tm("powerspec");
|
---|
321 | NamedObjMgr omg;
|
---|
322 | AnyDataObj* obj=omg.GetObj(nom);
|
---|
323 | if (obj == NULL) {
|
---|
324 | cout << "SophyaFFT() Error , Pas d'objet de nom " << nom << endl;
|
---|
325 | return;
|
---|
326 | }
|
---|
327 |
|
---|
328 | Vector* vin = dynamic_cast<Vector *>(obj);
|
---|
329 | if (vin == NULL) {
|
---|
330 | cout << "SophyaFFT() Error , Objet n'est pas un vecteur " << endl;
|
---|
331 | return;
|
---|
332 | }
|
---|
333 | TVector< complex<double> > * vout = new TVector< complex<double> > ;
|
---|
334 | FFTPackServer ffts;
|
---|
335 | cout << "SophyaFFT() - Computing FFT of vector size " << vin->NElts() << endl;
|
---|
336 | ffts.FFTForward(*vin, *vout);
|
---|
337 | // cout << " SophyaFFT - FFT done " << endl;
|
---|
338 | // tm.Split(" FFT done ");
|
---|
339 |
|
---|
340 | omg.AddObj(vout, nomout);
|
---|
341 | omg.DisplayObj(nomout, dopt);
|
---|
342 | return;
|
---|
343 |
|
---|
344 | }
|
---|