| 1 | #include "machdefs.h"
 | 
|---|
| 2 | #include <math.h>
 | 
|---|
| 3 | #include <complex>
 | 
|---|
| 4 | 
 | 
|---|
| 5 | #include "pexceptions.h"
 | 
|---|
| 6 | #include "spheregorski.h"
 | 
|---|
| 7 | #include "strutil.h"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | extern "C" 
 | 
|---|
| 10 | {
 | 
|---|
| 11 | #include <stdio.h>
 | 
|---|
| 12 | #include <stdlib.h>
 | 
|---|
| 13 | #include <unistd.h>
 | 
|---|
| 14 | }
 | 
|---|
| 15 |       
 | 
|---|
| 16 | 
 | 
|---|
| 17 | //*******************************************************************
 | 
|---|
| 18 | // Class PIXELS_XY 
 | 
|---|
| 19 | // Construction des tableaux necessaires a la traduction des indices RING en 
 | 
|---|
| 20 | // indices NESTED (ou l'inverse)
 | 
|---|
| 21 | //*******************************************************************
 | 
|---|
| 22 | 
 | 
|---|
| 23 | PIXELS_XY::PIXELS_XY()
 | 
|---|
| 24 | {
 | 
|---|
| 25 |   pix2x_.ReSize(1024);
 | 
|---|
| 26 |   pix2x_.Reset();
 | 
|---|
| 27 |   pix2y_.ReSize(1024);
 | 
|---|
| 28 |   pix2y_.Reset();
 | 
|---|
| 29 |   x2pix_.ReSize(128);
 | 
|---|
| 30 |   x2pix_.Reset();
 | 
|---|
| 31 |   y2pix_.ReSize(128);
 | 
|---|
| 32 |   y2pix_.Reset();
 | 
|---|
| 33 |   mk_pix2xy(); 
 | 
|---|
| 34 |   mk_xy2pix(); 
 | 
|---|
| 35 | }
 | 
|---|
| 36 | 
 | 
|---|
| 37 | PIXELS_XY& PIXELS_XY::instance()
 | 
|---|
| 38 | {
 | 
|---|
| 39 |   static PIXELS_XY single;
 | 
|---|
| 40 |   return (single);
 | 
|---|
| 41 | }
 | 
|---|
| 42 | 
 | 
|---|
| 43 | void PIXELS_XY::mk_pix2xy() 
 | 
|---|
| 44 | {
 | 
|---|
| 45 |   /*
 | 
|---|
| 46 |     ==================================================
 | 
|---|
| 47 |     subroutine mk_pix2xy
 | 
|---|
| 48 |     ==================================================
 | 
|---|
| 49 |     c     constructs the array giving x and y in the face from pixel number
 | 
|---|
| 50 |     c     for the nested (quad-cube like) ordering of pixels
 | 
|---|
| 51 |     c
 | 
|---|
| 52 |     c     the bits corresponding to x and y are interleaved in the pixel number
 | 
|---|
| 53 |     c     one breaks up the pixel number by even and odd bits
 | 
|---|
| 54 |     ==================================================
 | 
|---|
| 55 |   */
 | 
|---|
| 56 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 57 |   //  (16/12/98)
 | 
|---|
| 58 | 
 | 
|---|
| 59 |   int kpix, jpix, IX, IY, IP, ID;
 | 
|---|
| 60 |   
 | 
|---|
| 61 |   for(kpix = 0; kpix < 1024; kpix++) 
 | 
|---|
| 62 |     {
 | 
|---|
| 63 |       jpix = kpix;
 | 
|---|
| 64 |       IX = 0;
 | 
|---|
| 65 |       IY = 0;
 | 
|---|
| 66 |       IP = 1 ;//  ! bit position (in x and y)
 | 
|---|
| 67 |       while( jpix!=0 )
 | 
|---|
| 68 |         { // ! go through all the bits
 | 
|---|
| 69 |           ID=jpix%2;//  ! bit value (in kpix), goes in ix
 | 
|---|
| 70 |           jpix = jpix/2;
 | 
|---|
| 71 |           IX = ID*IP+IX;
 | 
|---|
| 72 |       
 | 
|---|
| 73 |           ID=jpix%2;//  ! bit value (in kpix), goes in iy
 | 
|---|
| 74 |           jpix = jpix/2;
 | 
|---|
| 75 |           IY = ID*IP+IY;
 | 
|---|
| 76 |      
 | 
|---|
| 77 |           IP = 2*IP;//        ! next bit (in x and y)
 | 
|---|
| 78 |         }
 | 
|---|
| 79 |       pix2x_(kpix) = IX;//     ! in 0,31
 | 
|---|
| 80 |       pix2y_(kpix) = IY;//     ! in 0,31
 | 
|---|
| 81 |     }
 | 
|---|
| 82 | }
 | 
|---|
| 83 | 
 | 
|---|
| 84 | void PIXELS_XY::mk_xy2pix() 
 | 
|---|
| 85 | {
 | 
|---|
| 86 |   /*
 | 
|---|
| 87 |     =================================================
 | 
|---|
| 88 |     subroutine mk_xy2pix
 | 
|---|
| 89 |     =================================================
 | 
|---|
| 90 |     c     sets the array giving the number of the pixel lying in (x,y)
 | 
|---|
| 91 |     c     x and y are in {1,128}
 | 
|---|
| 92 |     c     the pixel number is in {0,128**2-1}
 | 
|---|
| 93 |     c
 | 
|---|
| 94 |     c     if  i-1 = sum_p=0  b_p * 2^p
 | 
|---|
| 95 |     c     then ix = sum_p=0  b_p * 4^p
 | 
|---|
| 96 |     c          iy = 2*ix
 | 
|---|
| 97 |     c     ix + iy in {0, 128**2 -1}
 | 
|---|
| 98 |     =================================================
 | 
|---|
| 99 |   */
 | 
|---|
| 100 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 101 |   //  (16/12/98)
 | 
|---|
| 102 | 
 | 
|---|
| 103 |   int K,IP,I,J,ID;
 | 
|---|
| 104 |   for(I = 1; I <= 128; I++) 
 | 
|---|
| 105 |     {
 | 
|---|
| 106 |       J  = I-1;//            !pixel numbers
 | 
|---|
| 107 |       K  = 0;//
 | 
|---|
| 108 |       IP = 1;//
 | 
|---|
| 109 |       truc : if( J==0 ) 
 | 
|---|
| 110 |         {
 | 
|---|
| 111 |           x2pix_(I-1) = K;
 | 
|---|
| 112 |           y2pix_(I-1) = 2*K;
 | 
|---|
| 113 |         }
 | 
|---|
| 114 |       else 
 | 
|---|
| 115 |         {
 | 
|---|
| 116 |           ID = (int)fmod(J,2);
 | 
|---|
| 117 |           J  = J/2;
 | 
|---|
| 118 |           K  = IP*ID+K;
 | 
|---|
| 119 |           IP = IP*4;
 | 
|---|
| 120 |           goto truc;
 | 
|---|
| 121 |         }
 | 
|---|
| 122 |     }     
 | 
|---|
| 123 | }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | //*******************************************************************
 | 
|---|
| 126 | //++ 
 | 
|---|
| 127 | // Class        SphereGorski
 | 
|---|
| 128 | //
 | 
|---|
| 129 | // include      spheregorski.h strutil.h
 | 
|---|
| 130 | //
 | 
|---|
| 131 | //    Pixelisation Gorski  
 | 
|---|
| 132 | //
 | 
|---|
| 133 | //
 | 
|---|
| 134 | //|    -----------------------------------------------------------------------
 | 
|---|
| 135 | //|     version 0.8.2  Aug97 TAC  Eric Hivon, Kris Gorski
 | 
|---|
| 136 | //|    -----------------------------------------------------------------------
 | 
|---|
| 137 | //
 | 
|---|
| 138 | //    the sphere is split in 12 diamond-faces containing nside**2 pixels each
 | 
|---|
| 139 | //
 | 
|---|
| 140 | //    the numbering of the pixels (in the nested scheme) is similar to
 | 
|---|
| 141 | //    quad-cube
 | 
|---|
| 142 | //    In each face the first pixel is in the lowest corner of the diamond
 | 
|---|
| 143 | //
 | 
|---|
| 144 | //    the faces are                    (x,y) coordinate on each face
 | 
|---|
| 145 | //|        .   .   .   .   <--- North Pole
 | 
|---|
| 146 | //|       / \ / \ / \ / \                          ^        ^     
 | 
|---|
| 147 | //|      . 0 . 1 . 2 . 3 . <--- z = 2/3             \      /      
 | 
|---|
| 148 | //|       \ / \ / \ / \ /                        y   \    /  x   
 | 
|---|
| 149 | //|      4 . 5 . 6 . 7 . 4 <--- equator               \  /                     
 | 
|---|
| 150 | //|       / \ / \ / \ / \                              \/        
 | 
|---|
| 151 | //|      . 8 . 9 .10 .11 . <--- z = -2/3              (0,0) : lowest corner  
 | 
|---|
| 152 | //|       \ / \ / \ / \ /                                  
 | 
|---|
| 153 | //|        .   .   .   .   <--- South Pole
 | 
|---|
| 154 | //|
 | 
|---|
| 155 | //    phi:0               2Pi                                 
 | 
|---|
| 156 | //
 | 
|---|
| 157 | //    in the ring scheme pixels are numbered along the parallels
 | 
|---|
| 158 | //    the first parallel is the one closest to the north pole and so on
 | 
|---|
| 159 | //    on each parallel, pixels are numbered starting from the one closest
 | 
|---|
| 160 | //    to phi = 0
 | 
|---|
| 161 | //
 | 
|---|
| 162 | //    nside MUST be a power of 2 (<= 8192)
 | 
|---|
| 163 | //--
 | 
|---|
| 164 | //++
 | 
|---|
| 165 | //
 | 
|---|
| 166 | // Links        Parents
 | 
|---|
| 167 | //
 | 
|---|
| 168 | //    SphericalMap 
 | 
|---|
| 169 | //-- 
 | 
|---|
| 170 | 
 | 
|---|
| 171 | /* --Methode-- */
 | 
|---|
| 172 | //++
 | 
|---|
| 173 | // Titre        Constructors
 | 
|---|
| 174 | //--
 | 
|---|
| 175 | //++
 | 
|---|
| 176 | 
 | 
|---|
| 177 | template<class T>
 | 
|---|
| 178 | SphereGorski<T>::SphereGorski()
 | 
|---|
| 179 | 
 | 
|---|
| 180 | //--
 | 
|---|
| 181 | {
 | 
|---|
| 182 |   InitNul();
 | 
|---|
| 183 |   pixels_.Reset();
 | 
|---|
| 184 | }
 | 
|---|
| 185 | 
 | 
|---|
| 186 | //++
 | 
|---|
| 187 | template<class T>
 | 
|---|
| 188 | SphereGorski<T>::SphereGorski(int_4 m)
 | 
|---|
| 189 | 
 | 
