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