       subroutine bdryr(rho1,rho2,cp1,cp2,cs2,ap,as,theta,refl)

c***********************************************************************
c      BDRYR.FOR
c      BounDaRY Reflection coefficient
c      Faro, 27/07/2010 at 19:00
c      Written by Orlando Camargo Rodriguez
c****&******************************************************************

c      Define parameters:

       include 'params.for'

c      Define local variables:

       real*8 rho1,rho2,cp1,cp2,cs2,ap,as,theta
       real*8 a1,tilap,tilas

       complex*16 d,a2,a3,a4,a5,a6,a7
       complex*16 tilcp2,tilcs2
       complex*16 refl

c***********************************************************************

c      Reference: "Recovery of the properties of an elastic bottom using
c      reflection coefficient measurements", P.J.Papadakis et al,
c      Proc. of the 2nd. ECUA, Vol II, page 943, 1994.

       tilap = ap/( 40.0*pi*log10( e ) )
       tilas = as/( 40.0*pi*log10( e ) )

       tilcp2 = cp2*(1.0-imunit*tilap)/(1.0+tilap*tilap)
       tilcs2 = cs2*(1.0-imunit*tilas)/(1.0+tilas*tilas)
 
       a1   = rho2/rho1
       a2   = tilcp2/cp1
       a3   = tilcs2/cp1
       a4   = a3*sin( theta )
       a5   = 2.0*a4*a4
       a6   = a2*sin( theta )
       a7   = 2.0*a5-a5*a5
       
       d    = a1*( a2*(1.0-a7)/sqrt(1.0-a6*a6)+a3*a7/sqrt(1.0-0.5*a5) )
       
       refl = (d*cos(theta)-1.0)/(d*cos(theta)+1.0)

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

       end
