     	SUBROUTINE RRWRIO
C
C  PROGRAMMER:  R. L. SNYDER
C		ALFRED UNIVERSITY,  March 1989
C
C	THIS ROUTINE READS IN A RIGAKU ORIGINAL UNFORMATED RAW DATA FILE
C	TO THE CORRESPONDING COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
        INTEGER*2 FILNUM, MONTH, DAY, YEAR, MPTS
        CHARACTER INSTR*4
C
     	CLOSE( UNIT=IINP )
     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD',
     1 FORM='UNFORMATTED', ACCESS='SEQUENTIAL' )
C     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD',
C     1 FORM='UNFORMATTED', ACCESS='SEQUENTIAL',ERR=888 )
C
C *********************************************************************
C * READ FIRST RECORD OF THE RAW DATA FILE CONTAINING SAMPLE IDENTIFICATION
C * AND EXPERIMENTAL DATA COLLECTION PARAMETERS
C *********************************************************************
C
      READ( IINP, ERR=888, IOSTAT=IERR) FILNUM, MONTH, DAY, 
     &          YEAR, INSTR,
     &		(SLID(I),I=1,12), BANG(1), BANG(3), BANG(10), ANODE(6), 
     &		XLAMDA, BANG(2), MPTS
C
     	DATM = IDAY + MONTH*100 + YEAR
     	TIMM = 0.0
C
	if((ANODE(6).EQ.'Cr').or.(ANODE(6).eq.'CR'))then
			iele=1
	else if((ANODE(6).eq.'Fe').or.(ANODE(6).eq.'FE'))then
			iele=2
	else if((ANODE(6).eq.'Co').or.(ANODE(6).eq.'CO'))then
			iele=3
	else if((ANODE(6).eq.'Cu').or.(ANODE(6).eq.'CU'))then
			iele=4
	else if((ANODE(6).eq.'Mo').or.(ANODE(6).eq.'MO'))then
			iele=5
	else
			iele=6
	endif
C
     	IF( XLAMDA .NE. 0.0) WAVE(3,IELE) = XLAMDA
C
C Read the intensities from each input record 32 per record.
C
     	NPTS = MPTS
C	NREC = (MPTS-1)/32 + 1
        DO 50 I = 1, NPTS, 32
	READ( IINP, ERR=777, END=666) (YOBS(J), J=I,I+31)
50	CONTINUE
     	GO TO 999
666	NPTS = I-1
     	IF( NPTS.GT.0 ) GOTO 999
777	IERR = 1
     	GOTO 999
888	IERR = 2
999	RETURN
     	END
