module OW_parms_areal

use sep
use OW_type

implicit none

logical,public, save					:: encode
type (axis) ,public, save					:: kz, ksh, kxm, xm, z, sh
type (mod_grid)	 ,public, save				:: sog
type (velo) ,public, save					:: v, v0
integer	 ,public, save					:: iwb,ikxa,tapertr,padtraces,dref,isp,rndcte
integer, public, save					:: imgxn,nphi,nx,ngap,seed1,seed2,funct,nwbott
real ,public, save						:: xmin,xmax,ymin,ymax,zmin,zmax,pi,dwbott
real, public, save						:: vsal,dphi,ophi,hmax,zmx,t0,eps

contains

subroutine owparam()

logical							:: migrate
real							:: t1,wbott
integer							:: i,m

 call from_history("n1",sog%z%n);	call from_history("d1",sog%z%d);	call from_history("o1",sog%z%o)
 call from_history("n2",sog%sh%n);	call from_history("d2",sog%sh%d);	call from_history("o2",sog%sh%o)
 call from_history("n3",sog%xm%n);	call from_history("d3",sog%xm%d);	call from_history("o3",sog%xm%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)

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

 if (sog%sh%d .ne. v%xm%d) then
    call seperr("source/receiv offset interval .ne. velocity trace interval")
 end if
 if (sog%z%d .ne. v%z%d) then
    call seperr("source/receiv depth interval .ne. velocity depth interval")
 end if
 if (sog%xm%d .ne. sog%sh%d) then
    call seperr("ODCIG trace spacing .ne. image spacing")
 end if
 if (v0%z%d .ne. v%z%d) then
    call seperr("vel0/vel z intervals are diffetent")
 end if
 if (v0%z%o .ne. v%z%o) then
    call seperr("vel0/vel z origins are diffetent")
 end if
 if (v0%z%n .ne. v%z%n) then
    call seperr("vel0/vel z sizes are diffetent")
 end if
 if (v0%xm%d .ne. v%xm%d) then
    call seperr("vel0/vel xm intervals are diffetent")
 end if
 if (v0%xm%o .ne. v%xm%o) then
    call seperr("vel0/vel xm origins are diffetent")
 end if
 if (v0%xm%n .ne. v%xm%n) then
    call seperr("vel0/vel xm sizes are diffetent")
 end if

 pi=4*atan(1.)

 call to_history("n1",sog%z%n);call to_history("d1",sog%z%d);call to_history("o1",sog%z%o)
 call to_history("n2",sog%sh%n);call to_history("d2",sog%sh%d);call to_history("o2",sog%sh%o)
 call to_history("n3",sog%xm%n);call to_history("d3",sog%xm%d);call to_history("o3",sog%xm%o)  

!--------------------------------------------------
! Wavenumber vectors
!

!!!kz
kz%n = sog%z%n
allocate(kz%all(kz%n))
kz%all=0.
if(kz%n/=1) then
  m = kz%n/2
  do i=1,m+1
     kz%all(i)=i-1
  end do
  do i=m+2,kz%n
     kz%all(i)=i-kz%n-1
  end do
else
  kz%all=0. !! make sure k=0 if n=1
end if

kz%all = kz%all / (kz%n*sog%z%d)      !! 1/length
kz%all = 2 * PI * kz%all     !! radians


!!! ksh
ksh%n = sog%sh%n
allocate(ksh%all(ksh%n))
ksh%all=0.
if(ksh%n/=1) then
  m = ksh%n/2
  do i=1,m+1
     ksh%all(i)=i-1
  end do
  do i=m+2,ksh%n
     ksh%all(i)=i-ksh%n-1
  end do
else
  ksh%all=0. !! make sure k=0 if n=1
end if

ksh%all = ksh%all / (ksh%n*sog%sh%d)      !! 1/length
ksh%all = 2 * PI * ksh%all     !! radians

!!!kxm
kxm%n = sog%xm%n
allocate(kxm%all(kxm%n))
kxm%all=0.
if(kxm%n/=1) then
  m = kxm%n/2
  do i=1,m+1
     kxm%all(i)=i-1
  end do
  do i=m+2,kxm%n
     kxm%all(i)=i-kxm%n-1
  end do
else
  kxm%all=0. !! make sure k=0 if n=1
end if

kxm%all = kxm%all / (kxm%n*sog%xm%d)      !! 1/length
kxm%all = 2 * PI * kxm%all     !! radians

write(0,*) kz%all
write(0,*) "============"
write(0,*) ksh%all
write(0,*) "============"
write(0,*) kxm%all
write(0,*) "============"


write(0,*) "============"
write(0,*) "HEADER WORDS"
write(0,*) "============"
write(0,*) //
write(0,*) "Rotated CIG input"
write(0,*) "================="
write(0,*) "no.offsets      = ", sog%sh%n
write(0,*) "offset spacing  = ", sog%sh%d
write(0,*) "min.offset      = ", sog%sh%o
write(0,*) "no.rotated CIGs = ", sog%xm%n
write(0,*) "CIG spacing     = ", sog%xm%d
write(0,*) "min.CIG x-coord = ", sog%xm%o
write(0,*) //
write(0,*) "VELOCITY MODEL"
write(0,*) "=============="
write(0,*) "no.of traces    = ", v%xm%n
write(0,*) "trace spacing   = ", v%xm%d
write(0,*) "min.trace-x     = ", v%xm%o
write(0,*) "no.depth samples= ", v%z%n
write(0,*) "depth interval  = ", v%z%d
write(0,*) "minimum depth   = ", v%z%o
write(0,*) //
write(0,*) "WAVENUMBERS"
write(0,*) "==========="
write(0,*) " kz_n  = ", kz%n
write(0,*) " ksh_n  = ", ksh%n
write(0,*) " kxm_n  = ", kxm%n

end subroutine

end module
