      SUBROUTINE SEDRIP (T1,B1,T2,B2,T,B,N,MD)
C
C****  =U2ADS.SEDRIP       05-OCT-79     ALLAN SILVER
C
      REAL*8 T1,T2,T
      REAL*4 B1(1),B2(1),B(1)
C --> REAL*4 RL(3)/0.,-3.1415927E0,0./       <-- REPLACED 86-APR-19,
C --> REAL*4 RU(3)/+3.1415927E0,+3.1415927E0,+360./    JAJONES, SAR
      REAL*4 RL(4)/0.,-3.1415927E0,0.,-90./
      REAL*4 RU(4)/+3.1415927E0,+3.1415927E0,+360.,+90./
C***********************************************************************
C******** LINEAR INTERPOLATION WITHIN LIMITS & NORMALIZATION ***********
C***********************************************************************
C****  INDEPENDENT VARIABLE     FUNCTION VALUE(S)                      *
C****    T1 (INPUT)              B1(1...N) (INPUT)                     *
C****    T2 (INPUT)              B2(1...N) (INPUT)                     *
C****     T (INPUT)               B(1...N) (OUTPUT; LINEAR INTERP.)    *
C***********************************************************************
C****         MD         LIMITS OF FUNCTION                            *
C****          0          UNLIMITED                                    *
C****          1          0 TO PI                                      *
C****          2          - PI TO + PI                                 *
C****          3          0 TO 360                                     *
C****          4          - 90 TO + 90  ( <-- ADDED BY JAJ 86-APR19 )  *
C***********************************************************************
C****  T1<0  ---> DO NOT USE B1  ****  T2<0  ---> DO NOT USE B2        *
C****                    T1=T2  ---> USE B1 ONLY                       *
C***********************************************************************
C**** FOR N=9 & MD=0, TREAT B AS A 3X3 MATRIX & NORMALIZE BY ROWS      *
C***********************************************************************
C
C**** COMPUTE RANGE AND HALF RANGE
C
      IF (MD.NE.0)  THEN
       RG = RU(MD) - RL(MD)
       RGH = .5E0*RG
      END IF
C
C**** COMPUTE LINEAR INTERPOLATION COEFFICIENTS
C
      IF (T1.GE.0.D0) THEN
       IF ( T2.GE.0.D0 .AND. T1.NE.T2 ) THEN 
        ALF = (T2 - T)/(T2 - T1)
        BET = (T - T1)/(T2 - T1)
       ELSE
        ALF = 1.E0
        BET = 0.E0
       END IF
      ELSE IF (T2.LT.0.D0)  THEN
       WRITE (6,2001) T1,T2  ! ERROR
       RETURN
      ELSE
       ALF = 0.E0
       BET = 1.E0
      END IF
C
C**** DO THE INTERPOLATION
C
      DO I = 1,N
       B(I) = ALF*B1(I) + BET*B2(I)
       IF ( MD.NE.0 ) THEN
C**** PUT B1 AND B2 WITHIN HALF-RANGE OF EACH OTHER
        K = INT((B2(I) - B1(I))/RGH)
        B(I) = B(I) + RGH*ALF*(K + MOD(K,2))
C**** PUT B WITHIN LIMITS
        B(I) = B(I) - RG*INT((B(I) - RL(MD))/RG)
        IF ( B(I).LT.RL(MD) ) B(I) = B(I) + RG
       END IF
      END DO
      IF (N.NE.9.OR.MD.NE.0) RETURN  ! EXIT ROUTINE IF NOT 3X3 MATRIX
C
C**** NORMALIZE THE MATRIX
C
      DO J = 1,7,3
       FCT = SQRT(B(J)**2 + B(J+1)**2 + B(J+2)**2)
       IF ( FCT.NE.0.E0 ) THEN
        B(J) = B(J)/FCT
        B(J+1) = B(J+1)/FCT
        B(J+2) = B(J+2)/FCT
       END IF
      END DO
C
      RETURN
 2001 FORMAT (' SEDRIP ERROR: ',1P2D15.7)
      END
