     	SUBROUTINE DIARAW
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY,  FEB-1987
C
C	THIS ROUTINE CONDUCTS THE INTERATIVE DIALOGUE
C	FOR INPUT RAW DATA FILE CONVERSION.
C
     	INCLUDE 'FILECONV.CBS'	
     	INTEGER*4 SPIKE, RESET
     	CHARACTER TEXT*80, SAMP*80, USER*12, SYM*1, KEY*2
    	DIMENSION RP(5), KP(5)
     	EQUIVALENCE (SAMP, SLID), (USER, NAME)
C
C  FIND THE MAXIMUM AND MINIMUM POINTS IN THE PATTERN...
C
     	BANG(4) =-1.0E+38
     	BANG(6) = 1.0E+38

C        TYPE*,' NPTS=',NPTS

     	DO I=1, NPTS


C        IF(I.GE.4950 .AND. I.LE.5050) THEN
C        TYPE*,'YOBS(',I,')=',YOBS(I)
C        ENDIF

     	    IF( YOBS(I).GT.BANG(4) ) THEN
     		BANG(4) = YOBS(I)
     		BANG(5) = I
     	    ENDIF

     	    IF( YOBS(I).LT.BANG(6) .AND. YOBS(I).NE.0 ) THEN   !S.Z.
C     	    IF( YOBS(I).LT.BANG(6) ) THEN
     		BANG(6) = YOBS(I)
     		BANG(7) = I
     	    ENDIF
     	ENDDO
     	BANG(5) = BANG(1) + BANG(3)*(BANG(5)-1.0)
     	BANG(7) = BANG(1) + BANG(3)*(BANG(7)-1.0)
C
C  LOAD THE "DANG" ARRAY...
C
     	DO I=1, 14
     	   DANG(I) = BANG(I)			!200
     	ENDDO

     	NRNG = 1		!RESET RANGES TO 1 FOR OUTPUT
     	NREP = 1		!RESET SERIES TO 1 FOR OUTPUT
     	RESET= 1		!ZERO POINT RESET LEVEL
c  spike changed to 1,000,000 to avoid truncatuing large peaks
     	SPIKE= 500000 		!VOLTAGE SPIKE DELTA COUNTS
1	CALL CLEARS( 0 )
     	CALL COLORS(-1)
     	CALL COLORS(80)
     	TEXT = 'VAXCONV --- Dialogue Menu for Raw Data File Conversion'
     	CALL HEADER( TEXT )
     	CALL COLORS(1)
C					!50
C  DISPLAY THE DIALOGUE MENU...
C
     	WRITE(6,2)
2	FORMAT(X,80('='),/
     	1'  INPUT FILE:',27X,'INPUT FILE TYPE:'/
     	1' OUTPUT FILE:',26X,'OUTPUT FILE TYPE:'/
     	1' DATA COLLECTION MODE:'/,X,80('='),/
     	1' 1=SAMPLE ID:'/,X,80('-'),/
     	1' 2=RUN DATE:',11X,'3=RUN TIME:',10X,'4=USER NAME:'/,X,80('-'),/
     	1' 5=ANODE:'4X'6=KA1:'9X'7=KA2:'9X'8=KA:'9X'9=KA1/KA2 RATIO:'/
     	1X,80('-')/' 10=STARTING ANGLE:',9X,'11=ENDING ANGLE:',
     	19X,'12=OUTPUT STEPSIZE:'/' 13=COUNTTIME(SEC):',
     	18X'NUMBER OF POINTS:',13X,'INPUT STEPSIZE:'/
     	1' 14=VOLTAGE SPIKE DELTA(COUNTS):         15=ZERO POINT',
     	1' RESET(COUNTS):'/' MAX CPS=',15X,'AT 2TH=',10X,'MIN CPS=',15X,
     	1'AT 2TH='/,X,80('=')/
     	2' Only the numbered fields can be accessed to and be changed',
     	2' interactively.'/
     	2' e.g. INPUT> 1=Si SRM640A internal calibration run<return>'/
     	2' Enter RE to refresh the menu; LIST, TYPE to list raw pattern,',
     	2' CTRL_Z to quit.'/' Enter blank RETURN or EXIT to exit from',
     	2' the menu to start the conversion.')
