       subroutine grayp(imax,irefl,i,q0,rh,dzdr,tauray,zray,
     & aray,qray,w)
	  
c***********************************************************************
c      Get RAY Parameters
c      Written by Orlando Camargo Rodriguez
c      orodrig@ualg.pt
c      Universidade do Algarve
c      Physics Department
c      Signal Processing Laboratory
c      Faro, Sun Jun 15 13:47:02 WEST 2014
c****&******************************************************************

c      Include global (common) variables:

       include 'global.for'

c      Define local variables:

       integer*4 irefl(np)

       integer*4 i,imax

       real*8 xl(2),yl(2)

       real*8 rh,tauray,zray,qray,dzdr,thta,q0,w
       
       real*8 dummy

       complex*16 zl(2)

       complex*16 aray

       complex*16 dummi

c***********************************************************************
       
       if ((irefl(i+1).eq.1).and.(i.ne.1)) then 
       i = i - 1
       end if 
       
       xl(1) = r( i )
       xl(2) = r(i+1)
       
       yl(1) = z( i )
       yl(2) = z(i+1)
       
       call lini1d(xl,yl,rh,zray,dzdr)
          
       yl(1) = tau( i )
       yl(2) = tau(i+1)

       call lini1d(xl,yl,rh,tauray,dummy)
       
       zl(1) = amp( i )
       zl(2) = amp(i+1)

       call clin1d(xl,zl,rh,aray,dummi)

       yl(1) = q( i )
       yl(2) = q(i+1)

       call lini1d(xl,yl,rh,qray,dummy)
       
       thta = atan( dzdr )

       w = max( abs( q(i) ) , abs( q(i+1) ) )
       
       w = w/( q0*cos( thta ) )

c***********************************************************************
c      Back to main:
c*********************************************************************** 

       return 
        
       end
