      Program ORBINT
      implicit real*8 (a-h,o-z)
      dimension recf1(3),vecf1(3),recf2(3),vecf2(3),recf3(3),      
     1 vecf3(3)
      dimension idsvs(37)
      Logical next,redyes
      character*40 PVFILE,PSFILE
      msgsup=0
      iprint=0
      write(6,100)
  100 Format('Enter GREG. DATE-TIME OF START:yy,mm,dd,hh,mm,    
     1 ss.sss')
      Read(5,*)iyr,imon,iday,ihr,imin,seci
      write(6,125)iyr,imon,iday,ihr,imin,seci
  125 Format('Greg.',5i3,f13.8)
c     write(6,200)
c 200 Format('enter satelite sv ID.')
c     read(5,*)idsv
      write(6,300)
  300 Format('Enter seconds between epochs')
      read(5,*)deltat
c     write(6,350)idsv,deltat
c 350 Format('idsv=',i3,'deltat=',f13.8)
c     write(6,350)deltat
c 350 Format(' deltat=',f13.8)
 5000 Format(a40)
      write(6,400)
  400 Format('Enter input Pos-Vel d.a. file: ')
      read(5,5000) PVFILE
      write(6,500)
  500 Format('Enter output Pos-Vel d.a. file: ')
      read(5,5000) PSFILE
      open(2222,file=PVFILE,status='old',access='direct',
     1 iostat=ios,err=9000,recl=52)
      open(3333,file=PSFILE,status='new',access='direct',
     1 iostat=ios,err=9001,recl=52)
      go to 550
c9000 STOP 'Either PVFILE or PSFILE could not be opened'
 9000 STOP ' PVFILE could not be opened'
 9001 STOP ' PSFILE could not be opened'
 9002 STOP ' D.A. file could not be read'
 9003 STOP ' New D.A. file could not be written'
  550 continue
      irn=1
      read(2222,err=9002,rec=irn) jyear,jmon,jday,
     +  jhr,jmin,secj,deltaj,mjds,fmjds,nepoch
c     write(6,*)jyear,jmon,jday,jhr,jmin,secj,deltaj,mjds,fmjds,nepoch
      irn=2
      read(2222,err=9002,rec=irn) numsv,(idsvs(k),k=1,12)
c     read(2222,err=9002,rec=irn) iblk,numsv,(idsvs(k),k=1,11)
c     write(6,*) iblk,numsv,(idsvs(k),k=1,11)
      irn=3
      read(2222,err=9002,rec=irn) (idsvs(k),k=13,25)
c     read(2222,err=9002,rec=irn) (idsvs(k),k=12,24)
c     write(6,*) (idsvs(k),k=12,24)
      irn=4
      read(2222,err=9002,rec=irn) (idsvs(k),k=26,37)
c     read(2222,err=9002,rec=irn) (idsvs(k),k=25,37)
c     write(6,*) (idsvs(k),k=25,37)
c
      diff=mod(deltaj,deltat)
      if(diff.ne.0.d0) then
        write(6,901) deltat,deltaj
 901    format(3x,'Your epoch increment',d6.2,' must be a',
     +            ' multiple of ',f6.2)
        stop 901
      endif
c     write(6,'("diff,deltaj,deltat=",3f18.5)')diff,deltaj,deltat
      numa=deltaj/deltat
      numb=((nepoch-1)*numa)+1
      numc=numb*numsv
c
      irn=1
      write(3333,err=9003,rec=irn) jyear,jmon,jday,
     +  jhr,jmin,secj,deltat,mjds,fmjds,numb
      irn=2
      write(3333,err=9003,rec=irn) numsv,(idsvs(k),k=1,12)
      irn=3
      write(3333,err=9003,rec=irn) (idsvs(k),k=13,25)
      irn=4
      write(3333,err=9003,rec=irn) (idsvs(k),k=26,37)
c
c     write(6,'("numsv,idsvs= ",38i4)') numsv,idsvs     
      call grcmjl(iyr,imon,iday,ihr,imin,seci,mjdt,fmjdt)
      loop=0
      k=0
c     jumpfo=1
      irec=irn
 1000 k=k+1
      mjd=mjdt
      fmjd=fmjdt
      if(k.EQ.1) go to 1010
c     call ajmjd(mjd,fmjd,jumpfo*deltat,mjdt,fmjdt)
      call ajmjd(mjd,fmjd,deltat,mjdt,fmjdt)
 1010 call mjlcgr(mjdt,fmjdt,kyr,kmon,kday,khr,kmin,seck)
      write(6,1020)kyr,kmon,kday,khr,kmin,seck
      do 888 ii=1,numsv
        call svpvf(2222,idsvs(ii),mjdt,fmjdt,ierr,recf1,vecf1)   
 1020   Format('GREG. DATE-TIME',/,5i3,f14.8,/)
        write(6,1030)ierr,idsvs(ii),recf1,vecf1
 1030   Format('svpv ierr,svn,xyz xdot,ydot,zdot'i8,i9,/,3f20.10,/,
     1   3f20.10)
        dist=recf1(1)*recf1(1)+recf1(2)*recf1(2)+recf1(3)*recf1(3)
        iflag=0
        if(dist.lt.1.d0) iflag=1
        irec=irec+1
        write(3333,rec=irec) iflag,recf1,vecf1
 888  continue
      loop=loop+1
c     write(6,'("loop,numa,numb=",3i8)')loop,numa,numb
      if(loop.ge.numb) go to 8000
      go to 1000
 8000 STOP 'NORMAL TERMINATION'
      END
