	character*133 a1(50000),a2(50000)
	character*60 f1,f2
	character*133 dis
	character*1 color(16),col
	character*5 c5

	if(iargc().lt.3)then
	  write(*,*)' readput T*.mag1 batchfile T*.mag'
	  stop
	endif
	call getarg(1,f1)
	call getarg(3,f2)
	open(1,file=f1,status='old')
	open(3,file=f2,status='unknown')
	k=index(f1,'.')-1
        read(f1(k-1:),'(i2)')n16
	  write(*,*)n16
	read(1,'(a)')dis
	write(3,'(a)')dis
	do 22 i=1,n16
	j=i*6+36
22	color(i)=dis(j:j)
	  write(*,*)color
	i=0
10	i=i+1
	read(1,'(a)',end=30)a1(i)
	read(1,'(a)')a2(i)
	goto 10
30	n=i-1
	close(1)
	do 12 i=1,n
	do 12 j=1,n16
	k=j*6+34
12	a2(i)(k:k)=' '

	write(*,*)n
	call getarg(2,f1)
	open(1,file=f1,status='old')
210	read(1,'(a)',end=200)f1
	write(*,*)f1
100	open(2,file=f1,status='old')
	k=lnblnk(f1)
	col=f1(k:k)
	read(2,'(a)')f1
	read(2,'(a)')f1
	do 101 k=1,n16
101	if(col.eq.color(k))goto 102
102	write(*,*)k
	i=0
110	i=i+1
	read(2,*,end=190)i1,i2,x
	i3=x*1000.+0.1
	write(c5(1:),'(i5)')i2
	m=6*k+33
	a1(i1)(m:m+4)=c5
	write(c5(1:),"('X',i4)")i3
	a2(i1)(m:m+4)=c5
	goto 110
190	close(2)
	m=i-1
	write(*,*)m
	goto 210
200	close(1)	

	do 11 i=1,n
	write(3,'(a)')a1(i)
11	write(3,'(a)')a2(i)
	close(3)	
	end
