module OW_parms

implicit none

public						::
type (axis) 					:: kxm, h, w, x, xm, z, sh
type (dat_grid)					:: rec, sou
type (mod_grid)					:: img
type (velo)					:: v
integer						:: nref
real						:: xmin,xmax,ymin,ymax,zmin,zmax

contains

subroutine owparam()

 call from_history("n1",rec%h%n);	call from_history("d1",rec%h%d);	call from_history("o1",rec%h%o)
 call from_history("n3",rec%w%n);	call from_history("d3",rec%w%d);	call from_history("o3",rec%w%o)
 call from_history("n4",rec%x%n);	call from_history("d4",rec%x%d);	call from_history("o4",rec%x%o)  

 call from_aux("sou","n1",sou%h%n);	call from_aux("sou","d1",sou%h%d);	call from_aux("sou","o1",sou%h%o)
 call from_aux("sou","n3",sou%w%n);	call from_aux("sou","d3",sou%w%d);	call from_aux("sou","o3",sou%w%o)
 call from_aux("sou","n4",sou%x%n);	call from_aux("sou","d4",sou%x%d);	call from_aux("sou","o4",sou%x%o)  

 call from_aux("vel","n1",v%z%n);	call from_aux("vel","d1",v%z%d);	call from_aux("vel","o1",v%z%o)
 call from_aux("vel","n2",v%xm%n);	call from_aux("vel","d2",v%xm%d);	call from_aux("vel","o2",v%xm%o)

 if (sou%w%n .ne. rec%w%n) then
    call seperr("# source freq. .ne. # receiver freq.")
 end if
 if (sou%w%d .ne. rec%w%d) then
    call seperr("source freq.interval .ne. receiver freq.interval")
 end if
 if (sou%w%o .ne. rec%w%o) then
    call seperr("source freq.origin .ne. receiver freq.origin")
 end if

 !!  get parameters
  call from_param("nrefvel",nref) 
  call from_param("xmin",xmin) 
  call from_param("xmax",xmax)
  call from_param("ymin",ymin,0.)
  call from_param("ymax",ymax,0.)
  call from_param("zmin",zmin,0.)
  call from_param("zmax",zmax)
  call from_param("nh",img%sh%n,1)
  call from_param("oh",img%sh%o,0.)
  call from_param("dh",img%sh%d,0.)

 if (xmin < v%xm%o ) call seperr("Min.x-image space < Min.x-velocity")
 if (xmax > v%xm%o+(v%xm%n-1)*v%xm%d ) call seperr("Max.x-image space > Max.x-velocity")

 if (zmin < v%xm%o ) call seperr("Min.z-image space < Min.z-velocity")
 if (zmax > v%z%o+(v%z%n-1)*v%z%d ) call seperr("Max.z-image space > Max.z-velocity")

 if (rec%h%o + rec%x%o < xmin ) call seperr("Min.x-receiver < Min.x-image space")
 if (rec%h%o+(rec%h%n-1)*rec%h%d + rec%x%o+(rec%x%n-1)*rec%x%d > xmax ) call seperr("Max.x-receiver < Max.x-image space")

 if (sou%h%o + sou%x%o < xmin ) call seperr("Min.x-source < Min.x-image space")
 if (sou%h%o+(sou%h%n-1)*sou%h%d + sou%x%o+(sou%x%n-1)*sou%x%d > xmax ) call seperr("Max.x-source < Max.x-image space")

 if (rec%h%d .ne. v%xm%d) call seperr("x-offset interval .ne. velocity x-interval")

 img%xm%n=ceiling((xmax-xmin)/v%xm%d)
 img%xm%d=v%xm%d
 img%xm%o=xmin

 img%z%n=ceiling((zmax-zmin)/v%z%d)
 img%z%o=zmin
 img%z%d=v%z%d

 call to_history("n1",img%z%n) ; call to_history("d1",img%z%d) ; call to_history("o1",img%z%o)
 call to_history("n2",img%sh%n); call to_history("d2",img%sh%d); call to_history("o2",img%sh%o)
 call to_history("n3",img%xm%n); call to_history("d3",img%xm%d); call to_history("o3",img%xm%o)  
 call to_history("n4",1); call to_history("d4",1); call to_history("o4",1)
 call to_history("n5",1); call to_history("d5",1); call to_history("o5",1)  
 call to_history("esize",4)

end subroutine

end module