C
C  INSERT THE PARAMETERS...
C
     	CALL COLORS(-1)			!REVERSE VIDEO ON
     	CALL PUTEXT( FILINP, 25, 3, 13 )
     	CALL PUTEXT( FILOUT, 25, 4, 13 )
     	CALL PUTEXT( FILTYP(IFLI), 24, 3, 57 )
     	CALL PUTEXT( FILTYP(IFLO), 24, 4, 57 )
     	IF( MODE.EQ.0 ) TEXT = 'PATTERN STEP SCAN (STEPING IN TWO-THETA)'
     	IF( MODE.EQ.1 ) TEXT = 'PATTERN STEP SCAN (STEPING IN D-SPACING)'
     	IF( MODE.EQ.2 ) TEXT = 'PATTERN STEP SCAN (STEPING IN Q (2pi/d)'
     	CALL PUTEXT( TEXT, 40, 5, 22 )

     	CALL PUTEXT( SAMP, 68, 7, 13 )
     	CALL CODDAT( TEXT(1:9), DATM )
     	CALL PUTEXT( TEXT(1:9), 9, 9, 12  )
     	CALL CODTIM( TEXT(1:8), TIMM )
     	CALL PUTEXT( TEXT(1:8), 8, 9, 34  )
     	CALL PUTEXT( USER, 12, 9, 56 )


        IF(IELE.LE.0 .OR. IELE.GT.6) IELE=4	!S.Z.


     	CALL PUTEXT( ANODE(IELE), 2, 11, 9 )
     	CALL PUTFFL( WAVE(1,IELE), 1, 7.4, 11, 19 )
     	CALL PUTFFL( WAVE(2,IELE), 1, 7.4, 11, 34 )
     	CALL PUTFFL( WAVE(3,IELE), 1, 7.4, 11, 48 )
     	CALL PUTFFL( WAVE(5,IELE), 1, 4.1, 11, 73 )

     	CALL PUTFFL( DANG(1), 1, 7.3, 13, 19 )
     	CALL PUTFFL( DANG(2), 1, 7.3, 13, 44 )			
     	CALL PUTFFL( DANG(3), 1, 7.3, 13, 72 )
C     	CALL PUTFFL( dang(10), 1, 7.0, 14, 19 )
     	CALL PUTFFL( dang(10), 1, 7.1, 14, 19 )  !S.Z. JUN-8-95
     	CALL PUTFFL( BANG(3), 1, 7.3, 14, 72 )
     	CALL PUTIFL( SPIKE, 1, 6, 15, 32 )
     	CALL PUTIFL( RESET, 1, 6, 15, 69 )

     	CALL PUTFFL(         DANG( 5), 1,  7.3, 16, 31)
     	CALL PUTFFL(         DANG( 7), 1,  7.3, 16, 71)
     	CALL COLORS(80)
     	CALL PUTGFL( DANG(4)/DANG(10), 1, 13.6, 16, 9 )
     	CALL PUTGFL( DANG(6)/DANG(10), 1, 13.6, 16, 49)
     	CALL PUTIFL( NPTS,  1, 5, 14, 44 )
C
C  START THE DIALOGUE CYCLE...
C
111	CALL COLORS(1)				!REVERSE VIDEO OFF
    	CALL PUTEXT( 'INPUT> ', 7, 23, 1 )
    	IERR = 1				!ERROR FLAG ON
    	READ(5,100,ERR=999,END=999) TEXT
