module dot_fft_mod
  use wei_myfft_mod

  integer, private :: nt, nw, nw1
  real, parameter, private :: PI = 3.14159265359
contains

  integer function dot_fft_init(nt_in, nw_in, nw1_in) result(stat)
    integer :: nt_in, nw_in, nw1_in
    nt  = nt_in
    nw  = nw_in
    nw1 = nw1_in
    stat = 0
  end function

  integer function dot_fft_oper(adj, add, mod, dat) result(stat)
    logical :: adj, add
    !complex   , dimension(:)  :: dat
    real   , dimension(:)  :: dat
    complex, dimension(:)  :: mod
    complex, dimension(nt) :: ctrace

    ctrace = 0.

    if (adj) then
       ctrace = dat
       call FFT1DT(ctrace, 1)
       do iw=1, nw
          mod(iw) = mod(iw) + ctrace(nw1+iw-1)
       end do
    else
       do iw=1, nw
          ctrace(nw1+iw-1) = mod(iw)
       end do
       call FFT1DT(ctrace, -1)
       dat = dat + real(ctrace)
    end if
   
  end function  



end module
