subroutine frantic_trackr(ZELEV)
  !
  !  THIS ROUTINE WAS WRITTEN BY HARRY H. TOWNER OF THE PRINCETON
  !  PLASMA PHYSICS LAB.  THIS ROUTINE WILL TRACK A GIVEN
  !  TRAJECTORY THROUGH THE MESH FOR A GIVEN Y.  IT WILL CALCULATE
  !  THE NUMBER OF BOUNDARIES CROSSED (NBCROS), THE NUMBER OF
  !  THE ZONE CROSSED FROM LEFT TO RIGHT (NZCROS(I)) AND THE
  !  PATH LENGTH IN EACH ZONE (DIST(I)).
  !
  !  parameter:
  !  ELEV  - THE DISTANCE OF CLOSEST APPROACHED.  (CM)
  !
  !
  use iso_c_binding, only: fp => c_double
  use physconst_mod, only: two
  use frantic_module
  implicit none
  !
  ! Argument variables:
  real(fp), intent(in) :: zelev
  ! Locat variables:
  integer :: i,ic,imzone,ip,im,imzp1
  real(fp) :: zelev2,zrb,zdistm,zdistp,zxdist
  ZELEV2=ZELEV*ZELEV
  !  I NOW LOOP OVER ALL BOUNDARIES TO FIND THE BOUNDARY WHICH
  !  IS GREATER THAN Y.
  do I=2,NBOUND
    IC=I
    ZRB=RBOUND(I)
    if(ZRB.GE.ZELEV) GO TO 20
  end do
  !  MZONE CONTAINS THE ZONE NUMBER FOR THE CENTER REGION.
20 IMZONE=IC-1
  !  NBCROS CONTAINS THE NUMBER OF BOUNDARIES CROSSED = NUMBER OF ZONES
  !  TRAJECTORY PASSED THROUGH.
  NBCROS=2*(NZONEC-IMZONE)+1
  !  I NOW FIND THE ARRAY ELEMENT FOR THE MID ZONE.
  MID=NBCROS/2+1
  !  I NOW FILL NZCROS AND DIST FOR THE CENTER REGION.
  NZCROS(MID)=IMZONE
  ZDISTM=SQRT(ZRB*ZRB-ZELEV2)
  DIST(MID)=TWO*ZDISTM
  if(MID.EQ.1) GO TO 40
  !  DUE TO SYMMETRY I NOW ONLY HAVE TO LOOP OVER MID-1 POINTS
  !  TO FILL UP DIST AND NZCROS ARRAYS
  do I=1,MID-1
    IP=MID+I
    IM=MID-I
    IMZP1=IMZONE+I
    ZDISTP=SQRT(RBOUND(IC+I)**2-ZELEV2)
    ZXDIST=ZDISTP-ZDISTM
    ZDISTM=ZDISTP
    NZCROS(IP)=IMZP1
    NZCROS(IM)=IMZP1
    DIST(IP)=ZXDIST
    DIST(IM)=ZXDIST
  end do
40 continue
  return
end subroutine frantic_trackr
