PROGRAM divdw1
C
C fmc 97/03
C Finds the differences between the vdW energies of two different 
C mm outputs contained in vdw1.res vdw2.res
C Order of differences: vdw2 -vdw1
C
      IMPLICIT NONE
C
      REAL*8 llind,ene1,ene2,diene,sdito,sdise,nfra,sfra
      INTEGER i,maxlin,ndito,ndise
      CHARACTER nores*80,aux11*22,aux21*22,aux12*35,aux22*35
      CHARACTER	aux13*13,aux23*13
C
  10  FORMAT(A80)
  20  FORMAT(A22,A35,F11.4,A13)
  30  FORMAT(2X,'Discrepancy between the two files!',/,
     1 A22,/,A22)
  40  FORMAT(2X,'Program stops.')
  50  FORMAT(A22,3F11.4,A13)
  60  FORMAT(2X,'Threshold:',F10.4,/,
     1 'Total number inter.:',I6, '  Total inter. energy:',F10.4,/,
     2 'Sel.  number inter.:',I6, '  Sel.  inter. energy:',F10.4,/,
     2 'Frac. number inter.:',F6.3, '  Frac. inter. energy:',F10.3)
C
      maxlin= 1000000
      sdito= 0.
      sdise= 0.
      ndito= 0
      ndise= 0
      OPEN(15,file='vdw1.res')
      OPEN(25,file='vdw2.res')
C
      WRITE(6,*) ' Threshold energy?'
      READ(5,*) llind
C
      READ(15,10) nores
      READ(25,10) nores
      DO i=1,maxlin
        READ(15,20,END=500) aux11,aux12,ene1,aux13
        READ(25,20) aux21,aux22,ene2,aux23
        IF(aux11.NE.aux21) THEN
          WRITE(6,30) aux11,aux21
          WRITE(6,40) 
          STOP
          END IF
        diene= ene2 - ene1
        sdito= sdito + diene
        ndito= ndito + 1
        IF(ABS(diene).GT.llind) THEN
          WRITE(6,50) aux11,ene1,ene2,diene,aux13
          sdise= sdise + diene
          ndise= ndise + 1
          END IF
        END DO
C
      WRITE(6,*) ' More than',maxlin,' lines!!'
      WRITE(6,40) 
      STOP
C
 500  CONTINUE
      nfra= float(ndise)/float(ndito)
      sfra= sdise/sdito
      WRITE(6,60) llind,ndito,sdito,ndise,sdise,nfra,sfra
      END