3232
3333#include <math.h>
3434#include "sharp_geomhelpers.h"
35+ #include "sharp_legendre_roots.h"
3536#include "c_utils.h"
3637#include "ls_fft.h"
3738#include <stdio.h>
@@ -106,69 +107,6 @@ void sharp_make_weighted_healpix_geom_info (int nside, int stride,
106107 sharp_make_subset_healpix_geom_info (nside , stride , 4 * nside - 1 , NULL , weight , geom_info );
107108 }
108109
109- static inline double one_minus_x2 (double x )
110- { return (fabs (x )> 0.1 ) ? (1. + x )* (1. - x ) : 1. - x * x ; }
111-
112- /* Function adapted from GNU GSL file glfixed.c
113- Original author: Pavel Holoborodko (http://www.holoborodko.com)
114-
115- Adjustments by M. Reinecke
116- - adjusted interface (keep epsilon internal, return full number of points)
117- - removed precomputed tables
118- - tweaked Newton iteration to obtain higher accuracy */
119- static void gauss_legendre_tbl (int n , double * x , double * w )
120- {
121- const double pi = 3.141592653589793238462643383279502884197 ;
122- const double eps = 3e-14 ;
123- int m = (n + 1 )>>1 ;
124-
125- double t0 = 1 - (1 - 1. /n ) / (8. * n * n );
126- double t1 = 1. /(4. * n + 2. );
127-
128- #pragma omp parallel
129- {
130- int i ;
131- #pragma omp for schedule(dynamic,100)
132- for (i = 1 ; i <=m ; ++ i )
133- {
134- double x0 = cos (pi * ((i <<2 )- 1 ) * t1 ) * t0 ;
135-
136- int dobreak = 0 ;
137- int j = 0 ;
138- double dpdx ;
139- while (1 )
140- {
141- double P_1 = 1.0 ;
142- double P0 = x0 ;
143- double dx , x1 ;
144-
145- for (int k = 2 ; k <=n ; k ++ )
146- {
147- double P_2 = P_1 ;
148- P_1 = P0 ;
149- // P0 = ((2*k-1)*x0*P_1-(k-1)*P_2)/k;
150- P0 = x0 * P_1 + (k - 1. )/k * (x0 * P_1 - P_2 );
151- }
152-
153- dpdx = (P_1 - x0 * P0 ) * n / one_minus_x2 (x0 );
154-
155- /* Newton step */
156- x1 = x0 - P0 /dpdx ;
157- dx = x0 - x1 ;
158- x0 = x1 ;
159- if (dobreak ) break ;
160-
161- if (fabs (dx )<=eps ) dobreak = 1 ;
162- UTIL_ASSERT (++ j < 100 ,"convergence problem" );
163- }
164-
165- x [i - 1 ] = - x0 ;
166- x [n - i ] = x0 ;
167- w [i - 1 ] = w [n - i ] = 2. / (one_minus_x2 (x0 ) * dpdx * dpdx );
168- }
169- } // end of parallel region
170- }
171-
172110void sharp_make_gauss_geom_info (int nrings , int nphi , double phi0 ,
173111 int stride_lon , int stride_lat , sharp_geom_info * * geom_info )
174112 {
@@ -181,7 +119,7 @@ void sharp_make_gauss_geom_info (int nrings, int nphi, double phi0,
181119 ptrdiff_t * ofs = RALLOC (ptrdiff_t ,nrings );
182120 int * stride_ = RALLOC (int ,nrings );
183121
184- gauss_legendre_tbl (nrings ,theta ,weight );
122+ sharp_legendre_roots (nrings ,theta ,weight );
185123 for (int m = 0 ; m < nrings ; ++ m )
186124 {
187125 theta [m ] = acos (- theta [m ]);
0 commit comments