1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
module four2a_legacy_wrap_mod
use iso_c_binding
use four2a_mod, only: four2a
implicit none
integer, parameter :: JT65_NFFT = 512
integer, parameter :: JT65_NH = JT65_NFFT/2
contains
subroutine r2c_legacy(s_real, cs_half)
use iso_c_binding
use four2a_mod, only: four2a
implicit none
real, intent(in) :: s_real(JT65_NFFT)
complex, intent(out) :: cs_half(0:JT65_NH)
integer :: k
integer(c_int) :: nfft_c, ndim_c, isign_c, iform_c
block
real(c_float), save, target :: work(2*(JT65_NH+1))
complex(c_float_complex), pointer :: work_c(:)
call c_f_pointer(c_loc(work), work_c, [JT65_NH+1])
work(1:JT65_NFFT) = real(s_real, kind=c_float)
nfft_c = JT65_NFFT
ndim_c = 1
isign_c = 1
iform_c = 0
call four2a(work_c, nfft_c, ndim_c, isign_c, iform_c)
do k = 0, JT65_NH
cs_half(k) = cmplx(real(work_c(k+1)), aimag(work_c(k+1)))
enddo
end block
end subroutine r2c_legacy
subroutine c2r_legacy(cs_half, s_real)
use iso_c_binding
use four2a_mod, only: four2a
implicit none
complex, intent(in) :: cs_half(0:JT65_NH)
real, intent(out) :: s_real(JT65_NFFT)
integer :: k
integer(c_int) :: nfft_c, ndim_c, isign_c, iform_c
block
real(c_float), target :: work(2*(JT65_NH+1))
complex(c_float_complex), pointer :: work_c(:)
call c_f_pointer(c_loc(work), work_c, [JT65_NH+1])
! load packed half-spectrum: cs_half(0..nh) → work_c(1..nh+1)
do k = 0, JT65_NH
work_c(k+1) = cmplx(real(cs_half(k), kind=c_float), &
aimag(cs_half(k)), kind=c_float)
enddo
! c2r: iform = -1
nfft_c = JT65_NFFT
ndim_c = 1
isign_c = 1
iform_c = -1
call four2a(work_c, nfft_c, ndim_c, isign_c, iform_c)
! real output in first nfft reals
s_real = real(work(1:JT65_NFFT))
end block
end subroutine c2r_legacy
end module four2a_legacy_wrap_mod
|