      subroutine st_glc(elatd,elond,geo_info)
c
c ...... determine distances and bearing to nearest landmark
c
c
c Modified 21 nov 94 to acquire file names from config.h
c
      implicit real*8 (a-h,o-z)
      implicit integer*4 (i-n)
      include "config.h"
      real*8 elatd,elond,dmin
      character*40 geo_loc
      character*80 geo_info
      character*3 geo_dir
      integer*4 geo_dist
      real*8 plat(250),plon(250),pdel(250),pdir(250)
      character*40 place(250)
      character*256 aline
c
c     write(*,*) 'st_glc - elatd & elond = ',elatd,elond
c
      open(23,file=landmark_file(1:lnblnk(landmark_file)),
     1    status='old')
      npl=0
    1 npl=npl+1
      read(23,'(a)',end=2) aline
      lnba=lnblnk(aline)
      if(aline(1:2).eq.'  ') then
        read(aline(1:lnba),'(2f10.2,3x,a)')
     1           plat(npl),plon(npl),place(npl)
        plat(npl)=datand(0.993277d0*dtand(plat(npl)))
      elseif(aline(19:19).ne.' ') then
        read(aline(1:lnba),'(i2,1x,f4.1,1x,i4,1x,f4.1,1x,a)')
     1           ilad,flam,ilod,flom,place(npl)
        plat(npl)=real(ilad)+flam/60.d0
        plat(npl)=datand(0.993277d0*dtand(plat(npl)))
        if (ilod.ge.0.d0) then
          plon(npl)=dble(ilod)+flom/60.d0
        else
          plon(npl)=dble(ilod)-flom/60.d0
        endif
      else
        read(aline(1:lnba),'(i2,1x,f4.1,1x,i4,1x,f4.1,7x,a)')
     1           ilad,flam,ilod,flom,place(npl)
        plat(npl)=real(ilad)+flam/60.d0
        plat(npl)=datand(0.993277d0*dtand(plat(npl)))
        if (ilod.ge.0.d0) then
          plon(npl)=dble(ilod)+flom/60.d0
        else
          plon(npl)=dble(ilod)-flom/60.d0
        endif
      endif
      elatg=datand(0.993277d0*dtand(elatd))
      elong=elond
      dy=111.195d0*(elatg-plat(npl))
      dx=111.195d0*(elong-plon(npl))*dcosd((elatg+plat(npl))/2.d0)
      pdel(npl)=dx*dx+dy*dy
      if(pdel(npl).gt.0.d0) pdel(npl)=sqrt(pdel(npl))
      if((dx.eq.0.d0).and.(dy.eq.0.d0)) then
        pdir(npl)=0.d0
      else
        pdir(npl)=datan2d(dx,dy)
      endif
      if(pdir(npl).lt.0.d0) pdir(npl)=pdir(npl)+360.d0
c      write(*,*) 'npl, elatg, elong, plat & plon = ',
c     1            npl,elatg,elong,plat(npl),plon(npl)
c      write(*,*) 'dx, dy, pdel & pdir = ',
c     1            dx,dy,pdel(npl),pdir(npl)
      go to 1
    2 continue
      close(23)
      npl=npl-1
      dmin=pdel(1)
      idmin=1
      do 3 i=2,npl
      if(pdel(i).lt.dmin) then
        dmin=pdel(i)
        idmin=i
      endif
    3 continue
      geo_loc='                                        '
      geo_loc=place(idmin)(1:lnblnk(place(idmin)))
      geo_dist=nint(sngl(pdel(idmin)))
      if(geo_dist.lt.1) geo_dist=1
      pd=pdir(idmin)
      if(pd.le.11.25d0) then
        geo_dir='N  '
      elseif(pd.le.33.75d0) then
        geo_dir='NNE'
      elseif(pd.le.56.25d0) then
        geo_dir='NE '
      elseif(pd.le.78.75d0) then
        geo_dir='ENE'
      elseif(pd.le.101.25d0) then
        geo_dir='E  '
      elseif(pd.le.123.75d0) then
        geo_dir='ESE'
      elseif(pd.le.146.25d0) then
        geo_dir='SE '
      elseif(pd.le.168.75d0) then
        geo_dir='SSE'
      elseif(pd.le.191.25d0) then
        geo_dir='S  '
      elseif(pd.le.213.75d0) then
        geo_dir='SSW'
      elseif(pd.le.236.25d0) then
        geo_dir='SW '
      elseif(pd.le.258.75d0) then
        geo_dir='WSW'
      elseif(pd.le.281.25d0) then
        geo_dir='W  '
      elseif(pd.le.303.75d0) then
        geo_dir='WNW'
      elseif(pd.le.326.25d0) then
        geo_dir='NW'
      elseif(pd.le.348.75d0) then
        geo_dir='NNW'
      else
        geo_dir='N  '
      endif
      if(geo_dist.lt.10) then
        write(geo_info,'(i1,1x,"km",1x,a,1x,"of",1x,a)')
     1        geo_dist,geo_dir(1:lnblnk(geo_dir)),
     2        geo_loc(1:lnblnk(geo_loc))
      elseif(geo_dist.lt.100) then
        write(geo_info,'(i2,1x,"km",1x,a,1x,"of",1x,a)')
     1        geo_dist,geo_dir(1:lnblnk(geo_dir)),
     2        geo_loc(1:lnblnk(geo_loc))
      elseif(geo_dist.lt.1000) then
        write(geo_info,'(i3,1x,"km",1x,a,1x,"of",1x,a)')
     1        geo_dist,geo_dir(1:lnblnk(geo_dir)),
     2        geo_loc(1:lnblnk(geo_loc))
      else
        write(geo_info,'(i4,1x,"km",1x,a,1x,"of",1x,a)')
     1        geo_dist,geo_dir(1:lnblnk(geo_dir)),
     2        geo_loc(1:lnblnk(geo_loc))
      endif
c
c      write(*,'(a)') geo_loc
c      write(*,'(a)') geo_info
c
      return
      end

