C
C *** CUT-OFF OMEGA OF LOVE WAVE (C=VS(NL))
C
      SUBROUTINE LOVECT(DOM,NOM,NDOM,CFOM,NEMD,MMD,NCFOM)
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 NEMD : HIGHEST OUTPUT MODE OF LOVE WAVE
C MMD  : NMD IN MAIN PROGRAM DIMENSION
C ** OUTPUT DATA
C CFOM(I): CUT-OFF OMEGA OF Ith MODE LOVE WAVE
C NCFOM  : NUMBER OF CUT-OFF OMEGA
C
      IMPLICIT REAL*8(A-H,O-Z)
      DIMENSION CFOM(0:MMD)
      EXTERNAL FNCA21
C
C *** 0 th MODE CUT-OFF OMEGA ***
C
      ICO=0
      CFOM(ICO)=0.0D0
      IF(NEMD.EQ.0)GOTO 40
C
C *** INCREMENT OF OMEGA ***
C
      DDOM=DFLOAT(NOM)*DOM/DFLOAT(NDOM)
C
C *** INPUT OF CONVERGENCE JUDGMENT CRITERIA FOR D2ROOT ***
C
      DXEPS=100.0D0
      XEPSO=DDOM/DXEPS
      DFEPS=1000.0D0
      ITMAX=100
      WRITE(*,*)
      WRITE(*,*)'From SUBROUTINE LOVECT :'
      WRITE(*,*)
      WRITE(*,*)'Convergence Criteria for Cut-Off Omega :'
      WRITE(*,1000)XEPSO
      WRITE(*,1010)DFEPS
      WRITE(*,1020)ITMAX
      WRITE(*,1030)
      READ(*,*)IYES
      IF(IYES.NE.0)THEN
        WRITE(*,*)
        WRITE(*,1040)
        READ(*,*)XEPSO,DFEPS,ITMAX
      END IF
      WRITE(*,*)
 1000 FORMAT(/' XEPS = DDOM/DXEPS           : XEPS =',F15.10)
 1010 FORMAT( ' FEPS = DABS(FL1-FL2)/DFEPS : DFEPS =',F15.3)
 1020 FORMAT( ' Maximum Iteration Number   : ITMAX =',I15/)
 1030 FORMAT( ' Are These Criteria OK ? ( yes = 0 ) :',\)
 1040 FORMAT( ' Enter New DDOM, DXEPS, DFEPS, ITMAX :',\)
C
C *** LOWER TRIAL OMEGA AND EIGEN VALUE EQUATION ***
C
      OM1=DDOM
      FL1=FNCA21(OM1)
C
C *** LOWER TRIAL OMEGA CHECK ***
C
      ICO=1
      IFOM=2
      IF(FL1.EQ.0.0D0)THEN
        CFOM(1)=OM1
        IF(NEMD.EQ.1)GOTO 40
        OM1=2.0D0*DDOM
        FL1=FNCA21(OM1)
        ICO=2
        IFOM=3
      ENDIF
C
C *** SEARCH OF CUT-OFF OMEGA OF HIGHER LOVE MODE ***
C
      DO 100 IOM=IFOM,NDOM
C
C  ** HIGHER TRIAL OMEGA AND EIGEN VALUE EQUATION **
C
        OM2=DFLOAT(IOM)*DDOM
        FL2=FNCA21(OM2)
C
C  ** LOWER AND HIGER OMEGA CHECK **
C
        IF(FL1*FL2)10,20,30
C
C   * CASE OF LOWER OM < CUT-OFF OM < HIGHER OM *
C
C     * SEARCH OF CUT-OFF OM BY D2ROOT *
C
   10     XEPS=XEPSO
          FEPS=DABS(FL1-FL2)/DFEPS
          ITR=ITMAX
          OML=OM1
          OMR=OM2
          CALL D2ROOT(FNCA21,OML,OMR,XEPS,FEPS,ITR,OMLR,IER)
C
C     * D2ROOT ERROR OR NOT CONVERGENCE WORK *
C
          IF(IER.NE.0)THEN
            WRITE(*,*)
            WRITE(*,*)' FROM SUBROUTINE LOVECT :'
            WRITE(*,*)' D2ROOT ERROR, IER =',IER
            WRITE(*,*)' XEPS,FEPS,ITMAX =',XEPS,FEPS,ITR
            WRITE(*,*)' OM1,OM2 =',OM1,OM2
            WRITE(*,*)' FL1,FL2 =',FL1,FL2
            IF(IER.EQ.3000)THEN
              WRITE(*,*)' NOT CONVERGENCE (IER=3000) !!!'
              WRITE(*,*)' OML,OMR =',OML,OMR
              FLL=FNCA21(OML)
              FLR=FNCA21(OMR)
              WRITE(*,*)' FLL,FLR =',FLL,FLR
              WRITE(*,*)' OMEGA IS CHANGED BY MEAN OMEGA !!!'
              OMLR=(OMR+OML)/2.0D0
              FLLR=FNCA21(OMLR)
              WRITE(*,*)' NEW OM, FL =',OMLR,FLLR
            ELSE
              WRITE(*,*)' IER=2000 INPUT DATA ERROR  !!!'
              WRITE(*,*)' IER=2100 FL1*FL2 > 0       !!!'
              WRITE(*,*)' STOP  !!!'
              STOP
            ENDIF
          ENDIF
C
C     * ENTER OF CUT-OFF OMEGA *
C
          CFOM(ICO)=OMLR
          IF(NEMD.EQ.ICO)GOTO 40
          ICO=ICO+1
          GOTO 30
C
C   * CASE OF HIGER TRIAL OM = CUT-OFF OM *
C
   20     CFOM(ICO)=OM2
          IF(NEMD.EQ.ICO)GOTO 40
          ICO=ICO+1
          OM2=OM1+DDOM/2.0D0
          FL2=FNCA21(OM2)
C
C   * CASE OF LOWER OM < HIGHER OM < CUT-OFF OM *
C
C     * HIGHER OM ==> LOWER OM AND NEXT STEP *
C
   30     OM1=OM2
          FL1=FL2
C
  100 CONTINUE
C
C *** NUMBER OF CUT-OFF OMEGA ***
C
      NCFOM=ICO-1
      RETURN
C
   40 NCFOM=ICO
C
      RETURN
      END
