        SUBROUTINE RRWS
C
C       TEMPORARY ROUTINE TO READ RAW DATA FILE COLLECTED 
C                 AT BROOKHAVEN SYNCHROTRON LAB.
C
C       S.I. ZDZIESZYNSKI 
C       AUG-16-93
C
     	INCLUDE 'FILECONV.CBS'
     	CHARACTER DAY*9, TIM*8,VEKTOR*15,ENERGY*10,UNITS*14,UNK*5
        INTEGER*4 MON(15000),ITIM(15000),ICTS(15000)
        REAL*4    TTH(15000),CT(15000)
        CHARACTER POWDAT*40
        BYTE BYTES(80)
C
C
        IERR=0
C
111	CLOSE( UNIT=IINP )
     	OPEN( UNIT=IINP, FILE=FILINP, STATUS='OLD', READONLY,
     	1 FORM='FORMATTED', CARRIAGECONTROL='LIST',ERR=888)
C
C  READ THE FILE HEADER INFORMATION...
C
        DO I=1,7 
        READ(IINP,102,END=777) BYTES
102     FORMAT(80A1)
100     ENDDO
        READ(IINP,103,END=777)VEKTOR,WVEKTOR,ENERGY,WENERGY,UNITS  
103     FORMAT(A15,F9.6,A10,F9.6,A14)     
C
105     READ(IINP,102,END=777) BYTES
        READ(IINP,1000,END=777) (SLID(I),I=1,20)
1000	FORMAT(20A4)
        IELE=6
        ANODE(6)='  '
        WAVE(1,6)=6.283185307/WVEKTOR

        CALL CLEARS(0)
        TYPE 1,WAVE(1,6)
1       FORMAT(' WAVE LENGTH:',F10.7,'E-010 [m]',/, 
     & $,' ENTER NEW VALUE, WHEN YOU WANT TO CHANGE 
     & WAVE LENGTH <CR NO CHANGE>:')
C       
        ACCEPT 2,WAVELEN
2       FORMAT(F10.7)
C
        IF(WAVELEN.NE.0) WAVE(1,6)=WAVELEN
C
C  READ THE SCAN PARAMETERS...
C
C     	READ(IINP,1100,END=777) UNK,START,STEP,ICOD,LCOD,NPTS,NTIM
C1100	FORMAT(A5,F5.2,1X,F5.3,1X,I1,1X,I1,1X,I5,I2)

        READ(IINP,1100,END=777)IQ,POWDAT
1100    FORMAT(Q,A<IQ>)

        TYPE*,(POWDAT(I:I),I=1,IQ)
        TYPE*,'              FIGURE OUT WHAT IS WHAT AND ENTER BELOW:'
        TYPE 1101
1101    FORMAT($,' ENTER STARTING ANGLE ( F FORMAT ):')
        ACCEPT 1102, START
1102    FORMAT(F8.4)
        TYPE 1103
1103    FORMAT($,' ENTER STEP ( F FORMAT ):')
        ACCEPT 1102, STEP
        TYPE 1104
1104    FORMAT($,' ENTER NUMBER OF DATA POINTS ( I FORMAT ):')
        ACCEPT 1105, NPTS
1105    FORMAT(I5)

        BANG(1)=START
        BANG(3)=STEP
        BANG(2)=START+(NPTS-1)*STEP
        BANG(10)= 1      !  NTIM        
        DO I=1,3
        READ(IINP,102,END=111) BYTES
        ENDDO
C        
C
C  READ THE INTENSITY DATA...
C
C
C
     	IF( NPTS.GT.15000 ) NPTS=15000
C
        DO I=1,NPTS-1
     	READ(IINP,1200,ERR=777,END=776) MON(I),ITIM(I),ICTS(I),TTH(I)
        IF(I.GE.10000) THEN
C        TYPE*,I, MON(I),ITIM(I),ICTS(I),TTH(I)
        ENDIF
1200	FORMAT(I9,I7,I8,F9.4)

776     IF(MON(I).EQ.0. OR .ITIM(I).EQ.O)THEN
        YOBS(I)=0        
        GO TO 1300
        ENDIF
        CT(I)=MON(1)/MON(I)
C        YOBS(I)= (ICTS(I)*MON(1)/MON(I))/(ITIM(I)*0.001)
C        YOBS(I)= (ICTS(I)*CT(I))/(ITIM(I)*0.001)
         YOBS(I)= ICTS(I)/(ITIM(I)*0.001)
1300    ENDDO
     	GOTO 999
777	IERR = 1
     	GOTO 999
888	IERR = 2
C
999     RETURN
     	END
