program main
  use sep
  implicit none

  integer :: n1, n2, n3
  integer :: i1, i2, i3
  real    :: d1, d2, d3
  real    :: o1, o2, o3
  real    :: v1, v2
  real, dimension(:,:,:), allocatable :: velo, refl

  call initpar()

  call from_history("n1", n1); call from_history("d1", d1); call from_history("o1", o1)
  call from_history("n2", n2); call from_history("d2", d2); call from_history("o2", o2)
  call from_history("n3", n3); call from_history("d3", d3); call from_history("o3", o3)
  

  allocate(velo(n1,n2,n3))
  allocate(refl(n1,n2,n3))


  call sep_read(velo)

  refl = 0.

  do i1=1, n1
  do i2=1, n2
  do i3=1, n3-1
     v1 = velo(i1,i2,i3)
     v2 = velo(i1,i2,i3+1)
     refl(i1,i2,i3) = (v2 - v1)/max(v1,v2)
  end do
  end do
  end do

  call sep_write(refl)

end program