|---|
| 190 | //    m is the "nside" of the Gorski algorithm
 | 
|---|
| 191 | //
 | 
|---|
| 192 | //    The total number of pixels will be Npix =  12*nside**2
 | 
|---|
| 193 | //
 | 
|---|
| 194 | //    nside MUST be a power of 2 (<= 8192)
 | 
|---|
| 195 | //--
 | 
|---|
| 196 | {
 | 
|---|
| 197 | 
 | 
|---|
| 198 |   if(m <= 0 || m > 8192) 
 | 
|---|
| 199 |     {
 | 
|---|
| 200 |       cout << "SphereGorski : m hors bornes [0,8192], m= " << m << endl;
 | 
|---|
| 201 |       throw RangeCheckError("SphereGorski<T>::SphereGorski() - Out of bound nside (< 8192)!");
 | 
|---|
| 202 |     }
 | 
|---|
| 203 |   // verifier que m est une puissance de deux 
 | 
|---|
| 204 |   int x= m;
 | 
|---|
| 205 |   while(x%2 == 0) x/=2;
 | 
|---|
| 206 |   if(x != 1) 
 | 
|---|
| 207 |     {  
 | 
|---|
| 208 |       cout<<"SphereGorski: m doit etre une puissance de deux, m= "<<m<<endl;
 | 
|---|
| 209 |       throw ParmError("SphereGorski<T>::SphereGorski() - nside != 2^n !");
 | 
|---|
| 210 |     }
 | 
|---|
| 211 |   InitNul();
 | 
|---|
| 212 |   Pixelize(m);
 | 
|---|
| 213 |   SetThetaSlices();
 | 
|---|
| 214 | }
 | 
|---|
| 215 | //++
 | 
|---|
| 216 | template<class T>
 | 
|---|
| 217 | SphereGorski<T>::SphereGorski(const SphereGorski<T>& s, bool share)
 | 
|---|
| 218 |   : pixels_(s.pixels_, share)
 | 
|---|
| 219 | //    copy constructor
 | 
|---|
| 220 | //--
 | 
|---|
| 221 | {
 | 
|---|
| 222 |   if(s.mInfo_) mInfo_= new DVList(*s.mInfo_);
 | 
|---|
| 223 | 
 | 
|---|
| 224 |   nSide_= s.nSide_;
 | 
|---|
| 225 |   nPix_ = s.nPix_;
 | 
|---|
| 226 |   omeg_ = s.omeg_;
 | 
|---|
| 227 | }
 | 
|---|
| 228 | 
 | 
|---|
| 229 | //++
 | 
|---|
| 230 | // Titre        Destructor
 | 
|---|
| 231 | //--
 | 
|---|
| 232 | //++
 | 
|---|
| 233 | template<class T>
 | 
|---|
| 234 | SphereGorski<T>::~SphereGorski()
 | 
|---|
| 235 | 
 | 
|---|
| 236 | //--
 | 
|---|
| 237 | {
 | 
|---|
| 238 | }
 | 
|---|
| 239 | 
 | 
|---|
| 240 | //++
 | 
|---|
| 241 | // Titre        Public Methods
 | 
|---|
| 242 | //--
 | 
|---|
| 243 | 
 | 
|---|
| 244 | //++
 | 
|---|
| 245 | template<class T>
 | 
|---|
| 246 | void SphereGorski<T>::Resize(int_4 m)
 | 
|---|
| 247 | 
 | 
|---|
| 248 | //    m is the "nside" of the Gorski algorithm
 | 
|---|
| 249 | //
 | 
|---|
| 250 | //    The total number of pixels will be Npix =  12*nside**2
 | 
|---|
| 251 | //
 | 
|---|
| 252 | //    nside MUST be a power of 2 (<= 8192)
 | 
|---|
| 253 | //--
 | 
|---|
| 254 | {
 | 
|---|
| 255 |   if (m<=0 || m> 8192) {
 | 
|---|
| 256 |     cout << "SphereGorski : m hors bornes [0,8192], m= " << m << endl;
 | 
|---|
| 257 |     exit(1);
 | 
|---|
| 258 |   }
 | 
|---|
| 259 |   // verifier que m est une puissance de deux 
 | 
|---|
| 260 |   int x= m;
 | 
|---|
| 261 |   while (x%2==0) x/=2;
 | 
|---|
| 262 |   if(x != 1) 
 | 
|---|
| 263 |     {  
 | 
|---|
| 264 |       cout<<"SphereGorski: m doit etre une puissance de deux, m= "<<m<<endl;
 | 
|---|
| 265 |       exit(1);
 | 
|---|
| 266 |     }
 | 
|---|
| 267 |   InitNul();
 | 
|---|
| 268 |   Pixelize(m);
 | 
|---|
| 269 |   SetThetaSlices();
 | 
|---|
| 270 | }
 | 
|---|
| 271 | 
 | 
|---|
| 272 | template<class T>
 | 
|---|
| 273 | void  SphereGorski<T>::Pixelize( int_4 m) 
 | 
|---|
| 274 | 
 | 
|---|
| 275 | //    prépare la pixelisation Gorski (m a la même signification 
 | 
|---|
| 276 | //    que pour le constructeur)
 | 
|---|
| 277 | //
 | 
|---|
| 278 | //    
 | 
|---|
| 279 | {
 | 
|---|
| 280 |   // On memorise les arguments d'appel
 | 
|---|
| 281 |   nSide_= m;  
 | 
|---|
| 282 | 
 | 
|---|
| 283 |   // Nombre total de pixels sur la sphere entiere
 | 
|---|
| 284 |   nPix_= 12*nSide_*nSide_;
 | 
|---|
| 285 | 
 | 
|---|
| 286 |   // pour le moment les tableaux qui suivent seront ranges dans l'ordre 
 | 
|---|
| 287 |   // de l'indexation GORSKY "RING"
 | 
|---|
| 288 |   // on pourra ulterieurement changer de strategie et tirer profit
 | 
|---|
| 289 |   // de la dualite d'indexation GORSKY (RING et NEST) : tout dependra 
 | 
|---|
| 290 |   // de pourquoi c'est faire
 | 
|---|
| 291 | 
 | 
|---|
| 292 |   // Creation et initialisation du vecteur des contenus des pixels 
 | 
|---|
| 293 |   pixels_.ReSize(nPix_);
 | 
|---|
| 294 |   pixels_.Reset();
 | 
|---|
| 295 | 
 | 
|---|
| 296 |   // solid angle per pixel   
 | 
|---|
| 297 |   omeg_= 4.0*Pi/nPix_;
 | 
|---|
| 298 | }
 | 
|---|
| 299 | 
 | 
|---|
| 300 | template<class T>
 | 
|---|
| 301 | void SphereGorski<T>::InitNul()
 | 
|---|
| 302 | //
 | 
|---|
| 303 | //    initialise à zéro les variables de classe 
 | 
|---|
| 304 | {
 | 
|---|
| 305 |   nSide_= 0;
 | 
|---|
| 306 |   nPix_ = 0;
 | 
|---|
| 307 |   omeg_ = 0.;
 | 
|---|
| 308 | //  pixels_.Reset();  -  Il ne faut pas mettre les pixels a zero si share !
 | 
|---|
| 309 | }
 | 
|---|
| 310 | 
 | 
|---|
| 311 | /* --Methode-- */
 | 
|---|
| 312 | //++
 | 
|---|
| 313 | template<class T>
 | 
|---|
| 314 | int_4 SphereGorski<T>::NbPixels() const
 | 
|---|
| 315 | 
 | 
|---|
| 316 | //    Retourne le nombre de pixels du découpage
 | 
|---|
| 317 | //--
 | 
|---|
| 318 | {  
 | 
|---|
| 319 |   return(nPix_);
 | 
|---|
| 320 | }
 | 
|---|
| 321 | 
 | 
|---|
| 322 | //++
 | 
|---|
| 323 | template<class T>
 | 
|---|
| 324 | uint_4 SphereGorski<T>::NbThetaSlices() const 
 | 
|---|
| 325 | 
 | 
|---|
| 326 | //    Return number of slices in theta direction on the  sphere
 | 
|---|
| 327 | //--
 | 
|---|
| 328 | {
 | 
|---|
| 329 |   uint_4 nbslices = uint_4(4*nSide_-1);
 | 
|---|
| 330 |   if (nSide_<=0) 
 | 
|---|
| 331 |     {
 | 
|---|
| 332 |       nbslices = 0;
 | 
|---|
| 333 |       throw PException(" sphere not pixelized, NbSlice=0 ");
 | 
|---|
| 334 |     }
 | 
|---|
| 335 |   return nbslices;
 | 
|---|
| 336 | }
 | 
|---|
| 337 | 
 | 
|---|
| 338 | //++
 | 
|---|
| 339 | template<class T>
 | 
|---|
| 340 | void SphereGorski<T>::GetThetaSlice(int_4 index, r_8& theta,TVector<r_8>& phi,TVector<T>& value) const 
 | 
|---|
| 341 | 
 | 
|---|
| 342 | //    For a theta-slice with index 'index', return : 
 | 
|---|
| 343 | //
 | 
|---|
| 344 | //    the corresponding "theta" 
 | 
|---|
| 345 | //
 | 
|---|
| 346 | //    a vector containing the phi's of the pixels of the slice
 | 
|---|
| 347 | //
 | 
|---|
| 348 | //    a vector containing the corresponding values of pixels 
 | 
|---|
| 349 | //
 | 
|---|
| 350 | //--
 | 
|---|
| 351 | {
 | 
|---|
| 352 | 
 | 
|---|
| 353 |   if (index<0 || index >= NbThetaSlices()) 
 | 
|---|
| 354 |     {
 | 
|---|
| 355 |       // THROW(out_of_range("SphereGorski::PIxVal Pixel index out of range")); 
 | 
|---|
| 356 |       cout << " SphereGorski::GetThetaSlice : Pixel index out of range" <<endl;
 | 
|---|
| 357 |       THROW(rangeCheckErr);
 | 
|---|
| 358 |     }
 | 
|---|
| 359 | 
 | 
|---|
| 360 | 
 | 
|---|
| 361 |   int_4 iring= sliceBeginIndex_(index);
 | 
|---|
| 362 |   int_4 lring  =  sliceLenght_(index);
 | 
|---|
| 363 | 
 | 
|---|
| 364 | 
 | 
|---|
| 365 |   phi.ReSize(lring);
 | 
|---|
| 366 |   value.ReSize(lring);
 | 
|---|
| 367 |   double TH= 0.;
 | 
|---|
| 368 |   double FI= 0.;
 | 
|---|
| 369 |   for(int_4 kk = 0; kk < lring;kk++) 
 | 
|---|
| 370 |     {
 | 
|---|
| 371 |       PixThetaPhi(kk+iring,TH,FI);
 | 
|---|
| 372 |       phi(kk)= FI;
 | 
|---|
| 373 |       value(kk)= PixVal(kk+iring);
 | 
|---|
| 374 |     }
 | 
|---|
| 375 |   theta= TH;
 | 
|---|
| 376 | }
 | 
