C ===DIRECT POTENTIAL IN HARTREE-FOCK===
C ===== EQUATIONS========================
      SUBROUTINE DIREC3(ALFA,BET,H,R1,IS,ISIGM,IG,NU,
     *GAM,GAM1,GAM2,IQ,KK,ISIGM1,ISIGM2,
     *R4,R5,R6,R7,R8,NE5)
      INTEGER IQ(IS),ISIGM1(NU),KK(NU),ISIGM2(NU)
       REAL*8  ALFA,BET,H,Q1,GAM(NU ), GAM1(NU), GAM2(IS),
     * NOR,GAMA,R8(NE5,*), R1(*),R7(*),
     *R6(*),R5(*),R4(*)
      NE=NE5-15
      NE2=NE+2
      IG1=IG+1
      DO 1 IW=1,NE
      R7(IW+1)=0.
   1  R4(IW+1)=0.
      DO 2 I=1,IS
      CALL COLUMN(NE5,R8(1,I),R5)
      Q1=DFLOAT(IQ(I))
      IF(I.EQ.ISIGM) Q1=Q1-1.
      DO 3 IW=1,NE
      NOR=R5(IW+2)**2
      R6(IW+1)=R6(IW+1)+Q1*NOR
    3 R7(IW+1)=R7(IW+1)+GAM2(I)*NOR
    2 CONTINUE
      IA=0
      CALL POT(ALFA,BET,H,R1,R6,IA,NE5)
      CALL POT(ALFA,BET,H,R1,R7,IA,NE5)
      DO 4 I=1,NE2
      R6(I)=R6(I+1)
    4 CONTINUE
      IF (IG1.GT.NU) GOTO 302
      DO 5 I=IG1,NU
      IA=ISIGM1(I)
      CALL COLUMN(NE5,R8(1,IA),R5)
      DO 55 IW=1,NE
      R5(IW+1)=R5(IW+2)**2
   55 CONTINUE
      IW=KK(I)
      CALL POT(ALFA,BET,H,R1,R5,IW,NE5)
      IF(ISIGM1(I).NE.ISIGM2(I)) GOTO 13
      DO 6 IW=1,NE
   6  R4(IW+1)=R4(IW+1)+GAM1(I)*R5(IW+1)
      GOTO 5
   13 GAMA=GAM(I)/DFLOAT(IQ(ISIGM))
      IF(ISIGM.EQ.IA) GAMA=GAMA*2.
      DO 7 IW=1,NE
      R6(IW)=R6(IW)-GAMA*R5(IW+1)
    7 R7(IW+1)=R7(IW+1)+GAM1(I)*R5(IW+1)
    5 CONTINUE
 302  DO 8 IW=1,NE
    8 R4(IW+1)=R4(IW+1)+R7(IW+1)
      CALL COLUMN(NE5,R7,R8(1,IS+2))
      CALL COLUMN(NE5,R4,R8(1,IS+3))
      RETURN
      END
