3434#include "sharp_geomhelpers.h"
3535#include "c_utils.h"
3636#include "ls_fft.h"
37+ #include <stdio.h>
3738
38- void sharp_make_weighted_healpix_geom_info (int nside , int stride ,
39- const double * weight , sharp_geom_info * * geom_info )
39+ void sharp_make_subset_healpix_geom_info (int nside , int stride , int nrings ,
40+ const int * rings , const double * weight , sharp_geom_info * * geom_info )
4041 {
4142 const double pi = 3.141592653589793238462643383279502884197 ;
4243 ptrdiff_t npix = (ptrdiff_t )nside * nside * 12 ;
4344 ptrdiff_t ncap = 2 * (ptrdiff_t )nside * (nside - 1 );
44- int nrings = 4 * nside - 1 ;
4545
4646 double * theta = RALLOC (double ,nrings );
4747 double * weight_ = RALLOC (double ,nrings );
4848 int * nph = RALLOC (int ,nrings );
4949 double * phi0 = RALLOC (double ,nrings );
5050 ptrdiff_t * ofs = RALLOC (ptrdiff_t ,nrings );
5151 int * stride_ = RALLOC (int ,nrings );
52+ ptrdiff_t curofs = 0 , checkofs ; /* checkofs used for assertion introduced when adding rings arg */
5253 for (int m = 0 ; m < nrings ; ++ m )
5354 {
54- int ring = m + 1 ;
55+ int ring = ( rings == NULL )? ( m + 1 ) : rings [ m ] ;
5556 ptrdiff_t northring = (ring > 2 * nside ) ? 4 * nside - ring : ring ;
5657 stride_ [m ] = stride ;
5758 if (northring < nside )
5859 {
5960 theta [m ] = 2 * asin (northring /(sqrt (6. )* nside ));
6061 nph [m ] = 4 * northring ;
6162 phi0 [m ] = pi /nph [m ];
62- ofs [ m ] = 2 * northring * (northring - 1 )* stride ;
63+ checkofs = 2 * northring * (northring - 1 )* stride ;
6364 }
6465 else
6566 {
@@ -71,14 +72,21 @@ void sharp_make_weighted_healpix_geom_info (int nside, int stride,
7172 phi0 [m ] = 0 ;
7273 else
7374 phi0 [m ] = pi /nph [m ];
74- ofs [m ] = (ncap + (northring - nside )* nph [m ])* stride ;
75+ checkofs = (ncap + (northring - nside )* nph [m ])* stride ;
76+ ofs [m ] = curofs ;
7577 }
7678 if (northring != ring ) /* southern hemisphere */
7779 {
7880 theta [m ] = pi - theta [m ];
79- ofs [m ] = (npix - nph [m ])* stride - ofs [m ];
81+ checkofs = (npix - nph [m ])* stride - checkofs ;
82+ ofs [m ] = curofs ;
8083 }
8184 weight_ [m ]= 4. * pi /npix * ((weight == NULL ) ? 1. : weight [northring - 1 ]);
85+ if (rings == NULL ) {
86+ UTIL_ASSERT (curofs == checkofs , "Bug in computing ofs[m]" );
87+ }
88+ ofs [m ] = curofs ;
89+ curofs += nph [m ];
8290 }
8391
8492 sharp_make_geom_info (nrings , nph , ofs , stride_ , phi0 , theta , weight_ ,
@@ -92,6 +100,12 @@ void sharp_make_weighted_healpix_geom_info (int nside, int stride,
92100 DEALLOC (stride_ );
93101 }
94102
103+ void sharp_make_weighted_healpix_geom_info (int nside , int stride ,
104+ const double * weight , sharp_geom_info * * geom_info )
105+ {
106+ sharp_make_subset_healpix_geom_info (nside , stride , 4 * nside - 1 , NULL , weight , geom_info );
107+ }
108+
95109static inline double one_minus_x2 (double x )
96110 { return (fabs (x )> 0.1 ) ? (1. + x )* (1. - x ) : 1. - x * x ; }
97111
0 commit comments