100	FORMAT(A)

    	IERR = 0
    	IF( TEXT.EQ.' ' ) GOTO 999
     	NCHS = NALPHA( TEXT, 80 )
     	NCH  = NBLANK( TEXT(1:NCHS), NCHS )
     	IF( NCH.GT.0 ) THEN
     	    TEXT = TEXT(NCH+1:)
     	    NCHS = NCHS - NCH
     	ENDIF
    	SYM = TEXT(1:1)
     	KEY = TEXT(1:2)
     	NCH = NALPHA( SYM, -1 )
     	NCH = NALPHA( KEY, -2 )
    	IF( KEY.EQ.'EX' ) GOTO 999
     	IERR = 1
    	IF( KEY.EQ.'QU' ) GOTO 999
     	IF( KEY.EQ.'RE' ) GOTO 1		!REFRESH THE MENU
     	IF( KEY.EQ.'LI' .OR. KEY.EQ.'TY' ) THEN
     	    CALL SHOWPN				!SHOW THE PATTERN
     	    GOTO 1
     	ENDIF
     	CALL CURSOR( 23, 1 )
    	CALL CLEARS( 2 )
C
C  DECODE THE ENTRY NUMBER...
C
     	IF( NCHS.LT.3 ) GOTO 120
    	DECODE( 2, 110, KEY, ERR=120 ) INDX
110	FORMAT(I)
    	GOTO 130			          	!150
120	IF( NCHS.LT.2 ) GOTO 888
     	DECODE( 1, 110, SYM, ERR=888 ) INDX

130    	IF( INDX.LT.1 .OR. INDX.GT.15 ) GOTO 777

    	NPS = INDEX( TEXT(1:3), '=' )
    	IF( NPS.EQ.0 ) GOTO 888		!WRONG ACCESS
    	NCH = NCHS - NPS
     	IF( NCH.EQ.0 ) GOTO 111
     	CALL COLORS(-1)
    	CALL COLORS(80)
    	NPS = NPS + 1
    	GOTO (50,51,52,53,54,55,55,55,55,55,55,55,55,55,55), INDX
C
C  ERROR TRANSFER...
C
777	CALL COLORS(-1)
     	CALL PUTEXT('_ERROR: entry value out of range. Entry ignored!',
     	1 48, 24, 1 )
    	GOTO 111
