	parameter (n=9999)
	character*30 f2
	character*12 ac,dc
	real a1(n),d1(n),x1(n)
	real a2(n),d2(n),x2(n)

	second=4.
        pi=4.*datan(1d0)
        cx=pi/12.
        cy=pi/180.


	call getarg(1,f2)
	call getstar(f2,a1,d1,x1,n1,delta)

	call getarg(2,f2)
	call getstar(f2,a2,d2,x2,n2,dummy)

        cosdelta=cos(delta)*15.
	ip=0
	do 10 i=1,n1
	a=a1(i)
	d=d1(i)
	r=30.
	do 20 j=1,n2
        z=((a2(j)-a)*cosdelta)**2+(d2(j)-d)**2
	z=z*3600.*3600.
        if(z.lt.r)k=j
20      if(z.lt.r)r=z
        if(r.lt.second)then
	  call toms(a1(i),ac,1)
	  call toms(d1(i),dc,0)
	  ip=ip+1
	  write(*,'(i4,2a,2f6.2)')ip,ac,dc,x1(i),x2(k)
        endif
10	continue
	end

	subroutine getstar(f2,al,de,xm,n,d)
	real al(1),de(1),xm(1)
	character*30 f1,f2,a
	real*8 a8(8)

        i=index(f2,'.')
	k=lnblnk(f2)
	if(i.ne.0) k=i-1
	f1=f2(1:k)//'.mes'
	inquire(file=f1,exist=i)
	if(i.eq.0)stop '*.mes file not found !'
	open(1,file=f1,status='old')
	do 10 i=1,12
10	read(1,'(a)')a
	do 11 i=1,8
	read(1,'(a)')a
11	read(a(11:),*)a8(i)
	close(1)

	f1=f2(1:k)//'.als'
	inquire(file=f1,exist=i)
	if(i.eq.0)stop '.als file not found !'
	open(1,file=f1,status='old')
	do 19 i=1,3
19	read(1,'(a)')a
	i=0
20	i=i+1
	read(1,*,err=100,end=100)z,x,y,xm(i)
        call xy_rad(2049.-x,2049.-y,a8,al(i),de(i))
	goto 20
100	n=i-1
	write(*,*)f2,n
	d=a8(8)
	end

        subroutine xy_rad(x,y,a8,alpha,delta)
c 2048*2048 ccd's X Y (in pixel) -------------> alpha delta (in h,d)
        real x,y,alpha,delta
        real*8 a8(8),pi,xi,xn,rc,dc,cd,td,alph,delt         
        pi=4.*datan(1d0)
        xi=a8(1)*x+a8(3)*y+a8(5)
        xn=a8(2)*x+a8(4)*y+a8(6)
        rc=a8(7)                                ! center of ccd (in rad.)
        dc=a8(8)
        cd=dcos(dc)
        td=dtan(dc)
        alph=datan(xi/cd/(1.-xn*td))
        delt=datan((xn+td)*dcos(alph)/(1.-xn*td))
        alph=alph+rc
        if(abs(dc-delt).gt.2.)then
          delt=-delt
          alph=alph+pi
        endif
        alpha=alph*12./pi
        delta=delt*180./pi
        end
