c=====================================================================
c ==================================================
c         Copyright And License Agreement
c ==================================================
c
c MMSQ Version 1.0, 4th of april 1991.
c
c You may copy and distribute copies of the complete MMSQ source
c code as you receive it, in any medium, provided that you
c conspicuously and appropriately publish on each file a valid
c copyright notice "Copyright (C) 1991 Rob Hooft, Utrecht
c University"; keep intact the notices on all files that refer to
c this License Agreement and give other recipients of MMSQ a copy
c of this license agreement along with the program. You may charge
c a distribution fee for the physical act of transferring a copy. 
c
c You may copy and distribute MMSQ in object code or executable
c form under the terms mentioned above provided that you also
c accompany it with the complete corresponding machine-readable
c source code, which must also be distributed under the terms
c mentioned above.
c
c You may not copy, sublicense, distribute or transfer MMSQ except 
c as expressly provided under this license agreement.
c
c (This license agreement has been modelled after the 
c GNU GENERAL PUBLIC LICENSE)
c
c=====================================================================
      PROGRAM cleanhis
      real a(10000,3)
      call readfile(1,'square.his',iostat)
      if (iostat.ne.0) stop 'File open error on history file'
      na=0
      nb=0
10    continue
      nb=nb+1
      read(1,*,end=20) x,y,E
      do i=1,na
        if (x.eq.a(i,1).and.y.eq.a(i,2)) then
          a(i,3)=min(a(i,3),E)
          goto 10
        endif
      enddo
      na=na+1
      a(na,1)=x
      a(na,2)=y
      a(na,3)=E
      goto 10
20    continue
      write(*,*) nb,' Points read.'
      close(1)
      call newfile(2,'clean.his',iostat)
      if (iostat.ne.0) stop 'Could not create outputfile'
      do i=1,na
        write(2,'(2(f6.1,x),f10.4)') a(i,1),a(i,2),a(i,3)
      enddo
      write(*,*) na,' Points written.'
      close(2)
      end