666	CALL COLORS(-1)
     	CALL PUTEXT('_ERROR: original radiation sources are
     	1 not modifiable.', 54, 24, 1 )
     	GOTO 111
888    	CALL COLORS(-1)
     	CALL PUTEXT('_ERROR: invalid entry. Check spelling.', 38, 24, 1 )
    	GOTO 111
C
C  GET THE SAMPLE ID...
C
50	SAMP = TEXT(NPS:NCHS)
     	CALL PUTEXT( SAMP, 68, 7, 13 )
     	GOTO 111
C
C  GET THE DATE...
C
51	NCH = NALPHA( TEXT(1:NCHS), -NCHS )	!CONVERT TO UPPERCASES
     	DUMY = DATCOD( TEXT(NPS:NCHS) )
     	IF( DUMY.EQ.0.0 ) GOTO 888
     	DATM = DUMY
     	CALL CODDAT( TEXT(1:9), DATM )
     	CALL PUTEXT( TEXT(1:9), 9, 9, 12  )
     	GOTO 111
C
C  GET THE TIME...
C
52	NCH = NALPHA( TEXT(1:NCHS), -NCHS )	!CONVERT TO UPPERCASES
     	DUMY = TIMCOD( TEXT(NPS:NCHS) )
     	IF( DUMY.EQ.0.0 ) GOTO 888
     	TIMM = DUMY				!200
     	CALL CODTIM( TEXT(1:8), TIMM )
     	CALL PUTEXT( TEXT(1:8), 8, 9, 34  )
     	GOTO 111
C
C  GET THE USER NAME...
C
53	USER = TEXT(NPS:NCHS)
     	CALL PUTEXT( USER, 12, 9, 56 )
     	GOTO 111
C
C  GET THE ANODE...
C
54      CONTINUE      
!	IF( IELE.NE.6 ) GOTO 666   !S.Z.
     	KEY = TEXT(NPS:(NPS+1))
     	NCH = NALPHA( KEY, -2 )			!CONVERT TO UPPERCASES
     	IF( KEY.EQ.ANODE(IELE) ) GOTO 111
     	DO I=1, 5
     	   IF( KEY.EQ.ANODE(I) ) GOTO 200
     	ENDDO
     	IELE = 6
     	ANODE(IELE) = KEY
     	CALL PUTEXT( ANODE(IELE), 2, 11, 9 )
     	CALL COLORS(-1)
     	CALL PUTEXT('_Please enter the correct values
     	1 for field 6,7,8,9.', 51, 24, 1 )
     	GOTO 111
C
C  DISPLAY NEW WAVELENGTHS...
C
200	IELE = I
     	CALL PUTEXT( ANODE(IELE), 2, 11, 9 )
     	CALL PUTFFL( WAVE(1,IELE), 1, 7.4, 11, 19 )
     	CALL PUTFFL( WAVE(2,IELE), 1, 7.4, 11, 34 )
     	CALL PUTFFL( WAVE(3,IELE), 1, 7.4, 11, 48 )
     	CALL PUTFFL( WAVE(5,IELE), 1, 4.1, 11, 73 )
     	GOTO 111
C
C  GET THE WAVELENGTHS, SCANING PARAMETERS...
C
55	IF( TEXT(NCHS:NCHS) .EQ. ',' ) NCHS = NCHS - 1
    	NCH = NCHS - NPS + 1
    	IF( NCH.EQ.0 ) GOTO 111
    	CALL COMMAS( TEXT(NPS:NCHS), NCH, 1, RP, KP, IDUM )
    	IF( NCH.EQ.0 ) GOTO 888		!ERROR INPUT

     	IF( INDX.LT.10 ) THEN
!     	    IF( IELE.NE.6 ) GOTO 666  S.Z.
     	    IF( RP(1).LT.0.01 .OR. RP(1).GE.10.0 ) GOTO 777
     	    IF( INDX.EQ.6 ) THEN
     		WAVE(1,IELE) = RP(1)			!250
     		CALL PUTFFL( RP(1), 1, 7.4, 11, 19 )
     	    ENDIF
     	    IF( INDX.EQ.7 ) THEN
     		WAVE(2,IELE) = RP(1)
     		CALL PUTFFL( RP(1), 1, 7.4, 11, 34 )
     	    ENDIF
     	    IF( INDX.EQ.8 ) THEN
     		WAVE(3,IELE) = RP(1)
     		CALL PUTFFL( RP(1), 1, 7.4, 11, 48 )
     	    ENDIF
     	    IF( INDX.EQ.9 ) THEN
     		WAVE(5,IELE) = RP(1)
     		CALL PUTFFL( RP(1), 1, 4.1, 11, 73 )
     	    ENDIF
     	ENDIF

     	IF( INDX.EQ.10 ) THEN
     	    IF( RP(1).GE.BANG(2) ) GOTO 777
     	    IF( RP(1).LT.BANG(1) ) RP(1) = BANG(1)
     	    DANG(1)= BANG(1)+BANG(3)*INT((RP(1)-BANG(1))/BANG(3)+0.1)
     	    CALL PUTFFL( DANG(1), 1, 7.3, 13, 19 )
     	ENDIF

     	IF( INDX.EQ.11 ) THEN
     	    IF( RP(1).LE.BANG(1) ) GOTO 777
     	    IF( RP(1).GT.BANG(2) ) RP(1) = BANG(2)
     	    DANG(2)= BANG(1)+BANG(3)*INT((RP(1)-BANG(1))/BANG(3)+0.1)
     	    CALL PUTFFL( DANG(2), 1, 7.3, 13, 44 )
     	ENDIF

     	IF( INDX.EQ.12 ) THEN
     	    IF( RP(1).GT.(DANG(2)-DANG(1)) ) GOTO 777
     	    IF( RP(1).LT.BANG(3) ) RP(1) = BANG(3)
     	    DANG(3) = BANG(3)*INT(RP(1)/BANG(3)+0.5)
     	    CALL PUTFFL( DANG(3), 1, 7.3, 13, 72 )
     	ENDIF

     	IF( INDX.EQ.13 ) THEN
     	    IF( RP(1).LE.0.0 .OR. RP(1).GT.9999.0 ) GOTO 777
     	    DANG(10) = RP(1)
     	    CALL PUTFFL( DANG(10), 1, 7.3, 14, 19 )
            CALL PUTGFL( DANG(4)/DANG(10), 1, 13.6, 16, 9 ) !added S.Z. 
     	    CALL PUTGFL( DANG(6)/DANG(10), 1, 13.6, 16, 49) ! JUN-8-95

     	ENDIF

     	IF( INDX.EQ.14 ) THEN
     	    IF( RP(1).LT.10.0 .OR. RP(1).GT.999999.0 ) GOTO 777
     	    SPIKE = RP(1)
     	    CALL PUTIFL( SPIKE, 1, 6, 15, 32 )
     	ENDIF
     	IF( INDX.EQ.15 ) THEN
     	    IF( RP(1).LT.0.00 .OR. RP(1).GT.999999.0 ) GOTO 777
     	    RESET = RP(1)
     	    CALL PUTIFL( RESET, 1, 6, 15, 69 )
     	ENDIF

     	IF( INDX.LT.10 .OR. INDX.GT.12 ) GOTO 111
     	NPTS = INT( (DANG(2)-DANG(1))/DANG(3) + 0.1 ) + 1
     	CALL PUTIFL( NPTS, 1, 5, 14, 44 )
     	GOTO 111
999	IF( IERR.GT.0 ) GOTO 9999
C
C  REPACK "YOBS" ARRAY ACCORDING THE NEW SCAN PARAMETERS...
C
     	NCH = DANG(3)/BANG(3) + 0.1			!STEP NUMBER
     	NCHS = 1 + INT((DANG(1)-BANG(1))/BANG(3)+0.1)	!STARTING POINT
     	DO I=1, NPTS
        YOBS(I) = YOBS(NCHS+(I-1)*NCH)
     	ENDDO
C
C  SEARCH FOR MAX, MIN POINTS, ZERO POINTS, VOLTAGE SPIKES IN "YOBS" ARRAY...
C   
     	DANG(5) = 0.0
     	DANG(7) = 0.0
     	DANG(6) = 1.0E+38
     	DANG(4) = 0.0
     	DOLD = YOBS(1)
     	IF( DOLD.LT.RESET ) DOLD = RESET
     	DO I=1, NPTS
     	   DUMY = YOBS(I)
     	   IF( DUMY.LT.RESET .OR. DUMY.GT.SPIKE+DOLD ) DUMY = DOLD
     	   YOBS(I) = DUMY
     	   DOLD = DUMY
     	   IF( DUMY.GT.DANG(4) ) THEN
     	       DANG(4) = DUMY
     	       DANG(5) = I
     	   ENDIF
     	   IF( DUMY.LT.DANG(6) ) THEN
	DANG(6) = DUMY
     	       DANG(7) = I
     	   ENDIF
     	ENDDO
     	DANG(5) = DANG(1) + DANG(3)*(DANG(5)-1.0)
     	DANG(7) = DANG(1) + DANG(3)*(DANG(7)-1.0)
C
C  LET'S GET OUT...
C
        DO I=1,14        ! to save run parameters changed during an
        BANG(I)=DANG(I)  ! interactive mode.
        ENDDO


9999	RETURN
     	END
