C
C *** THE HASKELL'S MATRIX: AR AND AL ***
C
      SUBROUTINE ARAL(OM2,WN,CV2,DNS,VP,VS,THK,ML,AR,AL)
C
      IMPLICIT REAL*8(A-H,O-Z)
      DIMENSION DNS(ML),THK(ML)
      COMPLEX*16 VP(ML),VS(ML),CPX,SM
     *          ,AR(4,4),SAR(4,4),SBR(4,4)
     *          ,AL(2,2),SAL(2,2),SBL(2,2)
     *          ,WP2,WS2,CMP,CMS,BM2,PM,QM,RBM,RAM
     *          ,CQ,SQ,STQ,SDQ,CP,SP,STP,SDP,GM
     *          ,C11,C12,C13,C14,C15,C16,D11,D12,D13,D14,D15
      COMMON /FDAT/ OM,NL,RR
C
      WN2=WN*WN
      CPX=DCMPLX(0.D0,1.D0)
C
C *** AA MATRIX ***
C
      DO 100 I=1,4
        DO 110 J=1,4
          AR(I,J) =(0.0D0,0.0D0)
  110   CONTINUE
        AR(I,I)=(1.0D0,0.0D0)
  100 CONTINUE
C
      AL(1,1)=(1.D0,0.D0)
      AL(1,2)=(0.D0,0.D0)
      AL(2,1)=(0.D0,0.D0)
      AL(2,2)=(1.D0,0.D0)
C
      DO 200 IL=NL-1,1,-1
C
        DO 160 I=1,4
          DO 170 J=1,4
            SAR(I,J) =AR(I,J)
  170     CONTINUE
  160   CONTINUE
C
        SAL(1,1)=AL(1,1)
        SAL(1,2)=AL(1,2)
        SAL(2,1)=AL(2,1)
        SAL(2,2)=AL(2,2)
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)
        CP=CDCOS(PM)
        SP=CDSIN(PM)
        STP=RAM*SP
        SDP=SP/RAM
C
        RBM=CMS/WN
        QM=CMS*THK(IL)
        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
        SBR(1,1)= C11*CP-C12*CQ
        SBR(1,2)= (C12*SDP+C11*STQ)*CPX
        SBR(1,3)=-C15*D11
        SBR(1,4)= C15*D12*CPX
        SBR(2,1)=-(C11*STP+C12*SDQ)*CPX
        SBR(2,2)=-C12*CP+C11*CQ
        SBR(2,3)= C15*D13*CPX
        SBR(2,4)= SBR(1,3)
        SBR(3,1)= C16*C11*C12*D11
        SBR(3,2)= C16*D14*CPX
        SBR(3,3)= SBR(2,2)
        SBR(3,4)= SBR(1,2)
        SBR(4,1)= C16*D15*CPX
        SBR(4,2)= SBR(3,1)
        SBR(4,3)= SBR(2,1)
        SBR(4,4)= SBR(1,1)
C
        SM=DNS(IL)*BM2
        SBL(1,1)= CQ
        SBL(1,2)= CPX*SDQ/SM
        SBL(2,1)= CPX*STQ*SM
        SBL(2,2)= CQ
C
        DO 210 I=1,4
          DO 220 J=1,4
            AR(I,J)=(0.D0,0.D0)
            DO 230 K=1,4
              AR(I,J) =AR(I,J) +SAR(I,K)*SBR(K,J)
  230       CONTINUE
  220     CONTINUE
  210   CONTINUE
C
        DO 250 I=1,2
          DO 260 J=1,2
            AL(I,J)=(0.D0,0.D0)
            DO 270 K=1,2
              AL(I,J) =AL(I,J) +SAL(I,K)*SBL(K,J)
  270       CONTINUE
  260     CONTINUE
  250   CONTINUE
C
  200 CONTINUE
C
      RETURN
      END
