      SUBROUTINE REFCO( THEINT, RINT, PHIINT, THETA, R, PHI, NPTS )

C     Given an angle THEINT, REFCO returns the magnitude and
C     phase of the reflection coefficient (RINT, PHIINT).

C     Uses linear interpolation using the two nearest abscissas 

      IMPLICIT REAL*8 (A-H, O-Z)
      REAL*8 THETA( * ), R( * ), PHI( * )

      ILEFT  = 1
      IRIGHT = NPTS

C     Three cases: THEINT left, in, or right of tabulated interval

      IF ( THEINT .LT. THETA( ILEFT ) ) THEN
         RINT   = R(   ILEFT )
         PHIINT = PHI( ILEFT )
      ELSE IF( THEINT .GT. THETA( IRIGHT ) ) THEN
         RINT   = R(   IRIGHT )
         PHIINT = PHI( IRIGHT )
      ELSE 

C        Search for bracketting abscissas:
C        Log base 2 (NPTS) stabs required for a bracket

C        ------ DO WHILE ...
 1000    IF ( ILEFT .NE. IRIGHT - 1 ) THEN
            IMID = ( ILEFT + IRIGHT ) / 2
            IF ( THETA( IMID ) .GT. THEINT ) THEN
               IRIGHT = IMID
            ELSE
               ILEFT  = IMID
            ENDIF
         GOTO 1000
         ENDIF

C        Linear interpolation for reflection coef

         ALPHA = ( THEINT          - THETA( ILEFT ) ) /
     &           ( THETA( IRIGHT ) - THETA( ILEFT ) )
         RINT   = ( 1 - ALPHA ) * R(   ILEFT ) + ALPHA * R(   IRIGHT )
         PHIINT = ( 1 - ALPHA ) * PHI( ILEFT ) + ALPHA * PHI( IRIGHT )
C        ------ Problem: PHI may change discontinuously ...
      ENDIF

      RETURN
      END
