module OW_arealexe_mod

use sep 

implicit none

contains

subroutine owarealexe(G1,synshot)

integer				:: ni,ixs,nsy
real				:: owrk
complex,allocatable			:: recv(:,:)
complex				:: G1(:,:),synshot(:,:)

!---------------------------------------------------
!
! Synthesizing areal shots
!
!---------------------------------------------------
write(0,*) "Synthesizing areal shots"
write(0,*) "========================"
allocate(recv(rec%h%n,rec%w%n))
recv=0;synshot=0
!write(0,*) "SHOT   SHOT-X     OWRK  FIndI LIinI  G1ind  S2SYN  img_x_n"
    do ixs=1,rec%x%n
       owrk=(ixs-1)*rec%x%d+rec%x%o+rec%h%o
       ni = floor((owrk-img%xm%o)/img%xm%d)+1
       nsy=floor(((ixs-1)*rec%x%d+rec%x%o-img%xm%o)/img%xm%d)+1
!       write(0,5) ixs,owrk-rec%h%o,owrk,ni,ni+rec%h%n-1,nsy,size(synshot,2),img%xm%n
!5      format(i4,2f10.2,5i6)
       call sreed("in",recv,rec%w%n*rec%h%n*8)
       do ih = 1,rec%h%n
          do iw=1,rec%w%n
             synshot(iw,ni+ih-1)=synshot(iw,ni+ih-1)+recv(ih,iw)*(G1(iw,nsy))
          end do
       end do
    end do

deallocate(recv)
end subroutine

end module
