     	SUBROUTINE RDIRIG
C
C  PROGRAMMER:  R. L. SNYDER
C		ALFRED UNIVERSITY,  Jan 1988
C
C	THIS ROUTINE READS FROM A RIGAKU DIFILE
C	AND STORES IN THE CORRESPONDING COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
     	REAL*4 LAMDA, W(4)
     	INTEGER*2 ITIT(40), HH, KK, LL
     	EQUIVALENCE (ITIT,SLID)
     	DIMENSION NRNS(20)
     	CHARACTER DAY*12, TIM*8, JUNK*4, EL(4)*1, AST*1
C
     	CLOSE( UNIT=IINP )
     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD', ERR=888,
     	1 ACCESS='DIRECT', RECL=9, READONLY )
C
C  READ RECORD 1 - 3
C
     	JERR = 1
     	READ(IINP,REC= 1,ERR=777) JUNK, DAY, TIM
     	JERR = 2
     	READ(IINP,REC= 2,ERR=777) (SLID(I),I=1,6)
     	JERR = 3
     	READ(IINP,REC= 3,ERR=777) (SLID(I),I=7,10)
     	JERR = 4
     	DATM = DATCOD( DAY(1:9) )
     	TIMM = TIMCOD( TIM(1:8) )
C
C  READ THE LINE MEASUREMENT RECORD 4
C DMAX, DMIN, START, END, STEP, SCAN SPEED, COUNT TIME - REAL*4
C
     	READ(IINP,REC= 4,ERR=777) A,A,BANG(1),BANG(2),BANG(3),A,BANG(10)
     	IF( BANG(3).LE.0.0 .OR. BANG(10).LE.0.0 ) GOTO 777
C
C  READ THE RADIATION 
C EL SYM (A2), KA1, KA2, KB1, KBAR
C
     	JERR = 5
     	READ(IINP,REC= 5,ERR=777) EL, W
     	IELE = 0
C	WAVE(*,1) --- Cr
C	WAVE(*,2) --- Fe
C	WAVE(*,3) --- Co
C	WAVE(*,4) --- Cu
C	WAVE(*,5) --- Mo
C	WAVE(*,6) --- USER SPECIFIED
     	IF(EL(1) .EQ. 'C' .AND. EL(2) .EQ. 'r') IELE = 1
     	IF(EL(1) .EQ. 'F' .AND. EL(2) .EQ. 'E') IELE = 2
     	IF(EL(1) .EQ. 'C' .AND. EL(2) .EQ. 'o') IELE = 3
     	IF(EL(1) .EQ. 'C' .AND. EL(2) .EQ. 'u') IELE = 4
     	IF(EL(1) .EQ. 'M' .AND. EL(2) .EQ. 'o') IELE = 5
     	IF(IELE .EQ. 0) IELE = 6
     	WAVE(1,IELE) = W(1)
     	WAVE(2,IELE) = W(2)
     	WAVE(4,IELE) = W(3)
     	WAVE(3,IELE) = W(4)
C	WAVE(1,*) --- WAVELENGTH OF K-ALPHA 1
C	WAVE(2,*) --- WAVELENGTH OF K-ALPHA 2
C	WAVE(3,*) --- WAVELENGTH OF K-ALPHA
C	WAVE(4,*) --- WAVELENGTH OF K-BETA
C	WAVE(5,*) --- KA1/KA2 RATIO
C
C  SKIP THE NEXT 3 RECORDS
C
C  READ THE NUMBER OF PEAKS...
C
     	JERR = 9
     	READ(IINP,REC= 9,ERR=777) NPKS
     	IF( NPKS.LT.1 ) GOTO 777
C
C  READ THE DIFILE DATA BLOCK...
C
     	IREC = 9
     	DO I=1, NPKS
     	   IREC = IREC + 1
     	   JERR = IREC
     	   READ(IINP,REC= IREC,ERR=111) AST, F2TH(I), FDSP(I), 
     1		RELA(I), PHGH(I), FWHM(I)
     	   IF(AST.EQ.'*') WRITE(6,1010) I
1010	   FORMAT(' Warning: Line ',I3,' May be an alpha 2')
     	   CDSP(I) = FDSP(I)
     	   C2TH(I) = F2TH(I)
     	ENDDO
     	GOTO 999
111	NPKS = I - 1			!END OF THE FILE
     	IF( NPKS.EQ.0 ) GOTO 777
     	GOTO 999
C  ERROR EXIT
777	IERR = 1
     	GOTO 999
888	IERR = 2
999	RETURN
     	END
