module weiop_ssf
  !! Split-Step Fourier

  use wei_util
  use wei_pro
  use wei_comp
  !---------------
  implicit none

contains
  !----------------------------------------------------------------
  integer function weiop_phsh_init() result(st)
    integer :: er
#ifdef DEBUG
    character(len=128), parameter :: unit='weiop_phsh_init'
    if(wpro%dbg>0) call in(unit)
#endif
    !! do nothing
#ifdef DEBUG
    if(wpro%dbg>0) call out(unit)
#endif
    st=weiOK
  end function weiop_phsh_init
  !----------------------------------------------------------------
  !! Phase-shift
  integer function weiop_phsh(iws,izs,ifk,ith,wfld,slow) result(st)
    integer, intent(in) :: iws,izs,ifk,ith
    complex, dimension(:,:,:,:,:), pointer :: wfld,slow
#ifdef DEBUG
    character(len=128), parameter :: unit='weiop_phsh'
    if(wpro%dbg>9) call in(unit)
#endif
    !! do nothing
#ifdef DEBUG
    if(wpro%dbg>9) call out(unit)
#endif
    st=weiOK
  end function weiop_phsh
  !----------------------------------------------------------------
  integer function weiop_ssf3_init() result(st)
    integer :: er
#ifdef DEBUG
    character(len=128), parameter :: unit='weiop_ssf3_init'
    if(wpro%dbg>0) call in(unit)
#endif
    !! do nothing
#ifdef DEBUG
    if(wpro%dbg>0) call out(unit)
#endif
    st=weiOK
  end function weiop_ssf3_init
  !----------------------------------------------------------------
  !! Split-step
  integer function weiop_ssf3(iws,izs,ifk,ith,wfld) result(st)
    integer, intent(in) :: iws,izs,ifk,ith
    complex, dimension(:,:,:,:,:), pointer :: wfld
    real    ::  w
    complex :: iwdz
#ifdef DEBUG
    character(len=128), parameter :: unit='weiop_ssf3'
    if(wpro%dbg>9) call in(unit)
#endif
    w    = wpro%bw%o + (iws-1)*wpro%bw%d
    iwdz = (0,1)* wpro%opsign*w*wpro%az%d

    !! SSF: dkz/ds = 1/2 ( 2 w (ss-so) + 2 w (sr-so))

    wfld(:,:,:,:,iws) = &
    wfld(:,:,:,:,iws) * exp(iwdz * (srp(ith)%ss(:,:,:,:,izs)-srp(ith)%rs(izs,ifk)))

#ifdef DEBUG
    if(wpro%dbg>9) call out(unit)
#endif
    st=weiOK
  end function weiop_ssf3
  !----------------------------------------------------------------
end module weiop_ssf













