Skip to content

Commit 765831e

Browse files
author
Dag Sverre Seljebotn
committed
legendre transforms: Fortran wrapper
1 parent f2fe4f9 commit 765831e

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

fortran/sharp.f90

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,32 @@ subroutine c_sharp_execute_mpi(comm, type, spin, alm, map, geom_info, alm_info,
103103
type(c_ptr), intent(in) :: alm(*), map(*)
104104
end subroutine c_sharp_execute_mpi
105105

106+
! Legendre transforms
107+
subroutine c_sharp_legendre_transform(bl, recfac, lmax, x, out, nx) &
108+
bind(c, name='sharp_legendre_transform')
109+
use iso_c_binding
110+
integer(c_ptrdiff_t), value :: lmax, nx
111+
real(c_double) :: bl(lmax + 1), x(nx), out(nx)
112+
real(c_double), optional :: recfac(lmax + 1)
113+
end subroutine c_sharp_legendre_transform
114+
115+
subroutine c_sharp_legendre_transform_s(bl, recfac, lmax, x, out, nx) &
116+
bind(c, name='sharp_legendre_transform_s')
117+
use iso_c_binding
118+
integer(c_ptrdiff_t), value :: lmax, nx
119+
real(c_float) :: bl(lmax + 1), x(nx), out(nx)
120+
real(c_float), optional :: recfac(lmax + 1)
121+
end subroutine c_sharp_legendre_transform_s
106122
end interface
107123

108124
interface sharp_execute
109125
module procedure sharp_execute_d
110126
end interface
111127

128+
interface sharp_legendre_transform
129+
module procedure sharp_legendre_transform_d, sharp_legendre_transform_s
130+
end interface sharp_legendre_transform
131+
112132
contains
113133
! alm info
114134

@@ -240,6 +260,25 @@ subroutine sharp_execute_d(type, spin, nmaps, alm, alm_info, map, geom_info, &
240260
end if
241261
end subroutine sharp_execute_d
242262

263+
subroutine sharp_legendre_transform_d(bl, x, out)
264+
use iso_c_binding
265+
real(c_double) :: bl(:)
266+
real(c_double) :: x(:), out(size(x))
267+
!--
268+
integer(c_ptrdiff_t) :: lmax, nx
269+
call c_sharp_legendre_transform(bl, lmax=int(size(bl) - 1, c_ptrdiff_t), &
270+
x=x, out=out, nx=int(size(x), c_ptrdiff_t))
271+
end subroutine sharp_legendre_transform_d
272+
273+
subroutine sharp_legendre_transform_s(bl, x, out)
274+
use iso_c_binding
275+
real(c_float) :: bl(:)
276+
real(c_float) :: x(:), out(size(x))
277+
!--
278+
integer(c_ptrdiff_t) :: lmax, nx
279+
call c_sharp_legendre_transform_s(bl, lmax=int(size(bl) - 1, c_ptrdiff_t), &
280+
x=x, out=out, nx=int(size(x), c_ptrdiff_t))
281+
end subroutine sharp_legendre_transform_s
243282

244283

245284
end module

fortran/test_sharp.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,31 @@ program test_sharp
5454
print *, 'DONE'
5555
call MPI_Finalize(ierr)
5656

57+
print *, 'LEGENDRE TRANSFORMS'
58+
59+
call test_legendre_transforms()
60+
61+
contains
62+
subroutine test_legendre_transforms()
63+
integer, parameter :: lmax = 20, nx=10
64+
real(c_double) :: bl(0:lmax)
65+
real(c_double) :: x(nx), out(nx)
66+
real(c_float) :: out_s(nx)
67+
!--
68+
integer :: l, i
69+
70+
do l = 0, lmax
71+
bl(l) = 1.0 / real(l + 1, c_double)
72+
end do
73+
do i = 1, nx
74+
x(i) = 1 / real(i, c_double)
75+
end do
76+
out = 0
77+
call sharp_legendre_transform(bl, x, out)
78+
print *, out
79+
call sharp_legendre_transform(real(bl, c_float), real(x, c_float), out_s)
80+
print *, out_s
81+
end subroutine test_legendre_transforms
82+
83+
5784
end program test_sharp

0 commit comments

Comments
 (0)