      PROGRAM PSCOEFF
C  THIS PROGRAMME TAKES THE OUTPUT FILE FROM STRUCFAC FOR ANOMALOUS
C  SCATTERING AND GIVES AN OUTPUT FILE WHICH, USED AS AN INPUT FILE
C  FOR FOUR2, GIVES A PS-FUNCTION MAP. 
      REAL F(1000),PHI(1000)
      INTEGER H(1000),K(1000)
      CHARACTER ANS*1, FNAME*10
C  GIVE THE NAME OF THE INPUT DATA FILE.
      FNAME='SF1.DAT'
    3 WRITE(6,'('' THE INPUT FILE IS ASSUMED TO BE SF1.DAT '')')
      WRITE(6,'('' DO YOU WANT TO CHANGE 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)   
      FNAME='PSF.DAT'
   13 WRITE(6,'('' THE OUPUT FILE IS ASSUMED TO BE PSF.DAT '')')
      WRITE(6,'('' DO YOU WANT 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)
C  MODIFY ARRAY F TO CONTAIN ANOMALOUS INTENSITY DIFFERENCE 
C  MAGNITUDES AND ARRAY PHI TO CONTAIN PI/2 OR -PI/2 DEPENDING 
C  ON WHETHER |F(h)|**2-|F(-h)|**2 IS POSITIVE OR NEGATIVE.
C  THIS WILL GIVE THE PS-FUNCTION.   SINCE THE REFLECTIONS ARE
C  IN ADJACENT PAIRS WITH INDICES h AND -h THE OUTPUT FILE HAS
C  ONLY ONE HALF THE NUMBER OF REFLECTIONS ON THE INPUT FILE.
      READ(10,*)NOREF,(H(I),K(I),F(I),PHI(I),I=1,NOREF)
      DO 10 I=1,NOREF-1,2
      X=(F(I)**2-F(I+1)**2)
      F(I)=X*X
      PHI(I)=90.0*SIGN(1.0,X)
   10 CONTINUE
C  READ IN TO FILE FOR INPUT TO FOUR2    
      NOREF2=NOREF/2
      WRITE(11,*)NOREF2,(H(I),K(I),F(I),PHI(I),I=1,NOREF-1,2)   
      STOP
      END


