| [2615] | 1 | #include "sopnamsp.h" | 
|---|
| [722] | 2 | #include "machdefs.h" | 
|---|
|  | 3 | #include <stdio.h> | 
|---|
|  | 4 | #include <stdlib.h> | 
|---|
| [2322] | 5 | #include <iostream> | 
|---|
| [2921] | 6 | #include <ctype.h> | 
|---|
| [722] | 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 |  | 
|---|
| [1540] | 25 | #include "pidrawer.h" | 
|---|
|  | 26 | #include "nomgadapter.h" | 
|---|
| [2595] | 27 | #include "nomskymapadapter.h" | 
|---|
| [1540] | 28 |  | 
|---|
| [722] | 29 | extern "C" { | 
|---|
|  | 30 | void sopiamodule_init(); | 
|---|
|  | 31 | void sopiamodule_end(); | 
|---|
|  | 32 | } | 
|---|
|  | 33 |  | 
|---|
| [3430] | 34 | // --- fonctions pour faire FFT | 
|---|
| [2920] | 35 | void SophyaFFT_forw(string& nom, string& nomout, string dopt); | 
|---|
| [2921] | 36 | void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8=false); | 
|---|
|  | 37 | // void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt); | 
|---|
|  | 38 | void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec=false); | 
|---|
| [722] | 39 |  | 
|---|
| [3430] | 40 | //--- fonctions pour trace d'ellipse d'erreur | 
|---|
|  | 41 | int  diag_ellipse(double s1, double s2, double c, | 
|---|
|  | 42 | double &a, double &b, double& tet, double& phi, int prt=0); | 
|---|
|  | 43 |  | 
|---|
|  | 44 | void 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 | 
|---|
| [722] | 48 | class sopiamoduleExecutor : public CmdExecutor { | 
|---|
|  | 49 | public: | 
|---|
|  | 50 | sopiamoduleExecutor(); | 
|---|
|  | 51 | virtual       ~sopiamoduleExecutor(); | 
|---|
| [1267] | 52 | virtual int   Execute(string& keyw, vector<string>& args, string& toks); | 
|---|
| [722] | 53 | }; | 
|---|
|  | 54 |  | 
|---|
| [3430] | 55 | //---  Classe pour trace de grille en projection spherique Mollweide | 
|---|
| [1540] | 56 | class MollweideGridDrawer : public PIDrawer { | 
|---|
|  | 57 | public: | 
|---|
|  | 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 |  | 
|---|
|  | 65 | protected: | 
|---|
|  | 66 | double xlarg, x0; | 
|---|
|  | 67 | double ylarg, y0; | 
|---|
|  | 68 | int nbparall, nbmerid; | 
|---|
|  | 69 | int nbpt; | 
|---|
|  | 70 | bool fgrevtheta; | 
|---|
|  | 71 | }; | 
|---|
|  | 72 |  | 
|---|
| [722] | 73 | /* --Methode-- */ | 
|---|
| [1540] | 74 | MollweideGridDrawer::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-- */ | 
|---|
|  | 88 | MollweideGridDrawer::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-- */ | 
|---|
|  | 110 | MollweideGridDrawer::~MollweideGridDrawer() | 
|---|
|  | 111 | { | 
|---|
|  | 112 | } | 
|---|
|  | 113 |  | 
|---|
|  | 114 | /* --Methode-- */ | 
|---|
|  | 115 | void 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-- */ | 
|---|
|  | 195 | void MollweideGridDrawer::UpdateLimits() | 
|---|
|  | 196 | { | 
|---|
|  | 197 | SetLimits(x0-xlarg/2., x0+xlarg/2., y0-ylarg/2., y0+ylarg/2.); | 
|---|
|  | 198 | } | 
|---|
| [3430] | 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 | 
|---|
| [1540] | 202 |  | 
|---|
| [3430] | 203 | //--------------------------------------------------------------------------- | 
|---|
|  | 204 | //--- Fonctions de trace d'ellipses d'erreur | 
|---|
|  | 205 | //--------------------------------------------------------------------------- | 
|---|
|  | 206 |  | 
|---|
|  | 207 | /* Nouvelle-Fonction */ | 
|---|
|  | 208 | int  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 */ | 
|---|
|  | 270 | void 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 | //--------------------------------------------------------------------------- | 
|---|
| [1540] | 295 | /* --Methode-- */ | 
|---|
| [722] | 296 | sopiamoduleExecutor::sopiamoduleExecutor() | 
|---|
|  | 297 | { | 
|---|
|  | 298 |  | 
|---|
|  | 299 | PIACmd * mpiac; | 
|---|
|  | 300 | NamedObjMgr omg; | 
|---|
|  | 301 | mpiac = omg.GetImgApp()->CmdInterpreter(); | 
|---|
|  | 302 |  | 
|---|
| [2920] | 303 | string kw,usage; | 
|---|
| [2921] | 304 | // ------------- Help group FFT | 
|---|
|  | 305 | string hgrp = "FFT"; | 
|---|
| [2920] | 306 |  | 
|---|
|  | 307 | kw = "fftforw"; | 
|---|
| [2921] | 308 | usage = "FFT on a vector -> computes forward Fourier transform"; | 
|---|
|  | 309 | usage += "\n Usage: fftforw vecSig vecSpec [graphic_att] "; | 
|---|
|  | 310 | usage += "\n vecSpec = FFTForward(vecSig) "; | 
|---|
|  | 311 | usage += "\n vecSig: Input data vector of type r_8 or complex<r_8> "; | 
|---|
|  | 312 | usage += "\n vecSpec: Output data vector of type complex<r_8> "; | 
|---|
|  | 313 | usage += "\n See also : fftback fftfilter fftfuncfilter "; | 
|---|
| [2920] | 314 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 315 |  | 
|---|
|  | 316 | kw = "fftback"; | 
|---|
| [2921] | 317 | usage = "FFT on a vector -> computes backward Fourier transform "; | 
|---|
|  | 318 | usage += "\n Usage: fftback vecSpec vecSig [graphic_att] [C/Z] "; | 
|---|
|  | 319 | usage += "\n vecSig = FFTBackward(vecSpec) "; | 
|---|
|  | 320 | usage += "\n vecSpec: Input data vector of type complex<r_8> "; | 
|---|
|  | 321 | usage += "\n vecSig:  Output Data vector of type r_8 (default) "; | 
|---|
|  | 322 | usage += "\n    or complex<r_8> if C/Z specified or "; | 
|---|
|  | 323 | usage += "\n    vecSpec computed by fftforw on a complex vector"; | 
|---|
|  | 324 | usage += "\n See also : fftforw fftfilter fftfuncfilter "; | 
|---|
| [2920] | 325 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 326 |  | 
|---|
| [2921] | 327 | kw = "fftfilter"; | 
|---|
|  | 328 | usage = "Filter (multiply) vecSpec (vector complex<r_8>) by Filter (vector<r_8>)"; | 
|---|
|  | 329 | usage += "\n Usage: fftfilter vecSpec FilterVec vecFiltSpec [graphic_att] "; | 
|---|
|  | 330 | usage += "\n   vecFiltSpec(i) = vecSpec(i) * complex(FilterVec(i),0) "; | 
|---|
|  | 331 | usage += "\n See also : fftforw fftbackw fftfuncfilter "; | 
|---|
| [2920] | 332 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 333 |  | 
|---|
| [2921] | 334 | kw = "fftfuncfilter"; | 
|---|
|  | 335 | usage = "Filter (multiply) vecSpec (vector complex<r_8>) by FilterFunc(i) "; | 
|---|
|  | 336 | usage += "\n Usage: fftfilter vecSpec FilterFunc vecFiltSpec [graphic_att] "; | 
|---|
|  | 337 | usage += "\n   vecFiltSpec(i) = vecSpec(i) * complex(FilterFunc(i),0) "; | 
|---|
|  | 338 | usage += "\n See also : fftforw fftbackw fftfilter "; | 
|---|
| [2920] | 339 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 340 |  | 
|---|
| [2921] | 341 | //-------------------------- | 
|---|
|  | 342 | hgrp = "SophyaCmd"; | 
|---|
|  | 343 |  | 
|---|
| [1540] | 344 | kw = "mollgrid"; | 
|---|
|  | 345 | usage = "Creates a spherical coordinate grid in Molleweide projection "; | 
|---|
| [3434] | 346 | usage += "\n Usage: mollgrid [Nb_Parallel] [Nb_Meridien] [graphic_att] "; | 
|---|
| [1540] | 347 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| [2920] | 348 |  | 
|---|
| [2595] | 349 | kw = "setprjmoldefval"; | 
|---|
|  | 350 | usage = "Set default value for Molleweide projection of spherical maps (outside maps)"; | 
|---|
|  | 351 | usage += "\n Usage: setprjmoldefval OutOfMapValue "; | 
|---|
|  | 352 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| [722] | 353 |  | 
|---|
| [3430] | 354 | //--- Trace d'ellipse d'erreur | 
|---|
|  | 355 | hgrp = "SophyaCmd"; | 
|---|
|  | 356 | kw = "errorellipse"; | 
|---|
|  | 357 | usage = " Error ellipse plotter \n"; | 
|---|
|  | 358 | usage += "Usage: errellipse [-fill] xc yc sx2 sy2 cov [scale=1] [gr_opt] [npt=128] \n"; | 
|---|
|  | 359 | usage = "   Adds an error ellipse, specified by its center (xc,yc) \n"; | 
|---|
|  | 360 | usage += "  and error matrix (covariance) parameters  SigX^2,SigY^2,Covar \n" ; | 
|---|
|  | 361 | usage += "  A global scaling parameters scale , graphic attributes and \n"; | 
|---|
|  | 362 | usage += "   nomber of points can optionnaly be specified\n"; | 
|---|
|  | 363 | usage += "  if the -fill flag specified, plots a filled ellipse \n" ; | 
|---|
|  | 364 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 365 |  | 
|---|
| [722] | 366 | } | 
|---|
|  | 367 |  | 
|---|
|  | 368 | /* --Methode-- */ | 
|---|
|  | 369 | sopiamoduleExecutor::~sopiamoduleExecutor() | 
|---|
|  | 370 | { | 
|---|
|  | 371 | } | 
|---|
|  | 372 |  | 
|---|
|  | 373 | /* --Methode-- */ | 
|---|
| [1267] | 374 | int sopiamoduleExecutor::Execute(string& kw, vector<string>& tokens, string& toks) | 
|---|
| [722] | 375 | { | 
|---|
|  | 376 |  | 
|---|
| [2920] | 377 | if (kw == "powerspec" || kw == "fftforw") { | 
|---|
| [722] | 378 | if (tokens.size() < 2) { | 
|---|
| [2921] | 379 | cout << "Usage: fftforw vecSig vecSpec [graphic_att] " << endl; | 
|---|
| [722] | 380 | return(0); | 
|---|
|  | 381 | } | 
|---|
| [2920] | 382 | if (tokens.size() < 3)  tokens.push_back((string)""); | 
|---|
|  | 383 | SophyaFFT_forw(tokens[0], tokens[1], tokens[2]); | 
|---|
| [2921] | 384 | } | 
|---|
| [2920] | 385 | else if (kw == "fftback") { | 
|---|
|  | 386 | if (tokens.size() < 2) { | 
|---|
| [2921] | 387 | cout << "Usage: fftback vecSpec vecSig [graphic_att] [C/Z]" << endl; | 
|---|
| [2920] | 388 | return(0); | 
|---|
|  | 389 | } | 
|---|
| [2921] | 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 | } | 
|---|
| [2920] | 395 | if (tokens.size() < 3)  tokens.push_back((string)""); | 
|---|
| [2921] | 396 | SophyaFFT_back(tokens[0], tokens[1], tokens[2], forcez8); | 
|---|
|  | 397 | } | 
|---|
|  | 398 | else if ( (kw == "fftfilter") || (kw == "fftfuncfilter") ) { | 
|---|
| [2920] | 399 | if (tokens.size() < 3) { | 
|---|
| [2925] | 400 | cout << "Usage: fftfilter/fftfuncfilter vecSpec Filter vecFiltSpec [graphic_att]" << endl; | 
|---|
| [2920] | 401 | return(0); | 
|---|
|  | 402 | } | 
|---|
|  | 403 | if (tokens.size() < 4)  tokens.push_back((string)""); | 
|---|
| [2921] | 404 | bool fgvec = false; | 
|---|
|  | 405 | if (kw == "fftfilter") fgvec = true; | 
|---|
|  | 406 | SophyaFFT_filter(tokens[0], tokens[1], tokens[2], tokens[3], fgvec); | 
|---|
|  | 407 | } | 
|---|
| [2920] | 408 |  | 
|---|
| [2595] | 409 | else 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()) ); | 
|---|
| [2921] | 415 | } | 
|---|
| [3434] | 416 | // Grille de coordonnees en projection molleweide | 
|---|
|  | 417 | else if (kw == "mollgrid") { | 
|---|
| [1540] | 418 | NamedObjMgr omg; | 
|---|
|  | 419 | MollweideGridDrawer * mollgrid = NULL; | 
|---|
|  | 420 | string dopt=""; | 
|---|
| [3434] | 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 |  | 
|---|
| [1540] | 429 | if (mollgrid == NULL) { | 
|---|
|  | 430 | cout << "mollgridsph Error/BUG !!! mollgrid = NULL "  << endl; | 
|---|
|  | 431 | return(0); | 
|---|
|  | 432 | } | 
|---|
|  | 433 |  | 
|---|
|  | 434 | int wrsid = 0; | 
|---|
| [2179] | 435 | //bool fgsr = true; | 
|---|
| [1540] | 436 |  | 
|---|
|  | 437 | string name = "mollgrid"; | 
|---|
| [1972] | 438 | wrsid = omg.GetImgApp()->DispScDrawer(mollgrid, name, dopt); | 
|---|
| [3434] | 439 | } | 
|---|
|  | 440 | // Trace d'ellipse d'erreur | 
|---|
| [3430] | 441 | else 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()); | 
|---|
| [1540] | 462 |  | 
|---|
| [3430] | 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 |  | 
|---|
| [722] | 476 | return(0); | 
|---|
|  | 477 |  | 
|---|
|  | 478 | } | 
|---|
|  | 479 |  | 
|---|
|  | 480 | static sopiamoduleExecutor * piaerex = NULL; | 
|---|
|  | 481 | /* Nouvelle-Fonction */ | 
|---|
|  | 482 | void sopiamodule_init() | 
|---|
|  | 483 | { | 
|---|
|  | 484 | // Fonction d'initialisation du module | 
|---|
|  | 485 | // Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule()) | 
|---|
|  | 486 | if (piaerex) delete piaerex; | 
|---|
|  | 487 | piaerex = new sopiamoduleExecutor; | 
|---|
|  | 488 | } | 
|---|
|  | 489 |  | 
|---|
|  | 490 | /* Nouvelle-Fonction */ | 
|---|
|  | 491 | void sopiamodule_end() | 
|---|
|  | 492 | { | 
|---|
|  | 493 | // Desactivation du module | 
|---|
|  | 494 | if (piaerex) delete piaerex; | 
|---|
|  | 495 | piaerex = NULL; | 
|---|
|  | 496 | } | 
|---|
|  | 497 |  | 
|---|
|  | 498 |  | 
|---|
| [2920] | 499 | /*  Nouvelle-Fonction */ | 
|---|
|  | 500 | void SophyaFFT_forw(string& nom, string& nomout, string dopt) | 
|---|
| [722] | 501 | { | 
|---|
| [2920] | 502 | //Timer tm("powerspec"); | 
|---|
| [722] | 503 | NamedObjMgr omg; | 
|---|
|  | 504 | AnyDataObj* obj=omg.GetObj(nom); | 
|---|
|  | 505 | if (obj == NULL) { | 
|---|
| [2920] | 506 | cout<<"SophyaFFT_forw() Error , Pas d'objet de nom "<<nom<<endl; | 
|---|
| [722] | 507 | return; | 
|---|
|  | 508 | } | 
|---|
|  | 509 |  | 
|---|
| [2920] | 510 | TVector<r_8>* vin = dynamic_cast<TVector<r_8> *>(obj); | 
|---|
|  | 511 | TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj); | 
|---|
|  | 512 | if (vin == NULL && vinc == NULL) { | 
|---|
|  | 513 | cout<<"SophyaFFT_forw() Error , Objet n'est pas un vecteur r_8 ou complex<r_8>"<<endl; | 
|---|
| [722] | 514 | return; | 
|---|
| [2920] | 515 | } | 
|---|
|  | 516 | TVector< complex<r_8> > * vout = new TVector< complex<r_8> >  ; | 
|---|
| [722] | 517 | FFTPackServer ffts; | 
|---|
| [2920] | 518 | if(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; | 
|---|
| [2921] | 522 | vout->Info()["FFTTYPE"]="F:R8->Z8"; | 
|---|
| [2920] | 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; | 
|---|
| [2921] | 527 | vout->Info()["FFTTYPE"] = "F:Z8->Z8"; | 
|---|
| [2920] | 528 | } | 
|---|
| [1481] | 529 | // cout << " SophyaFFT - FFT done " << endl; | 
|---|
|  | 530 | // tm.Split(" FFT done "); | 
|---|
| [722] | 531 |  | 
|---|
|  | 532 | omg.AddObj(vout, nomout); | 
|---|
| [2925] | 533 | omg.DisplayObj(nomout, dopt); | 
|---|
| [722] | 534 | return; | 
|---|
|  | 535 |  | 
|---|
|  | 536 | } | 
|---|
| [2920] | 537 |  | 
|---|
|  | 538 |  | 
|---|
|  | 539 | /*  Nouvelle-Fonction */ | 
|---|
| [2921] | 540 | void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8) | 
|---|
| [2920] | 541 | { | 
|---|
|  | 542 | //Timer tm("powerspec"); | 
|---|
|  | 543 | NamedObjMgr omg; | 
|---|
|  | 544 | AnyDataObj* obj=omg.GetObj(nom); | 
|---|
|  | 545 | if (obj == NULL) { | 
|---|
|  | 546 | cout << "SophyaFFT_back() Error , Pas d'objet de nom " << nom << endl; | 
|---|
|  | 547 | return; | 
|---|
|  | 548 | } | 
|---|
|  | 549 |  | 
|---|
|  | 550 | TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj); | 
|---|
|  | 551 | if (vinc == NULL) { | 
|---|
|  | 552 | cout << "SophyaFFT_back() Error , Objet n'est pas un vecteur complex<r_8>" <<  endl; | 
|---|
|  | 553 | return; | 
|---|
|  | 554 | } | 
|---|
|  | 555 |  | 
|---|
|  | 556 | TVector< r_8 > * vout = NULL; | 
|---|
|  | 557 | TVector< complex<r_8> > * voutc = NULL; | 
|---|
| [2921] | 558 |  | 
|---|
|  | 559 | if (forcez8 || (vinc->Info().GetS("FFTTYPE") == "F:Z8->Z8") ) { | 
|---|
| [2920] | 560 | voutc = new TVector< complex<r_8> >; | 
|---|
| [2921] | 561 | } | 
|---|
|  | 562 | else { | 
|---|
|  | 563 | vout = new TVector< r_8 >; | 
|---|
| [2920] | 564 | } | 
|---|
|  | 565 |  | 
|---|
|  | 566 | FFTPackServer ffts; | 
|---|
|  | 567 | cout << "SophyaFFT_back() - Computing Backward FFT of vector size " << vinc->NElts() << endl; | 
|---|
|  | 568 | if(vout!=NULL) { | 
|---|
|  | 569 | ffts.FFTBackward(*vinc, *vout); | 
|---|
|  | 570 | cout<<"...Output TVector<r_8> of size: "<<vout->NElts()<<endl; | 
|---|
| [2921] | 571 | vout->Info()["FFTTYPE"]="B:Z8->R8"; | 
|---|
| [2920] | 572 | omg.AddObj(vout, nomout); | 
|---|
|  | 573 | } else { | 
|---|
|  | 574 | ffts.FFTBackward(*vinc, *voutc); | 
|---|
|  | 575 | cout<<"...Output TVector<complex<r_8>> of size: "<<voutc->NElts()<<endl; | 
|---|
| [2921] | 576 | voutc->Info()["FFTTYPE"]="B:Z8->Z8"; | 
|---|
| [2920] | 577 | omg.AddObj(voutc, nomout); | 
|---|
|  | 578 | } | 
|---|
|  | 579 |  | 
|---|
| [2925] | 580 | omg.DisplayObj(nomout, dopt); | 
|---|
| [2920] | 581 | return; | 
|---|
|  | 582 | } | 
|---|
|  | 583 |  | 
|---|
|  | 584 | /*  Nouvelle-Fonction */ | 
|---|
|  | 585 | void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt) | 
|---|
|  | 586 | { | 
|---|
|  | 587 | NamedObjMgr omg; | 
|---|
|  | 588 | AnyDataObj* obj=omg.GetObj(nomvec); | 
|---|
|  | 589 | if(obj == NULL) { | 
|---|
|  | 590 | cout<<"SophyaFFT_crefilter() Error , Pas d'objet de nom "<<nomvec<<endl; | 
|---|
|  | 591 | return; | 
|---|
|  | 592 | } | 
|---|
|  | 593 |  | 
|---|
|  | 594 | TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj); | 
|---|
|  | 595 | if(vfft == NULL) { | 
|---|
|  | 596 | cout<<"SophyaFFT_crefilter() Error , Objet "<<nomvec<<" n'est pas un Tvector<complex<r_8>>"<< endl; | 
|---|
|  | 597 | return; | 
|---|
|  | 598 | } | 
|---|
| [2921] | 599 | sa_size_t n = vfft->Size(); | 
|---|
| [2920] | 600 | if(n<=0) return; | 
|---|
|  | 601 |  | 
|---|
|  | 602 | cout<<"Creating filter "<<nomfilter<<"("<<n<<") from vec "<<nomvec<<" with fun "<<func<<endl; | 
|---|
|  | 603 | omg.GetServiceObj()->PlotFunc(func,nomfilter,0.,(double)n,n,dopt); | 
|---|
|  | 604 | } | 
|---|
|  | 605 |  | 
|---|
|  | 606 | /*  Nouvelle-Fonction */ | 
|---|
| [2921] | 607 | void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec) | 
|---|
| [2920] | 608 | { | 
|---|
|  | 609 | NamedObjMgr omg; | 
|---|
|  | 610 | AnyDataObj* obj=omg.GetObj(nom); | 
|---|
|  | 611 | if(obj == NULL) { | 
|---|
|  | 612 | cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nom<<endl; | 
|---|
|  | 613 | return; | 
|---|
|  | 614 | } | 
|---|
| [2921] | 615 | TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj); | 
|---|
|  | 616 | if(vfft == NULL) { | 
|---|
|  | 617 | cout<<"SophyaFFT_filter() Error , Objet "<<nom<<" n'est pas un Tvector<complex<r_8>>"<< endl; | 
|---|
|  | 618 | return; | 
|---|
|  | 619 | } | 
|---|
|  | 620 | int n = vfft->Size(); | 
|---|
|  | 621 | if(n<=0) { | 
|---|
|  | 622 | cout<<"SophyaFFT_filter() Error , vector size = 0 " << endl; | 
|---|
|  | 623 | return; | 
|---|
|  | 624 | } | 
|---|
| [2920] | 625 |  | 
|---|
| [2921] | 626 | string nomfilter = "/autoc/fft_filter"; | 
|---|
|  | 627 | if (fgvec) { | 
|---|
|  | 628 | nomfilter = filt; | 
|---|
|  | 629 | cout<<"SophyaFFT_filter(): using vector " << filt << " for filtering spectrum ..." << endl; | 
|---|
|  | 630 | } | 
|---|
|  | 631 | else { | 
|---|
|  | 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 | } | 
|---|
| [2920] | 637 | AnyDataObj* objfilter=omg.GetObj(nomfilter); | 
|---|
|  | 638 | if(objfilter == NULL) { | 
|---|
|  | 639 | cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nomfilter<<endl; | 
|---|
|  | 640 | return; | 
|---|
|  | 641 | } | 
|---|
|  | 642 |  | 
|---|
|  | 643 | TVector<r_8>* vfilter = dynamic_cast<TVector<r_8>*>(objfilter); | 
|---|
|  | 644 | if(vfft == NULL) { | 
|---|
|  | 645 | cout<<"SophyaFFT_filter() Error , Objet "<<nomfilter<<" n'est pas un Tvector<r_8>"<<endl; | 
|---|
|  | 646 | return; | 
|---|
|  | 647 | } | 
|---|
|  | 648 |  | 
|---|
| [2921] | 649 | n = (vfilter->Size()<vfft->Size()) ? vfilter->Size(): vfft->Size(); | 
|---|
| [2920] | 650 |  | 
|---|
| [2921] | 651 | cout<<" SophyaFFT_filter(): filtering from 0 to "<<n<<endl; | 
|---|
|  | 652 | TVector< complex<r_8> > * filtfft = new TVector< complex<r_8> >(*vfft, false); | 
|---|
|  | 653 | for(int i=0;i<n;i++) (*filtfft)(i) *= (*vfilter)(i); | 
|---|
|  | 654 |  | 
|---|
|  | 655 | cout<<"SophyaFFT_filter(): Adding obj: " << outvec << endl; | 
|---|
|  | 656 | omg.AddObj(filtfft, outvec); | 
|---|
|  | 657 | omg.DisplayObj(outvec, dopt); | 
|---|
| [2920] | 658 | return; | 
|---|
|  | 659 | } | 
|---|