     	SUBROUTINE RRWNIC
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   FEB-1987
C
C	THIS ROUTINE READS FROM A NICOLET RAW DATA FILE
C	AND STORES IN THE CORRESPONDING COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
     	INTEGER*2 ITIT(40), DATTIM(6), NRNS, IDUM, IBUF(100)
     	EQUIVALENCE (ITIT, SLID)
     	REAL*4 FWAVE(4), DUMY(12), RANGE(9,100)

     	CLOSE( UNIT=IINP )
     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD',
     	1 FORM='UNFORMATTED', READONLY, ERR=888 )
C
C  READ THE FILE HEADER INFORMATION...
C
     	READ(IINP,ERR=777,END=777) ITIT, DATTIM, FWAVE, DUMY, IDUM,
     	1 IDUM, IDUM, DUMY, NRNS, RANGE

     	IF( NRNS.LT.1 .OR. NRNS.GT.100 ) GOTO 777
     	NRNG = NRNS
     	WAVE(1,6) = FWAVE(2)
     	WAVE(2,6) = FWAVE(3)
     	WAVE(3,6) = FWAVE(1)
     	WAVE(5,6) = 2.0
     	DO I=1, 5
     	   IF( ABS(WAVE(1,6)-WAVE(1,I)).LT.0.001 ) IELE = I
     	ENDDO
     	IF( NRNG.EQ.1 ) GOTO 111
C
C  ONLY ONE RANGE CAN BE HANDLED AT A TIME...
C
100	NRNS = LDIGIT( NRNG )
     	WRITE(6,1000) NRNG
1000	FORMAT(/
     	1' Input file contains ',I<NRNS>,' ranges of data'/
     	1' but only one range can be converted at a time.'/
     	1'$Which range to use? <1> ')
     	READ(5,1001,ERR=100,END=100) NRNS
1001	FORMAT(I)
     	IF( NRNS.LT.1 .OR. NRNS.GT.NRNG ) NRNS = 1
     	IF( NRNS.EQ.1 ) GOTO 111
C
C  SKIP THE RANGES...
C
     	IDIR = 0
     	DO I=1, NRNS-1
     	   NPTS = RANGE(8,I)
     	   IDUM = NPTS/100
     	   IF( IDUM*100 .LT. NPTS ) IDUM = IDUM + 1
     	   IDIR = IDIR + IDUM
     	ENDDO
     	DO I=1, IDIR
     	   READ(IINP,ERR=777,END=777) IDUM
     	ENDDO
C
C  READ THE INTENSITY DATA...
C
111	BANG(1) = RANGE(1,NRNS)
     	BANG(2) = RANGE(2,NRNS)
     	BANG(3) = RANGE(5,NRNS)
     	BANG(10)= RANGE(7,NRNS)
     	NPTS = RANGE(8,NRNS)
     	IDIR = RANGE(9,NRNS)		!SCAN DIRECTION: 1=F, 2=R
     	IJ = 0
     	K  = 1
     	IF( IDIR.EQ.2 ) THEN
     	    IJ = NPTS+1			!COUNT DOWN
     	    K  = -1
     	ENDIF
     	NRNS = NPTS/100
     	IF( NRNS*100 .LT. NPTS ) NRNS = NRNS + 1
     	DO I=1, NRNS
     	   READ(IINP,ERR=777,END=777) IBUF
     	   DO J=1, 100
     	      IJ = IJ + K
     	      YOBS(IJ) = IBUF(J)
     	   ENDDO
     	ENDDO
     	GOTO 999

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