|---|
| 377 | //++
 | 
|---|
| 378 | //++
 | 
|---|
| 379 | 
 | 
|---|
| 380 | template<class T>
 | 
|---|
| 381 | void SphereGorski<T>::GetThetaSlice(int_4 sliceIndex,r_8& theta, r_8& phi0, TVector<int_4>& pixelIndices,TVector<T>& value) const 
 | 
|---|
| 382 | 
 | 
|---|
| 383 | //    For a theta-slice with index 'sliceIndex', return : 
 | 
|---|
| 384 | //
 | 
|---|
| 385 | //    the corresponding "theta" 
 | 
|---|
| 386 | //    the corresponding "phi" for first pixel of the slice 
 | 
|---|
| 387 | //
 | 
|---|
| 388 | //    a vector containing the indices of the pixels of the slice
 | 
|---|
| 389 | //    (equally distributed in phi)
 | 
|---|
| 390 | //
 | 
|---|
| 391 | //    a vector containing the corresponding values of pixels 
 | 
|---|
| 392 | //
 | 
|---|
| 393 | //--
 | 
|---|
| 394 | {
 | 
|---|
| 395 | 
 | 
|---|
| 396 |   if (sliceIndex<0 || sliceIndex >= NbThetaSlices()) 
 | 
|---|
| 397 |     {
 | 
|---|
| 398 |       // THROW(out_of_range("SphereGorski::PIxVal Pixel index out of range")); 
 | 
|---|
| 399 |       cout << " SphereGorski::GetThetaSlice : Pixel index out of range" <<endl;
 | 
|---|
| 400 |       THROW(rangeCheckErr);
 | 
|---|
| 401 |     }
 | 
|---|
| 402 | 
 | 
|---|
| 403 |   int_4 iring= sliceBeginIndex_(sliceIndex);
 | 
|---|
| 404 |   int_4 lring  =  sliceLenght_(sliceIndex);
 | 
|---|
| 405 |   pixelIndices.ReSize(lring);
 | 
|---|
| 406 |   value.ReSize(lring);
 | 
|---|
| 407 |   for(int_4 kk = 0; kk < lring;kk++) 
 | 
|---|
| 408 |     {
 | 
|---|
| 409 |       pixelIndices(kk)= kk+iring;
 | 
|---|
| 410 |       value(kk)= PixVal(kk+iring);
 | 
|---|
| 411 |     }
 | 
|---|
| 412 |   PixThetaPhi(iring, theta, phi0);
 | 
|---|
| 413 | }
 | 
|---|
| 414 | //++
 | 
|---|
| 415 | template<class T>
 | 
|---|
| 416 | void SphereGorski<T>::SetThetaSlices()  
 | 
|---|
| 417 | 
 | 
|---|
| 418 | //--
 | 
|---|
| 419 | {
 | 
|---|
| 420 |   sliceBeginIndex_.ReSize(4*nSide_-1);
 | 
|---|
| 421 |   sliceLenght_.ReSize(4*nSide_-1);
 | 
|---|
| 422 |   for (int sliceIndex=0; sliceIndex<  nSide_-1; sliceIndex++)
 | 
|---|
| 423 |     {
 | 
|---|
| 424 |       sliceBeginIndex_(sliceIndex)  = 2*sliceIndex*(sliceIndex+1);
 | 
|---|
| 425 |       sliceLenght_(sliceIndex) = 4*(sliceIndex+1);
 | 
|---|
| 426 |     }
 | 
|---|
| 427 |   for (int sliceIndex= nSide_-1; sliceIndex<  3*nSide_; sliceIndex++)
 | 
|---|
| 428 |     {
 | 
|---|
| 429 |       sliceBeginIndex_(sliceIndex)  = 2*nSide_*(2*sliceIndex-nSide_+1);
 | 
|---|
| 430 |       sliceLenght_(sliceIndex) = 4*nSide_;
 | 
|---|
| 431 |     }
 | 
|---|
| 432 |   for (int sliceIndex= 3*nSide_; sliceIndex< 4*nSide_-1; sliceIndex++)
 | 
|---|
| 433 |     {
 | 
|---|
| 434 |       int_4 nc= 4*nSide_-1-sliceIndex;
 | 
|---|
| 435 |       sliceBeginIndex_(sliceIndex)  = nPix_-2*nc*(nc+1); 
 | 
|---|
| 436 |       sliceLenght_(sliceIndex) = 4*nc;
 | 
|---|
| 437 |     }
 | 
|---|
| 438 | }
 | 
|---|
| 439 | 
 | 
|---|
| 440 | /* --Methode-- */
 | 
|---|
| 441 | //++
 | 
|---|
| 442 | template<class T>
 | 
|---|
| 443 | T& SphereGorski<T>::PixVal(int_4 k)
 | 
|---|
| 444 | 
 | 
|---|
| 445 | //    Return value of  pixel with "RING" index k 
 | 
|---|
| 446 | //--
 | 
|---|
| 447 | {
 | 
|---|
| 448 |   if((k < 0) || (k >= nPix_)) 
 | 
|---|
| 449 |     {
 | 
|---|
| 450 |       // THROW(out_of_range("SphereGorski::PIxVal Pixel index out of range")); 
 | 
|---|
| 451 |       cout << " SphereGorski::PIxVal : exception  a mettre en place, k= " << k <<endl;
 | 
|---|
| 452 |       THROW(rangeCheckErr);
 | 
|---|
| 453 |     }
 | 
|---|
| 454 |   return pixels_(k);
 | 
|---|
| 455 | }
 | 
|---|
| 456 | 
 | 
|---|
| 457 | /* --Methode-- */
 | 
|---|
| 458 | //++
 | 
|---|
| 459 | template<class T>
 | 
|---|
| 460 | T const& SphereGorski<T>::PixVal(int_4 k) const
 | 
|---|
| 461 | 
 | 
|---|
| 462 | //    Return value of  pixel with "RING" index k 
 | 
|---|
| 463 | //--
 | 
|---|
| 464 | {
 | 
|---|
| 465 |   if((k < 0) || (k >= nPix_)) 
 | 
|---|
| 466 |     {
 | 
|---|
| 467 |       //THROW(out_of_range("SphereGorski::PIxVal Pixel index out of range")); 
 | 
|---|
| 468 |       cout << " SphereGorski::PIxVal : exception  a mettre en place, k= " << k <<endl;
 | 
|---|
| 469 |       THROW(rangeCheckErr);
 | 
|---|
| 470 |     }
 | 
|---|
| 471 |   return *(pixels_.Data()+k);
 | 
|---|
| 472 | }
 | 
|---|
| 473 | 
 | 
|---|
| 474 | //++
 | 
|---|
| 475 | template<class T>
 | 
|---|
| 476 | T& SphereGorski<T>::PixValNest(int_4 k)
 | 
|---|
| 477 | 
 | 
|---|
| 478 | //    Return value of  pixel with "NESTED" index k 
 | 
|---|
| 479 | //--
 | 
|---|
| 480 | {
 | 
|---|
| 481 |   if((k < 0) || (k >= nPix_)) 
 | 
|---|
| 482 |     { 
 | 
|---|
| 483 |       //THROW(out_of_range("SphereGorski::PIxValNest Pixel index out of range")); 
 | 
|---|
| 484 |       cout<<" SphereGorski::PIxValNest : exceptions a mettre en place" <<endl;
 | 
|---|
| 485 |       THROW(rangeCheckErr);
 | 
|---|
| 486 |     }
 | 
|---|
| 487 |   return pixels_(nest2ring(nSide_,k));
 | 
|---|
| 488 | }
 | 
|---|
| 489 | //++
 | 
|---|
| 490 | 
 | 
|---|
| 491 | template<class T>
 | 
|---|
| 492 | T const& SphereGorski<T>::PixValNest(int_4 k) const
 | 
|---|
| 493 | 
 | 
|---|
| 494 | //    Return value of  pixel with "NESTED" index k 
 | 
|---|
| 495 | //--
 | 
|---|
| 496 | {
 | 
|---|
| 497 |   if((k < 0) || (k >= nPix_)) 
 | 
|---|
| 498 |     { 
 | 
|---|
| 499 |       //THROW(out_of_range("SphereGorski::PIxValNest Pixel index out of range")); 
 | 
|---|
| 500 |       cout<<" SphereGorski::PIxValNest : exceptions a mettre en place" <<endl;
 | 
|---|
| 501 |       THROW(rangeCheckErr);
 | 
|---|
| 502 |   }
 | 
|---|
| 503 |   int_4 pix= nest2ring(nSide_,k);
 | 
|---|
| 504 |   return *(pixels_.Data()+pix);
 | 
|---|
| 505 | }
 | 
|---|
| 506 | 
 | 
|---|
| 507 | /* --Methode-- */
 | 
|---|
| 508 | //++
 | 
|---|
| 509 | template<class T>
 | 
|---|
| 510 | bool SphereGorski<T>::ContainsSph(double /*theta*/, double /*phi*/) const
 | 
|---|
| 511 | //--
 | 
|---|
| 512 | {
 | 
|---|
| 513 | return(true);
 | 
|---|
| 514 | }
 | 
|---|
| 515 | 
 | 
|---|
| 516 | /* --Methode-- */
 | 
|---|
| 517 | //++
 | 
|---|
| 518 | template<class T>
 | 
|---|
| 519 | int_4 SphereGorski<T>::PixIndexSph(double theta,double phi) const
 | 
|---|
| 520 | 
 | 
|---|
| 521 | //    Return "RING" index of the pixel corresponding to 
 | 
|---|
| 522 | //    direction (theta, phi).
 | 
|---|
| 523 | //--
 | 
|---|
| 524 | {
 | 
|---|
| 525 |   return ang2pix_ring(nSide_,theta,phi);
 | 
|---|
| 526 | }
 | 
|---|
| 527 | 
 | 
|---|
| 528 | //++
 | 
|---|
| 529 | template<class T>
 | 
|---|
| 530 | int_4 SphereGorski<T>::PixIndexSphNest(double theta,double  phi) const
 | 
|---|
| 531 | 
 | 
|---|
| 532 | //    Return "NESTED" index of the pixel corresponding to 
 | 
|---|
| 533 | //    direction (theta, phi).
 | 
|---|
| 534 | //--
 | 
|---|
| 535 | {
 | 
|---|
| 536 |   return ang2pix_nest(nSide_,theta,phi);
 | 
|---|
| 537 | }
 | 
|---|
| 538 | 
 | 
|---|
| 539 | 
 | 
|---|
| 540 | /* --Methode-- */
 | 
|---|
| 541 | //++
 | 
|---|
| 542 | template<class T>
 | 
|---|
| 543 | void SphereGorski<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
 | 
|---|
| 544 | 
 | 
|---|
| 545 | //   Return (theta,phi) coordinates of middle of  pixel with "RING" index k
 | 
|---|
| 546 | //--
 | 
