      PROGRAM CALOBS
C  THIS PROGRAMME COMBINES OUTPUT FILES THE FIRST OF WHICH IS IN
C  THE FORM GIVEN BY STRUCFAC AND HAS "OBSERVED" F's AND THE SECOND
C  OF WHICH HAS "CALCULATED" F's AND PHI's FROM AN APPROXIMATE 
C  STRUCTURE.  THE OUTPUT FILE COMBINES THE OBSERVED F's WITH THE
C  CALCULATED PHI'S AND IS SUITABLE FOR INPUT TO FOUR2.   THIS 
C  PROGRAMME ENABLES THE FOURIER REFINEMENT OF STRUCTURES.
C  THE PROGRAMME ALSO OUTPUTS THE RESIDUAL FOR THE CALCULATED F's.
      REAL F1(1000),PHI2(1000),F2(1000)
      INTEGER  H(1000),K(1000)
      CHARACTER ANS*1,FNAME*10
      OPEN(UNIT=9,FILE='LPT1')
      FNAME='SF1.DAT'
    3 WRITE(6,'('' IT IS ASSUMED THAT THE FIRST FILE CONTAINING'')')
      WRITE(6,'(''THE F[OBS] IS SF1.DAT.   DO YOU WANT TO CHANGE '')')
      WRITE(6,'(''THIS?   Y/N '')')
      READ(5,50)ANS
   50 FORMAT(A1)
      IF(ANS.EQ.'N'.OR.ANS.EQ.'n')GOTO 1
      IF(ANS.EQ.'Y'.OR.ANS.EQ.'y')GOTO 2
      GOTO 3
    2 WRITE(6,'(''READ IN THE FILE NAME [<= 10 CHARACTERS]. '')')
      READ(5,100)FNAME
  100 FORMAT(A10)
    1 OPEN(UNIT=10,FILE=FNAME)
      READ(10,*)NOREF,(H(I),K(I),F1(I),FI,I=1,NOREF)
      FNAME='SF2.DAT'
   13 WRITE(6,'('' IT IS ASSUMED THAT THE SECOND FILE CONTAINING'')')
      WRITE(6,'(''F[CALC] AND  PHI[CALC] IS SF2.DAT. DO YOU WANT '')')
      WRITE(6,'(''TO CHANGE THIS?   Y/N '')')
      READ(5,50)ANS
      IF(ANS.EQ.'N'.OR.ANS.EQ.'n')GOTO 11
      IF(ANS.EQ.'Y'.OR.ANS.EQ.'y')GOTO 12
      GOTO 13
   12 WRITE(6,'(''READ IN THE FILE NAME [<= 10 CHARACTERS]. '')')
      READ(5,100)FNAME
   11 OPEN(UNIT=11,FILE=FNAME)
      READ(11,*)NOREF,(H(I),K(I),F2(I),PHI2(I),I=1,NOREF)
      FNAME='COMB.DAT'
   23 WRITE(6,'('' IT IS ASSUMED THAT THE OUTPUT FILE CONTAINING'')')
      WRITE(6,'('' F[OBS] AND PHI[CALC] IS COMB.DAT.   DO YOU '')')
      WRITE(6,'('' WANT TO CHANGE THIS?   Y/N '')')
      READ(5,50)ANS
      IF(ANS.EQ.'N'.OR.ANS.EQ.'n')GOTO 21
      IF(ANS.EQ.'Y'.OR.ANS.EQ.'y')GOTO 22
      GOTO 23
   22 WRITE(6,'(''READ IN THE FILE NAME [<= 10 CHARACTERS]. '')')
      READ(5,100)FNAME
   21 OPEN(UNIT=12,FILE=FNAME)
      WRITE(12,*)NOREF,(H(I),K(I),F1(I),PHI2(I),I=1,NOREF)
C  NOW CALCULATE AND OUTPUT THE RESIDUAL
      SUMDIF=0
      SUM=0
      DO 40 I=1,NOREF
      SUMDIF=SUMDIF+ABS(F1(I)-F2(I))
      SUM=SUM+F1(I)
   40 CONTINUE
      RESID=SUMDIF/SUM
      WRITE(9,300)RESID
  300 FORMAT(39H THE RESIDUAL FOR THE INPUT F[CALC] IS ,F6.3)
      STOP
      END


