C*****************************************************************************
C
	PROGRAM AUTO
C
C	DATA COLLECTOR FOR THE XRAY QUANT PROGRAMS USING ASCII DATA FILES.
C
C	THE OLD VERSION OF AUTO WAS ORIGINALLY DESIGNED TO OPERATE
C	TWO DIFFRACTOMETERS SIMULTANEOUSLY AND, AS A RESULT, IS VERY
C	COMPLICATED.  THIS NEW VERSION IS MUCH SIMPLER.
C
C	This version, for Radix databox and VAX computer, written by:
C		James Walker   (More of a computer bum than a scientist.)
C		NYS College of Ceramics
C		Alfred University
C		Alfred, NY 14802
C
C	In general, subroutines that are specific to the interface you are
C	using begin with IF.  Subroutines specific to the computer system
C	begin with SY.  Exceptions are subroutines taken from other programs.
C
C*****************************************************************************
C
C	THIS IS THE VARIABLE DICTIONARY FROM THE OLD VERSION.  SOME OF THIS
C	IS OBSELETE.
C
C     IF1, IF2     =  ?2 - THE LOGICAL UNIT NUMBER OF THE X-RAY INTERFACE
C     IRD          =  5 - TERMINAL INPUT
C     ITYP         =  6 - TERMINAL OUTPUT
C
C
C     BANG         = THE BEGINNING 2-THETA FOR RUN
C     BKGTIM       = BACKGROUND COUNT TIME IN SECONDS
C     BKGTI1	   = SAVES BKGTIM FOR MULTIPLE REPITITONS
C     CANG         = THE CURRENT 2-THETA OF THE DIFFRACTOMETER
C     DANG         = THE DELTA 2-THETA OR STEP WIDTH
C     DELPK        = LAST CALCULATED SHIFT IN USER'S PANG AS
C                    CALCULATED IN PKFIND (PEAK HEIGHT MODE).
C     EANG         = THE ENDING 2-THETA FOR THE RUN
C     FIXERR       = 0 - FIXED TIME COUNT MODE (WITH OPTIMIZATION)
C                  = NN.NN - PERCENT ERROR FOR FIXED ERROR COUNT MODE.
C     IACT         = A CURRENT ACTIVITY CODE FOR A UNIT
C                     = -1 LIMIT SWITCH HIT OR INTERFACE ERROR,
C		           2-THETA WAS LOST
C                     =  0 UNIT NOT ACTIVE
C                     =  1 UNIT IS COUNTING
C                     =  2 UNIT IS STEPPING
C                     =  3 UNIT IS SLEWING
C     CNT          = THE ARRAY FOR COLLECTED INTENSITY VALUES
C     			USED AS A SCRATCH ARRAY USED IN VARIOUS PLACES
C     IDAT         = THE DATE OF THE START OF THE RUN
C     IDBUG        =  0 - NO DEBUG PROCEDURES
C                  = >0 - RUN APPROPRIATE ROUTINES
C     IFLAG        = RUN CONTROL FLAGS READ FROM QUANT RUN FILE
C        IFLAG(1)     = FILE TYPE DESCRIPTOR
C                        = 0 DATA FILE FROM PATTERN COLLECTION
C                        = 1 OUTPUT DATA FILE FROM QUANT
C                        = 2 QUANT RUN FILE FOR STANDARD DETERMINATION
C                        = 3 QUANT RUN FILE FOR UNKNOWN DETERMINATION
C                        = 4 OUTPUT FILE FROM CALIBRATION RUN
C        IFLAG(2)     = RUN TYPE DESCRIPTOR
C                        = 0 PATTERN COLLECTION
C                        = 1 QUANT ANALYSIS FOR WEIGHT PERCENT
C                        = 2 DETERMINE CONSTANTS FROM STANDARDS
C                           (QUANT, I-REL, OR CALIBRATION)
C			 = 3 MEASURE RELATIVE INTENSITIES
C        IFLAG(3)     = QUANTITATIVE ANALYSIS TYPE
C                        = 0 QUAL
C                        = 1 INTERNAL STANDARD METHOD
C                        = 2 INTENSITY RATIO METHOD
C                        = 3 SPIKING METHOD
C                        = 4 RELATIVE INTENSITY RUN
C                        = 5 CALIBRATION RUN (PROFILE MEASUREMENT)
C        IFLAG(4)     = ELEMENTAL ANALYSIS FLAG
C                        = 0 ELEMENTAL COMPOSITION WILL NOT BE ENTERED
C                        = 1 ELEMENTAL COMPOSITION WILL BE USED
C        NREP		 = NUMBER OF REPETIONS FOR EACH SAMPLE MOUNT
C	 NMOUNT		 = NUMBER OF MOUNTINGS FOR THIS COMPOUND OR MIXTURE
C        IFLAG(7-10)	 = AVAILABLE FOR FUTURE EXPANSION
C     IPK          = DATA COLLECTION MODE FLAG
C                     = 0 STEP SCAN (I.E. TO BE LATER INTEGRATED)
C                     = 1 PEAK COUNT MODE
C     IPKFND       = RESULT OF PEAK FIND ROUTINE
C		      = -1 NO PEAK FOUND
C		      =  0 PEAK FOUND IN UNSMOOTHED EXTREMES
C		      =  1 PEAK LOCATED NEAR EXPECTED VALUE
C     IPT          = THE NUMBER OF THE CURRENT GROUP OF 16 DATA POINTS
C                    WHICH IS BEING COLLECTED OR WAS JUST COLLECTED
C     IRATE        = GONIOMETER MOVEMENT RATE CODE
C     ????         = A STATUS FLAG FOR THE DIFFRACTOMETER
C                     = 0 NOT IN USE
C                     = 1 QUALITATIVE ANALYSIS RUN
C                     = 2 QUANTITATIVE ANALYSIS RUN
C                     = 3 INTENSITY MEASURING RUN
C                     = 4 CALIBRATION RUN
C                     = 5 ALIGNMENT RUN
C     ISAVE        = 0 DO NOT SAVE INTEGRATED COUNTS
C		   = 1 SAVE COUNTS ACCUMULATED DURING SCAN
C     ISTATS       = THE ADDRESS OF INTERFACE MODULE THAT COMPLETED
C     ITOT         = THE TOTAL NUMBER OF DATA POINTS COLLECTED:
C                    FOR QUAL ALL POINTS, FOR QUANT THE POINTS
C                    OF THE PEAK CURRENTLY BEING MEASURED
C     ITIM         = TIME RETURNED BY SUBROUTINE DATE
C     TITLE(20)   = THE RUN TITLE (20A4)
C     USER(5)      = THE OPERATOR'S NAME (5A4)
C     IZRST        = A FLAG TO INDICATE A ZERO STEP REQUEST TO SLEW
C                     = 0 (FALSE) - NON ZERO STEP REQUEST
C                     = 1 (TRUE)  - A ZERO STEP REQUEST. WE ARE AT
C                      THE DESIRED ANGLE.
C     CNTLIM       = THE MAXIMUM COUNTS ALLOWED AT A POINT
C     MODULE(I)	   = MODULE ADDRESSES OF INTERFACES
C		      (1) = COUNTER
C		      (2) = TIMER
C		      (3) = AXIS POSITIONER
C		      (4) = GENERIC ADDRESS OF COUNTER/TIMER (40)
C     MVCNT        = A FLAG TO ESTABLISH STEP AND COUNT METHOD
C		     = 0 ERROR
C                    = 1 FOR INDEPENDENT STEP THEN COUNT
C                    = 2 FOR SIMULTANEOUS STEP AND COUNT
C     NBG          = THE NUMBER OF BACKGROUND POINTS TO MEASURE ON
C                    ON EACH SIDE OF THE PEAK
C     NPK          = THE NUMBER OF POINTS TO MEASURE AT THE PEAK IN PEAK
C                    COUNT MODE OR THE NUMBER OF POINTS TO AVERAGE OVER
C                    AT THE MAXIMUM IN INTEGRATE MODE TO ESTIMATE THE
C                    THE PEAK INTENSITY
C     NPTPK       = NUMBER OF POINTS IN PEAK REGION (QUANT RUN)
C                    = NPK IF IPK=1
C                    = (EANG-BANG)/DANG+1-NPTBG
C			WHERE NPTBG=NBG OR 2*NBG
C     PANG        = THE 2-THETA OF THE PEAK MAXIMUM
C     PPD         = PULSES PER DEGREE FOR GONIOMETER STEPPER MOTOR
C     RATE        = THE MOVE RATE IN DEGREES PER MINUTE
C     SCONC       = CONCENTRATION OF STANDARD FOR A STANDARD RUN
C     SIMTIM      = COUNT TIME CALCULATION VARIABLE
C     TANG        = THE TARGET ANGLE OF THE CURRENT OR NEXT MOVE
C     TEANG       = TRUE ENDING ANGLE OF SCAN
C     TIME        = THE COUNT TIME PER POINT (IN SECONDS)
C     TIME1	  = SAVES TIME FOR MULTIPLE REPITIONS
C     TIMLIM      = THE MAXIMUM TIME TO COUNT A LINE IN MINUTES
C                   (IE THE SUM OF THE TOTAL BACKGROUND AND PEAK TIMES)
C
C     CONC        = CONCENTRATION OF ADDED STANDARD FOR SPIKING METHOD
C                   OR CONCENTRATION OF INTERNAL STANDARD.
C     MOUNT	  = THE CURRENT NUMBER OF TIMES A SAMPLE HAS BEEN
C                   MOUNTED IN THE PRESENT RUN (.LE.IFLAG(6)).
C     LPK         = THE SEQUENTIAL NUMBER OF THE PEAK FROM THE RUN
C                   FILE CURRENTLY BEING DETERMINED
C     NUM         = THE SEQUENCE NUMBERS OF THE LINES FROM THE
C                   RUN FILE TO BE DETERMINED FOR THIS UNKNOWN SAMPLE
C     IREP       = THE CURRENT REPITION NUMBER FOR THE PRESENT MOUNT
C                   (.LE.IFLAG(5)).
C
C     NMFIL(15)   = NAME OF THE OUTPUT FILE
C     NREC        = NUMBER OF RECORDS WRITTEN ON THE OUTPUT FILE
C     IENRN(5)    = ESTIMATED TIME OF END OF RUN
C
C
C    IOFF         = FLAG FOR USE OR NONUSE OF TEMPERATURE MONITORS
C                    = 0  CONTINUE TO READ TEMPERATURE
C                    = 1  DO NOT READ TEMPERATURE
C    ITEMP        >  0  100 TIMES THE TEMPERATURE IN DEGREES CENTIGRADE
C                 =  0  TEMPERATURE READING TURNED OFF (IOFF=1)
C                 = -1 64BIT I/O CARD NOT OPERATIONAL
C                 = -2 OMEGA 410A+002A DID NOT RESPOND TO DATA REQUEST
C                 = -3 OMEGA 410A+002A OVERFLOW BIT SET
C***********************************************************************
C
C
      INCLUDE 'COMMON.FTN'
