module fft2D_mod

  use fft2D_fftw_mod

  implicit none

  real, private,save :: fract

contains

  subroutine fftw_init(sax,rax)
    complex :: sax(:,:),rax(:,:)
    integer :: i1

    !! . . Scaling Factor
    fract=sqrt(real(size(sax,2))/real(size(sax)))
    
    !! . . Set up FFTW plans
    call fftw_init_ser(sax,rax)

  end subroutine fftw_init

  !! ########################################3

  subroutine RAX_Forward(rax,id)
    complex  :: rax(:,:)
    integer  :: i1,id
    call RAX_F_fft(rax,id)

    do i1=1,size(rax,1)
       rax(i1,id)=rax(i1,id)*fract
    end do

  end subroutine RAX_Forward

  !! ########################################3

  subroutine RAX_Backward(rax,id)
    complex  :: rax(:,:)
    integer  :: i1,id
    call RAX_B_fft(rax,id)

    do i1=1,size(rax,1)
       rax(i1,id)=rax(i1,id)*fract
    end do

  end subroutine RAX_Backward

  !! ########################################3
  
  subroutine SAX_Forward(sax,id)
    complex  :: sax(:,:)
    integer  :: i1,id
    call SAX_F_fft(sax,id)

    do i1=1,size(sax,1)
       sax(i1,id)=sax(i1,id)*fract
    end do

  end subroutine SAX_Forward

  !! ########################################3

  subroutine SAX_Backward(sax,id)
    complex  :: sax(:,:)
    integer  :: i1,id
    call SAX_B_fft(sax,id)

    do i1=1,size(sax,1)
       sax(i1,id)=sax(i1,id)*fract
    end do

  end subroutine SAX_Backward

  !! ########################################3

end module fft2D_mod
