module parmrot

use sep
use typerot

implicit none

type (mod_grid)					:: cig
type (axis)					:: kz,ksh,kxm
logical,public					:: push
integer,public					:: signal, node
real,public					:: PI

contains

subroutine parms()

integer						:: i,m

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

 !!  get parameters
  call from_param("sign",signal) !!! 1 for source and -1 for receiver wavefield
  call from_param("node",node,9999)
  call from_param("push",push,.false.)
!  call from_param("npadz",npadz,int(z%n/4))
!  call from_param("npadx",npadx,int(x%n/4))
!  call from_param("npadh",npadh,int(h%n/4))


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

PI=4*atan(1.)


!--------------------------------------------------
! kz vector
!
kz%n = cig%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*cig%z%d)      !! 1/length
kz%all = 2 * PI * kz%all     !! radians
kz%d=kz%all(2)-kz%all(1)
kz%o = minval(kz%all)

!write(0,*) kz%all
!write(0,*) kz%d,kz%o

!--------------------------------------------------
! ksh vector
!
ksh%n = cig%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*cig%sh%d)      !! 1/length
ksh%all = 2 * PI * ksh%all     !! radians
ksh%d=ksh%all(2)-ksh%all(1)
ksh%o = minval(ksh%all)

write(0,*) ksh%all
write(0,*) ksh%d,ksh%o

!--------------------------------------------------
! kxm vector
!
kxm%n = cig%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*cig%xm%d)      !! 1/length
kxm%all = 2 * PI * kxm%all     !! radians
kxm%d=kxm%all(2)-kxm%all(1)
kxm%o = minval(kxm%all)

!write(0,*) kxm%all
!write(0,*) kxm%d,kxm%o

end subroutine

end module