|---|
| 547 | {
 | 
|---|
| 548 |   pix2ang_ring(nSide_,k,theta,phi);
 | 
|---|
| 549 | }
 | 
|---|
| 550 | 
 | 
|---|
| 551 | template <class T>
 | 
|---|
| 552 | T SphereGorski<T>::SetPixels(T v)
 | 
|---|
| 553 | {
 | 
|---|
| 554 | pixels_.Reset(v);
 | 
|---|
| 555 | return(v);
 | 
|---|
| 556 | }
 | 
|---|
| 557 | 
 | 
|---|
| 558 | //++
 | 
|---|
| 559 | template<class T>
 | 
|---|
| 560 | double SphereGorski<T>::PixSolAngle(int_4 /*dummy*/) const
 | 
|---|
| 561 | //    Pixel Solid angle  (steradians)
 | 
|---|
| 562 | //    All the pixels have the same solid angle. The dummy argument is
 | 
|---|
| 563 | //    for compatibility with eventual pixelizations which would not 
 | 
|---|
| 564 | //    fulfil this requirement.
 | 
|---|
| 565 | //--
 | 
|---|
| 566 | {
 | 
|---|
| 567 |   return omeg_;
 | 
|---|
| 568 | }
 | 
|---|
| 569 | 
 | 
|---|
| 570 | //++
 | 
|---|
| 571 | template<class T>
 | 
|---|
| 572 | void SphereGorski<T>::PixThetaPhiNest(int_4 k,double& theta,double& phi) const
 | 
|---|
| 573 | 
 | 
|---|
| 574 | //   Return (theta,phi) coordinates of middle of  pixel with "NESTED" index k
 | 
|---|
| 575 | //--
 | 
|---|
| 576 | {   
 | 
|---|
| 577 |   pix2ang_nest(nSide_,k,theta,phi);
 | 
|---|
| 578 | }
 | 
|---|
| 579 | 
 | 
|---|
| 580 | //++
 | 
|---|
| 581 | template<class T>
 | 
|---|
| 582 | int_4 SphereGorski<T>::NestToRing(int_4 k) const
 | 
|---|
| 583 | 
 | 
|---|
| 584 | //    translation from NESTED index  into RING index 
 | 
|---|
| 585 | //
 | 
|---|
| 586 | //--
 | 
|---|
| 587 | {
 | 
|---|
| 588 |   return  nest2ring(nSide_,k);
 | 
|---|
| 589 | }
 | 
|---|
| 590 | 
 | 
|---|
| 591 | //++
 | 
|---|
| 592 | template<class T>
 | 
|---|
| 593 | int_4 SphereGorski<T>::RingToNest(int_4 k) const
 | 
|---|
| 594 | //
 | 
|---|
| 595 | //    translation from  RING index  into NESTED index 
 | 
|---|
| 596 | //
 | 
|---|
| 597 | //--
 | 
|---|
| 598 | {
 | 
|---|
| 599 |   return  ring2nest(nSide_,k);
 | 
|---|
| 600 | }
 | 
|---|
| 601 | 
 | 
|---|
| 602 | 
 | 
|---|
| 603 | template<class T>
 | 
|---|
| 604 | int_4 SphereGorski<T>::nest2ring(int_4 nside, int_4 ipnest) const 
 | 
|---|
| 605 | {
 | 
|---|
| 606 |   /*
 | 
|---|
| 607 |     ====================================================
 | 
|---|
| 608 |     subroutine nest2ring(nside, ipnest, ipring)
 | 
|---|
| 609 |     ====================================================
 | 
|---|
| 610 |     c     conversion from NESTED to RING pixel number
 | 
|---|
| 611 |     ====================================================
 | 
|---|
| 612 |   */
 | 
|---|
| 613 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 614 |   //  (16/12/98)
 | 
|---|
| 615 |   
 | 
|---|
| 616 |   const PIXELS_XY& PXY= PIXELS_XY::instance();
 | 
|---|
| 617 | 
 | 
|---|
| 618 |   int npix, npface, face_num, ncap, n_before;
 | 
|---|
| 619 |   int ipf, ip_low, ip_trunc, ip_med, ip_hi;
 | 
|---|
| 620 |   int ix, iy, jrt, jr, nr, jpt, jp, kshift, nl4;
 | 
|---|
| 621 |   int ns_max=8192;
 | 
|---|
| 622 |   int jrll[12]={2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};
 | 
|---|
| 623 |   int jpll[12]={1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};
 | 
|---|
| 624 |   
 | 
|---|
| 625 |   if(  nside<1 ||  nside>ns_max ) {
 | 
|---|
| 626 |     cout << "nside out of range" << endl;
 | 
|---|
| 627 |     exit(0);
 | 
|---|
| 628 |   }
 | 
|---|
| 629 |   npix = 12 *  nside* nside;
 | 
|---|
| 630 |   if( ipnest<0 || ipnest>npix-1 ) {
 | 
|---|
| 631 |     cout << "ipnest out of range" << endl;
 | 
|---|
| 632 |     exit(0);
 | 
|---|
| 633 |   }
 | 
|---|
| 634 | 
 | 
|---|
| 635 |   ncap  = 2* nside*( nside-1);// ! number of points in the North Polar cap
 | 
|---|
| 636 |   nl4   = 4* nside;
 | 
|---|
| 637 |   
 | 
|---|
| 638 |   //c     finds the face, and the number in the face
 | 
|---|
| 639 |   npface =  nside* nside;
 | 
|---|
| 640 |   //cccccc      ip = ipnest - 1         ! in {0,npix-1}
 | 
|---|
| 641 |   
 | 
|---|
| 642 |   face_num = ipnest/npface;//  ! face number in {0,11}
 | 
|---|
| 643 |   ipf =ipnest%npface;//  ! pixel number in the face {0,npface-1}
 | 
|---|
| 644 |   //c     finds the x,y on the face (starting from the lowest corner)
 | 
|---|
| 645 |   //c     from the pixel number
 | 
|---|
| 646 |   ip_low=ipf%1024;                //   ! content of the last 10 bits
 | 
|---|
| 647 |   ip_trunc =   ipf/1024;         //    ! truncation of the last 10 bits
 | 
|---|
| 648 |   ip_med=ip_trunc%1024;         //     ! content of the next 10 bits
 | 
|---|
| 649 |   ip_hi  =     ip_trunc/1024;//   ! content of the high weight 10 bits
 | 
|---|
| 650 |   
 | 
|---|
| 651 |   ix = 1024*PXY.pix2x_(ip_hi)+32*PXY.pix2x_(ip_med)+PXY.pix2x_(ip_low);
 | 
|---|
| 652 |   iy = 1024*PXY.pix2y_(ip_hi)+32*PXY.pix2y_(ip_med)+PXY.pix2y_(ip_low);
 | 
|---|
| 653 |   
 | 
|---|
| 654 |   //c     transforms this in (horizontal, vertical) coordinates
 | 
|---|
| 655 |   jrt = ix + iy;//  ! 'vertical' in {0,2*(nside-1)}
 | 
|---|
| 656 |   jpt = ix - iy;//  ! 'horizontal' in {-nside+1,nside-1}
 | 
|---|
| 657 |   
 | 
|---|
| 658 |   //c     computes the z coordinate on the sphere
 | 
|---|
| 659 |   //      jr =  jrll[face_num+1]*nside - jrt - 1;//   ! ring number in {1,4*nside-1}
 | 
|---|
| 660 |   jr =  jrll[face_num]*nside - jrt - 1;
 | 
|---|
| 661 |   nr = nside;//                  ! equatorial region (the most frequent)
 | 
|---|
| 662 |   n_before = ncap + nl4 * (jr - nside);
 | 
|---|
| 663 |   kshift=(jr - nside)%2;
 | 
|---|
| 664 |   if( jr<nside ) {//then     ! north pole region
 | 
|---|
| 665 |     nr = jr;
 | 
|---|
| 666 |     n_before = 2 * nr * (nr - 1);
 | 
|---|
| 667 |     kshift = 0;
 | 
|---|
| 668 |   }
 | 
|---|
| 669 |   else if( jr>3*nside ) {//then ! south pole region
 | 
|---|
| 670 |     nr = nl4 - jr;
 | 
|---|
| 671 |     n_before = npix - 2 * (nr + 1) * nr;
 | 
|---|
| 672 |     kshift = 0;
 | 
|---|
| 673 |   }
 | 
|---|
| 674 |   
 | 
|---|
| 675 |   //c     computes the phi coordinate on the sphere, in [0,2Pi]
 | 
|---|
| 676 |   jp = (jpll[face_num]*nr + jpt + 1 + kshift)/2;//  ! 'phi' number in the ring in {1,4*nr}
 | 
|---|
| 677 |   
 | 
|---|
| 678 |   if( jp>nl4 ) jp = jp - nl4;
 | 
|---|
| 679 |   if( jp<1 )   jp = jp + nl4;
 | 
|---|
| 680 |   
 | 
|---|
| 681 |   int aux=n_before + jp - 1;
 | 
|---|
| 682 |   return (n_before + jp - 1);// ! in {0, npix-1}
 | 
|---|
| 683 | }
 | 
|---|
| 684 | 
 | 
|---|
| 685 | template<class T>
 | 
|---|
| 686 | int_4 SphereGorski<T>::ring2nest(int_4 nside, int_4 ipring) const 
 | 
