	program addgrades
c
c	program to add new grade values (from orbits.6) to orb6.master
c
	dimension grade(3200)
	character*243 data1(3200),data11
	character*32 data2(3200),data22
	integer iflag(3200)
        character*278 title
        character*10 rad
c
	open(10,file='orbits.6',status='UNKNOWN')
	open(11,file='orb6.master',status='UNKNOWN')
	open(12,file='orb6.master.new',status='UNKNOWN')
	open(13,file='addgrades.check',status='UNKNOWN')
c
c	read star names, periods, reference codes, and grades
c
        norbs=3116
        do 100 n=1,norbs
        read(10,901,err=950) data1(n),grade(n),data2(n)
  901   format(a243,f3.1,a32)
        iflag(n)=0
  100   continue
c
        do 200 n=1,4
        read(11,902) title
        write(12,902) title
  902   format(a278)
  200   continue
c
  300   read(11,903,end=600) data11,grade1,data22,rad
  903   format(a243,f3.1,a32,t1,a10)
        if (rad .ne. '          ') go to 400
        write(12,904)
  904   format(277x,' ')
        go to 300
c
  400   do 500 n=1,norbs
        if (data11 .ne. data1(n)) go to 500
        if (data22 .ne. data2(n)) go to 500
        iflag(n)=iflag(n)+1
        dgrade=abs(grade(n)-grade1)
        if (dgrade .le. 0.35) grade1=grade(n)
        if (dgrade .gt. 0.35) write(13,905) data1(n),grade1,
     $     data2(n),grade1,grade(n)
  905   format(a243,f3.1,a32,2f6.1)
        write(12,901) data11,grade1,data22
        go to 300
  500   continue
        write(12,901) data11,grade1,data22
        go to 300
c
  600   write(13,904)
        do 700 n=1,norbs
        if (iflag(n) .ne. 1) write(13,906) data1(n),grade(n),
     $     data2(n),iflag(n)
  906   format(a243,f3.1,a32,i6)
  700   continue
        go to 999
c
  950   write(6,901) data1(n),grade(n),data2(n)
  999	stop
  	end
