program Dmo
  ! <in.H Dmokirch  adj=1 v0=1.5 n3=1 > out.H
  !
  !	adj=1	    	migration, i.e. data processing.
  !
  !	velocity=1.5		velocity at surface.
  ! 
  ! keyword Kirchhoff
  ! JFC
  !%
  use sep
  use dmokirch

  implicit none
  integer                            :: n1, n2, n3, adj, pul, i3, int
  logical                            :: conj
  real, dimension (:,:), allocatable :: data, modl
  real                               :: v0, o1, o2, d1, d2, h, h0, dh 

  call sep_init ()
  call from_history (n1, n2)
  call from_history ("n3", n3, 1)

  call from_par ("adj", adj, 1) ; conj = (adj == 1)
  call from_par ("pul", pul, 1)
  call from_par ("int", int, 1)

  call from_history ("o1", o1) ; call from_history ("d1", d1)
  call from_history ("o2", o2) ; call from_history ("d2", d2)
  call from_history ("o3", h0) ; call from_history ("d3", dh)

  call from_par ("velocity", v0, 1.5)

  allocate (data(n1,n2), modl(n1,n2))

  do i3= 1, n3      ! Loop over offsets?
     call from_par ("h", h, (h0 + dh* (i3-1))/2.)
     call dmokirch_init (pul == 1, int, h, d2, n2, o1, d1, n1, v0)
     if (conj) then
        call sep_read (data) ; modl = 0.
     else
        call sep_read (modl) ; data = 0.
     end if

     ! call dmokirch_apply (conj, modl, data)
     call dmokirch_lop2 (conj, modl, data)

     if (conj) then
        call sep_write (modl) 
     else
        call sep_write (data) 
     end if
  end do
  call dmokirch_close ()

  call sep_close ()
  deallocate (modl, data)
  call exit (0)
end program Dmo