|---|
| 687 | {
 | 
|---|
| 688 |   /*
 | 
|---|
| 689 |     ==================================================
 | 
|---|
| 690 |     subroutine ring2nest(nside, ipring, ipnest)
 | 
|---|
| 691 |     ==================================================
 | 
|---|
| 692 |     c     conversion from RING to NESTED pixel number
 | 
|---|
| 693 |     ==================================================
 | 
|---|
| 694 |   */
 | 
|---|
| 695 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 696 |   //  (16/12/98)
 | 
|---|
| 697 | 
 | 
|---|
| 698 |   const PIXELS_XY& PXY= PIXELS_XY::instance();
 | 
|---|
| 699 | 
 | 
|---|
| 700 |   double fihip, hip;
 | 
|---|
| 701 |   int npix, nl2, nl4, ncap, ip, iphi, ipt, ipring1;
 | 
|---|
| 702 |   int     kshift, face_num, nr;
 | 
|---|
| 703 |   int irn, ire, irm, irs, irt, ifm , ifp;
 | 
|---|
| 704 |   int ix, iy, ix_low, ix_hi, iy_low, iy_hi, ipf;
 | 
|---|
| 705 |   int ns_max(8192);
 | 
|---|
| 706 |   
 | 
|---|
| 707 |   // coordinate of the lowest corner of each face
 | 
|---|
| 708 |   int jrll[12]={2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};// ! in unit of nside
 | 
|---|
| 709 |   int jpll[12]={1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};//! in unit of nside/2
 | 
|---|
| 710 |   
 | 
|---|
| 711 |   if( nside<1 || nside>ns_max ) {
 | 
|---|
| 712 |     cout << "nside out of range" << endl;
 | 
|---|
| 713 |     exit(0);
 | 
|---|
| 714 |   }
 | 
|---|
| 715 |   npix = 12 * nside*nside;
 | 
|---|
| 716 |   if( ipring<0 || ipring>npix-1 ) {
 | 
|---|
| 717 |     cout << "ipring out of range" << endl;
 | 
|---|
| 718 |     exit(0);
 | 
|---|
| 719 |   }
 | 
|---|
| 720 |   
 | 
|---|
| 721 |   nl2 = 2*nside;
 | 
|---|
| 722 |   nl4 = 4*nside;
 | 
|---|
| 723 |   npix = 12*nside*nside;//      ! total number of points
 | 
|---|
| 724 |   ncap = 2*nside*(nside-1);// ! points in each polar cap, =0 for nside =1
 | 
|---|
| 725 |   ipring1 = ipring + 1;
 | 
|---|
| 726 |   
 | 
|---|
| 727 |   //c     finds the ring number, the position of the ring and the face number
 | 
|---|
| 728 |   if( ipring1<=ncap ) {//then
 | 
|---|
| 729 |     
 | 
|---|
| 730 |     hip   = ipring1/2.;
 | 
|---|
| 731 |     fihip = floor ( hip );
 | 
|---|
| 732 |     irn   = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;// ! counted from North pole
 | 
|---|
| 733 |     iphi  = ipring1 - 2*irn*(irn - 1);
 | 
|---|
| 734 |     
 | 
|---|
| 735 |     kshift = 0;
 | 
|---|
| 736 |     nr = irn   ;//               ! 1/4 of the number of points on the current ring
 | 
|---|
| 737 |     face_num = (iphi-1) / irn;// ! in {0,3}
 | 
|---|
| 738 |   }
 | 
|---|
| 739 |   else if( ipring1<=nl2*(5*nside+1) ) {//then
 | 
|---|
| 740 |     
 | 
|---|
| 741 |     ip    = ipring1 - ncap - 1;
 | 
|---|
| 742 |     irn   = (int)floor( ip / nl4 ) + nside;//               ! counted from North pole
 | 
|---|
| 743 |     iphi  = (int)fmod(ip,nl4) + 1;
 | 
|---|
| 744 |     
 | 
|---|
| 745 |     kshift  = (int)fmod(irn+nside,2);//  ! 1 if irn+nside is odd, 0 otherwise
 | 
|---|
| 746 |     nr = nside;
 | 
|---|
| 747 |     ire =  irn - nside + 1;// ! in {1, 2*nside +1}
 | 
|---|
| 748 |     irm =  nl2 + 2 - ire;
 | 
|---|
| 749 |     ifm = (iphi - ire/2 + nside -1) / nside;// ! face boundary
 | 
|---|
| 750 |     ifp = (iphi - irm/2 + nside -1) / nside;
 | 
|---|
| 751 |     if( ifp==ifm ) {//then          ! faces 4 to 7
 | 
|---|
| 752 |       face_num = (int)fmod(ifp,4) + 4;
 | 
|---|
| 753 |     }
 | 
|---|
| 754 |     else if( ifp + 1==ifm ) {//then ! (half-)faces 0 to 3
 | 
|---|
| 755 |       face_num = ifp;
 | 
|---|
| 756 |     }
 | 
|---|
| 757 |     else if( ifp - 1==ifm ) {//then ! (half-)faces 8 to 11
 | 
|---|
| 758 |       face_num = ifp + 7;
 | 
|---|
| 759 |     }
 | 
|---|
| 760 |   }
 | 
|---|
| 761 |   else {
 | 
|---|
| 762 |     
 | 
|---|
| 763 |     ip    = npix - ipring1 + 1;
 | 
|---|
| 764 |     hip   = ip/2.;
 | 
|---|
| 765 |     fihip = floor ( hip );
 | 
|---|
| 766 |     irs   = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;//  ! counted from South pole
 | 
|---|
| 767 |     iphi  = 4*irs + 1 - (ip - 2*irs*(irs-1));
 | 
|---|
| 768 |     
 | 
|---|
| 769 |     kshift = 0;
 | 
|---|
| 770 |     nr = irs;
 | 
|---|
| 771 |     irn   = nl4 - irs;
 | 
|---|
| 772 |     face_num = (iphi-1) / irs + 8;// ! in {8,11}
 | 
|---|
| 773 |   }
 | 
|---|
| 774 |   
 | 
|---|
| 775 |   //c     finds the (x,y) on the face
 | 
|---|
| 776 |   irt =   irn  - jrll[face_num]*nside + 1;//       ! in {-nside+1,0}
 | 
|---|
| 777 |   ipt = 2*iphi - jpll[face_num]*nr - kshift - 1;// ! in {-nside+1,nside-1}
 | 
|---|
| 778 | 
 | 
|---|
| 779 | 
 | 
|---|
| 780 |   if( ipt>=nl2 ) ipt = ipt - 8*nside;// ! for the face #4
 | 
|---|
| 781 |   
 | 
|---|
| 782 |   ix =  (ipt - irt ) / 2;
 | 
|---|
| 783 |   iy = -(ipt + irt ) / 2;
 | 
|---|
| 784 |   
 | 
|---|
| 785 |   ix_low = (int)fmod(ix,128);
 | 
|---|
| 786 |   ix_hi  = ix/128;
 | 
|---|
| 787 |   iy_low = (int)fmod(iy,128);
 | 
|---|
| 788 |   iy_hi  = iy/128;
 | 
|---|
| 789 |   ipf=(PXY.x2pix_(ix_hi)+PXY.y2pix_(iy_hi))*(128*128)+(PXY.x2pix_(ix_low)+PXY.y2pix_(iy_low));
 | 
|---|
| 790 | 
 | 
|---|
| 791 |   return (ipf + face_num* nside *nside);//   ! in {0, 12*nside**2 - 1}
 | 
|---|
| 792 | }
 | 
|---|
| 793 | 
 | 
|---|
| 794 | template<class T>
 | 
|---|
| 795 | int_4 SphereGorski<T>::ang2pix_ring(int_4 nside, double theta, double phi) const 
 | 
|---|
| 796 | {
 | 
|---|
| 797 |   /*
 | 
|---|
| 798 |     ==================================================
 | 
|---|
| 799 |     c     gives the pixel number ipix (RING) 
 | 
|---|
| 800 |     c     corresponding to angles theta and phi
 | 
|---|
| 801 |     c==================================================
 | 
|---|
| 802 |   */
 | 
|---|
| 803 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 804 |   //  (16/12/98)
 | 
|---|
| 805 | 
 | 
|---|
| 806 |   int nl2, nl4, ncap, npix, jp, jm, ipix1;
 | 
|---|
| 807 |   double  z, za, tt, tp, tmp;
 | 
|---|
| 808 |   int ir, ip, kshift;
 | 
|---|
| 809 | 
 | 
|---|
| 810 |   double piover2(Pi/2.);
 | 
|---|
| 811 |   double twopi(2.*Pi);
 | 
|---|
| 812 |   double z0(2./3.);
 | 
|---|
| 813 |   int ns_max(8192);
 | 
|---|
| 814 | 
 | 
|---|
| 815 |   if( nside<1 || nside>ns_max ) {
 | 
|---|
| 816 |     cout << "nside out of range" << endl;
 | 
|---|
| 817 |     exit(0);
 | 
|---|
| 818 |   }
 | 
|---|
| 819 | 
 | 
|---|
| 820 |   if( theta<0. || theta>Pi) {
 | 
|---|
| 821 |     cout << "theta out of range" << endl;
 | 
|---|
| 822 |     exit(0);
 | 
|---|
| 823 |   }
 | 
|---|
| 824 | 
 | 
|---|
| 825 |   z = cos(theta);
 | 
|---|
| 826 |   za = fabs(z);
 | 
|---|
| 827 |   if( phi >= twopi)  phi = phi - twopi;
 | 
|---|
| 828 |   if (phi < 0.)     phi = phi + twopi;
 | 
|---|
| 829 |   tt = phi / piover2;//  ! in [0,4)
 | 
|---|
| 830 | 
 | 
|---|
| 831 |   nl2 = 2*nside;
 | 
|---|
| 832 |   nl4 = 4*nside;
 | 
|---|
| 833 |   ncap  = nl2*(nside-1);// ! number of pixels in the north polar cap
 | 
|---|
| 834 |   npix  = 12*nside*nside;
 | 
|---|
| 835 | 
 | 
|---|
| 836 |   if( za <= z0 ) {
 | 
|---|
| 837 |     
 | 
|---|
| 838 |     jp = (int)floor(nside*(0.5 + tt - z*0.75));// ! index of  ascending edge line 
 | 
|---|
| 839 |     jm = (int)floor(nside*(0.5 + tt + z*0.75));// ! index of descending edge line
 | 
|---|
| 840 | 
 | 
|---|
| 841 |     ir = nside + 1 + jp - jm;// ! in {1,2n+1} (ring number counted from z=2/3)
 | 
|---|
| 842 |     kshift = 0;
 | 
|---|
| 843 |     if (fmod(ir,2)==0.) kshift = 1;// ! kshift=1 if ir even, 0 otherwise
 | 
|---|
| 844 |     
 | 
|---|
| 845 |     ip = (int)floor( ( jp+jm - nside + kshift + 1 ) / 2 ) + 1;// ! in {1,4n}
 | 
|---|
| 846 |     if( ip>nl4 ) ip = ip - nl4;
 | 
|---|
| 847 |     
 | 
|---|
| 848 |     ipix1 = ncap + nl4*(ir-1) + ip ;
 | 
|---|
| 849 |   }
 | 
|---|
| 850 |   else {
 | 
|---|
| 851 | 
 | 
|---|
| 852 |     tp = tt - floor(tt);//      !MOD(tt,1.d0)
 | 
|---|
| 853 |     tmp = sqrt( 3.*(1. - za) );
 | 
|---|
| 854 | 
 | 
|---|
| 855 |     jp = (int)floor( nside * tp * tmp );// ! increasing edge line index
 | 
|---|
| 856 |     jm = (int)floor( nside * (1. - tp) * tmp );// ! decreasing edge line index
 | 
|---|
| 857 | 
 | 
|---|
| 858 |     ir = jp + jm + 1;//        ! ring number counted from the closest pole
 | 
|---|
| 859 |     ip = (int)floor( tt * ir ) + 1;// ! in {1,4*ir}
 | 
|---|
| 860 |     if( ip>4*ir ) ip = ip - 4*ir;
 | 
|---|
| 861 |       
 | 
|---|
| 862 |     ipix1 = 2*ir*(ir-1) + ip;
 | 
|---|
| 863 |       if( z<=0. ) {
 | 
|---|
| 864 |         ipix1 = npix - 2*ir*(ir+1) + ip;
 | 
|---|
| 865 |       }
 | 
|---|
| 866 |   }
 | 
|---|
| 867 |     return (ipix1 - 1);// ! in {0, npix-1}
 | 
|---|
| 868 | }
 | 
