C ===DIRECT POTENTIAL IN HARTREE-FOCK===
C ===== EQUATIONS========================
      SUBROUTINE DIRECT(ALFA,BET,H,GAM,R1,R5,
     *R6,R8,NE5,IS,IQ,IG,NU,
     *ISIGM1,ISIGM2,KK,ISIGM,KSU)
      INTEGER IQ(IS),ISIGM1(NU),KK(NU),ISIGM2(NU)
       REAL*8  ALFA,BET,H,GAM(NU),B,
     * GAMA,R8(NE5,*), R1(NE5),
     *R6(NE5 ),R5(NE5),R52
      NE=NE5-15
      DO 1 IW=1,NE
      R6(IW+1)=0.D 00
 1    CONTINUE
      DO 21 J=1,IS
      ISIGMT=J
      IQ1=IQ(J)
      IF(IQ1.EQ.1.AND.J.EQ.ISIGM) GOTO 21
      CALL COLUMN(NE5,R8(1,J),R5)
      B=DFLOAT(IQ1)
      IF(KSU.NE.3.AND.J.EQ.ISIGM) B=B-1.D 00
C     WRITE(*,100) J,B
C100  FORMAT(' SHELL No of elect.',I5,E15.8)
      B=B/R5(2)
      DO 2 IW=1,NE
      R6(IW+1)=R6(IW+1)+B*R5(IW+2)**2
    2 CONTINUE
21    CONTINUE
      IA=0
      CALL POT(ALFA,BET,H,R1,R6,IA,NE5)
      DO 3 IW=1,NE
      R6(IW)=R6(IW+1)
    3 CONTINUE
      IRA=IG+1
      IF (IRA.GT.NU) GOTO 302
      DO 4 J=IRA,NU
      IA=0
      IF(ISIGM.EQ.ISIGM1(J)) IA=ISIGM2(J)
      IF(ISIGM.EQ.ISIGM2(J)) IA=ISIGM1(J)
      IF(IA.EQ.0) GOTO 111
      CALL COLUMN(NE5,R8(1,IA),R5)
      R52=R5(2)
      DO 5 IW=1,NE
      R5(IW+1)=R5(IW+2)**2
    5 CONTINUE
      IW=KK(J)
      CALL POT(ALFA,BET,H,R1,R5,IW,NE5)
      IF(ISIGM.NE.IA) GOTO 13
      GAMA=2.*GAM(J)/(R52*DFLOAT(IQ(ISIGM)))
      GOTO 14
   13 GAMA=GAM(J)/(R52*DFLOAT(IQ(ISIGM)))
   14 CONTINUE
      DO 6 IW=1,NE
      R6(IW)=R6(IW)-GAMA*R5(IW+1)
    6 CONTINUE
  111 CONTINUE
    4 CONTINUE
  302 CONTINUE
      RETURN
      END
