anchor.diff:      DOUBLE PRECISION :: TMPQ, TMPI
       LOGICAL :: FILEEXISTS
       INTEGER :: IERR, UNIT_NO
  -        
  +
       UNIT_NO = 12
  -    
  +
       INQUIRE(FILE=FILENAME, EXIST=FILEEXISTS)
       IF (.NOT. FILEEXISTS) THEN
           WRITE(*,*) 'Specified file does not exist: ', FILENAME
  
positive.code:     END DO
  
      RETURN
        
  END SUBROUTINE QRANGE_MATCH
        
  DOUBLE PRECISION FUNCTION AVERAGE_DATA (DATAIN, N)
      
      ! Calculate average of values in DATAIN for indices 0 to N
      DOUBLE PRECISION, DIMENSION(*), INTENT(IN) :: DATAIN
      INTEGER, INTENT(IN) :: N
      
      INTEGER :: I
      DOUBLE PRECISION :: TOTAL
      
      TOTAL = 0
      DO I = 1, N
          TOTAL = TOTAL + DATAIN(I)
  
negative.code:                 NO = NO + 1
              END IF
          END DO
  
          CLOSE(UNIT_NO)
      END IF
  
      RETURN
  
  END SUBROUTINE READ_SCATTER_FILE
  
  SUBROUTINE QRANGE_MATCH(QOBS, QCALC, ICALC, XNO, CNO, IMATCH, MNO)
  
      ! Match modelled I values with experimental Q range
  
      ! QOBS = Experimental Q values
      ! QCALC, ICALC = Modelled Q and I values
      ! XNO = no. experimental values, CNO = no. modelled values
      ! IMATCH = Modelled I values matched to experimental Q values
      ! MNO = no. matched values
      DOUBLE PRECISION, DIMENSION(*), INTENT(IN) :: QOBS, QCALC, ICALC
      INTEGER, INTENT(IN) :: XNO, CNO
      DOUBLE PRECISION, DIMENSION(*), INTENT(INOUT) :: IMATCH
      INTEGER, INTENT(OUT) :: MNO
  
      INTEGER :: I, J
      DOUBLE PRECISION :: QMINDIFF, DELTAQ
  
  