|---|
| 869 | 
 | 
|---|
| 870 | template<class T>
 | 
|---|
| 871 | int_4 SphereGorski<T>::ang2pix_nest(int_4 nside, double theta, double phi) const 
 | 
|---|
| 872 | {
 | 
|---|
| 873 |   /*
 | 
|---|
| 874 |     ==================================================
 | 
|---|
| 875 |     subroutine ang2pix_nest(nside, theta, phi, ipix)
 | 
|---|
| 876 |     ==================================================
 | 
|---|
| 877 |     c     gives the pixel number ipix (NESTED) 
 | 
|---|
| 878 |     c     corresponding to angles theta and phi
 | 
|---|
| 879 |     c
 | 
|---|
| 880 |     c     the computation is made to the highest resolution available (nside=8192)
 | 
|---|
| 881 |     c     and then degraded to that required (by integer division)
 | 
|---|
| 882 |     c     this doesn't cost more, and it makes sure 
 | 
|---|
| 883 |     c     that the treatement of round-off will be consistent 
 | 
|---|
| 884 |     c     for every resolution
 | 
|---|
| 885 |     ==================================================
 | 
|---|
| 886 |   */
 | 
|---|
| 887 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 888 |   //  (16/12/98)
 | 
|---|
| 889 |   
 | 
|---|
| 890 |   const PIXELS_XY& PXY= PIXELS_XY::instance();
 | 
|---|
| 891 | 
 | 
|---|
| 892 |   double    z, za, z0, tt, tp, tmp;
 | 
|---|
| 893 |   int face_num,jp,jm;
 | 
|---|
| 894 |   int ifp, ifm;
 | 
|---|
| 895 |   int  ix, iy, ix_low, ix_hi, iy_low, iy_hi, ipf, ntt;
 | 
|---|
| 896 |   double piover2(Pi/2.), twopi(2.*Pi);
 | 
|---|
| 897 |   int ns_max(8192);
 | 
|---|
| 898 |   
 | 
|---|
| 899 |   if( nside<1 || nside>ns_max ) {
 | 
|---|
| 900 |     cout << "nside out of range" << endl;
 | 
|---|
| 901 |     exit(0);
 | 
|---|
| 902 |   }
 | 
|---|
| 903 |   if( theta<0 || theta>Pi ) {
 | 
|---|
| 904 |     cout << "theta out of range" << endl;
 | 
|---|
| 905 |     exit(0);
 | 
|---|
| 906 |   }
 | 
|---|
| 907 |   z  = cos(theta);
 | 
|---|
| 908 |   za = fabs(z);
 | 
|---|
| 909 |   z0 = 2./3.;
 | 
|---|
| 910 |   if( phi>=twopi ) phi = phi - twopi;
 | 
|---|
| 911 |   if( phi<0. )    phi = phi + twopi;
 | 
|---|
| 912 |   tt = phi / piover2;// ! in [0,4[
 | 
|---|
| 913 |   if( za<=z0 ) { // then ! equatorial region
 | 
|---|
| 914 |     
 | 
|---|
| 915 |     //(the index of edge lines increase when the longitude=phi goes up)
 | 
|---|
| 916 |     jp = (int)floor(ns_max*(0.5 + tt - z*0.75));// !  ascending edge line index
 | 
|---|
| 917 |     jm = (int)floor(ns_max*(0.5 + tt + z*0.75));// ! descending edge line index
 | 
|---|
| 918 |     
 | 
|---|
| 919 |     //c        finds the face
 | 
|---|
| 920 |     ifp = jp / ns_max;//  ! in {0,4}
 | 
|---|
| 921 |     ifm = jm / ns_max;
 | 
|---|
| 922 |     if( ifp==ifm ) face_num = (int)fmod(ifp,4) + 4; //then  ! faces 4 to 7
 | 
|---|
| 923 |     else if( ifp<ifm ) face_num = (int)fmod(ifp,4); // (half-)faces 0 to 3
 | 
|---|
| 924 |     else face_num = (int)fmod(ifm,4) + 8;//! (half-)faces 8 to 11
 | 
|---|
| 925 |     
 | 
|---|
| 926 |     ix = (int)fmod(jm, ns_max);
 | 
|---|
| 927 |     iy = ns_max - (int)fmod(jp, ns_max) - 1;
 | 
|---|
| 928 |   }
 | 
|---|
| 929 |   else { //! polar region, za > 2/3
 | 
|---|
| 930 |     
 | 
|---|
| 931 |     ntt = (int)floor(tt);
 | 
|---|
| 932 |     if( ntt>=4 ) ntt = 3;
 | 
|---|
| 933 |     tp = tt - ntt;
 | 
|---|
| 934 |     tmp = sqrt( 3.*(1. - za) );//  ! in ]0,1]
 | 
|---|
| 935 |     
 | 
|---|
| 936 |     //(the index of edge lines increase when distance from the closest pole goes up)
 | 
|---|
| 937 |     jp = (int)floor(ns_max*tp*tmp); // ! line going toward the pole as phi increases
 | 
|---|
| 938 |     jm = (int)floor(ns_max*(1.-tp)*tmp); // ! that one goes away of the closest pole
 | 
|---|
| 939 |     jp = (int)min(ns_max-1, jp);// ! for points too close to the boundary
 | 
|---|
| 940 |     jm = (int)min(ns_max-1, jm);
 | 
|---|
| 941 |     
 | 
|---|
| 942 |     // finds the face and pixel's (x,y)
 | 
|---|
| 943 |     if( z>=0 ) {
 | 
|---|
| 944 |       face_num = ntt;//  ! in {0,3}
 | 
|---|
| 945 |       ix = ns_max - jm - 1;
 | 
|---|
| 946 |       iy = ns_max - jp - 1;
 | 
|---|
| 947 |     }
 | 
|---|
| 948 |     else {
 | 
|---|
| 949 |       face_num = ntt + 8;// ! in {8,11}
 | 
|---|
| 950 |       ix =  jp;
 | 
|---|
| 951 |       iy =  jm;
 | 
|---|
| 952 |     }
 | 
|---|
| 953 |   }
 | 
|---|
| 954 |   
 | 
|---|
| 955 |   ix_low = (int)fmod(ix,128);
 | 
|---|
| 956 |   ix_hi  =     ix/128;
 | 
|---|
| 957 |   iy_low = (int)fmod(iy,128);
 | 
|---|
| 958 |   iy_hi  =     iy/128;
 | 
|---|
| 959 |   ipf= (PXY.x2pix_(ix_hi)+PXY.y2pix_(iy_hi))*(128*128)+(PXY.x2pix_(ix_low)+PXY.y2pix_(iy_low));
 | 
|---|
| 960 |   //  ipf = ipf / pow(ns_max/nside,2.);//  ! in {0, nside**2 - 1}
 | 
|---|
| 961 |   //  return ( ipf + face_num*pow(nside,2));//    ! in {0, 12*nside**2 - 1}
 | 
|---|
| 962 |   // $CHECK$  Reza 25/10/99 , pow remplace par *
 | 
|---|
| 963 |   ipf = ipf / ((ns_max/nside)*(ns_max/nside));
 | 
|---|
| 964 |   return (ipf + face_num*nside*nside);
 | 
|---|
| 965 | }
 | 
|---|
| 966 | 
 | 
|---|
| 967 | template<class T>
 | 
|---|
| 968 | void SphereGorski<T>::pix2ang_ring(int_4 nside,int_4 ipix,double& theta,double& phi) const {
 | 
|---|
| 969 |   /*
 | 
|---|
| 970 |     ===================================================
 | 
|---|
| 971 |     c     gives theta and phi corresponding to pixel ipix (RING) 
 | 
|---|
| 972 |     c     for a parameter nside
 | 
|---|
| 973 |     ===================================================
 | 
|---|
| 974 |   */
 | 
|---|
| 975 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 976 |   //  (16/12/98)
 | 
|---|
| 977 |   
 | 
|---|
| 978 |   int nl2, nl4, npix, ncap, iring, iphi, ip, ipix1;
 | 
|---|
| 979 |   double  fact1, fact2, fodd, hip, fihip;
 | 
|---|
| 980 |   
 | 
|---|
| 981 |   int ns_max(8192);
 | 
|---|
| 982 |   
 | 
|---|
| 983 |   if( nside<1 || nside>ns_max ) {
 | 
|---|
| 984 |     cout << "nside out of range" << endl;
 | 
|---|
| 985 |     exit(0);
 | 
|---|
| 986 |   }
 | 
|---|
| 987 |   npix = 12*nside*nside;      // ! total number of points
 | 
|---|
| 988 |   if( ipix<0 || ipix>npix-1 ) {
 | 
|---|
| 989 |     cout << "ipix out of range" << endl;
 | 
|---|
| 990 |     exit(0);
 | 
|---|
| 991 |   }
 | 
|---|
| 992 |   
 | 
|---|
| 993 |   ipix1 = ipix + 1; // in {1, npix}
 | 
|---|
| 994 |   nl2 = 2*nside;
 | 
|---|
| 995 |   nl4 = 4*nside;
 | 
|---|
| 996 |   ncap = 2*nside*(nside-1);// ! points in each polar cap, =0 for nside =1
 | 
|---|
| 997 |   fact1 = 1.5*nside;
 | 
|---|
| 998 |   fact2 = 3.0*nside*nside;
 | 
|---|
| 999 |   
 | 
|---|
| 1000 |   if( ipix1 <= ncap ) {  //! North Polar cap -------------
 | 
|---|
| 1001 |     
 | 
|---|
| 1002 |     hip   = ipix1/2.;
 | 
|---|
| 1003 |     fihip = floor(hip);
 | 
|---|
| 1004 |     iring = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;// ! counted from North pole
 | 
|---|
| 1005 |     iphi  = ipix1 - 2*iring*(iring - 1);
 | 
|---|
| 1006 |     
 | 
|---|
| 1007 |     theta = acos( 1. - iring*iring / fact2 );
 | 
|---|
| 1008 |     phi   = ((double)iphi - 0.5) * Pi/(2.*iring);
 | 
|---|
| 1009 |     //    cout << theta << " " << phi << endl;
 | 
|---|
| 1010 |   }
 | 
|---|
| 1011 |   else if( ipix1 <= nl2*(5*nside+1) ) {//then ! Equatorial region ------
 | 
|---|
| 1012 |     
 | 
|---|
| 1013 |     ip    = ipix1 - ncap - 1;
 | 
|---|
| 1014 |     iring = (int)floor( ip / nl4 ) + nside;// ! counted from North pole
 | 
|---|
| 1015 |     iphi  = ip%nl4 + 1;
 | 
|---|
| 1016 |     
 | 
|---|
| 1017 |     fodd  = 0.5 * (1 + (iring+nside)%2 );//  ! 1 if iring+nside is odd, 1/2 otherwise
 | 
|---|
| 1018 |     theta = acos( (nl2 - iring) / fact1 );
 | 
|---|
| 1019 |     phi   = ((double)iphi - fodd) * Pi /(2.*nside);
 | 
|---|
| 1020 |   }
 | 
|---|
| 1021 |   else {//! South Polar cap -----------------------------------
 | 
|---|
| 1022 |     
 | 
|---|
| 1023 |     ip    = npix - ipix1 + 1;
 | 
|---|
| 1024 |     hip   = ip/2.;
 | 
|---|
| 1025 |     fihip = floor(hip);
 | 
|---|
| 1026 |     iring = (int)floor( sqrt( hip - sqrt(fihip) ) ) + 1;//     ! counted from South pole
 | 
|---|
| 1027 |     iphi  = (int)(4.*iring + 1 - (ip - 2.*iring*(iring-1)));
 | 
|---|
| 1028 |     
 | 
|---|
| 1029 |     theta = acos( -1. + iring*iring / fact2 );
 | 
|---|
| 1030 |     phi   = ((double)iphi - 0.5) * Pi/(2.*iring);
 | 
|---|
| 1031 |     //    cout << theta << " " << phi << endl;
 | 
|---|
| 1032 |   }
 | 
|---|
| 1033 | }
 | 
