c###gettop.for
      SUBROUTINE  GETTOP(DIKM, GMKM)
C--------------------------------
C
C     THIS SUBROUTINE FINDS THE DISTANCE SUPPORTING M MODES,
C     E.G., NIGHT-DAY-NIGHT PATH
C
      COMMON/CON/D2R,DCL,GAMA,PI,PI2,PIO2,R2D,RZ,VOFL
      COMMON/FRQ/FREA(13),FREL(29),FREQ,JMODE,ITXRCP(2)
      COMMON/LPATH/ GCDLNG,TXRGML(45,2),DELOPT,GMIN,YMIN,LTXRGM(2)
      COMMON /RON /CLAT(5), CLONG(5), GLAT(5), RD(5), FI(3,5), YI(3,5),
     1HI(3,5), HPRIM(30,5), HTRUE(30,5), FVERT(30,5),KM,KFX, AFAC(30,5),
     2HTR(50,3), FNSQ(50,3)
      DIMENSION FPE(3)
C  FIND DISTANCE THAT SUPPORT  E (M)  MODE.
      DEL = DELOPT*D2R
      RCOSD = RZ*COS(DEL)
      DO 105  JF = 1,3
      HT = HI(1,JF)
      FV = FI(1,JF)
      SPHE = RCOSD/(RZ +HT)
      SPHE = SPHE*SPHE
      SPHE = AMIN1(SPHE, 0.9999)
C.....E PENETRATION FREQUENCIES
  105 FPE(JF) = FV/SQRT(1.-SPHE)
C.....END
      FP1 = AMAX1(FPE(1),FPE(3))
C.....MIDDLE
      FP2 = FPE(2)
C.....END
      FP3 = AMIN1(FPE(1),FPE(3))
C.....THE MIDDLE IS --
      IF(FP1-FP2) 170,235,235
  170 IF(FREQ -FP2 -.001) 175,235,235
  175 IF(FREQ -FP1 +.001) 235,235,185
  185 GMKM =  0.5 * DIKM * (FP2-FREQ) * (1./(FP2-FP1) + 1./(FP2-FP3))
      IF(GMKM - 1000.) 235,235,225
C.....MUST BE ABLE TO GET UP THERE FOR M MODE
  225 IF(DIKM -GMKM -1000.) 235,235,240
  235 GMKM=0.
  240 CONTINUE
      RETURN
      END
C--------------------------------
