     	SUBROUTINE RDI011
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   FEB-1987
C
C	THIS ROUTINE READS FROM A DIFFRAC-11 DIFILE
C	AND STORES IN THE CORRESPONDING COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
     	DIMENSION NRNS(20)
     	REAL*4 LAMDA
     	CHARACTER DAY*12, TIM*8

     	CLOSE( UNIT=IINP )
     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD', ERR=888,
     	1 ACCESS='DIRECT', RECL=1, READONLY )
C
C  READ THE FILE HEADER BLOCK...
C
     	READ(IINP,REC= 1,ERR=777) SLID(1)
     	READ(IINP,REC= 2,ERR=777) SLID(2)
     	READ(IINP,REC= 3,ERR=777) SLID(3)
     	READ(IINP,REC= 4,ERR=777) SLID(4)
     	READ(IINP,REC= 5,ERR=777) DAY(1:4)
     	READ(IINP,REC= 6,ERR=777) DAY(5:8)
     	READ(IINP,REC= 7,ERR=777) DAY(9:12)
     	READ(IINP,REC= 8,ERR=777) TIM(1:4)
     	READ(IINP,REC= 9,ERR=777) TIM(5:8)
     	DATM = DATCOD( DAY(1:9) )
     	TIMM = TIMCOD( TIM(1:8) )
     	READ(IINP,REC= 10,ERR=777) NAME(1)
     	READ(IINP,REC= 11,ERR=777) NAME(2)
     	READ(IINP,REC= 12,ERR=777) NAME(3)
C
C  READ THE LINE MEASUREMENT BLOCK...
C
     	READ(IINP,REC= 13,ERR=777) BANG(1)
     	READ(IINP,REC= 14,ERR=777) BANG(2)
     	READ(IINP,REC= 15,ERR=777) BANG(3)
     	READ(IINP,REC= 16,ERR=777) BANG(10)
     	IF( BANG(3).LE.0.0 .OR. BANG(10).LE.0.0 ) GOTO 777
C
C  READ THE INSTRUMENTATION BLOCK...
C
     	READ(IINP,REC= 19,ERR=777) WAVE(1,6)	!WAVE LENGTH: KA1
     	IF( WAVE(1,6).LE.0.0 ) GOTO 777
     	DO I=1, 5
     	   IF( ABS(WAVE(1,6)-WAVE(1,I)).LT.0.001 ) IELE = I
     	ENDDO
C
C  READ THE NUMBER OF PEAKS...
C
     	READ(IINP,REC= 21,ERR=777) NPKS
     	IF( NPKS.LT.1 ) GOTO 777
C
C  READ THE DIFILE DATA BLOCK...
C
     	IREC = 40
     	LAMDA = 0.5*WAVE(1,IELE)
     	DO I=1, NPKS
     	   READ(IINP,REC= IREC+1,ERR=111) FDSP(I)
     	   READ(IINP,REC= IREC+2,ERR=111) AREA(I,1)
     	   READ(IINP,REC= IREC+3,ERR=111) FWHM(I)
     	   READ(IINP,REC= IREC+4,ERR=111) AREA(I,2)
     		IF( AREA(I,2).LT.1.0 ) AREA(I,2) = 0.0
     		IF( AREA(I,2).GE.1.0 ) IRES = 1
     	   IREC = IREC + 6
     	   PHKL(1,I) = 0
     	   PHKL(2,I) = 0
     	   PHKL(3,I) = 0
     	   PEAK(I) = 'KA1'
     	   CDSP(I) = FDSP(I)
     	   PHGH(I) = AREA(I,JRES)
     	   F2TH(I) = RTOD*ASIN( LAMDA / FDSP(I) )
     	   C2TH(I) = F2TH(I)
     	ENDDO
     	GOTO 222
111	NPKS = I - 1			!END OF THE FILE
     	IF( NPKS.EQ.0 ) GOTO 777
C
C  FIGURE OUT THE RELATIVE INTENSITY...
C
222	PMAX = AREA(1,JRES)
     	DO I=2, NPKS
     	   IF( AREA(I,JRES).GT.PMAX ) PMAX = AREA(I,JRES)
     	ENDDO
     	DO I=1, NPKS
     	   RELA(I) = 100.0*AREA(I,JRES)/PMAX
     	ENDDO
     	GOTO 999

777	IERR = 1
     	GOTO 999
888	IERR = 2
999	RETURN
     	END
