module OW_grabvel_areal

use OW_type
use OW_parms_areal

implicit none

contains

subroutine owgrab_velim(velint,vel)

integer				:: nv,j,k
real				:: velint(:), vel(img%xm%n,img%z%n)

   nv = floor((img%xm%o-v%xm%o)/v%xm%d)+1
   vel=0
   do k=1,img%z%n
   do j=nv,nv+img%xm%n-1
      if (velint((k-1)*v%xm%n+j) == 0) then
         vel(j-nv+1,k)=0
      else
         vel(j-nv+1,k)=velint((k-1)*v%xm%n+j)
      end if
   end do
   end do
   if (exist_file("xxx")) then
      call to_history("n1",img%xm%n,"xxx"); call to_history("d1",img%xm%d,"xxx"); call to_history("o1",img%xm%o,"xxx")  
      call to_history("n2",1,"xxx") ; call to_history("d2",1.,"xxx") ; call to_history("o2",0.,"xxx")
      call to_history("n3",img%z%n,"xxx") ; call to_history("d3",img%z%d,"xxx") ; call to_history("o3",img%z%o,"xxx")
      call to_history("n4",1,"xxx"); call to_history("d4",1,"xxx"); call to_history("o4",0,"xxx")
      call to_history("n5",1,"xxx"); call to_history("d5",1,"xxx"); call to_history("o5",0,"xxx")  
      call to_history("esize",4,"xxx")
      call srite("xxx",1/vel,4*img%z%n*img%xm%n)
   end if
end subroutine
!====================================
subroutine owgrab_velsht(velint,vel,ni,ixs)

integer,optional			:: ixs,ni
integer				:: nv,j,k
real				:: velint(:), vel(kxm%n,img%z%n),owrk

   vel=0
   if (marine) then
      owrk=(ixs-1)*rec%xd%d+rec%xd%o+rec%h%o-(padtraces+tapertr)*rec%h%d
   else
      owrk=rec%xd%o+rec%h%o-(padtraces+tapertr)*rec%h%d
   end if
   ni = (owrk-img%xm%o)/img%xm%d+1.5
   write(0,*) owrk,ni
   vel=0
   do k=1,img%z%n
   do j=ni,ni+kxm%n-1
      vel(j-ni+1,k)=velint((k-1)*img%xm%n+j)
   end do
   end do
   if (exist_file("zzz")) then
      call to_history("n1",kxm%n,"zzz"); call to_history("d1",img%xm%d,"zzz"); call to_history("o1",owrk,"zzz")  
      call to_history("n2",1,"zzz") ; call to_history("d2",1.,"zzz") ; call to_history("o2",0.,"zzz")
      call to_history("n3",img%z%n,"zzz") ; call to_history("d3",img%z%d,"zzz") ; call to_history("o3",img%z%o,"zzz")
      call to_history("n4",1,"zzz"); call to_history("d4",1,"zzz"); call to_history("o4",0,"zzz")
      call to_history("n5",1,"zzz"); call to_history("d5",1,"zzz"); call to_history("o5",0,"zzz")  
      call to_history("esize",4,"zzz")
      call srite("zzz",1/vel,4*img%z%n*kxm%n)
   end if

end subroutine
!=========================
end module
