C
      SUBROUTINE FNC21(AA,LL,DEP,OM2,CV2,WN,DNS,VP,VS,THK,ML)
C
      IMPLICIT REAL*8(A-H,O-Z)
      DIMENSION DNS(ML),THK(ML),VP(ML),VS(ML)
      COMPLEX*16 AA(4,4),SA(4,4),SB(4,4),CPX
     *          ,CMP,CMS,PM,QM,RBM,RAM
     *          ,CQ,SQ,STQ,SDQ,CP,SP,STP,SDP,GM
     *          ,C11,C12,C13,C14,C15,C16,D11,D12,D13,D14,D15
C
      CPX=DCMPLX(0.D0,1.D0)
      WN2=WN*WN
C
      DO 100 I=1,4
        DO 110 J=1,4
          AA(I,J) =(0.0D0,0.0D0)
  110   CONTINUE
        AA(I,I)=(1.0D0,0.0D0)
  100 CONTINUE
C
      DO 150 IL=LL,1,-1
C
        DO 160 I=1,4
          DO 170 J=1,4
            SA(I,J) =AA(I,J)
  170     CONTINUE
  160   CONTINUE
C
        BM2=VS(IL)*VS(IL)
        WP2=OM2/(VP(IL)*VP(IL))
        WS2=OM2/BM2
C
        CMP=CDSQRT(WP2-WN2)
        CMS=CDSQRT(WS2-WN2)
        IF(IMAG(CMP).GT.0.D0)CMP=-CMP
        IF(IMAG(CMS).GT.0.D0)CMS=-CMS
C
        RAM=CMP/WN
        PM=CMP*THK(IL)
        IF(IL.EQ.LL)PM=CMP*DEP
        CP=CDCOS(PM)
        SP=CDSIN(PM)
        STP=RAM*SP
        SDP=SP/RAM
C
        RBM=CMS/WN
        QM=CMS*THK(IL)
        IF(IL.EQ.LL)QM=CMS*DEP
        CQ=CDCOS(QM)
        SQ=CDSIN(QM)
        STQ=RBM*SQ
        SDQ=SQ/RBM
C
        GM=2.D0*BM2/CV2
        C11=GM
        C12=GM-1.D0
        C13=GM*GM
        C14=C12*C12
        C16=DNS(IL)*CV2
        C15=1.D0/C16
C
        D11=CP-CQ
        D12=SDP+STQ
        D13=STP+SDQ
        D14=C14*SDP+C13*STQ
        D15=C13*STP+C14*SDQ
C
        SB(1,1)= C11*CP-C12*CQ
        SB(1,2)= (C12*SDP+C11*STQ)*CPX
        SB(1,3)=-C15*D11
        SB(1,4)= C15*D12*CPX
        SB(2,1)=-(C11*STP+C12*SDQ)*CPX
        SB(2,2)=-C12*CP+C11*CQ
        SB(2,3)= C15*D13*CPX
        SB(2,4)= SB(1,3)
        SB(3,1)= C16*C11*C12*D11
        SB(3,2)= C16*D14*CPX
        SB(3,3)= SB(2,2)
        SB(3,4)= SB(1,2)
        SB(4,1)= C16*D15*CPX
        SB(4,2)= SB(3,1)
        SB(4,3)= SB(2,1)
        SB(4,4)= SB(1,1)
C
        DO 180 I=1,4
          DO 190 J=1,4
            AA(I,J)=(0.D0,0.D0)
            DO 195 K=1,4
              AA(I,J) =AA(I,J) +SA(I,K)*SB(K,J)
  195       CONTINUE
  190     CONTINUE
  180   CONTINUE
C
  150 CONTINUE
C
      RETURN
      END
