module wei_ssf
  !! Split-Step Fourier

  use wei_util
  use wei_process
  use wei_obj_S
  !---------------
  implicit none

contains
  !----------------------------------------------------------------
  integer function weissf0_init() result(st)
    integer :: er
#ifdef DEBUG
    character(len=128), parameter :: unit='weissf0_init'
    if(pro%debug) call in(unit)
#endif
    !! do nothing
#ifdef DEBUG
    if(pro%debug) call out(unit)
#endif
    st=OK
  end function weissf0_init
  !----------------------------------------------------------------
  !! Phase-shift
  integer function weissf0(iws,izs,ifk,ith,wfld) result(st)
    integer, intent(in) :: iws,izs,ifk,ith
    complex, dimension(:,:,:,:,:), pointer :: wfld
#ifdef DEBUG
    character(len=128), parameter :: unit='weissf0'
    if(pro%depar) call in(unit)
#endif
    !! do nothing
#ifdef DEBUG
    if(pro%depar) call out(unit)
#endif
    st=OK
  end function weissf0
  !----------------------------------------------------------------
!!$
!!$=head1 NAME
!!$
!!$ weissf_init - Initialize split step operator
!!$
!!$=head1 SYNOPSIS
!!$
!!$ ierr=weissf_init()
!!$
!!$=head1 DESCRIPTION
!!$
!!$ Initialize split step operator
!!$
!!$=head1 SEE ALSO
!!$
!!$L<weissf>
!!$
!!$=head1 LIBRARY
!!$
!!$ sepweif90
!!$
!!$=cut
!!$

  integer function weissf_init() result(st)
    integer :: er
#ifdef DEBUG
    character(len=128), parameter :: unit='weissf_init'
    if(pro%debug) call in(unit)
#endif
    !! do nothing
#ifdef DEBUG
    if(pro%debug) call out(unit)
#endif
    st=OK
  end function weissf_init
  !----------------------------------------------------------------
!!$
!!$=head1 NAME
!!$
!!$ weissf - Split step operator
!!$
!!$=head1 SYNOPSIS
!!$
!!$ ierr=weissf_init(iws,izs,ifk,ith,wfld)
!!$
!!$=head1 PARAMETERS
!!$
!!$=over 4
!!$
!!$=item iws - integer
!!$
!!$  Current frequency slice
!!$
!!$=item izs - integer
!!$
!!$  Current depth slice
!!$
!!$=item ifk - integer
!!$
!!$  Current fk operation
!!$
!!$=item ith - integer
!!$
!!$  Current thread
!!$
!!$=item wfld - complex(:,:,:,:,:)
!!$
!!$ Wavefield
!!$
!!$
!!$=back
!!$
!!$=head1 DESCRIPTION
!!$
!!$ Split step operator
!!$
!!$=head1 SEE ALSO
!!$
!!$L<weissf_init>
!!$
!!$=head1 LIBRARY
!!$
!!$ sepweif90
!!$
!!$=cut
!!$
  !! Split-step
  integer function weissf(iws,izs,ifk,ith,wfld) result(st)
    integer, intent(in) :: iws,izs,ifk,ith
    complex, dimension(:,:,:,:,:), pointer :: wfld
    real    ::  w
    integer :: i1,i2,i3,i4
    complex :: iwdz
#ifdef DEBUG
    character(len=128), parameter :: unit='weissf'
    if(pro%depar) call in(unit)
#endif
    w    = pro%bw%o + (iws-1)*pro%bw%d
    iwdz = (0,1)* pro%opsign*w*pro%dzb(izs)
    do i4=1,size(wfld,4)
    do i3=1,size(wfld,3)
    do i2=1,size(wfld,2)
    do i1=1,size(wfld,1)

    wfld(i1,i2,i3,i4,iws) = &
    wfld(i1,i2,i3,i4,iws) * exp( iwdz *(&
    ( real(S%pba(i1,i2,i3,i4,izs))-slo%ssz(izs,ifk)) + &
    (aimag(S%pba(i1,i2,i3,i4,izs))-slo%ssz(izs,ifk))  ))
    end do; end do; end do; end do;

#ifdef DEBUG
    if(pro%depar) call out(unit)
#endif
    st=OK
  end function weissf
  !----------------------------------------------------------------
end module wei_ssf













