	parameter (n=10000)
        parameter (n4=2)
        real a(n,n4),d(n,n4),x(n,n4),ad(n4)
	real za(n,n4)
	real xx(n,n4),yy(n,n4)
        integer m(n4),mn(n4)
        character*20 c,f0*80
	character*69 f1
	character*12 ac,dc

	pi=3.14159265
	k=iargc()
	if(k.lt.3)then
	  write(*,*)'*** Usage: no1 file1.cat file2.cat no1_out *****'
	  write(*,*)
	  write(*,*)'   *.cat come from j_xy4ad'
	  write(*,*) 
	  stop
	endif
        do 10 k=1,n4
	call getarg(k,c)
        open(k,file=c,status='old')
        read(k,'(a)',end=22)f0
	read(f0(1:),2)i1,i2,x3,j1,j2,y3
2	format(10x,i2,1x,i2,1x,f5.2,2x,i2,1x,i2,1x,f4.1)
	alpha_c=i1+i2/60.+x3/3600.
	delta_c=j1+j2/60.+y3/3600.
	write(*,'(2a,2f9.5)')c,'  center: ',alpha_c,delta_c
        ad(k)=delta_c
        i=0
20      read(k,'(a)',end=22)f0
	read(f0(1:),1)i1,i2,x3,j1,j2,y3,x1,y1,xmag
1	format(1x,i2,1x,i2,1x,f5.2,1x,i2,1x,i2,1x,f4.1,2f9.2,f7.2)
	i=i+1
	za(i,k)=i1*3600.+i2*60.+x3
 	d(i,k)=j1*3600.+j2*60.+y3
	x(i,k)=xmag
	xx(i,k)=x1
	yy(i,k)=y1
        goto 20
22      close(k)
	m(k)=i
10	continue
ccccccccccccccccccccccccc
        da=0.
        do 24 i=1,n4
24	da=da+ad(i)
	da=da/n4
	da=cos(da*pi/180)
	da=da*15
	do 25 k=1,n4
	do 25 i=1,m(k)
25	a(i,k)=za(i,k)*da
	open(2,file='no1.tmp',status='unknown')
	do 30 k=1,m(1)
	aa=a(k,1)
	dd=d(k,1)
        do 31 j=2,n4
	r=5
        do 32 i=1,m(j)
        z=(a(i,j)-aa)**2+(d(i,j)-dd)**2
        if(z.lt.r)then
	r=z
	mm=i
	endif
32	continue
	if(r.gt.4)goto 30
	ad(j)=x(mm,j)	
	mn(j)=mm        
31	continue
	call toms(za(k,1)/3600.,ac,1)
	call toms(dd/3600.,dc,0)
	write(2,'(2a,2f7.2,4f7.1)')ac,dc,x(k,1),
     *  (ad(j),j=2,n4),xx(k,1),yy(k,1),xx(mm,2),yy(mm,2)
30	continue	
	close(2)
	call getarg(3,f1)
	call system('sort no1.tmp > '//f1)
	end
