C
C *** READ OF SOIL DATA FROM DATA FILE
C
      SUBROUTINE RAYIN(DOM,NOM,NDOM,NSMD,NEMD,NDC)
C
C ** INPUT DATA **
C DOM   : INCREMENT OF CIRCULAR FREQUENCY ( DELTA OMEGA )
C NOM   : TOTAL NUMBER OF CIRCULAR FREQUENCY
C NDOM  : DIVISION NUMBER FROM 0 TO MAX OMEGA TO GET CUT-OFF OMEGA
C NSMD  : START OUTPUT MODE OF RAYLEIGH WAVE
C NEMD  : END OUTPUT MODE OF RAYLEIGH WAVE
C NDC   : DIVISION NUMBER FROM MIN TO MAX VS TO GET PHASE VELOCITY
C DNS(I): DENSITY OF Ith LAYER ==> SM(I):SHEAR MODULUS => COMMOM SM(50)
C VP (I): VP OF Ith LAYER                              => COMMON VP(50)
C VS (I): VS OF Ith LAYER                              => COMMON VS(50)
C DEP(I): DEPTH ( THICKNESS ) OF Ith LAYER             => COMMON DEP(50)
C NL    : TOTAL NUMBER OF LAYERS                       => COMMON NL
C
      IMPLICIT REAL*8(A-H,O-Z)
      CHARACTER FNAME*30
      COMMON / LAYER / NL,VP(50),VS(50),DEP(50),SM(50)
     *       / DNSITY / DNS(30)
     *       / MINMAX / VSMIN,VSMAX,CCMIN,CCMAX,MINIL,MAXIL
C
C *** SOIL DATA INPUT FROM FILE DATA ***
C
      WRITE(*,*)
      WRITE(*,1000)
   10 WRITE(*,1010)
      READ(*,'(A)')FNAME
      IF(FNAME(1:1).EQ.' ')GOTO 10
 1000 FORMAT( ' From SUBROUTINE RAYIN :')
 1010 FORMAT(/' Enter Soil Data File Name ',\)

      OPEN (7,FILE=FNAME)
      READ(7,1200)NL
      DO 100 IL=1,NL
        READ(7,1210)DNS(IL),VP(IL),VS(IL),DEP(IL),QF
        SM(IL)=DNS(IL)*VS(IL)*VS(IL)
  100 CONTINUE
      CLOSE(7)
 1200 FORMAT(I10)
 1210 FORMAT(5F10.0)
C
C *** DATA ECHO ***
C
      WRITE(*,2000)NL
      DO 200 IL=1,NL
        WRITE(*,2010)IL,DNS(IL),VP(IL),VS(IL),DEP(IL)
  200 CONTINUE
 2000 FORMAT(/' Total Layers Number            =',I5)
 2010 FORMAT( ' Layer Num., Density, Vp, Vs, Depth =',I3,4F10.3)
C
C *** MIN AND MAX VS AND SOIL DATA CHECK ***
C
      VSMIN=VS(NL)
      VSMAX=0.0D0
      VPMAX=0.0D0 
      MINIL=1
      MAXIL=1
      DO 300 IL=1,NL
        IF(VS(IL).LE.VSMIN)THEN
          VSMIN=VS(IL)
          MINIL=IL
        END IF
        IF(VS(IL).GE.VSMAX)THEN
          VSMAX=VS(IL)
          MAXIL=IL
        END IF
        VPMAX=MAX(VPMAX,VP(IL))
  300 CONTINUE
C
      IF(VSMAX.NE.VS(NL))THEN
        WRITE(*,*)' FROM SUBROUTINE RAYIN'
        WRITE(*,*)' VS(NL).NE.VSMAX, THUS STOP !!!'
        STOP
      END IF
      IF(VPMAX.NE.VP(NL))THEN
        WRITE(*,*)' FROM SUBROUTINE RAYIN'
        WRITE(*,*)' VP(NL).NE.VPMAX, THUS STOP !!!'
        STOP
      END IF
C
      IF(NL.GT.50)THEN
        WRITE(*,*)' FROM SUBROUTINE RAYIN'
        WRITE(*,*)' SOIL LAYERS NUMBER > 50, THUS STOP !!!'
        STOP
      END IF
C
C *** MINUMUM AND MAXIMUM PHASE VELOCITY ***
C
      CCMIN=FNCCR(VP(MINIL),VS(MINIL))
      CCMAX=FNCCR(VP(MAXIL),VS(MAXIL))
C
C *** DATA INPUT FROM SCREEN ***
C
      WRITE(*,3000)
      READ(*,*)DOM,NOM
      OMMAX=DOM*DFLOAT(NOM)
      WRITE(*,3010)0.D0,OMMAX
      WRITE(*,3020)
      READ(*,*)NDOM
      WRITE(*,3030)CCMIN,VSMAX
      WRITE(*,3040)
      READ(*,*)NDC
      WRITE(*,3050)
      READ(*,*)NSMD
      WRITE(*,3060)
      READ(*,*)NEMD
      WRITE(*,3070)
      READ(*,*)IYES
      IF(IYES.NE.0)GOTO 10
 3000 FORMAT(/' Enter Delta Omega and Omega Number        ? :',\)
 3010 FORMAT(/' Minimum Omega and Maximum Omega = ',2F8.3)
 3020 FORMAT( ' To Get Cut-Off Omega,  Enter',
     *       /' Division Number between Min and Max Omega ? :',\)
 3030 FORMAT(/' Minimum C and Maximum Vs = ',2F10.3)
 3040 FORMAT( ' To Get General Phase Velocity (C), Enter',
     *       /' Division Number between Min and Max C     ? :',\)
 3050 FORMAT(/' Enter Output Start Rayleigh Mode ( >= 0 ) ? :',\)
 3060 FORMAT( ' Enter Output End Rayleigh Mode            ? :',\)
 3070 FORMAT(/' Input Data OK ? ( yes = Enter 0 )         ? :',\)
      WRITE(*,*)
C
      RETURN
      END
