C
C *** CALCULATION OF URRX,URRZ,WRRX,WRRZ,AND VRRX ***
C
      SUBROUTINE UVWRL(WN,DNS,VP,VS,THK,ML,L1,DEP1,L2,DEP2
     *                ,WRR,URR,VLR)
C
      IMPLICIT REAL*8(A-H,O-Z)
      DIMENSION DNS(ML),THK(ML)
      COMPLEX*16 VP(ML),VS(ML),CPX,BN2,WP2,WS2,SN
     *          ,AR(4,4),AL(2,2),FR,FL,CMPN,CMSN
     *          ,GN,RAN,RBN,RL,RK,RN,RM,GS2,RS2,HS2,SS2
     *          ,FWZ0,FWX0,FUZ0,FUX0,FVX0,EPD,ESD
     *          ,B11,B12,B13,B14,B21,B22,B23,B24
     *          ,ASR2(4,4),ARR1(4,4),ASL2(2,2),ARL1(2,2)
     *          ,WR0(2),UR0(2),VL0,WRR(2),URR(2),VLR
      COMMON /FDAT/ OM,NL,RR
C
      WN2=WN*WN
      OM2=OM*OM
      CV=OM/WN
      CV2=CV*CV
      CPX=DCMPLX(0.D0,1.D0)
C
C *** AR AND AL MATRIX ***
C
      CALL ARAL(OM2,WN,CV2,DNS,VP,VS,THK,ML,AR,AL)
C
C *** RL-RM AND FR ***
C
      BN2=VS(NL)*VS(NL)
      WP2=OM2/(VP(NL)*VP(NL))
      WS2=OM2/BN2
      CMPN=CDSQRT(WP2-WN2)
      CMSN=CDSQRT(WS2-WN2)
      IF(IMAG(CMPN).GT.0.D0)CMPN=-CMPN
      IF(IMAG(CMSN).GT.0.D0)CMSN=-CMSN
C
      GN=2.D0*BN2/CV2
      RAN=CMPN/WN
      RBN=CMSN/WN
C
      B11=GN*RAN
      B12=GN-1.D0
      B14=1.D0/(DNS(NL)*CV2)
      B13=-RAN*B14
      B21=-B12
      B22=GN*RBN
      B23=B14
      B24=RBN*B14
C
      RL=B11*AR(1,1)+B12*AR(2,1)+B13*AR(3,1)+B14*AR(4,1)
      RK=B11*AR(1,2)+B12*AR(2,2)+B13*AR(3,2)+B14*AR(4,2)
      RN=B21*AR(1,1)+B22*AR(2,1)+B23*AR(3,1)+B24*AR(4,1)
      RM=B21*AR(1,2)+B22*AR(2,2)+B23*AR(3,2)+B24*AR(4,2)
C
      FR=RN*RK-RL*RM
C
C *** FL ***
C
      SN=DNS(NL)*BN2
      FL=(AL(2,1)+SN*RBN*AL(1,1))*CPX
C
C *** SP AND OB ***
C
      IF(L1.EQ.NL)THEN
C
        EPD=CDEXP(-CPX*CMPN*DEP1)
        ESD=CDEXP(-CPX*CMSN*DEP1)
C
        RS2= B14*EPD
        GS2=-RAN*RS2
        HS2= B14*ESD
        SS2= RBN*HS2
C
        FVX0=ESD
C
      ELSE
C
        CALL ARAL2(ASR2,ASL2,L1,DEP1,OM2,CV2,WN,DNS,VP,VS,THK,ML,NL)
C
        GS2=B11*ASR2(1,3)+B12*ASR2(2,3)+B13*ASR2(3,3)+B14*ASR2(4,3)
        RS2=B11*ASR2(1,4)+B12*ASR2(2,4)+B13*ASR2(3,4)+B14*ASR2(4,4)
        HS2=B21*ASR2(1,3)+B22*ASR2(2,3)+B23*ASR2(3,3)+B24*ASR2(4,3)
        SS2=B21*ASR2(1,4)+B22*ASR2(2,4)+B23*ASR2(3,4)+B24*ASR2(4,4)
C
        FVX0=ASL2(2,2)+SN*RBN*ASL2(1,2)
C
      END IF
C
      FWZ0=GS2*RN-HS2*RL
      FWX0=RS2*RN-SS2*RL
      FUZ0=GS2*RM-HS2*RK
      FUX0=RS2*RM-SS2*RK
C
C *** WR0 - VL0 ***
C
      P2I=0.15915494309D0
      WR0(1)=-CPX*P2I*FWX0/FR
      WR0(2)=     P2I*FWZ0/FR
      UR0(1)= CPX*P2I*FUX0/FR
      UR0(2)=    -P2I*FUZ0/FR
      VL0   = CPX*P2I*FVX0/FL
C
C *** WRR - VLR ***
C
      CALL ARAL1(ARR1,ARL1,L2,DEP2,OM2,CV2,WN,DNS,VP,VS,THK,ML)
C
      URR(1)= ARR1(1,1)*UR0(1)+ARR1(1,2)*WR0(1)
      URR(2)= ARR1(1,1)*UR0(2)+ARR1(1,2)*WR0(2)
      WRR(1)= ARR1(2,1)*UR0(1)+ARR1(2,2)*WR0(1)
      WRR(2)= ARR1(2,1)*UR0(2)+ARR1(2,2)*WR0(2)
      VLR   = ARL1(1,1)*VL0
C
      RETURN
      END
