cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c      program fldist
c      Calculates average distances between points along profile...

      character id1*8, id2*8, ans*1, prjans*1
      real post1(8), post2(8)
      real d(5000)

      print *,' Calculates distances in meters between data points.'
      print '(/a$)', ' Data projected or unprojected? [p/u]: '
      read '(a1)', prjans

      call getfile2(21,' Infile ','in','unformatted','.pos')

  5   print '(/a$)', ' Calc ave dist over n data intervals: n= '
      read *, nave
      print '(/a$)', ' Repeat calculation how many times: '
      read *, iter

      do 70 k=1,iter

 10   call getpost (21, id1, post1, *90)
      xlon1 = post1(1)
      xlat1 = post1(2)

      do 20 i=1,nave
      call getpost (21, id2, post2, *90)
      xlon2 = post2(1)
      xlat2 = post2(2)
      if(id1(1:6).ne.id2(1:6)) go to 10
      if(prjans.eq.'p') call pfldist(xlon1,xlat1,xlon2,xlat2,d(i))
      if(prjans.eq.'u') call ufldist(xlon1,xlat1,xlon2,xlat2,d(i))
      id1=id2
      xlon1=xlon2
      xlat1=xlat2
 20   continue

      sum=0.
      dmin=1.0E+38
      dmax=0.
      do 40 i=1,nave
      sum=sum+d(i)
      dmin=amin1(d(i),dmin)
 40   dmax=amax1(d(i),dmax)
      dave=sum/nave

      write(6,1010) dave,dmin,dmax
 1010 format(7x,'DAVE=',f10.2,'   DMIN=',f10.2,'   DMAX=',f10.2)

 70   continue

 80   print '(/a$)', ' Again or Exit? [a/e]:  '
      read '(a1)',ans
      call uc2lc(ans)
      if(ans.eq.'a') go to 5
      if(ans.ne.'e') go to 80

 90   close(21)
      stop ' '
      end


      subroutine pfldist(xlon1,xlat1,xlon2,xlat2,d)
      real kmtom
      parameter (kmtom=1.0E3)
      d=sqrt((xlon2-xlon1)**2+(xlat2-xlat1)**2)
      d=kmtom*d
      return
      end


      subroutine ufldist(xlon1,xlat1,xlon2,xlat2,d)
      real kmtom
      parameter (kmtom=1.0E3)
      rad=3.1415927/180.
      y=(xlat2-xlat1)*111.*kmtom
      x=(xlon2-xlon1)*111.*kmtom*cos(xlat1*rad)
      d=sqrt(x**2+y**2)
      return
      end


at2-xlat1)*111.*kmtom
      x=(xlon2-xlon1)*111.*kmtom*
