     	SUBROUTINE GRAHKL
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   FEB-1987
C
C	THIS ROUTINE WRITES OUT AN ASCII HKL AND D-SPACING FILE
C	FOR GRAFIT FROM THE COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'

     	CLOSE( UNIT=IOUT )
     	OPEN( UNIT=IOUT, FILE=FILOUT, STATUS='NEW',
     	1 CARRIAGECONTROL='LIST', FORM='FORMATTED', ERR=888 )
C
C  RENORMALIZE REFLECTION RELATIVE INTENSITIES ACCORDING TO FWHMS
C  AND LORENTZIAN PROFILE MODEL SO THAT THEY REFLECT THE RELATIVE
C  INTENSITIES OF PEAK HEIGHTS TO CERTAIN EXTENTS...
C
     	DO I=1, NPKS
     	   IF( RELA(I).EQ.100.0 ) GOTO 100
     	ENDDO
     	I = 1
100	DUMY = FWHM(I)
     	DO I=1, NPKS
     	   RELA(I)= RELA(I)*DUMY/FWHM(I)
     	ENDDO
     	DUMY = RELA(1)
     	DO I=2, NPKS
     	   IF( RELA(I).GT.DUMY ) DUMY = RELA(I)
     	ENDDO
     	DO I=1, NPKS
     	   RELA(I) = 100.0*RELA(I)/DUMY
     	ENDDO
C
C  WRITE THE HKL FILE...
C
     	WRITE(IOUT,1000,ERR=888)
1000	FORMAT(8X,'H   K   L    2-THETA  D-SPACING   I(%)')
     	DO I=1, NPKS
     	IF( PEAK(I).EQ.'KA1' ) WRITE(IOUT,1001,ERR=888)
     	1 (PHKL(J,I),J=1,3), F2TH(I), FDSP(I), RELA(I)
     	ENDDO
1001	FORMAT('DHKL=',3I4,X,3F10.4)
     	GOTO 999
888	IERR = 1		!ERROR DURING WRITE
999	RETURN
     	END
