	parameter (m=49999)
	character*133 a,b
	character*23 f1,f2
	character*1 color
	real ra(m),de(m),mag(m),err(m)
        real mago(m),magn(m),erro(m),errn(m)
	kk=iargc()
	if(kk.lt.3)then
	  write(*,*)
	  write(*,*)' compare 2 *.mag2 MAG + ERR in COLOR'
	  write(*,*)
	  write(*,*)' Usage: com62 old.mag2 new.mag2 i [! !]'
	  write(*,*)'  ! means no marked star'
          write(*,*)'  2nd ! means no X err'
	  write(*,*)
	  stop
	endif
	call getarg(1,f1)
	call getarg(2,f2)
	call getarg(3,color)
	
	open(1,file=f1,status='old')
	read(1,'(a)')a
        do 9 i=23,32
9       if(a(i:i).eq.':'.or.a(i:i).eq.'.')a(i:i)=','
        read(a(23:),*)i,j,k
        z=i+j/60.+k/3600.
        cosy=cos(z*3.141592654/180.)

	do 8 k=35,133,6
	if(color.eq.a(k:k))goto 7
8	continue
	write(*,*)'no color:',color
        stop
7	k=k-3
	k1=k+1

	n=0
10	read(1,'(a)',end=11)a
	read(1,'(a)')b
        if(kk.gt.3 .and. a(1:1).ne.' ')goto 10
        if(kk.gt.4 .and. b(k:k).ne.' ')goto 10
        n=n+1
	call ihd(a,ra(n),de(n))
	read(a(k:),*)mag(n)
	read(b(k1:),*)err(n)
	if(mag(n).eq.0.)n=n-1
	goto 10
11	close(1)
	n=n-1

	nn=0
	open(1,file=f2,status='old')
	read(1,'(a)')a
20	read(1,'(a)',end=99)a
	read(1,'(a)')b
        if(kk.gt.3 .and. a(1:1).ne.' ')goto 20
        if(kk.gt.4 .and. b(k:k).ne.' ')goto 20
	call ihd(a,x1,x2)
	r=8.
	do 30 j=1,n
        z=(ra(j)-x1)
        if(z.gt. 999999.)z=z-1296000.
        if(z.lt.-999999.)z=z+1296000.
        z=z*cosy
        z=z*z+(de(j)-x2)**2
        if(z.lt.r)then
          r=z
          jj=j
	endif
30	continue
	if(r.lt.4.)then
	  nn=nn+1
	  mago(nn)=mag(jj)
	  erro(nn)=err(jj)
	  read(a(k:),*)magn(nn)
	  read(b(k1:),*)errn(nn)
	endif
	goto 20
99	close(1)
	write(*,*)'color:',color,'  star:',nn
	call pgbegin(0,"/xw",2,1)
	call pgenv(12.,25.,12.,25.,1,1)
	call pgpoint(nn,mago,magn,-1)
        write(a(1:),'(a,i5)')color,nn
	call pglabel(f1,f2,a)
        do 40 i=1,nn
	ra(i)= erro(i)
40      de(i)=-errn(i) 
	call pgenv(12.,25.,-2.,2.,0,1)
        call pgpoint(nn,mago,ra,-1)
        call pgpoint(nn,mago,de,-1)
	call pgend
	end

        subroutine ihd(a,x,y)
        character*(*) a
        read(a(7:),'(2(1x,i2,1x,i2,1x,f5.2))')i1,j1,z1,i2,j2,z2
        x=(i1*3600+j1*60+z1)*15
        y= i2*3600+j2*60+z2
        k=index(a(2:18),'-')
        if(k.gt.0)y=-y
        end
