C===== OFF-DIAGONAL PARAMETERS ===========
C====== IN HFD-EQUATION====================
C==========================================
      SUBROUTINE OFFDR31(ALFA,BET,H,AL0,
     *ALA,ALA1,ALA2,ALM3,TETA,C3,SPI,UD,
     *IS,NE5,ISIGM,IN,IL,KF,
     * R1,R2,R4,R5,R8,R9,R12,R13,R14)
C===========================================
      REAL*8 ALFA,BET,H,TETMAX,C,D,P,A1,P1,AL0,
     * ALA(IS),ALA1(IS),ALA2(IS),
     * ALM3(IS),TETA(IS),C3(IS),
     * R1(*),R2(*),R4(*),R5(*),R9(*),
     * R12(*),R13(*),R14(*),R8(NE5,*)
      INTEGER UD(IS),IN(IS),IL(IS),SPI(IS)

      P1=H**2/12.
C     WRITE(*,1)
C     WRITE(6,1)
C1    FORMAT(' ORTOG. before EXCHANGE')
      NE=NE5-15
      IL1=IL(ISIGM)
      IN1=IN(ISIGM)
      IRA=IS-1
      DO 30 J=1,IRA
	UD(J)=0.
      TETMAX=0.0
      IF(IL1.EQ.IL(J).AND.SPI(J).EQ.SPI(IS)
     *     .AND.IN1.NE.IN(J))  THEN
      IA=J
      CALL COLUMN(NE5,R8(1,IA),R5)
      CALL COLUMN(NE5,R8(1,IA+IS),R14)
      CALL COLUMN(NE5,R8(1,IA+IS+IS),R9)
      CALL KSII(NE,AL0,R5(1),R9,R12)
      C=0.0
      D=0.0
      R5(NE+2)=C
      DO 10 IW=1,NE
      P=D
      D=C
       C=R2(IW+2)*R5(IW+2)*
     *    R13(IW)*R12(IW)
      C=C*(R1(IW+2)/(ALFA*R1(IW+2)+BET))**2
      C=C/DSQRT(ALM3(IS))
      A1=(5.*C+8.*D-P)*H/12.
      TETMAX=A1+TETMAX
   10 CONTINUE
      IF(DABS(TETMAX).LT.1.D-07.AND.
     * KF.NE.1) GOTO 301
      IF(KF.NE.1)  GOTO 122
      C3(J)=ALM3(J)+TETMAX
      ALA(J)=0.005
      ALA1(J)=TETMAX
      GOTO 123
122   CONTINUE
      IF(TETMAX *TETA(J).GT.0.0) GOTO 124
      ALA(J)=ALA2(J)
      ALA1(J)=TETA(J)
      IF(DABS(TETMAX).LT.0.001) GOTO 124
      C3(J)=(ALM3(J)+ALA2(J))/2.
      GOTO 123
124   C3(J)=(ALM3(J)*TETA(J)-
     * ALA2(J)*TETMAX)/(TETA(J)-TETMAX)
      IF(DABS(C3(J)-ALM3(J)).GT.5.*
     * DABS(ALM3(J)-ALA2(J)).AND.DABS(TETMAX).GT.0.003)
     * C3(J)=3.*ALM3(J)-ALA2(J)
 370  CONTINUE
123   CONTINUE
      IF(DABS(C3(J)).GT.20.) C3(J)=-C3(J)/10.
      ALA2(J)=ALM3(J)
C     ALA2(J)=(ALM3(J)-(R2(1)+R5(1))*TETMAX)
      ALM3(J)=C3(J)
      DO 9 IW=1,NE
       R4(IW+1)=R4(IW+1)+(ALM3(J)-ALA2(J))*R1(IW+2)
     *     *P1*R1(IW+2)/(ALFA*R1(IW+2)+BET)**2
     *     *R5(IW+2)/R5(2)
 9     CONTINUE
301   TETA(J)=TETMAX
      IF(DABS(TETA(J)).GT.0.D 00)
     *   WRITE(*,100)J,TETA(J),ALM3(J)
 100   FORMAT(' OFFD OVER. INT.FOR',I3,
     *     ' SHELL',E12.5,' 0FF.PAR',E12.5)
      END IF
30    CONTINUE
      RETURN
      END
