C
C *** RICKER WAVES IN THE 3D LAYERED HALF-SPACE USING 
C     THE NORMAL MODE SOLUTION ***
C
      PROGRAM MRICK
C
C ** PARAMETERS **
C MOM   : NOM  (NUMBER OF DELTA OMEGA)
C MMD   : NER OR NEL (NUMBER OF MODES FOR OUTPUT)
C ML    : NL   (NUMBER OF LAYERS)
C ** INPUT DATA **
C NOM   : NUMBER OF DELTA OMEGA
C DOM   : DELTA OMEGA
C NL    : TOTAL NUMBER OF LAYERS             
C DNS(I): DENSITY OF THE Ith LAYER 
C VS (I): VS OF THE Ith LAYER      
C THK(I): THICKNESS OF THE Ith LAYER   
C NDC   : NUMBER OF PARTITION FROM MIN Vs TO MAX Vs FOR PHASE VELOCITY
C NDOM  : NUMBER OF PARTITION FROM 0 TO MAX OMEGA FOR CUT-OFF OMEGA
C NSR   : THE STARTING MODE OF RAYLEIGH WAVE
C NER   : THE ENDING MODE OF RAYLEIGH WAVE
C NSL   : THE STARTING MODE OF LOVE WAVE
C NEL   : THE ENDING MODE OF LOVE WAVE
C ** CALCULATED DATA **
C COMR(I) : CUT-OFF OMEGA OF THE Ith RAYLEIGH MODE
C COML(I) : CUT-OFF OMEGA OF THE Ith LOVE MODE
C NCOMR   : NUMBER OF CUT-OFF OMEGA OF RAYLEIGH WAVE
C NCOML   : NUMBER OF CUT-OFF OMEGA OF LOVE WAVE
C NMDR(I) : NUMBER OF RAYLEIGH MODE AT THE Ith OMEGA FOR OUTPUT
C NMDL(I) : NUMBER OF LOVE MODE AT THE Ith OMEGA FOR OUTPUT
C CR(I,J) : PHASE VELOCITY OF THE Jth RAYLEIGH MODE AT THE Ith OMEGA
C CL(I,J) : PHASE VELOCITY OF THE Jth LOVE MODE AT THE Ith OMEGA
C UR(I,J) : GROUP VELOCITY OF THE Jth RAYLEIGH MODE AT THE Ith OMEGA
C UL(I,J) : GROUP VELOCITY OF THE Jth LOVE MODE AT THE Ith OMEGA
C ** OUTPUT DATA **
C QN(I,J) : RADIAL (OR X) COMPONENT OF THE NORMAL MODE 
C VN(I,J) : TRANSVERSE (OR Y) COMPONENT OF THE NORMAL MODE 
C WN(I,J) : VERTICAL (OR Z) COMPONENT OF THE NORMAL MODE 
C
      PARAMETER(MOM=50,ML=10,MOB=5,MMD=15)
      IMPLICIT REAL*8(A-H,O-Z)
      COMPLEX*16 QN(MOM,MOB),VN(MOM,MOB),WN(MOM,MOB)
      DIMENSION DNS(ML),VP(ML),VS(ML),THK(ML),ROB(MOB)
     *         ,COMR(0:MMD),COML(0:MMD),NMDR(MOM),NMDL(MOM)
     *         ,CR(MOM,0:MMD),CL(MOM,0:MMD)
     *         ,UR(0:MMD),UL(0:MMD)
     *         ,QXR(0:MMD),QZR(0:MMD),VXR(0:MMD)
     *         ,WXR(0:MMD),WZR(0:MMD),QXL(0:MMD),VXL(0:MMD)
      EXTERNAL FRCT,FLCT,FRCC,FLCC
      CHARACTER FNAME*15
      COMMON/OUT/NOUT
C
      WRITE(*,1000)
 1000 FORMAT(' MRICK: RICKER WAVE IN THE 3D LAYERED HALF-SPACE'/
     *       '         USING THE NORMAL MODE SOLUTION'/
     *       '        (SP AND OB ARE IN ANY LAYER),')
C
C *** DATA INPUT ***
C
      CALL DATIN(DOM,MOM,NOM,ML,NL,DNS,VP,VS,THK,NDOM,NDC
     *          ,MMD,NSR,NER,NSL,NEL
     *          ,LS,SDEP,LO,ODEP,MOB,NOB,ROB,RAD
     *          ,TP,TS,QX,QY,QZ,AMP,IQF,QFL
     *          ,VSMIN,VSMAX,CCMIN,CCMAX,MINIL,MAXIL)
C
      WRITE(*,2000)
      READ(*,*)NOUT
 2000 FORMAT(/' Output of CC and UU ? (Yes=1): ',\)
C
C *** CUT-OFF OMEGA ***
C
      CALL CTOF(FRCT,DOM,NOM,ML,NL,DNS,VP,VS,THK
     *         ,NDOM,COMR,NER,MMD,NCOMR)
      WRITE(*,*)
      WRITE(*,*)' FINAL RAYLEIGH MODE =',NCOMR
C
      IF(NL.NE.1)CALL CTOF(FLCT,DOM,NOM,ML,NL,DNS,VP,VS,THK
     *                    ,NDOM,COML,NEL,MMD,NCOML)
      WRITE(*,*)' FINAL LOVE MODE     =',NCOML
      WRITE(*,*)
      WRITE(*,*)
C
C *** PHASE VELOCITY ***
C
      CALL PHSE(FRCC,DOM,NOM,MOM,ML,NL,DNS,VP,VS,THK,VSMAX,CCMIN
     *         ,NDC,COMR,NSR,NER,MMD,CR,NMDR)
      IF(NL.NE.1)CALL PHSE(FLCC,DOM,NOM,MOM,ML,NL,DNS,VP,VS,THK
     *                    ,VSMAX,VSMIN,NDC,COML,NSL,NEL,MMD,CL,NMDL)
C
      IF(NOUT.EQ.1)THEN
        WRITE(*,*)' CR(IOM,MODE)'
        DO 100 MD=0,NCOMR
          WRITE(*,*)' MODE =',MD
          WRITE(*,3000)(CR(I,MD),I=1,NOM)
  100   CONTINUE
        WRITE(*,*)
        WRITE(*,*)' CL(IOM,MODE)'
        DO 200 MD=0,NCOML
          WRITE(*,*)' MODE =',MD
          WRITE(*,3100)(CL(I,MD),I=1,NOM)
  200   CONTINUE
        WRITE(*,*)
      END IF
 3000 FORMAT(' CR(*,MODE) =',5F7.1)
 3100 FORMAT(' CL(*,MODE) =',5F7.1)
C
C *** NORMAL MODE SOLUTION ***
C
      CALL NORM(DOM,MOM,NOM,ML,NL,DNS,VP,VS,THK
     *         ,LS,SDEP,LO,ODEP,MOB,NOB,ROB,RAD
     *         ,TP,TS,QX,QY,QZ,AMP,IQF,QFL
     *         ,MMD,NSR,COMR,CR,NMDR,NSL,COML,CL,NMDL
     *         ,UR,QXR,QZR,VXR,WXR,WZR,UL,QXL,VXL,QN,VN,WN)
C
C *** OUTPUT OF DATA (QN, VN AND WN)***
C
      CALL DATOT(DOM,MOM,NOM,NOB,MOB,ROB,RAD,QN,VN,WN)
C
      STOP
      END
