*//////////////////////////////////////////////////////////////////*
      SUBROUTINE Bounc2(K,K0, Mi, COD, C0,Cph, A,B, S,Z,SS,SQ,P,Q,W )
*  -  -------------------------------------------------------------*
      IMPLICIT  REAL*8 (A-H,O-Z)
      DIMENSION C0(K), A(K,K), S(K,K), B(K), Z(K), SS(K,K), SQ(K)
     *          ,P(K), Q(K), W(K), Cph(*)
* === =============================================================*

c      IF(Mi.EQ.0) THEN
c        CALL VEQC(K,0.D 00,W)
c        W(K0)=1.D 00
c        RETURN
c        END IF

      K2=K*K
      CALL VEQC(K2,0.D 00,SS)
      CALL VEQC(K,0.D 00,SQ)


      DO 5 JK=1,K

        IF(JK.NE.K0) THEN
         SQ(JK)=B(JK)*COD
         DO 10 IK=1,K
           IF(IK.NE.K0)
     *       SQ(JK)=SQ(JK) - B(IK)*A(JK,IK)
           C=0.D 00
           DO 15 KK=1,K
           IF(KK.NE.K0) C=C+A(IK,KK)*A(JK,KK)
   15         CONTINUE
           SS(IK,JK)=SS(IK,JK)+C-COD*A(IK,JK)
           IF(IK.NE.K0) SS(IK,JK)=SS(IK,JK)-COD*A(JK,IK)
c         IF(JK.GE.K0+1.AND.JK.LE.K0+3) SS(IK,JK)=0.D 00
cc         IF(JK.GE.K0+1.AND.JK.LE.K0+1) 
         IF(JK.GE.K0+1.AND.JK.LE.K0+3) 
cc04         IF(JK.GE.K0-4.AND.JK.LE.K0-1) 
     *     SS(IK,JK)=Cph(JK)*A(IK,JK)

   10     CONTINUE
c         IF(JK.GE.K0+1.AND.JK.LE.K0+3) SQ(JK)=0.D 00
         IF(JK.GE.K0+1.AND.JK.LE.K0+3) SQ(JK)=-Cph(JK)*B(JK)
cc04         IF(JK.GE.K0-4.AND.JK.LE.K0-3) SQ(JK)=-Cph(JK)*B(JK)
cc         IF(JK.GE.K0+1.AND.JK.LE.K0+1) SQ(JK)=-Cph(JK)*B(JK)
         END IF
        SS(JK,JK)=SS(JK,JK)+1.D 00

C          WRITE(10,*) 'SS ',(SS(KK,JK),KK=1,K)
C          WRITE(10,*) 'SQ ', SQ(JK)
    5    CONTINUE

      CALL INVM(K,QQ,SS)

C       DO 19 JK=1,K
C          WRITE(10,*) 'SS INV ',JK,(SS(KK,JK),KK=1,K)
C  19    CONTINUE

      DO 20 JK=1,K
         P(JK)=SS(K0,JK)
         Q(JK)= FSMV(K,SQ,SS(1,JK))
C       WRITE(10,*) 'SQ',JK,(SQ(KK),KK=1,K)
C          WRITE(10,*) 'SS INV ',JK,(SS(KK,JK),KK=1,K)
C          WRITE(10,*) ' JK, P, Q ',JK,P(JK),Q(JK)

   20    CONTINUE
C       WRITE(10,*) 'P',(P(JK),JK=1,K)
C       WRITE(10,*) 'Q',(Q(JK),JK=1,K)
C       WRITE(10,*) 'C0',(C0(JK),JK=1,K)
C        STOP

      DO 23 JK=1,K
         SQ(JK)=FSMV(K,P,S(1,JK))
         W(JK)=FSMV(K,Q,S(1,JK))
   23    CONTINUE

      XA=0.D 00
      XQ=0.D 00
      DO 25 JK=1,K
         XA=XA+SQ(JK)*SQ(JK)
   25    XQ=XQ+SQ(JK)*(C0(JK)-W(JK)-Z(JK))
      XL=XQ/XA
      Az=0.D 00
      Bz=0.D 00
      Cz=0.D 00
      DO 35 JK=1,K
        Az=Az+SQ(JK)*SQ(JK)
        Cz=Cz+(W(JK)+Z(JK))**2
        Bz=Bz+2.D 00*SQ(JK)*(W(JK)+Z(JK))
   35   CONTINUE
      Cz=Cz-1.D 00
      Dz=Bz**2-4.D 00*Az*Cz
      Zx=-Bz/(2.D 00*Az)
      WRITE(*,*) ' Dz, Zx = ', Dz,Zx
c      Pause

cc      IF(Dz.GE.0.D 00) THEN
c      IF(Dz.GE.0.D 00.AND.MI.LE.10) THEN
      IF(Dz.GE.0.D 00.AND.
     *    (MI.LE.9.OR.(MI.GE.120.AND.MI.LE.150))) THEN
      Zx1=(-Bz+DSQRT(Dz))/(2.D 00*Az)
      Cz1=0.D 00
      DO 36 JK=1,K
   36    Cz1=Cz1+(P(JK)*Zx1+Q(JK))*C0(JK)
      Zx2=(-Bz-DSQRT(Dz))/(2.D 00*Az)
      Cz2=0.D 00
      DO 37 JK=1,K
   37    Cz2=Cz2+(P(JK)*Zx2+Q(JK))*C0(JK)
      IF(DABS(Cz1-1.D 00).LE.DABS(Cz2-1.D 00)) Zx=Zx1
      IF(DABS(Cz2-1.D 00).LT.DABS(Cz1-1.D 00)) Zx=Zx2
c      END IF
      DO 40 JK=1,K
   40    W(JK)=P(JK)*Zx+Q(JK)

      ELSE
      WRITE(*,*) ' XL = ', XL
      DO 30 JK=1,K
   30    W(JK)=P(JK)*XL+Q(JK)
      END IF      

C       WRITE(10,*) 'XN',(W(KK),KK=1,K)
C       STOP
CQ      DO 25 JK=1,K
CQ         XA=XA+AD(JK)*AD(JK)
CQ   25    XQ=XQ+AD(JK)*(C0(JK)-AQ(JK))
CQ        WRITE(10,*) ' XA, XQ',XA,XQ
CQ      AJ=XQ/XA
CQ      DO 30 JK=1,K
CQ   30    AQ(JK)=AD(JK)*AJ+AQ(JK)

      END