module OW_grabvel

use OW_type
use OW_parms

implicit none

contains

subroutine owgrab_vel(ixs,velint,vel,ni)

integer						:: ixs, ni, nv
real						:: velint(:,:), vel(:,:)
real						:: owrk


! workspace origin 

    owrk=(ixs-1)*sou%x%d+sou%x%o+sou%h%o
! grab velocity in the workspace       
    nv = ceiling((owrk-v%xm%o)/v%xm%d)
    ni = nv-ceiling((sou%h%o-v%xm%o)/sou%h%d)

    vel=0;

    vel(:,:)=velint(:,nv:nv+sou%h%n-1);

    owrk=(ixs-1)*sou%x%d+sou%x%o+sou%h%o
    if (owrk < sou%h%o .or. owrk > sou%h%o+sou%h%d*(sou%h%n-1)) then
         call seperr('WORKING SPACE GREATER THAN ')
         write(0,*)  'THE IMAGE SPACE FOR SHOT # ',ixs
    end if

!    write(2,*) "   ixs      owrk        nv        ni    "
!    write(2,*) "  =====  ==========  ========  ========="
!    write(2,12) ixs,owrk,nv,ni
12 format(i7,f10.3,i10,i10)

end subroutine

end module
