	logical lo
	character*30 f1,f2
	character*70 f0
	real t(9200),v(9200),s(9200),s1(9200)
        integer*2 u(9200)
	real xx(2),yy(2)
	pi=3.141592654
        ik=iargc()
        if(ik.eq.0)then
          write(*,*)'               usage: all2048 f1 f2 !'
          write(*,*)'                                      '
          write(*,*)
          stop
        endif
        call getarg(1,f1)
        call getarg(2,f2)
        
	i=index(f1,'.')
	k=lnblnk(f1)
	if(i.ne.0)k=i-1
	f1=f1(1:k)//'.cat'
	inquire(file=f1,exist=lo)
	if(.not.lo)stop "file1 not found !"
	i=index(f2,'.')
	k=lnblnk(f2)
	if(i.ne.0)k=i-1
	f2=f2(1:k)//'.cat'
	inquire(file=f2,exist=lo)
	if(.not.lo)stop "file2 not found !"
        
	open(1,file=f1,status='old')
	read(1,'(a)')f0
	i=0
5	read(1,'(a)',end=6)f0
	call tohd(f0(2:),al,de)
	i=i+1
	t(i)=al
	v(i)=de
	read(f0(43:),*)s(i)            ! 42-44
	s1(i)=99.
	goto 5
6	close(1)
	n=i
	xra=cos(v(1)*pi/180.)*15.

	open(2,file=f2,status='old')
	read(2,'(a)')f0
        rr=2./3600.           ! 2 arcsec
        rrr=rr*rr
30	read(2,'(a)',end=40)f0
	call tohd(f0(2:),al,de)
        rr=rrr
	do 20 i=1,n
        r=((t(i)-al)*xra)**2+(v(i)-de)**2
	if(r.gt.rr)goto 20
        rr=r
	read(f0(43:),*)s1(i)            ! 42-44
20	continue
	goto 30
40	close(2)

	write(*,*)n
	if(ik.gt.2)call pgbegin(0,"/xw",1,1)
	if(ik.gt.2)call pgenv(10.,20.,-1.,1.,0,0)
	k=0
	do 50 i=1,n
	if(s1(i).ne.99)then
	  k=k+1
	  if(ik.gt.2)call pgpoint(1,s(i),s1(i)-s(i),-1)
          u(k)=(s1(i)-s(i)+10.)*100.+0.5
	endif
50	continue
	write(*,*)"matched: ",k
	call whitexblack(u,1,k,white,sigma)
	scale=white*0.01-10.
	write(*,*)"scale: dm=",scale,"  strength:",10.**(scale/-2.5)
	open(3,file="all2048.tmp",status='unknown')	
        write(3,*)10.**(scale/-2.5)
	close(3)	
        xx(1)=10.
	xx(2)=20.
	yy(1)=scale
	yy(2)=scale
	if(ik.gt.2)call pgline(2,xx,yy)
	if(ik.gt.2)call pgend
	end
 
        subroutine tohd(cc,alpha,delta)
        character*(*) cc
        character*80 dd
        k1=index(cc(2:),' ')
        k2=index(cc,',')
        k=min(k1,k2)
        if(k1.eq.0)k=k2
        if(k2.eq.0)k=k1
        if(k.lt.2.or.k.gt.13)goto 100
        dd=cc(1:k)
        do 10 i=1,9
10      if(dd(i:i).eq.':')dd(i:i)=','
        x=0
        y=0
        z=0
        read(dd(1:),*,end=15,err=100)x,y,z
15      alpha=x+y/60.+z/3600.
        do 16 i=k+1,k+6
        if(cc(i:i).ne.' ')goto 17
16      continue
           goto 100
17      dd=cc(i:)
        k1=index(dd,' ')
        k2=index(dd,',')
        k=min(k1,k2)
        if(k1.eq.0)k=k2
        if(k2.eq.0)k=k1
        do 20 i=1,k
20      if(dd(i:i).eq.':')dd(i:i)=','
        x=0
        y=0
        z=0
        read(dd(1:k),*,end=30,err=100)x,y,z
30      if(x.lt.0.)x=-x
        delta=x+y/60.+z/3600.
        if(index(cc,'-').ne.0)delta=-delta
100     return
   	end
