        SUBROUTINE RRWTAG
C------------------------------------------------------------------------------
C
C       THIS ROUTINE READS FROM A SCINTAG BINARY RAW DATA FILE
C       AND STORES IN THE CORRESPONDING COMMON BLOCKS
C
C       AUTHOR: MIHAI OLARIU
C       DATE:   DEC 31, 1990
C------------------------------------------------------------------------------
 
        INCLUDE 'FILECONV.CBS'
 
        character       char4(20)*4
        INTEGER         IARR2(2),IARR3(3),IARR12(12),ISPARE
        integer         IARR20(20)
        REAL            RARR3(3)
        EQUIVALENCE     (CHAR4(1),SLID)
 
        CLOSE( UNIT=IINP )
 
        OPEN( UNIT=IINP, FILE=FILINP,STATUS='OLD',
     1  FORM='UNFORMATTED', READONLY, ERR=888 )
 
C---------------------------------------------------------------
C  READ THE FILE HEADER INFORMATION...
C---------------------------------------------------------------
        DO I = 1,20,1
          READ(IINP,ERR=777,END=777) char4(I)
        ENDDO
        DO I=1,3,1
          READ(IINP,ERR=777,END=777) IARR3(I)   !start,stop,step
        ENDDO
        DO I=1,3,1
          READ(IINP,ERR=777,END=777) RARR3(I)   !preset time,counts,wavelen
        ENDDO
        DO I=1,12,1
          READ(IINP,ERR=777,END=777) IARR12(I) !microsteps,...,2 theta max
        ENDDO
        DO I=1,12,1
          READ(IINP,ERR=777,END=777) ISPARE     !records 39-50, not used
        ENDDO
 
 
C---------------------------------------------------------------
C  DEFAULT THE RADIATION TO CU
C---------------------------------------------------------------
        IELE = 4
 
C---------------------------------------------------------------
C  READ THE INTENSITY DATA...
C---------------------------------------------------------------
        NPTS = (IARR12(10) - 51)/2 + 1  ! number of data points
        DO I=1,NPTS,1
          READ( IINP,ERR=777,END=777 ) INT1
          YOBS(I) = FLOAT(INT1)/60. * RARR3(1)
          READ( IINP,ERR=777,END=777 ) INT2
 
C--------------------
C         WRITE(*,411) 2*I+49, YOBS(I)          !2*(I-1)+50+1
C411      FORMAT('  ',I10,F10.1 )
C--------------------
 
        ENDDO
        GOTO 800
 
C-------------------------------------------------------------------
C DIVIDE START, END AND STEP ANGLE BY NUMBEROF MICROSTEPS AND STORE
C INTO BANG ARRAY
C-------------------------------------------------------------------
800     BANG(1)  = FLOAT(IARR3(1))/FLOAT(IARR12(1))
        BANG(2)  = FLOAT(IARR3(2))/FLOAT(IARR12(1))
        BANG(3)  = FLOAT(IARR3(3))/FLOAT(IARR12(1))
        BANG(4)  = FLOAT(IARR12(11))/60. * RARR3(1)     ! MAX COUNTS
        BANG(5)  = FLOAT( ( IARR12(12) - 49 ) /2 )
        BANG(10) = RARR3(1)
 
C-------------------------------------------------------------------
C make date and time available in blocks format:
C-------------------------------------------------------------------
        DATM = CONV_SCT_DATE( IARR12(4)-1900,IARR12(5),IARR12(6) )
        TIMM = CONV_SCT_TIME( IARR12(7), IARR12(8), IARR12(9) )
 
        goto 999
 
777     IERR = 1
        GOTO 999
888     IERR = 2
        GOTO 999
 
C-------------------------------------------------------------
999     RETURN
        END
 
 
 
 
C-----------------------------------------------------------------------------
        FUNCTION CONV_SCT_DATE( Y,M,D )
        INTEGER         Y,M,D
        CHARACTER       DAY*6
 
1       FORMAT( I2 )
2       FORMAT( F7.0 )
 
        M = (M-1) * 3 + 1
        ENCODE( 2,1,DAY(1:2) ) D
        ENCODE( 2,1,DAY(3:4) ) M
        ENCODE( 2,1,DAY(5:6) ) Y
        DECODE( 6,2,DAY ) FDATE
        CONV_SCT_DATE = FDATE
 
        RETURN
        END
 
 
C-----------------------------------------------------------------------------
        FUNCTION CONV_SCT_TIME( H,M,S )
        INTEGER         H,M,S
        CHARACTER       TIM*6
 
1       FORMAT( I2 )
2       FORMAT( F7.0 )
 
        ENCODE( 2,1,TIM(1:2) )H
        ENCODE( 2,1,TIM(3:4) )M
        ENCODE( 2,1,TIM(5:6) )S
        DECODE( 6,2,TIM ) FTIME
        CONV_SCT_TIME = FTIME
 
        RETURN
        END
 
