	program addfigures
c
c	program to add new pngfile names to orb6.master
c
	character*243 data1(3500),data11
	character*8 data22
	character*18 png(3500),png1
	character*8 ref(3500),ref1
	character*3 grade
	integer iflag(3500)
        character*278 title
	character*1 keep
        character*10 wds1,wds2
c
	open(10,file='orbits.100123',status='UNKNOWN')
	open(11,file='png.100123',status='UNKNOWN')
	open(12,file='orb6.master2',status='UNKNOWN')
	open(13,file='orb6.master3',status='UNKNOWN')
	open(14,file='addfigures.check',status='UNKNOWN')
c
c	read star names, periods, reference codes, and grades
c
        norbs=3144
        do 100 n=1,norbs
        read(10,901) data1(n),ref(n),wds1
  901   format(a243,t252,a8,t20,a10)
        iflag(n)=0
	read(11,902) png(n),wds2
  902	format(t45,a18,t48,a10)
	if (wds1 .ne. wds2) write(6,991) wds1,wds2
  991	format(' wds mismatch: ',a10,2x,a10)
	if (wds1 .ne. wds2) go to 999
        iflag(n)=0
  100   continue
c
        do 200 n=1,4
        read(12,903) title
        write(13,903) title
  903   format(a278)
  200   continue
c
  300   read(12,904,end=600) data11,data22,ref1,png1,grade,keep,idate
  904   format(a243,2a8,1x,a18,t244,a3,t250,a1,t255,i4)
        if (ref1 .ne. '        ') go to 400
        write(13,905)
  905   format(277x,' ')
        go to 300
c
  400   do 500 n=1,norbs
        if (data11 .ne. data1(n)) go to 500
        if (ref1   .ne.   ref(n)) go to 500
        iflag(n)=iflag(n)+1
        png1=png(n)
        write(13,907) data11,data22,ref1,png1
  907   format(a243,2a8,1x,a18)
        go to 300
  500   continue
	if (grade .eq. '8.0') go to 550
	if (grade .eq. '9.0') go to 550
	if (keep  .eq.   'y') go to 550
	if (idate .gt.  1981) go to 550
	png1='                  '
  550   write(13,907) data11,data22,ref1,png1
        go to 300
c
  600   write(14,904)
        do 700 n=1,norbs
        if (iflag(n) .ne. 1) write(14,906) data1(n),ref(n),png(n)
  906   format(a243,2x,a8,2x,a18)
  700   continue
c
  999	stop
  	end
