	real x(9000),y(9000),z(9000)
	real me(9000)
	integer num(9000)
	character*60 f1
	character*133 dis
	character*1 color
	if(iargc().lt.2)then
	  write(*,*)' read *.mag1 file'
	  stop
	endif
	call getarg(2,f1)
	k=index(f1,'.')-1
	if(k.lt.0)k=lnblnk(f1)
	color=f1(k:k)
	open(1,file=f1(1:k)//'.ap',status='old')
	read(1,'(a)')f1
	read(1,'(a)')f1
	read(1,'(a)')f1
	read(1,'(a)')f1
	i=0
10	read(1,'(i6,37x,f9.3)',end=20)jk,xx
	read(1,'(43x,f9.3)')xe
	read(1,'(a)',end=21)f1
21	i=i+1
	x(i)=xx
	me(i)=xe
	num(i)=jk
	goto 10
20	n=i
	close(1)
	call getarg(1,f1)
	open(1,file=f1,status='old')
	read(1,'(a)')dis
	do 22 i=1,16
	j=i*6+36
22	if(color.eq.dis(j:j))goto 23
	write(*,*)' wrong color'
23	kk=i*6+32
	do 30 i=1,n
24	read(1,'(a)')dis
	if(dis(1:1).ne.' ')then
	  read(1,'(a)')f1
	  goto 24
	endif
	read(dis(kk:),'(i6)')k
	y(i)=k*0.001
30	read(1,'(a)')f1
	write(*,*)n
	k=0
	do 40 i=1,n
	if(y(i).ne.0.and.x(i).lt.30.)then
	  k=k+1
	  z(k)=y(i)-x(i)
	endif
40	continue
	do 50 i=1,k-1
	do 50 j=i+1,k
	if(z(i).gt.z(j))goto 50
	xx=z(i)
	z(i)=z(j)
	z(j)=xx
50	continue
	xx=z(k/2)
	write(*,*)k,xx
	do 60 i=1,n
60	if(y(i).eq.0.and.x(i).lt.30)
     *  write(*,'(i5,i6,f7.3)')num(i),nint((x(i)+xx)*1000),me(i)
	end
