
      subroutine rdapprox(flnm,lu,utlim,satut,satlat,satlon,satalt,
     +  mxpts,npts,iydsat,norbfr,ier)
c
c Read sat attitude file from file flnm on unit lu, limited to times
c   between utlim(1) and utlim(2).
c Return satut,lat,lon,alt,npts
c
      character*32 flnm,disk
      character*80 rec80,errmsg,flnm1
      logical isopen,exists
      dimension satut(mxpts),satlat(mxpts),satlon(mxpts),satalt(mxpts),
     +  utlim(2)
c
c Get sat attitude file from mss:
c (if not already obtained in previous call)
c
      ier = 0
      len = lenstr(flnm)
      inquire(lu,opened=isopen)
      if (.not.isopen) then
        call getms(flnm,"/usr/tmp/TIGCM",lu,iier)
        if (iier.eq.2) then
          write(6,"('>>> rdapprox: getvol could not find file ',a,
     +      ' on mss')") flnm(1:len)
          ier = 1
          return
        elseif (iier.ne.0) then
          write(6,"('>>> rdapprox: error ',i3,' from getms')") iier
          ier = 2
          return
        endif 
c
c 4 line header (get iydsat from first line):
c
        read(lu,"(28x,i5,16x,i4)",end=901) iyear,iday
        iydsat = (iyear-iyear/1900*1900)*1000+iday
        write(6,"('rdapprox: file ',a,' iydsat=',i6)") flnm,iydsat 
        do ii=1,3
          read(lu,"(a)",end=901) rec80
        enddo
      endif
c
c Read data between times utlim(1) and utlim(2):
c (Time on file is in msec, and there are 60*60*1000=3600000 msec/hr)
c
      npts = 0
      norb = 1
      prevlon = 0
      do ii=1,100000
        read(lu,"(i9,3f8.2)",end=901) imsec,rlat,rlon,ralt
        uthr = float(imsec)/3600000.	! ut(hrs)
        if (uthr.lt.utlim(1)) goto 100
        if (uthr.gt.utlim(2)) goto 200
        if (norbfr.gt.0.and.ii.gt.1) then
          if (rlon.lt.prevlon) then
            write(6,"('rdapprox: completed orb ',i2,' rlon,prevlon=',
     +        2f9.3,' npts=',i4)") norb,rlon,prevlon,npts
            if (norb.eq.norbfr) then
              backspace(lu)
              goto 200
            endif
            norb = norb+1
            write(6,"('rdapprox: continuing with ii=',i5,' norb=',i2)")
     +        ii,norb
          endif
        endif
        npts = npts+1
        if (npts.gt.mxpts) then
          write(6,"('>>> rdapprox: reached mxpts=',i6,
     +      ' -- returning')") mxpts
          ier = 1
          return
        endif
        satlat(npts) = rlat
c       satlon(npts) = rlon-180.	! convert from 0->360 to -180->180
        satlon(npts) = rlon
        if (satlon(npts).ge.180.) satlon(npts) = satlon(npts) - 360.
        satalt(npts) = ralt
        satut(npts) = uthr
 100    continue
        prevlon = rlon
      enddo
 901  write(6,"('EOF on file ',a,' npts = ',i5)") flnm(1:len),npts 
      return
 200  continue
      write(6,"('rdapprox returning with npts=',i4,' norb=',i4)")
     +  npts,norb
      return
      end
