
     	SUBROUTINE RDIKEY
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY,  SEPT-1987
C
C	THIS ROUTINE READS FROM A KEYBOARD DIFILE
C	AND STORES IN THE CORRESPONDING COMMON BLOCKS
C
C	THE FILE MUST HAVE ONE OF THE TWO PEAK ENTRY LINES:
C
C	1)	d-spacing(A), intensity(%), FWHM, H, K, L
C	2)	2-theta(deg), intensity(%), FWHM, H, K, L
C
     	INCLUDE 'FILECONV.CBS'
     	REAL*4 LAMDA
     	CHARACTER TEXT*80
     	DIMENSION RP(7), KP(7)
     	PARAMETER SCALE = 1.0

     	CLOSE( UNIT=IINP )
     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD',
     	1 FORM='FORMATTED', READONLY, ERR=888 )
C
C  SET THE DEFAULT RADIATION SOURCE TO CU...
C
     	IELE = 4
     	LAMDA = 0.5*WAVE(1,IELE)
C
C  READ THE PEAK LIST...
C
        HI = 0.0
     	NPKS = 0
111	READ(IINP,1000,ERR=666,END=666) TEXT
1000	FORMAT(A)
     	IF( TEXT.EQ.' ' ) GOTO 111
C
C  DECODE ENTRY LINE...
C
     	NCHS = NALPHA( TEXT, 80 )
     	CALL COMMAS( TEXT, NCHS, 6, RP, KP, IDUM )
C
C  SKIP INVALID ENTRY...
C
     	IF( NCHS.EQ.0 ) GOTO 111
     	IF( RP(1).LT.0.5*LAMDA .OR. RP(1).GE.180.0 ) GOTO 111
c     	IF( RP(2).LT.0.1 .OR. RP(2).GT.100.0 ) GOTO 111
C
C  STORE THE PEAK...
C
     	NPKS = NPKS + 1
     	F2TH(NPKS) = RP(1)
     	RELA(NPKS) = RP(2)
     	PHGH(NPKS) = SCALE*RP(2)
     	AREA(NPKS,JRES) = SCALE*RP(2)
        IF(RP(2) .GT. HI) HI = RP(2)
*     	FWHM(NPKS) = 0.1
*     	IF( KP(3).EQ.1 ) THEN
*         IF(RP(1).GE.CUTF(1).AND.RP(1).LE.CUTF(2)) FWHM(NPKS)=RP(3)
*     	ENDIF
     	FWHM(NPKS) = 0.1
     	IF( KP(3).EQ.1 )FWHM(NPKS)=RP(3)
     	IF( KP(4).EQ.1 ) PHKL(1,NPKS) = NINT(RP(4))
     	IF( KP(5).EQ.1 ) PHKL(2,NPKS) = NINT(RP(5))
     	IF( KP(6).EQ.1 ) PHKL(3,NPKS) = NINT(RP(6))
     	IF( KP(7).EQ.1 ) PHKL(4,NPKS) = NINT(RP(7))
     	PEAK(NPKS) = 'KA1'
     	GOTO 111

666	IF( NPKS.EQ.0 ) GOTO 777
C
C  CHECK D-SPACING/2-THETA INPUT...
C
     	write(6,211)
211	format('$Are 2-Theta''s (0) or d''s (1) on the file?',
     1 ' [0]: ')
     	read(5,212) itest
212	format(i)
C     	if(itest .eq. 1) go to 333  !S.Z.    
     	if(itest .eq. 0) go to 333  !S.Z.    
C
C   D-SPACING ENTRIES...
C
222	DO I=1, NPKS
     	   FDSP(I) = F2TH(I)
     	   CDSP(I) = FDSP(I)
     	   F2TH(I) = RTOD*ASIN(LAMDA/FDSP(I))
     	   C2TH(I) = F2TH(I)
     	ENDDO
     	GOTO 444
C
C   2-THETA ENTRIES...
C
333	DO I=1, NPKS
     	   C2TH(I) = F2TH(I)
     	   FDSP(I) = LAMDA / SIN(DTOR*F2TH(I))
     	   CDSP(I) = FDSP(I)
     	ENDDO
     	GOTO 444
C
C  SCALE THE INTENSITIES TO 100%
C
444     DO I=1, NPKS
     	   RELA(I) = RELA(I) * 100./HI
        ENDDO
     	go to 999
777	IERR = 1
     	GOTO 999
888	IERR = 2
999	RETURN
     	END