C Calls SYINIT, SYTIME, RUNFIL, QUANT, DEBUGF, EXIT
C
C======================================================================
C
C	START HERE
C
C  System specific initialization:
C  Assign units 5 & 6 to the terminal, & get the current date.
C
	CALL SYINIT
C
C  Write program heading and current date & time
C
	CALL SYTIME
	WRITE(ITYP,1000) ITIM,IDAT
1000	FORMAT(19X,'**  AUTO  **',/,
     &    ' A DATA COLLECTION PROGRAM FOR QUANTITIVE ANALYSIS',/,
     &    9X,'VERSION: AU3 VAX February 22, 1988 ',/,/
     &    ' Program started at',
     &    I3,':',I2.2,':',I2.2,' on ',I2,'/',I2,'/',I2.2,/)
C     &    I3,':',I2,':',I2,' on ',I2,'/',I2,'/',I2,/)
C
	GOTO 9000	! Print menu
C
C======================================================================
C
C   MAIN MENU -- GET AN OPTION AND BRANCH TO APPROPRIATE ROUTINE
C
C   Prompt for option
C
2000	WRITE(ITYP,2004)
2004	FORMAT(/,/,' Enter option number <0 for help>:',$)
C
C   Read otion number
C
	READ(IRD,2104,END=9999) IOPT
