     	SUBROUTINE RRWNBS
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   FEB-1987
C
C	THIS ROUTINE READS FROM A NBS RIETVELD RAW DATA FILE
C	AND STORES IN THE CORRESPONDING COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
     	CHARACTER IQS*1
    	DIMENSION IDATA(1000)

     	CLOSE( UNIT=IINP )
     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD', FORM='FORMATTED',
     	1 CARRIAGECONTROL='LIST', READONLY, ERR=888 )

     	WAVE(1,IELE) = 1.5416		!DEFAULT WAVELENGTH
     	SPAN = 20.0			!COVERED BY EACH DETECTOR
C
C  READ THE FILE HEADER...
C
     	READ(IINP,1000,ERR=777,END=777) SLID
1000	FORMAT(20A4)
     	READ(IINP,1000,ERR=777,END=777) IQS	!SKIP ONE LINE

     	NPTS = 0
     	ISEC = 0
C
C  READ THE SCAN PARAMETERS...
C
111	READ(IINP,1001,ERR=777,END=666) N1, N3, N2, SCALE
1001	FORMAT(3I8,2F8.0)

     	ISEC = ISEC + 1
     	IF( ISEC.EQ.1 ) THEN
     	    BANG(1) = 0.01 * N1
     	    BANG(2) = BANG(1)
     	    BANG(3) = 0.01 * N3
     	ENDIF
     	N2 = (N2-N1)/N3 + 1
     	READ(IINP,1002,ERR=777,END=666) (IDATA(I), I=1, N2)
1002	FORMAT(12I6)
     	IF( ISEC.EQ.5 ) SPAN = 0.01*(N2-1)*N3
     	N1 = SPAN / BANG(3)
     	IF( ISEC.EQ.5 ) N1 = N1 + 1
     	DO I=1, N1
     	   NPTS = NPTS + 1
     	   YOBS(NPTS) = IDATA(I)*SCALE
     	ENDDO
C
C  UPDATE THE ENDING ANGLE...
C
     	BANG(2) = BANG(2) + SPAN
     	GOTO 111

666	IF( ISEC.GT.0 ) GOTO 999
777	IERR = 1
     	GOTO 999
888	IERR = 2
999	RETURN
     	END
