       program readcat
         integer*4 m, n, icode
         parameter (m = 10000)
         real*4 x(m), y(m), mag(m), col(m)
         integer*4 icl(m)

         open(15, file='axfchk.tmp', status='unknown')
         read(15,*) x1, y1
         write(*,*) 
c         write(*,*) 'x = ', x1, ' y = ', y1
         close(15)

         open(11, file='axfchk.tmp.cat', status='old')
         read(11,*) n, tol
         if (n .gt. m) then
            write(*,*) 'readcat warning: n > m: ', n, m
            n = m
            write(*,*) 'resetting n = ', n
         end if

         dmin = 1.e6
         imin = 0
         do i = 1, n
            read(11,*) x(i), y(i), mag(i), icl(i), col(i)
            d = sqrt( (x1-x(i))**2. + (y1-y(i))**2. )
            if (d .lt. dmin) then
               dmin = d
               imin = i
            end if
         end do
         close(11)

         open(15, file='axfchk.tmp', status='unknown')

         if (imin .ne. 0. .and. dmin .le. tol) then
            write(*,10) imin, icl(imin), mag(imin), col(imin),
     $                   x(imin), y(imin)
            write(15,*) imin
            write(15,'(i5,x,i2,2(x,f6.2),2(x,f7.2))') 
     $             imin, icl(imin), mag(imin), col(imin),
     $                   x(imin), y(imin)
         else
            write(*,*) 'no object within ', tol, 
     $                 ' pixels of x, y = ', x1, y1
            write(15,*) 0
         end if
 10         format('ppp # ', i5, '  cl ', i2, '  mag ', f6.2,
     $             '  color ', f6.2, '  x ', f7.2, '  y ', f7.2)
         close(15)
         call exit(0)

       end
