c     This program merges the position and heading file
c
c     CCGS Hudson  June 24, 2001
c
c     Thomas Funck
c
      character*60 in1,in2,output
c
c--------------------------------------------------------------
c
c     Opening IO files
c
   15 write (*,*) 'Name of file with positions:'
      read (*,999) in1
  999 format (a60) 
      open (10,file=in1,status='old',err=10)
      goto 16
   10 write (*,*) 'File does not exist. Try again.'
      goto 15
c
   16 write (*,*) 'Name of file with heading:'
      read (*,999) in2
      open (11,file=in2,status='old',err=11)
      goto 20
   11 write (*,*) 'File does not exist. Try again.'
      goto 16
c
   20 write (*,*) 'Name of output file:'
      read (*,999) output
      open (12,file=output,status='new',err=30)
      goto 90
   30 write (*,*) 'File exists already. Try again.'
      goto 20
c
c--------------------------------------------------------------
c
c     Reading through files
c
 90   read (10,998,err=110,end=100) id1,ih1,im1,is1,y,x
 998  format (i3,3i2,2f11.6)
c
      read (11,997,err=110,end=100) id2,ih2,im2,is2,h
 997  format (i4,i3,1x,i2,1x,i2,f6.1)
c
      if (id1.eq.id2.and.ih1.eq.ih2.and.im1.eq.im2.
     +    and.is1.eq.is2) then
          write (12,996) id2,ih2,im2,float(is2),x,y,h
 996      format (i4,i3,':',i2,':',f6.3,2f11.5,f6.1)
          goto 90
        else
          write (*,*) 'Mismatch between input files'
          goto 100
      endif
c
 110  write (*,*) 'Error reading input files'
 100  close (10)
      close (11)
      close (12)
      stop
      end

