module OW_image_areal
!
! Imaging Condition -- crosscorrelation
!

use OW_type
use OW_parms_areal
use OW_fftw_areal
use OW_exec_time

implicit none

contains
!----------------------------------------------------------
subroutine owimage0(iw,ws,wr,GG) 

integer					:: ish, ihso, ixw,iw,iz
complex					:: wr(:),ws(:)
real					:: GG(:,:),phase

phase = cmplx(cos(pi/4.), -sin(pi/4.)) / sqrt(rec%w%all(iw))

do ish=1,img%sh%n
   ihso=nint(((ish-1)*img%sh%d+img%sh%o)/(img%xm%d))
   do ixw=1,rec%h%n
      if (ixw-ihso > 1 .and. ixw-ihso < rec%h%n .and. ixw+ihso > 1 .and. ixw+ihso < rec%h%n) then
          GG(ish,ixw)=GG(ish,ixw)+real(conjg(ws(ixw-ihso))*(wr(ixw+ihso)))*phase
      end if
   end do
end do

end subroutine
!----------------------------------------------------------
subroutine owimage(iw,ws,wr,dws,dwr,GG) 

integer					:: ish, ihso, ixw,iw,iz
complex					:: wr(:),ws(:),dwr(:),dws(:)
real					:: GG(:,:),phase

phase = cmplx(cos(pi/4.), -sin(pi/4.)) / sqrt(rec%w%all(iw))

do ish=1,img%sh%n
   ihso=nint(((ish-1)*img%sh%d+img%sh%o)/(img%xm%d))
   do ixw=1,rec%h%n
      if (ixw-ihso > 1 .and. ixw-ihso < rec%h%n .and. ixw+ihso > 1 .and. ixw+ihso < rec%h%n) then
         GG(ish,ixw)=GG(ish,ixw)+real(conjg(dws(ixw-ihso))*(wr(ixw+ihso))+conjg(ws(ixw-ihso))*(dwr(ixw+ihso)))*phase
      end if
   end do
end do

end subroutine
!----------------------------------------------------------
end module
