!!.. Author: Yaxun Tang, tang@sep.stanford.edu
module wem_fftwv3_mod
  use  base_fftwv3_mod

  implicit none

contains
  !---------------------------------------------------------------------------
  !.. generate plans for FFTW3
  !---------------------------------------------------------------------------
  subroutine wem_fftw_init(plan_2dxF, plan_2dxI, wfld_slice, nx, ny, nthread)
    integer*8, dimension(:)     :: plan_2dxF
    integer*8, dimension(:)     :: plan_2dxI
    complex  , dimension(:,:,:) :: wfld_slice
    integer                     :: nx, ny, nthread

    integer                     :: ithread
    do ithread=1, nthread
       call sfftw_dft_2dx_init(plan_2dxF(ithread), wfld_slice(:,:,ithread), nx, ny, +1)
       call sfftw_dft_2dx_init(plan_2dxI(ithread), wfld_slice(:,:,ithread), nx, ny, -1)
    end do
    return
  end subroutine

  !----------------------------------------------------------------------------
  !.. destory FFTW3 plans
  !----------------------------------------------------------------------------
  subroutine wem_fftw_clos(plan_2dxF, plan_2dxI, nthread)
    integer*8, dimension(:) :: plan_2dxF
    integer*8, dimension(:) :: plan_2dxI
    integer                 :: nthread

    integer                 :: ithread
    do ithread=1, nthread
       call sfftw_destroy_plan(plan_2dxF(ithread))
       call sfftw_destroy_plan(plan_2dxI(ithread))
    end do
    return
  end subroutine

end module
