program OWtim2off

use sep 
use OW_type
use OW_exec_time
use OW_parms_slt
use OW_slant1
!use OW_dotst

implicit none

real                                          :: start, finish, start1, finish1, start2, finish2
real                                          :: stat
real, allocatable                             :: velint(:,:)
real, allocatable                             :: R_image(:,:),B_image(:,:)
integer                                       :: ix
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 call sep_init()
 call sep_begin_prog()
 start=0.;finish=0.
 call owexec_time(start)
 call owparam()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Set up the taper
! call owtaper(tapertr,taper)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Read velocities
 allocate(velint(v%z%n,v%xm%n))
 call sreed("vel",velint,v%z%n*v%xm%n*4)
 if (adj) then 
    allocate(R_image(img%z%n,img%th%n));R_image=0.
    allocate(B_image(img%z%n,img%sh%n));B_image=0.
 else
    allocate(R_image(img%z%n,img%sh%n));R_image=0.
    allocate(B_image(img%z%n,img%th%n));B_image=0.
 end if
 do ix=1, img%xm%n
    if (adj) then 
       call sreed("R_image",R_image,4*img%z%n*img%th%n)
    else
       call sreed("R_image",R_image,4*img%z%n*img%sh%n)
    end if
    stat = owslant_init(v_in=velint(:,ix))
    call owslant_exe(adj,.false.,B_image,R_image)
    if (adj) then 
       call srite("B_image",B_image,4*img%z%n*img%sh%n)
    else
       call srite("B_image",B_image,4*img%z%n*img%th%n)
    end if
    stat = owslant_close()
    if (mod(ix,20).eq.1) write(0,*) "DONE CIG", ix, " FROM ", img%xm%n,B_image
 end do
 deallocate(R_image,B_image)
 deallocate(velint)
 call sep_end_prog()
end program