2104	FORMAT(I)
C
C  Branch to appropriate routine:
C
C 20 = exit
	IF(IOPT.EQ.20) GOTO 9999
C  0 or bad option prints menu     v--
        IF(IOPT.LE.0 .OR. IOPT.GT. 5 ) GOTO 9000
C  1-3 are valid.           This --^ is the highest valid option.
	GOTO (3001,3002,3003,3004,3005),IOPT
C  It should never get here, especially if option # was valid.
	GOTO 9000
C
C
C======================================================================
C
C  CALL SUBROUTINE TO DO OPTION
C
3001	CALL CONFIG
	GOTO 2000
C
3002	CALL RUNFIL
	GOTO 2000
C
3003	CALL QUANT
	GOTO 2000
C
3004	CALL QUAL
	GOTO 2000
C
3005	CALL DEBUGF
	GOTO 2000
C
C
C======================================================================
C
C  PRINT MENU WHEN ASKED OR WHEN INVALID OPTION IS GIVEN
C
C  Bark at invalid options; just print menu for option 0 (help)
C
9000	IF(IOPT.NE.0) WRITE(ITYP,9004)
9004	FORMAT(/,' Invalid option; try again.')
C
	WRITE(ITYP,9014)
9014	FORMAT(' Valid options are:',/,
     &  '    0 - Print this menu',/,
     &  '    1 - Edit configuration file',/,
     &  '    2 - Enter run control parameters (build a runfile)',/,
     &  '    3 - Collect data for quantitative analysis',/,
     &  '    4 - Powder Pattern scan',/,
     &  '    5 - Select rarely used debugging options',/,
     &  '   20 - Exit')
C
	GOTO 2000
C
C
C======================================================================
C
C  ALL DONE FOR TODAY.  SEE YA TOMORROW.
C
9999	WRITE(ITYP,9998)
9998	FORMAT(/,'      **   NORMAL TERMINATION OF AUTO.  ',
     1	'HAVE A NICE DAY.   **')
C
	CALL EXIT
	END
