module OW_image_areal
!
! Imaging Condition -- crosscorrelation
!

use OW_type
use OW_parms_areal

implicit none

contains
!----------------------------------------------------------
subroutine owimage(ws,wr,GG) 

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

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)+conjg(ws(ixw-ihso))*(wr(ixw+ihso))!*(cmplx(0,rec%w%all(iw)))
      end if
   end do
end do

end subroutine
!----------------------------------------------------------
subroutine owimage1(ws,wr,GG) 

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

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
          do iz=1,img%z%n
             GG(iz,ish,ixw)=GG(iz,ish,ixw)+conjg(ws(iz,ixw-ihso))*(wr(iz,ixw+ihso))!*(cmplx(0,rec%w%all(iw)))
          end do
      end if
   end do
end do

end subroutine

!       phase=cmplx(cos(pi/4.), -sin(pi/4.)) / sqrt(rec%w%all(iwa))           
!----------------------------------------------------------
subroutine owimage_wind(GGs,GGr,GG) 

integer					:: ish, ihso, ixw,iw,iwind,iz
complex					:: GGr(:,:),GGs(:,:),GG(:,:,:)

do iwind=1,n_wind
   do ixw=1,rec%h%n
      do ish=1,img%sh%n
         ihso=nint(((ish-1)*img%sh%d+img%sh%o)/(img%xm%d))
         if (ixw-ihso > 1 .and. ixw-ihso < rec%h%n .and. ixw+ihso > 1 .and. ixw+ihso < rec%h%n) then
            do iz=1,img%z%n
                GG(iz,ish,ixw)=GG(iz,ish,ixw)+conjg(GGs(iz,ixw-ihso))*(GGr(iz,ixw-ihso))*windf(iwind)
            end do
         end if
      end do
   end do
end do

end subroutine

end module
