C====COEFFICIENTS FOR HARTREE-FOCK EQUATION =====
C=====FOR EXCITED STATES========================
C  ---  into account nondipole parameters,ort(S)=1--
C-------------------------------------------------
      SUBROUTINE COEF3(S,G,NU,NU1,NU2,IT,Q,L,UD,KN,
     *                GAM,GAM1,GAM2,KK,SIGM1,SIGM2)
C
      REAL*8 GAM(1),GAM1(1),GAM2(1),A1,A2,EPS,GAMA
      INTEGER KK(1),SIGM1(1),SIGM2(1),UD(1),S,S1,A,
     *G,G1,G2,NU,NU1,L(1),Q(1),KN(1)
      NU=NU1
      G2=G
      J0=0
      S1=S-1
      EPS=0.00001
      A=4*L(S)+2
      DO 1 I=1,S1
    1 IF(L(I).EQ.L(S).AND.Q(I).NE.A) J0=I
      IF(UD(S).NE.1) GOTO 50
      I1=0
      IF(NU1.LE.G) GOTO 51
      G1=G+1
      DO 2 I=G1,NU1
      KK(2*NU1-I1)=KK(I)
      SIGM1(2*NU1-I1)=SIGM1(I)
      GAM(2*NU1-I1)=GAM(I)
    2 I1=I1+1
   51 CONTINUE
      I1=0
      DO 3 I=1,G
      IF(SIGM1(I).EQ.IT) GOTO 4
      GAM1(I)=0
      GOTO 3
    4 I1=I1+1
      KN(I1)=I
      CALL IOT31(L(IT),KK(I),L(S),0,0,0,A1)
      GAM1(I)=DFLOAT(Q(IT)+1)*A1*A1/2.-GAM(I)
    3 CONTINUE
      K4=IABS(L(IT)-L(S))+1
      K5=L(IT)+L(S)+1
      DO 5 K1=K4,K5,2
      K=K1-1
      I=0
    6 I=I+1
      IF(I.GT.I1) GOTO 7
      JJ=KN(I)
      IF(K.EQ.KK(JJ)) GOTO 5
      GOTO 6
    7 G=G+1
      CALL IOT31(L(IT),K,L(S),0,0,0,A1)
      GAM(G)=0
      GAM1(G)=DFLOAT(2*L(IT)+1)*A1*A1
      KK(G)=K
      SIGM1(G)=IT
      SIGM2(G)=S
    5 CONTINUE
      I1=0
      G1=G2+1
      IF(G1.GT.NU1) GOTO 52
      DO 8 J=G1,NU1
C     I=NU1-J+G1
      SIGM1(G1+I1)=SIGM1(2*NU-I1)
      KK(G1+I1)=KK(2*NU-I1)
      GAM(G1+I1)=GAM(2*NU-I1)
      GAM1(G1+I1)=GAM(2*NU-I1)
    8 I1=I1+1
   52 NU=G+I1
      DO 9 I=1,S1
    9 GAM2(I)=0
      GAM2(IT)=1
      IF(J0.EQ.0) GOTO 50
      NU2=0
      A2=DFLOAT(2*L(J0)+1)/DFLOAT(4*L(J0)+1)
      IF(IT.EQ.J0) GOTO 10
      A2=DFLOAT(1-Q(J0))*A2
      GOTO 11
   10 A2=-A2*DFLOAT(Q(IT))
   11 CONTINUE
      K5=2*L(S)+1
      DO 12 K1=1,K5,2
      K=K1-1
      IF(K.NE.0) GOTO 13
      GAMA=-1.
      GOTO 14
   13 CALL IOT31(L(J0),K,L(J0),0,0,0,A1)
      GAMA=A2*A1*A1
   14 CONTINUE
      DO 15 I=1,G
   15 IF(SIGM1(I).EQ.J0.AND.K.EQ.KK(I)) GAMA=GAMA+GAM(I)
      IF(ABS(GAMA).LT.EPS) GOTO 12
      NU2=NU2+1
      GAM(NU+NU2)=0
      GAM1(NU+NU2)=GAMA
      SIGM1(NU+NU2)=J0
      SIGM2(NU+NU2)=J0
      KK(NU+NU2)=K
   12 CONTINUE
   50 DO 16 I=NU+1,NU+NU2
      SIGM1(I)=J0
   16 SIGM2(I)=J0
      NU=NU+NU2
      SIGM1(NU+1)=IT
      SIGM2(NU+1)=J0
      RETURN
      END
