      SUBROUTINE SEDRIP (T1,B1,T2,B2,T,B,N,MD)                          00001000
C****  =U2ADS.SEDRIP       05-OCT-79     ALLAN SILVER                   00002000
      REAL*8 T1,T2,T                                                    00003000
      REAL*4 B1(1),B2(1),B(1)                                           00004000
C --> REAL*4 RL(3)/0.,-3.1415927E0,0./       <-- REPLACED 86-APR-19,    00005000
C --> REAL*4 RU(3)/+3.1415927E0,+3.1415927E0,+360./    JAJONES, SAR     00006000
      REAL*4 RL(4)/0.,-3.1415927E0,0.,-90./                             00005000
      REAL*4 RU(4)/+3.1415927E0,+3.1415927E0,+360.,+90./                00006000
C***********************************************************************00007000
C******** LINEAR INTERPOLATION WITHIN LIMITS & NORMALIZATION ***********00008000
C***********************************************************************00009000
C****  INDEPENDENT VARIABLE     FUNCTION VALUE(S)                      *00010000
C****    T1 (INPUT)              B1(1...N) (INPUT)                     *00011000
C****    T2 (INPUT)              B2(1...N) (INPUT)                     *00012000
C****     T (INPUT)               B(1...N) (OUTPUT; LINEAR INTERP.)    *00013000
C***********************************************************************00014000
C****         MD         LIMITS OF FUNCTION                            *00015000
C****          0          UNLIMITED                                    *00016000
C****          1          0 TO PI                                      *00017000
C****          2          - PI TO + PI                                 *00018000
C****          3          0 TO 360                                     *00019000
C****          4          - 90 TO + 90  ( <-- ADDED BY JAJ 86-APR19 )  *00019000
C***********************************************************************00020000
C****  T1<0  ---> DO NOT USE B1  ****  T2<0  ---> DO NOT USE B2        *00021000
C****                    T1=T2  ---> USE B1 ONLY                       *00022000
C***********************************************************************00023000
C**** FOR N=9 & MD=0, TREAT B AS A 3X3 MATRIX & NORMALIZE BY ROWS      *00024000
C***********************************************************************00025000
      IF (MD.EQ.0)  GO TO 10                                            00026000
C**** COMPUTE RANGE AND HALF RANGE                                      00027000
      RG = RU(MD) - RL(MD)                                              00028000
      RGH = .5E0*RG                                                     00029000
C**** COMPUTE LINEAR INTERPOLATION COEFFICIENTS                         00030000
   10 IF (T1.GE.0.D0) GO TO 20                                          00031000
      IF (T2.LT.0.D0)  GO TO 99                                         00032000
      ALF = 0.E0                                                        00033000
      BET = 1.E0                                                        00034000
      GO TO 40                                                          00035000
   20 IF (T2.GE.0.D0.AND.T1.NE.T2)  GO TO 30                            00036000
      ALF = 1.E0                                                        00037000
      BET = 0.E0                                                        00038000
      GO TO 40                                                          00039000
   30 ALF = (T2 - T)/(T2 - T1)                                          00040000
      BET = (T - T1)/(T2 - T1)                                          00041000
C**** DO THE INTERPOLATION                                              00042000
   40 DO 50  I = 1,N                                                    00043000
      B(I) = ALF*B1(I) + BET*B2(I)                                      00044000
      IF (MD.EQ.0)  GO TO 50                                            00045000
C**** PUT B1 AND B2 WITHIN HALF-RANGE OF EACH OTHER                     00046000
      K = INT((B2(I) - B1(I))/RGH)                                      00047000
      B(I) = B(I) + RGH*ALF*(K + MOD(K,2))                              00048000
C**** PUT B WITHIN LIMITS                                               00049000
      B(I) = B(I) - RG*INT((B(I) - RL(MD))/RG)                          00050000
      IF (B(I).LT.RL(MD)) B(I) = B(I) + RG                              00051000
   50 CONTINUE                                                          00052000
      IF (N.NE.9.OR.MD.NE.0) RETURN                                     00053000
C**** NORMALIZE THE MATRIX                                              00054000
      DO 60  J = 1,7,3                                                  00055000
      FCT = SQRT(B(J)**2 + B(J+1)**2 + B(J+2)**2)                       00056000
      IF (FCT.EQ.0.E0)  GO TO 60                                        00057000
      B(J) = B(J)/FCT                                                   00058000
      B(J+1) = B(J+1)/FCT                                               00059000
      B(J+2) = B(J+2)/FCT                                               00060000
   60 CONTINUE                                                          00061000
      RETURN                                                            00062000
C**** ERROR                                                             00063000
   99 WRITE (6,2001) T1,T2                                              00064000
 2001 FORMAT (' SEDRIP ERROR: ',1P2D15.7)                               00065000
      RETURN                                                            00066000
      END                                                               00067000
