     	SUBROUTINE RRW011
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   FEB-1987
C
C	THIS ROUTINE READS FROM A DIFFRAC-11 RAW DATA FILE
C	AND STORES IN THE CORRESPONDING COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
     	DIMENSION NRNS(20)
     	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)
     	READ(IINP,REC= 14,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 LINE MEASUREMENT BLOCK...
C
     	READ(IINP,REC= 30,ERR=777) NRNG		!NUMBER OF SCAN RANGES
     	IF( NRNG.LT.1 ) GOTO 777
C
C  SHOW ALL THE RANGES...
C
     	IF( NRNG.GT.1 ) WRITE(6,2000)
2000	FORMAT(/' RANGE  BEGIN  ENDING   STEP   SECS   MAXCOUNTS',
     	1'  MAX2THETA  MINCOUNTS  MIN2THETA'/,X,80('-'))
2001	FORMAT(X,I3,2X,4(F7.3,X),X,2(G11.4,X,F8.3))
     	IREC = 31
     	DO J=1, NRNG
     	   READ(IINP,REC= IREC,ERR=777) BANG(1)
     	   	IREC = IREC + 1
     	   READ(IINP,REC= IREC,ERR=777) BANG(2)
     	   	IREC = IREC + 1
     	   READ(IINP,REC= IREC,ERR=777) BANG(3)
     	   	IF( BANG(3).LE.0.0 ) GOTO 777
     	   	IREC = IREC + 1
     	   READ(IINP,REC= IREC,ERR=777) BANG(10)
     	   	IF( BANG(10).LE.0.0 ) GOTO 777
     	   	IREC = IREC + 1
     	   	IF( J.EQ.1 ) THEN
     	   READ(IINP,REC= IREC,ERR=777) BANG(14)
     		IREC = IREC + 1
     	   	ENDIF
     	   NPTS = INT( (BANG(2)-BANG(1))/BANG(3)+0.5 ) + 1
     	   	BANG(4) = -1.0E+38
     	   	BANG(6) =  1.0E+38
     	   DO I=1, NPTS				!SEARCH FOR MAX&MIN
     	      READ(IINP,REC= IREC,ERR=777) DUMY
     	      IREC = IREC + 1
     	      IF( DUMY.GT.BANG(4) ) THEN
     		  BANG(4) = DUMY
     		  IMAX = I
     	      ENDIF
     	      IF( DUMY.LT.BANG(6) ) THEN
     		  BANG(6) = DUMY
     		  IMIN = I
     	      ENDIF
     	      YOBS(I) = DUMY
     	   ENDDO
     	   BANG(5) = BANG(1) + BANG(3)*(IMAX-1)
     	   BANG(7) = BANG(1) + BANG(3)*(IMIN-1)
     	   IF( NRNG.GT.1 ) WRITE(6,2001) J, BANG(1),BANG(2),
     	1  BANG(3),BANG(10),BANG(4),BANG(5),BANG(6),BANG(7)
     	   NRNS(J) = NPTS + 4
     	   IF( J.EQ.1 ) NRNS(J) = NPTS + 5
     	ENDDO
     	IRNG = NRNG
     	IF( NRNG.EQ.1 ) GOTO 999	!EXIT
C
C  GET A SPECIFIC RANGE...
C
2004	WRITE(6,2005)
2005	FORMAT(/
     	1' Only one range can be converted at a time.'/
     	1'$Which range to use? <1> ')
     	READ(5,1001,ERR=2004,END=2004) IRNG
1001	FORMAT(I)
     	IF( IRNG.LT.1 .OR. IRNG.GT.NRNG ) IRNG = 1
C
C  READ THE INTENSITY DATA BLOCK...
C
     	IREC = 31
     	DO I=1, IRNG-1			!JUMP TO THE RANGE
     	   IREC = IREC + NRNS(I)
     	ENDDO

     	READ(IINP,REC= IREC,ERR=777) BANG(1)
     		IREC = IREC + 1
     	READ(IINP,REC= IREC,ERR=777) BANG(2)
     	   	IREC = IREC + 1
     	READ(IINP,REC= IREC,ERR=777) BANG(3)
     		IREC = IREC + 1
     	READ(IINP,REC= IREC,ERR=777) BANG(10)
     		IREC = IREC + 1
     		IF( IRNG.EQ.1 ) THEN
     	READ(IINP,REC= IREC,ERR=777) BANG(14)
     		IREC = IREC + 1
     		ENDIF
     	NPTS = INT( (BANG(2)-BANG(1))/BANG(3)+0.5 ) + 1
     		BANG(4) = -1.0E+38
     		BANG(6) =  1.0E+38
     		DO I=1, NPTS			!SEARCH FOR MAX&MIN
     	READ(IINP,REC= IREC,ERR=777) DUMY
     		IREC = IREC + 1
     		IF( DUMY.GT.BANG(4) ) THEN
     		    BANG(4) = DUMY
     		    IMAX = I
     		ENDIF
     		IF( DUMY.LT.BANG(6) ) THEN
     		    BANG(6) = DUMY
     		    IMIN = I
     		ENDIF
     		YOBS(I) = DUMY
     		ENDDO
     	BANG(5) = BANG(1) + BANG(3)*(IMAX-1)
     	BANG(7) = BANG(1) + BANG(3)*(IMIN-1)
     	GOTO 999

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