|---|
| 1034 | 
 | 
|---|
| 1035 | template<class T>
 | 
|---|
| 1036 | void SphereGorski<T>::pix2ang_nest(int_4 nside,int_4 ipix,double& theta,double& phi) const {
 | 
|---|
| 1037 |   /*
 | 
|---|
| 1038 |     ==================================================
 | 
|---|
| 1039 |     subroutine pix2ang_nest(nside, ipix, theta, phi)
 | 
|---|
| 1040 |     ==================================================
 | 
|---|
| 1041 |     c     gives theta and phi corresponding to pixel ipix (NESTED) 
 | 
|---|
| 1042 |     c     for a parameter nside
 | 
|---|
| 1043 |     ==================================================
 | 
|---|
| 1044 |   */
 | 
|---|
| 1045 |   // tranlated from FORTRAN (Gorski) to C, by B. Revenu, revised Guy Le Meur
 | 
|---|
| 1046 |   //  (16/12/98)
 | 
|---|
| 1047 | 
 | 
|---|
| 1048 |   const PIXELS_XY& PXY= PIXELS_XY::instance();
 | 
|---|
| 1049 |     
 | 
|---|
| 1050 |   int npix, npface, face_num;
 | 
|---|
| 1051 |   int ipf, ip_low, ip_trunc, ip_med, ip_hi;
 | 
|---|
| 1052 |   int ix, iy, jrt, jr, nr, jpt, jp, kshift, nl4;
 | 
|---|
| 1053 |   double z, fn, fact1, fact2;
 | 
|---|
| 1054 |   double piover2(Pi/2.);
 | 
|---|
| 1055 |   int ns_max(8192);
 | 
|---|
| 1056 |           
 | 
|---|
| 1057 |   // ! coordinate of the lowest corner of each face
 | 
|---|
| 1058 |   int jrll[12]={2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};//! in unit of nside
 | 
|---|
| 1059 |   int jpll[12]={1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};// ! in unit of nside/2
 | 
|---|
| 1060 |   
 | 
|---|
| 1061 |   if( nside<1 || nside>ns_max ) {
 | 
|---|
| 1062 |     cout << "nside out of range" << endl;
 | 
|---|
| 1063 |     exit(0);
 | 
|---|
| 1064 |   }
 | 
|---|
| 1065 |   npix = 12 * nside*nside;
 | 
|---|
| 1066 |   if( ipix<0 || ipix>npix-1 ) {
 | 
|---|
| 1067 |     cout << "ipix out of range" << endl;
 | 
|---|
| 1068 |     exit(0);
 | 
|---|
| 1069 |   }
 | 
|---|
| 1070 |   
 | 
|---|
| 1071 |   fn = 1.*nside;
 | 
|---|
| 1072 |   fact1 = 1./(3.*fn*fn);
 | 
|---|
| 1073 |   fact2 = 2./(3.*fn);
 | 
|---|
| 1074 |   nl4   = 4*nside;
 | 
|---|
| 1075 | 
 | 
|---|
| 1076 |   //c     finds the face, and the number in the face
 | 
|---|
| 1077 |   npface = nside*nside;
 | 
|---|
| 1078 |   
 | 
|---|
| 1079 |   face_num = ipix/npface;//  ! face number in {0,11}
 | 
|---|
| 1080 |   ipf = (int)fmod(ipix,npface);//  ! pixel number in the face {0,npface-1}
 | 
|---|
| 1081 |   
 | 
|---|
| 1082 |   //c     finds the x,y on the face (starting from the lowest corner)
 | 
|---|
| 1083 |   //c     from the pixel number
 | 
|---|
| 1084 |   ip_low = (int)fmod(ipf,1024);//       ! content of the last 10 bits
 | 
|---|
| 1085 |   ip_trunc =   ipf/1024 ;//       ! truncation of the last 10 bits
 | 
|---|
| 1086 |   ip_med = (int)fmod(ip_trunc,1024);//  ! content of the next 10 bits
 | 
|---|
| 1087 |   ip_hi  =     ip_trunc/1024   ;//! content of the high weight 10 bits
 | 
|---|
| 1088 |   
 | 
|---|
| 1089 |   ix = 1024*PXY.pix2x_(ip_hi)+32*PXY.pix2x_(ip_med)+PXY.pix2x_(ip_low);
 | 
|---|
| 1090 |   iy = 1024*PXY.pix2y_(ip_hi)+32*PXY.pix2y_(ip_med)+PXY.pix2y_(ip_low);
 | 
|---|
| 1091 |   
 | 
|---|
| 1092 |   //c     transforms this in (horizontal, vertical) coordinates
 | 
|---|
| 1093 |   jrt = ix + iy;//  ! 'vertical' in {0,2*(nside-1)}
 | 
|---|
| 1094 |   jpt = ix - iy;//  ! 'horizontal' in {-nside+1,nside-1}
 | 
|---|
| 1095 |   
 | 
|---|
| 1096 |   //c     computes the z coordinate on the sphere
 | 
|---|
| 1097 |   //      jr =  jrll[face_num+1]*nside - jrt - 1;//   ! ring number in {1,4*nside-1}
 | 
|---|
| 1098 |   jr =  jrll[face_num]*nside - jrt - 1;
 | 
|---|
| 1099 |   nr = nside;//                  ! equatorial region (the most frequent)
 | 
|---|
| 1100 |   z  = (2*nside-jr)*fact2;
 | 
|---|
| 1101 |   kshift = (int)fmod(jr - nside, 2);
 | 
|---|
| 1102 |   if( jr<nside ) { //then     ! north pole region
 | 
|---|
| 1103 |     nr = jr;
 | 
|---|
| 1104 |     z = 1. - nr*nr*fact1;
 | 
|---|
| 1105 |     kshift = 0;
 | 
|---|
| 1106 |   }
 | 
|---|
| 1107 |   else {
 | 
|---|
| 1108 |     if( jr>3*nside ) {// then ! south pole region
 | 
|---|
| 1109 |       nr = nl4 - jr;
 | 
|---|
| 1110 |       z = - 1. + nr*nr*fact1;
 | 
|---|
| 1111 |       kshift = 0;
 | 
|---|
| 1112 |     }
 | 
|---|
| 1113 |   }
 | 
|---|
| 1114 |   theta = acos(z);
 | 
|---|
| 1115 |   
 | 
|---|
| 1116 |   //c     computes the phi coordinate on the sphere, in [0,2Pi]
 | 
|---|
| 1117 |   //      jp = (jpll[face_num+1]*nr + jpt + 1 + kshift)/2;//  ! 'phi' number in the ring in {1,4*nr}
 | 
|---|
| 1118 |   jp = (jpll[face_num]*nr + jpt + 1 + kshift)/2;
 | 
|---|
| 1119 |   if( jp>nl4 ) jp = jp - nl4;
 | 
|---|
| 1120 |   if( jp<1 )   jp = jp + nl4;
 | 
|---|
| 1121 |   phi = (jp - (kshift+1)*0.5) * (piover2 / nr);
 | 
|---|
| 1122 | }
 | 
|---|
| 1123 | 
 | 
|---|
| 1124 | 
 | 
|---|
| 1125 | 
 | 
|---|
| 1126 | template <class T>
 | 
|---|
| 1127 | void SphereGorski<T>::print(ostream& os) const
 | 
|---|
| 1128 | {
 | 
|---|
| 1129 |   if(mInfo_) os << "  DVList Info= " << *mInfo_ << endl;
 | 
|---|
| 1130 |   //
 | 
|---|
| 1131 |   os << " nSide_ = " << nSide_  << endl;
 | 
|---|
| 1132 |   os << " nPix_   = " << nPix_   << endl;
 | 
|---|
| 1133 |   os << " omeg_ = " << omeg_   << endl;
 | 
|---|
| 1134 | 
 | 
|---|
| 1135 |   os << " content of pixels : ";
 | 
|---|
| 1136 |   for(int i=0; i < nPix_; i++)
 | 
|---|
| 1137 |     {
 | 
|---|
| 1138 |       if(i%5 == 0) os << endl;
 | 
|---|
| 1139 |       os <<  pixels_(i) <<", ";
 | 
|---|
| 1140 |     }
 | 
|---|
| 1141 |   os << endl;
 | 
|---|
| 1142 | 
 | 
|---|
| 1143 |   os << endl;
 | 
|---|
| 1144 |   //const PIXELS_XY& PXY= PIXELS_XY::instance();
 | 
|---|
| 1145 | 
 | 
|---|
| 1146 |   //os << endl;  os << " contenu des tableaux conversions "<<endl;
 | 
|---|
| 1147 |   //for(int i=0; i < 5; i++)
 | 
|---|
| 1148 |   //  {
 | 
|---|
| 1149 |   //   os<<PXY.pix2x_(i)<<", "<<PXY.pix2y_(i)<<", "<<PXY.x2pix_(i)<<", "<<PXY.y2pix_(i)<<endl;
 | 
|---|
| 1150 |   // }
 | 
|---|
| 1151 |   os << endl;
 | 
|---|
| 1152 | 
 | 
|---|
| 1153 | }
 | 
|---|
| 1154 | 
 | 
|---|
| 1155 | //*******************************************************************
 | 
|---|
| 1156 | // Class FIO_SphereGorski<T>
 | 
|---|
| 1157 | //  Les objets delegues pour la gestion de persistance 
 | 
|---|
| 1158 | //*******************************************************************
 | 
|---|
| 1159 | 
 | 
|---|
| 1160 | template <class T>
 | 
|---|
| 1161 | FIO_SphereGorski<T>::FIO_SphereGorski()
 | 
|---|
| 1162 | {
 | 
|---|
| 1163 |   dobj= new SphereGorski<T>;
 | 
|---|
| 1164 |   ownobj= true;
 | 
|---|
| 1165 | }
 | 
