Odd(sine) Fourier transform with FFTW package

Hi @mrudko ,

integer(C_FFTW_R2R_KIND) :: RODFT00

This variable is undefined. I guess you could import the constant FFTW_RODFT00 from the fftw3.f03 file: integer(C_FFTW_R2R_KIND), parameter :: RODFT00 = FFTW_RODFT00.

But you can also pass directly that parameter to the planner. Here is the revised code (essentially you can just substitute RODFT00 with FFTW_RODFT00), but it is also very important practice to use implicit none statement in the Fortran program, to make sure all variables are explicitly declared in the program.

program test
  use, intrinsic :: iso_c_binding
  implicit none
  include 'fftw3.f03'
  type(C_PTR) :: plan5
  integer(C_INT), parameter :: kk = 6
  real(C_DOUBLE) :: cff
  real(C_DOUBLE), dimension(kk) :: in1, out1
  real(C_DOUBLE), dimension(kk) :: test_in, test_out, test_out1
  !
  plan5 = fftw_plan_r2r_1d(kk,in1,out1,FFTW_RODFT00,FFTW_ESTIMATE)
  cff = dble(2*(kk+1))
  print*, 'cff = ', cff
  !
  test_in(1) = 1d0
  test_in(2) = 2d0
  test_in(3) = 3d0
  test_in(4) = 4d0
  test_in(5) = 5d0
  test_in(6) = 6d0
  !
  print*, 'test_in', test_in
  call fftw_execute_r2r(plan5,test_in,test_out)
  !
  print*, 'test_out', test_out
  call fftw_execute_r2r(plan5,test_out,test_out1)
  !
  print*, 'test_out1', test_out1/cff
  stop
end program test

Edit: here the expected results:

$ gfortran test.f90 -lfftw3 && ./a.out                                                                                                                                                                
 cff =    14.000000000000000     
 test_in   1.0000000000000000        2.0000000000000000        3.0000000000000000        4.0000000000000000        5.0000000000000000        6.0000000000000000     
 test_out   30.669003872743762       -14.535649776006355        8.7777223636389259       -5.5823137221768286        3.3710223316526999       -1.5977043207310500     
 test_out1  0.99999999999999967        2.0000000000000004        3.0000000000000000        4.0000000000000009        5.0000000000000000        6.0000000000000000
3 Likes