      PROGRAM ISOFILE
C  THIS PROGRAMME TAKES DATA FILES FROM STRUCFAC FOR TWO ISOMORPHOUS
C  COMPOUNDS.   THEY ARE COMBINED TO GIVE AN INPUT TAPE FOR FOUR2
C  TO GIVE A DIFFERENCE PATTERSON MAP.   IF THE STRUCTURE IS
C  CENTROSYMMETRIC THEN THE COEFFICIENTS ARE (|FA| - |FB|)**2;
C  IF NON-CENTROSYMMETRIC THEN THEY ARE |FA|**2 - |FB|**2.   IN BOTH 
C  CASES THE PHASE IS PUT AT ZERO.   BECAUSE THE COEFFICIENTS ARE 
C  ALREADY IN PATTERSON FORM FOUR2 SHOULD BE USED IN NORMAL MODE - 
C  NOT IN PATTERSON MODE.
      REAL FTAB(1000,2),PHI(1000)
      INTEGER HTAB(1000,2),KTAB(1000,2)
      CHARACTER FNAME*10,FNAME1*10,FNAME2*10,ANS*1
      OPEN(UNIT=9,FILE='LPT1')
      WRITE(6,'('' READ IN THE NAME OF THE FIRST DATA FILE '')')
      WRITE(6,'('' [<= 10 CHARACTERS] '')')
      READ(5,50)FNAME1
      OPEN(UNIT=10,FILE=FNAME1)
      WRITE(6,'('' READ IN THE NAME OF THE SECOND DATA FILE '')')
      WRITE(6,'('' [<= 10 CHARACTERS] '')')
      READ(5,50)FNAME2
      OPEN(UNIT=11,FILE=FNAME2)
   50 FORMAT(A10)
      FNAME='SF1.DAT'
    1 WRITE(6,'(''IT IS ASSUMED THAT THE OUTPUT DATA FILE IS NAMED'')')
      WRITE(6,'(''SF1.DAT.  DO YOU WANT TO CHANGE THIS?  Y/N '')')
      READ(5,100)ANS
  100 FORMAT(A1)
      IF(ANS.EQ.'N'.OR.ANS.EQ.'n')GOTO 2
      IF(ANS.EQ.'Y'.OR.ANS.EQ.'y')GOTO 3      
      GOTO 1 
    3 WRITE(6,'('' READ IN FILENAME [<= 10 CHARACTERS]'')')
      READ(5,50)FNAME
    2 OPEN(UNIT=12,FILE=FNAME)
      READ(10,*)NOREF,(HTAB(I,1),KTAB(I,1),FTAB(I,1),DUMMY,I=1,NOREF)
      READ(11,*)NOREF,(HTAB(I,2),KTAB(I,2),FTAB(I,2),DUMMY,I=1,NOREF)  
    7 WRITE(6,'('' INPUT C FOR A CENTROSYMMETRIC STRUCTURE OR N '')')
      WRITE(6,'('' FOR A N0N-CENTROSYMMETRIC STRUCTURE '')')
      READ(5,100)ANS
      IF(ANS.EQ.'C'.OR.ANS.EQ.'c')GOTO 5
      IF(ANS.EQ.'N'.OR.ANS.EQ.'n')GOTO 6
      GOTO 7      
    5 KEY=1
      GOTO 8
    6 KEY=2   
C  THE OUTPUT TAPE WILL NOW BE PRODUCED.   HOWEVER, A CHECK WILL BE 
C  MADE THAT THE INDICES ON THE TWO INPUT TAPES CORRESPOND.   IF NOT
C  THEN THE PROGRAMME IS TERMINATED WITH AN ERROR MESSAGE.
    8 DO 9 I=1,NOREF
      GOTO(10,11)KEY
   10 FTAB(I,1)=(FTAB(I,1)-FTAB(I,2))**2
      GOTO 12
   11 FTAB(I,1)=FTAB(I,1)**2-FTAB(I,2)**2
   12 IF(HTAB(I,1).NE.HTAB(I,2))GOTO 99
      IF(KTAB(I,1).NE.KTAB(I,2))GOTO 99
      PHI(I)=0
    9 CONTINUE
      WRITE(12,*)NOREF,(HTAB(I,1),KTAB(I,1),FTAB(I,1),PHI(I),I=1,NOREF)
      GOTO 101
   99 WRITE(6,'('' THE INDICES ON THE TWO INPUT TAPES DO NOT AGREE'')')
      WRITE(6,'('' THE PROGRAMME IS ABORTED.  CHECK PRINTOUTS OF '')')
      WRITE(6,'('' INPUT FILES '')')
  101 STOP
      END   

