      program maggps
      implicit none

      integer IGMAX
      parameter (IGMAX=3601)
      
      integer ig, im
      real*8  lon(IGMAX), lat(IGMAX)
      real*8  mag

      open(21,file='gps.dat')
      open(22,file='mag.dat')

 110  continue
      read(21,*,end=120) ig, lon(ig), lat(ig)
      if (ig.gt.IGMAX) then
          write(*,*) 'IGMAX is small'
          stop
      end if
      go to 110
 120  continue

 210  continue
      read(22,*,end=220) im, mag
      if (im.gt.ig) then
          write(*,*) 'GPS data is not enough'
          stop
      end if
      write(*,*) im, lon(im), lat(im), mag
      go to 210
 220  continue

      stop
      end
      