|---|
| 1166 | 
 | 
|---|
| 1167 | template <class T>
 | 
|---|
| 1168 | FIO_SphereGorski<T>::FIO_SphereGorski(string const& filename)
 | 
|---|
| 1169 | {
 | 
|---|
| 1170 |   dobj= new SphereGorski<T>;
 | 
|---|
| 1171 |   dobj->pixels_.SetTemp(true);
 | 
|---|
| 1172 |   ownobj= true;
 | 
|---|
| 1173 |   Read(filename);
 | 
|---|
| 1174 | }
 | 
|---|
| 1175 | 
 | 
|---|
| 1176 | template <class T>
 | 
|---|
| 1177 | FIO_SphereGorski<T>::FIO_SphereGorski(const SphereGorski<T>& obj)
 | 
|---|
| 1178 | {
 | 
|---|
| 1179 |   dobj= new SphereGorski<T>(obj, true);
 | 
|---|
| 1180 |   dobj->pixels_.SetTemp(true);
 | 
|---|
| 1181 |   ownobj= true;
 | 
|---|
| 1182 | }
 | 
|---|
| 1183 | 
 | 
|---|
| 1184 | template <class T>
 | 
|---|
| 1185 | FIO_SphereGorski<T>::FIO_SphereGorski(SphereGorski<T>* obj)
 | 
|---|
| 1186 | {
 | 
|---|
| 1187 |   dobj= obj;
 | 
|---|
| 1188 |   ownobj= false;
 | 
|---|
| 1189 | }
 | 
|---|
| 1190 | 
 | 
|---|
| 1191 | template <class T>
 | 
|---|
| 1192 | FIO_SphereGorski<T>::~FIO_SphereGorski()
 | 
|---|
| 1193 | {
 | 
|---|
| 1194 |   if (ownobj && dobj) delete dobj;
 | 
|---|
| 1195 | }
 | 
|---|
| 1196 | 
 | 
|---|
| 1197 | template <class T>
 | 
|---|
| 1198 | AnyDataObj* FIO_SphereGorski<T>::DataObj()
 | 
|---|
| 1199 | {
 | 
|---|
| 1200 |   return(dobj);
 | 
|---|
| 1201 | }
 | 
|---|
| 1202 | 
 | 
|---|
| 1203 | 
 | 
|---|
| 1204 | template <class T>
 | 
|---|
| 1205 | void FIO_SphereGorski<T>::SetDataObj(AnyDataObj & o)
 | 
|---|
| 1206 | {
 | 
|---|
| 1207 |   SphereGorski<T> * po = dynamic_cast< SphereGorski<T> * >(&o);
 | 
|---|
| 1208 |   if (po == NULL) return;
 | 
|---|
| 1209 |   if (ownobj && dobj) delete dobj;
 | 
|---|
| 1210 |   dobj = po; ownobj = false;
 | 
|---|
| 1211 | } 
 | 
|---|
| 1212 | 
 | 
|---|
| 1213 | template <class T>
 | 
|---|
| 1214 | void FIO_SphereGorski<T>::ReadSelf(PInPersist& is)
 | 
|---|
| 1215 | {
 | 
|---|
| 1216 | 
 | 
|---|
| 1217 |   if(dobj == NULL) 
 | 
|---|
| 1218 |     {
 | 
|---|
| 1219 |       dobj= new SphereGorski<T>;
 | 
|---|
| 1220 |       dobj->pixels_.SetTemp(true);
 | 
|---|
| 1221 |       ownobj= true;      
 | 
|---|
| 1222 |     }
 | 
|---|
| 1223 | 
 | 
|---|
| 1224 | // On lit les 3 premiers uint_8
 | 
|---|
| 1225 | uint_8 itab[3];
 | 
|---|
| 1226 | is.Get(itab, 3);
 | 
|---|
| 1227 | // Let's Read the SphereCoordSys object  -- ATTENTIOn - $CHECK$
 | 
|---|
| 1228 |   FIO_SphereCoordSys fio_scs( dobj->GetCoordSys());
 | 
|---|
| 1229 |   fio_scs.Read(is);
 | 
|---|
| 1230 |   // Pour savoir s'il y avait un DVList Info associe
 | 
|---|
| 1231 |   char strg[256];
 | 
|---|
| 1232 |   is.GetLine(strg, 255);
 | 
|---|
| 1233 |   bool hadinfo= false;
 | 
|---|
| 1234 |   if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0)  hadinfo= true;
 | 
|---|
| 1235 |   if(hadinfo) 
 | 
|---|
| 1236 |     {    // Lecture eventuelle du DVList Info
 | 
|---|
| 1237 |       is >> dobj->Info(); 
 | 
|---|
| 1238 |     }
 | 
|---|
| 1239 | 
 | 
|---|
| 1240 |   int_4 nSide;
 | 
|---|
| 1241 |   is.GetI4(nSide);
 | 
|---|
| 1242 |   int_4 nPix;
 | 
|---|
| 1243 |   is.GetI4(nPix);
 | 
|---|
| 1244 |   double Omega;
 | 
|---|
| 1245 |   is.GetR8(Omega);
 | 
|---|
| 1246 |   dobj->setParameters(nSide,nPix, Omega);
 | 
|---|
| 1247 | 
 | 
|---|
| 1248 | // On lit les DataBlocks;
 | 
|---|
| 1249 |   FIO_NDataBlock<T> fio_nd(&dobj->pixels_);
 | 
|---|
| 1250 |   fio_nd.Read(is);
 | 
|---|
| 1251 |   FIO_NDataBlock<int> fio_ndi1(&dobj->sliceBeginIndex_);
 | 
|---|
| 1252 |   fio_ndi1.Read(is);
 | 
|---|
| 1253 |   FIO_NDataBlock<int> fio_ndi2(&dobj->sliceLenght_);
 | 
|---|
| 1254 |   fio_ndi2.Read(is);
 | 
|---|
| 1255 | }
 | 
|---|
| 1256 | 
 | 
|---|
| 1257 | template <class T>
 | 
|---|
| 1258 | void FIO_SphereGorski<T>::WriteSelf(POutPersist& os) const
 | 
|---|
| 1259 | {
 | 
|---|
| 1260 |   if(dobj == NULL) 
 | 
|---|
| 1261 |     {
 | 
|---|
| 1262 |       cout << " WriteSelf:: dobj= null " << endl;
 | 
|---|
| 1263 |       return;
 | 
|---|
| 1264 |     }
 | 
|---|
| 1265 | 
 | 
|---|
| 1266 | //  On ecrit 3 uint_8 
 | 
|---|
| 1267 | //  0 : Numero de version,  1 : Size index,  2  reserve a l
 | 
|---|
| 1268 | uint_8 itab[3];
 | 
|---|
| 1269 | itab[0] = 1;
 | 
|---|
| 1270 | itab[1] = dobj->SizeIndex();
 | 
|---|
| 1271 | itab[2] = 0;
 | 
|---|
| 1272 | os.Put(itab, 3);
 | 
|---|
| 1273 | // Let's write the SphereCoordSys object
 | 
|---|
| 1274 |   FIO_SphereCoordSys fio_scs( dobj->GetCoordSys());
 | 
|---|
| 1275 |   fio_scs.Write(os);
 | 
|---|
| 1276 | 
 | 
|---|
| 1277 |   char strg[256];
 | 
|---|
| 1278 |   int_4 nSide= dobj->SizeIndex();
 | 
|---|
| 1279 |   int_4 nPix = dobj->NbPixels();
 | 
|---|
| 1280 |  
 | 
|---|
| 1281 |   if(dobj->ptrInfo()) 
 | 
|---|
| 1282 |     {
 | 
|---|
| 1283 |       sprintf(strg,"SphereGorski: NSide=%6d  NPix=%9d HasInfo",nSide,nPix);
 | 
|---|
| 1284 |       os.PutLine(strg);
 | 
|---|
| 1285 |       os << dobj->Info();
 | 
|---|
| 1286 |     }
 | 
|---|
| 1287 |   else 
 | 
|---|
| 1288 |     { 
 | 
|---|
| 1289 |       sprintf(strg,"SphereGorski: NSide=%6d  NPix=%9d ",nSide,nPix);
 | 
|---|
| 1290 |       os.PutLine(strg);  
 | 
|---|
| 1291 |     }
 | 
|---|
| 1292 | 
 | 
|---|
| 1293 |   os.PutI4(nSide);
 | 
|---|
| 1294 |   os.PutI4(nPix);
 | 
|---|
| 1295 |   os.PutR8(dobj->PixSolAngle());
 | 
|---|
| 1296 | // On ecrit les dataBlocks 
 | 
|---|
| 1297 |   FIO_NDataBlock<T> fio_nd(&dobj->pixels_);
 | 
|---|
| 1298 |   fio_nd.Write(os);
 | 
|---|
| 1299 |   FIO_NDataBlock<int> fio_ndi1(&dobj->sliceBeginIndex_);
 | 
|---|
| 1300 |   fio_ndi1.Write(os);
 | 
|---|
| 1301 |   FIO_NDataBlock<int> fio_ndi2(&dobj->sliceLenght_);
 | 
|---|
| 1302 |   fio_ndi2.Write(os);
 | 
|---|
| 1303 | }
 | 
|---|
| 1304 | 
 | 
|---|
| 1305 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 1306 | #pragma define_template SphereGorski<uint_2>
 | 
|---|
| 1307 | #pragma define_template SphereGorski<r_8>
 | 
|---|
| 1308 | #pragma define_template SphereGorski<r_4>
 | 
|---|
| 1309 | #pragma define_template SphereGorski< complex<r_4> >
 | 
|---|
| 1310 | #pragma define_template SphereGorski< complex<r_8> >
 | 
|---|
| 1311 | #pragma define_template FIO_SphereGorski<r_8>
 | 
|---|
| 1312 | #pragma define_template FIO_SphereGorski<r_4>
 | 
|---|
| 1313 | #pragma define_template FIO_SphereGorski< complex<r_4> >
 | 
|---|
| 1314 | #pragma define_template FIO_SphereGorski< complex<r_8> >
 | 
|---|
| 1315 | #endif
 | 
|---|
| 1316 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
| 1317 | template class SphereGorski<uint_2>;
 | 
|---|
| 1318 | template class SphereGorski<r_8>;
 | 
|---|
| 1319 | template class SphereGorski<r_4>;
 | 
|---|
| 1320 | template class SphereGorski< complex<r_4> >;
 | 
|---|
| 1321 | template class SphereGorski< complex<r_8> >;
 | 
|---|
| 1322 | template class FIO_SphereGorski<r_8>;
 | 
|---|
| 1323 | template class FIO_SphereGorski<r_4>;
 | 
|---|
| 1324 | template class FIO_SphereGorski< complex<r_4> >;
 | 
|---|
| 1325 | template class FIO_SphereGorski< complex<r_8> >;
 | 
|---|
| 1326 | #endif
 | 
|---|
| 1327 | 
 | 
|---|