       subroutine rnrefl(itop,sigma,tbdy,gradc,ci,rn)

c***********************************************************************
c      Reflection correction subroutine
c      Written by Orlando Camargo Rodriguez
c      orodrig@ualg.pt
c      Universidade do Algarve
c      Physics Department
c      Signal Processing Laboratory
c      Faro, 24/08/2009 at 02:30
c****&******************************************************************
       
c      Define local variables:
       
       integer*4 itop
       
       real*8  sigma(2),sigman(2),gradc(2),tbdy(2),nbdy(2)
       real*8  tg,th,ci,cn,cs,rm,rn
       
c***********************************************************************

       itop = -itop 
       
       nbdy(1) = -tbdy(2)
       nbdy(2) =  tbdy(1)
       
       if (itop.eq.1) then
       nbdy(1) = -nbdy(1)
       nbdy(2) = -nbdy(2)
       end if
       
       sigman(1) = -sigma(2)
       sigman(2) =  sigma(1)

       call dot( sigma,   tbdy, tg )
       call dot( sigma,   nbdy, th )
       call dot( gradc, sigman, cn )
       call dot( gradc, sigma , cs )
       
       rm = tg/th       
       
       if (itop.eq.1) then
       cn = -cn
       end if
        
       rn = rm*( 4.0*cn - 2.0*rm*cs )/ci

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

       return

       end
