CBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
C
C		QUANTITATIVE ANALYSIS COMMAND FILE CREATION
C
	SUBROUTINE RUNFIL
C
C
C***********************************************************************
C
C	DESCRIPTION:
C
C		THIS ROUTINE CREATES A RUN FILE TO DIRECT THE
C	   COLLECTION OF QUANTITATIVE ANALYSIS DATA.
C
C***********************************************************************
C
C	HISTORY:
C
C	  This subroutine was taken from the old, unwieldy version of
C	auto with a few minor changes.
C	  Answers to Yes/No questions can be given in lower case.
C	  Calls to subroutines FILUP, and ALOT have been replaced by
C	some read statements and a call to SYOPEN.
C
C	LATER REVISIONS:
C
C***********************************************************************
C
C  THE FORMAT OF THE RUN FILE IS AS FOLLOWS:
C
C
C  RECORD 1:  TITLE RECORD
C
C  COL   1- 80 TITLE
C  COL  81-100 OPERATOR'S NAME
C  COL 101-106 DATE OF FILE CREATION
C  COL 113-122 IFLAG - RUN OPTION SELECTION FLAGS
C
C
C  RECORD 2: ONE FOR N LINES TO BE ANALYSED (ONE RECORD PER PROFILE)
C
C  COL   1-  7  STARTING ANGLE OF PROFILE OR LOW ANGLE BACKGROUND
C  COL   8- 14  2-THETA OF PEAK MAXIMUM
C  COL  15- 21  ENDING ANGLE OF PROFILE OR HIGH ANGLE BACKGROUND
C  COL  22- 28  STEP WIDTH (NOT USED FOR PEAK COUNTING)
C  COL  29- 32  RATE OF MOTION BETWEEN DATA POINTS (DEGREES/MIN)
C               SET TO 60.0 DEGREES PER MINUTE
C  COL  33- 40  TIMLIM THE MAX TIME TO COUNT A LINE IN MINUTES
C  COL  41- 45  FIXERR THE PERCENT ERROR TO COUNT TO.  IF ZERO
C               A FIXED TIME COUNT WILL BE PERFORMED
C  COL  46- 50  CNTLIM THE MAX NUMBER OF COUNTS TO COLLECT AT A POINT
C  COL  51- 56  THE NAME OF THE PHASE
C  COL  57- 62  THE H K AND L OF THE LINE (3I2)
C  COL  63      KODE DESCRIBING THE TYPE OF LINE BEING ENTERED
C                 = 1 A LINE BELONGING TO THE UNKNOWN PHASE BEING
C                     ANALYSED
C                 = 2 A LINE OF THE INTERNAL STANDARD MATERIAL
C                 = 3 A REFERENCE LINE FROM THE SAMPLE HOLDER
C                 = 4 AN AMORPHOUS HALO LINE. NO BACKGROUND POINTS ARE
C                     TO BE MEASURED.
C  COL  64      IOVLP THE NUMBER OF OTHER LINES OVERLAPPING THIS ONE
C  COL  65      IPK = 0 - STEP SCAN THE PEAK
C                   = 1 - PEAK COUNT MODE
C  COL  66- 67  NPK THE NUMBER OF PEAK POINTS TO MEASURE. IN INTEGRATE
C               SCAN MODE THIS IS NUMBER TO AVERAGE AT MAX FOR PEAK I.
C  COL  68- 69  NBG THE NUMBER OF BACKGROUND POINTS ON EACH SIDE OF PEAK
C  COL  70- 75  RELATIVE INTENSITY OF THE LINE
C  COL  76- 79  STANDARD DEVIATION OF THE RELATIVE INTENSITY
C  COL  80- 88  STANDARD INTENSITY VALUE (I/ISTD OR IPURE OR I/IREF)
C  COL  89- 96  SIGMA OF STANDARD INTENSITY
C  COL  97-104  CONCENTRATION OF ADDED PHASE FOR SPIKING METHOD
C               OR OF REFERENCE PHASE FOR INTERNAL STD METHOD
C  COL 105-111  COUNT TIME AT PEAK POINTS
C  COL 112-118  COUNT TIME AT BACKGROUND POINTS
C  COL 119      IOPTIM = 1 - COUNT IN FIXED TIME OPTIMIZATION MODE
C                      = 2 - COUNT IN FIXED ERROR OPTIMIZATION MODE
C                      = 3 - COUNT WITH CONSTANT TIME FOR ALL STEPS
C  COL 120      ILOC = 0 - INTEGRATE COUNT MODE
C                    = 1 - FOUND PEAK WITHIN .09 DEGREES OF RUNFILE
C                          VALUE
C                    = 2 - FOUND PEAK OUTSIDE .09 DEGREES OF RUNFILE
C                          VALUE
C                    = 3 - FAILED TO LOCATE THE PEAK
C  COL 121-128  WEIGHT FRACTION OF THE STANDARD PHASE FOR INTERNAL
C               STANDARD METHOD OR FOR THE INTENSITY RATIO METHOD THE
C               MU/RO OF THE STANDARD.
C
C
C  RECORD 3: LINE OVERLAP INFORMATION AND CHEMICAL COMPOSITION
C            OF STANDARD LINES WHEN NEEDED
C
C  NOTE: RECORDS 2 AND 3 ARE REPEATED FOR EACH REGION TO BE MEASURED
C
C======================================================================
C
      INCLUDE 'COMMON.FTN'
C Calls SYTIME, SYOPEN.
C
C
C======================================================================
C
C	VARIABLE DECLARATION:
C
	BYTE IBLK
	BYTE IPHASE(6), IPHAS2(6), IPHAS3(6)
C
C  INITILIZE
C
	DATA IBLK/' '/, RATE/60.0/, MVMODE/0/, IOVLP/0/
C
	DATA IPHASE/' ',' ',' ',' ',' ',' '/
	DATA IPHAS2/' ',' ',' ',' ',' ',' '/
	DATA IPHAS3/' ',' ',' ',' ',' ',' '/
C
	DATA OANG1/0.0/, OANG2/0.0/
C
	DATA OINT1/0.0/, OINT2/0.0/
C
	DATA OSIG1/0.0/, OSIG2/0.0/
C
	DATA IH/0/, IK/0/, IL/0/
	DATA IH2/0/, IK2/0/, IL2/0/
	DATA IH3/0/, IK3/0/, IL3/0/
C
C======================================================================
C
C  WRITE OUT THE GREETING
C
	CALL SYTIME
	WRITE(ITYP,1004) ITIM, IDAT
1004	FORMAT(//,'    QUANTITATIVE ANALYSIS COMMAND FILE BUILDING AT '
     1	I2,':',I2,':',I2,' ON ',I2,'/',I2,'/',I2,/)
C     1	I2,':',I2.2,':',I2.2,' ON ',I2,'/',I2.2,'/',I2.2,/)
C
C======================================================================
C
C  INPUT THE NAME OF THE RUN FILE
C
	WRITE(ITYP,1014)
1014	FORMAT(' Enter the name of the run file <.RUN> ? ',$)
	READ(IRD,1024,END=9999) NMRUN
1024	FORMAT(40A1)
C
C  Create the file using .RUN as the default extension.
	CALL SYOPEN(IRUN,NMRUN,'.RUN',1)
C
C  Set flag indicating this is a run file.
	IFLAG(1) = 4
C
C  Enter title information
C
	WRITE(ITYP,1034)
1034	FORMAT(/,' Enter a title for this run file (80 characters max)',/
     &  ' Title? ',$)
	READ(IRD,1044,END=9900) TITLE
1044	FORMAT(20A4)
C
	WRITE(ITYP,1054)
1054	FORMAT(/,' Enter your name (20 characters) ? ',$)
	READ(IRD,1044,END=9900) USER
C
C======================================================================
C
C  WHAT TYPE OF ANALYSIS DOES HE WANT ?
C
C  The default is rel int.
	IDFLT = 4
1000	WRITE(ITYP,1010) IDFLT
1010	FORMAT(/,' METHOD OF ANALYSIS (I1) ? ',/,
     1	'      1 - INTERNAL STANDARD       2 - INTENSITY RATIO',/
     2	'      3 - SPIKING                 4 - REL. INTENSITY',/
     3	'      5 - PROFILE',/,
     4  ' CHOICE <ret=',I1,'> ? ',$)
C
	READ(IRD,1020,END=9999) IFLAG(3)
1020	FORMAT(I1)
C
C  If only a return was input set the default.
	IF (IFLAG(3).EQ.0) IFLAG(3) = IDFLT
C
C  Check for valid option; try again if necessary.
	IF (IFLAG(3).LT.0 .OR. IFLAG(3).GT.5) GOTO 1000
C
C  SET THE RUN TYPE DESCRIPTOR FLAGS IF NECESSARY
C
C  Internal standard & Intensity ratio: we only hand build the standards file
	IF(IFLAG(3).EQ.1 .OR.
     &     IFLAG(3).EQ.2) IFLAG(2) = 2
C Spiking method
	IF(IFLAG(3).EQ.3) IFLAG(2) = 1
C Relative intensity measurement
	IF(IFLAG(3).EQ.4) IFLAG(2) = 3
C Profile measurement (Note: this version of AUTO doesn't do profile meas.)
	IF(IFLAG(3).EQ.5) IFLAG(2) = 0
	IF(IFLAG(3).EQ.5) IFLAG(1) = 5
C
C  IF SPIKING, RELATIVE INTENSITY, OR PROFILE ANALYSIS, THEN
C  CHEMISTRY IS NOT USED
C
	IFLAG(4) = 0
	IF (IFLAG(3).GE.3) GOTO 100
C
	WRITE(ITYP,1030)
1030	FORMAT(//,' WILL CHEMICAL COMPOSITION BE ENTERED (Y/N,ret=N)?',$)
C
	READ(IRD,1040,END=9900) IY
1040	FORMAT(A1)
C
	IF (IY.EQ.'Y' .OR. IY.EQ.'y') IFLAG(4) = 1
C
C======================================================================
C
C  WRITE THE TITLE RECORD (RECORD #1)
C
100	WRITE(IRUN,1045) TITLE,USER,ITIM,IDAT,(IFLAG(I),I=1,4)
1045	FORMAT(20A4,5A4,3I2,3I2,4I1,'000000')
	NREC=1
C
C======================================================================
C
C  ENTER INFORMATION ON EACH LINE
C
	K = 0
200	K = K + 1
210	WRITE(ITYP,1050) K
1050	FORMAT(//' PLEASE ENTER THE FOLLOWING INFORMATION FOR LINE',
     1	' NO. ',I3,//,'   - NAME OF PHASE (BLANK TERMINATES INPUT)'/
     2	'   - H, K, AND L (3(X,I2))'/
     3	'   - SCAN CODE (I1) =0 INTEGRATE, =1 PEAK COUNT'/
     4	'   - LINE CODE (I1) =1 UNKNOWN, =2 STD, =3 REF, =4 AMORPH'/
     5	'   - DESIRED % ERROR (0=FIXED TIME)'/
     6	'   - TIME(MIN) TO COUNT PK + BKG'/
     7	'   - RELATIVE INTENSITY OF THE LINE'/
     8	'   - STANDARD DEVIATION OF RELATIVE INTENSITY'/
     9	'   - STANDARD INTENSITY'/
     *	'   - STANDARD DEVIATION OF STANDARD INTENSITY'//
     1	'          NAME    H  K  L S L ERROR TIME   RELINT  SIG.  ',
     2	'STDINT  SIG.'/
     3	' DEFAULT: ------  0  0  0 0 1  0.0   15.0    0.0   0.0   ',
     4	'  0.0   0.0'/
     5	' FORMAT:  AAAAAA NN NN NN N N NN.NN NNN.N  NNN.NN  N.NN  ',
     6	'NNN.NN  N.NN'/
     7	' --------------------------------------------------------',
     8	'------------'/
     9	' INPUT:   ',$)
C
	READ(IRD,1060,END=400) (IPHASE(I) ,I=1,6),IH,IK,IL,IPK,KODE,
     1	FIXERR,TIMLIM,FREL,STDREL,STD,SIGSTD
1060	FORMAT(6A1,3(X,I2),2(X,I1),X,F5.2,X,F5.1,2(2X,F6.2,2X,F4.2))
C
C======================================================================
C
C  ARE WE FINISHED?
C
	IF (IPHASE(1).EQ.IBLK.AND.IPHASE(2).EQ.IBLK.AND.
     1	IPHASE(3).EQ.IBLK.AND.IPHASE(4).EQ.IBLK.AND.
     2	IPHASE(5).EQ.IBLK.AND.IPHASE(6).EQ.IBLK)
     3	GOTO 400
C
C======================================================================
C
C  SET DEFAULT VALUES
C
	IF (KODE.EQ.0) KODE=1
	IF (TIMLIM.LT.0.01) TIMLIM  = 15.0
C
C======================================================================
C
C  ECHO INPUT
C
	WRITE(ITYP,1070) (IPHASE(I),I=1,6),IH,IK,IL,IPK,KODE,
     1	FIXERR,TIMLIM,FREL,STDREL,STD,SIGSTD
1070	FORMAT(' RESULT:  ',6A1,3(X,I2),2(X,I1),X,F5.2,X,F5.1,
     2	2(2X,F6.2,2X,F4.2))
C
	WRITE(ITYP,1080)
1080	FORMAT(/' IS THIS CORRECT (Y/N,ret=Y) ? ',$)
	READ(IRD,1090,END=200) IY
1090	FORMAT(A1)
	IF (IY.EQ.'N' .OR. IY.EQ.'n') GOTO 210
C
C======================================================================
C
C  REQUEST ANGLE CONTROL INFORMATION FOR THE CURRENT LINE
C
220	WRITE(ITYP,1100) K
1100	FORMAT(//' PLEASE ENTER THE FOLLOWING INFORMATION FOR LINE',
     1	' NO. ',I3,//,'   - PEAK 2-THETA'/
     2	'   - BACKGROUND LOW 2-THETA'/
     3	'   - BACKGROUND HIGH 2THETA'/
     4	'   - STEP WIDTH'/
     5	'   - MAXIMUM COUNTS'/
     6	'   - NUMBER OF PEAK POINTS TO COLLECT'/
     7	'   - NUMBER OF BACKGROUND POINTS TO COLLECT'/
     8	'   - MOVECOUNT METHOD  0 = INDEPENDANT, 1 = SIMULTANEOUS'//
     9	'          PK 2-TH BKGL2TH BKGH2TH STPWDTH CNT MAX #PK  #BKG M'/
     *	' DEFAULT:   0.0     0.0     0.0    0.01   900000.    5   10 0'/
     1	' FORMAT:  NNN.NNN NNN.NNN NNN.NNN NN.NNNN NNNNNN. NNNN NNNN N'/
     2	' ------------------------------------------------------------'/
     3	' INPUT:   ',$)
C
	READ(IRD,1110,END=200) PANGD,BANG,EANG,DANG,CNTLIM,NPK,NBG,MVMODE
1110	FORMAT(3(F7.3,X),F7.4,X,F7.0,X,I4,X,I4,X,I1)
C
C======================================================================
C
C  SET DEFAULT PARAMETERS
C
	IF (DANG.EQ.0.0) DANG = .01
	IF (CNTLIM.LT.1) CNTLIM = 900000.
	IF (NPK.LT.1) NPK = 5
	IF (NBG.LT.1) NBG = 10
	IF (KODE.EQ.4) NBG = 0
C  Note that some interface libraries may not support simultaneous movecount.
	IF (MVMODE.LT.1) MVMODE = 0
C
C======================================================================
C
C  ONLY MOTION TOWARD HIGH ANGLE WILL BE ALLOWED IN INTEGRATE MODE.
C  IN PEAK HEIGHT MODE EITHER ONE OR TWO BACKGROUNDS MAY BE ENTERED
C  IN ANY ORDER
C
	IF ((IPK.NE.0).OR.(EANG.GT.BANG)) GOTO 230
C
	WRITE(ITYP,1120)
1120	FORMAT('  >> ILLEGAL ANGLES << - EANG MUST BE > BANG')
	GOTO 220
C
C  IF NPK IS NOT ODD FORCE IT
C
230	IF ((INT(NPK/2.0)*2).EQ.NPK) NPK=NPK-1
C
C======================================================================
C
C  ECHO INPUT PARAMETERS
C
	WRITE(ITYP,1130) PANGD,BANG,EANG,DANG,CNTLIM,NPK,NBG,MVMODE
1130	FORMAT(' RESULT:  ',3(F7.3,X),F7.4,X,F7.0,X,I4,X,I4,X,I1)
C
	WRITE(ITYP,1140)
1140	FORMAT(/' IS THIS CORRECT (Y/N,ret=Y) ? ',$)
	READ(IRD,1150,END=200) IY
1150	FORMAT(A1)
	IF (IY.EQ.'N' .OR. IY.EQ.'n') GOTO 220
C
C======================================================================
C
C  READ OVERLAPPING LINE INFORMATION - NONE ALLOWED IF SPIKING,
C  RELATIVE INTENSITY, OR PROFILE ARE TO BE PERFORMED.
C
	IF (IFLAG(3).GE.3) GOTO 300
C
	WRITE(ITYP,1200)
1200	FORMAT(//' ENTER THE NUMBER OF LINES WHICH OVERLAP THIS LINE',
     1	'(MAX=2) ? ',$)
C
	READ(IRD,1210,END=200) IOVLP
1210	FORMAT(I1)
C
C======================================================================
C
C  READ THE OVERLAP LINE INFORMATION FOR RECORD 3
C
	IF(IOVLP.EQ.0) GOTO 300
C
240	IF (IFLAG(3).NE.5) GOTO 250
C
	WRITE(ITYP,1220)
1220	FORMAT(//,' ENTER THE FOLLOWING FOR THE OVERLAPPING LINE(S):',//
     1	'   - PHASE NAME'/
     2	'   - H, K, AND, L FOR THE LINE'/
     3	'   - ANGLE LOCATION IN 2-THETA'//
     4	'          NAME1   H  K  L PK1 2TH  NAME2   H  K  L PK2 2TH'/
     5	' DEFAULT: ------  0  0  0   0.0    ------  0  0  0   0.0'/
     6	' FORMAT:  AAAAAA NN NN NN NNN.NNN  AAAAAA NN NN NN NNN.NNN'/
     7	' ---------------------------------------------------'/
     8	' ENTER:   ',$)
C
	READ(IRD,1230,END=200) IPHAS2,IH2,IK2,IL2,OANG2,
     1	IPHAS3,IH3,IK3,IL3,OANG3
1230	FORMAT(2(6A1,3(X,I2),X,F7.3,2X))
C
C  ECHO THE INPUT
C
	WRITE(ITYP,1240) IPHAS2,IH2,IK2,IL2,OANG2,
     1	IPHAS3,IH3,IK3,IL3,OANG3
1240	FORMAT(' RESULT:  ',2(6A1,3(X,I2),X,F7.3,2X))
C
	GOTO 260
C
C======================================================================
C
250	WRITE(ITYP,1250)
1250	FORMAT(//,' ENTER THE FOLLOWING FOR THE OVERLAPPING LINE(S):',//
     1	'   - PHASE NAME'/
     2	'   - H, K, AND, L FOR THE LINE'/
     3	'   - RELATIVE INTENSITY'/
     4	'   - STANDARD DEVIATION OF THE INTENSITY'//
     5	'          NAME1  H K L REL-I SIG   NAME2  H K L REL-I SIG'/
     6	' DEFAULT: ------ 0 0 0 100.0 0.5   ------ 0 0 0 100.0 0.5'/
     7	' FORMAT:  AAAAAA N N N NNN.N N.NN  AAAAAA N N N NNN.N N.NN'/
     8	' ---------------------------------------------------------'/
     9	' ENTER:   ',$)
C
	READ(IRD,1260,END=200) IPHAS2,IH2,IK2,IL2,OINT2,OSIG2,
     1	IPHAS3,IH3,IK3,IL3,OINT3,OSIG3
1260	FORMAT(2(6A1,3(X,I2),X,F5.1,X,F4.2,2X))
C
C  ECHO THE INPUT
C
	WRITE(ITYP,1270) IPHAS2,IH2,IK2,IL2,OINT2,OSIG2,
     1	IPHAS3,IH3,IK3,IL3,OINT3,OSIG3
1270	FORMAT(' RESULT:  ',2(6A1,3(X,I2),X,F5.1,X,F4.2,2X))
C
C  IS EVERYTHING 'HUNKY-DOREY' ?
C
260	WRITE(ITYP,1280)
1280	FORMAT(/' IS THIS CORRECT (Y/N,ret=Y) ? ',$)
	READ(IRD,1290,END=200) IY
1290	FORMAT(A1)
	IF (IY.EQ.'N' .OR. IY.EQ.'n') GOTO 240
C
C======================================================================
C
C  NOW PROCEED TO WRITE RECORD 2 (TYPE 7) OF THE RUN FILE
C
300   WRITE(IRUN,1300) BANG,PANGD,EANG,DANG,
     1	RATE,MVMODE,TIMLIM,FIXERR,
     2	CNTLIM,IPHASE,IH,IK,IL,KODE,IOVLP,IPK,NPK,
     3	NBG,FREL,STDREL,STD,SIGSTD
1300  FORMAT(3F7.3,F7.4,F4.1,I1,F5.1,F5.2,F7.0,6A1,3I2,3I1,2I2,
     1	F6.1,F4.1,F9.4,F8.4)
C
C  THE CHEMICAL ANALYSIS SECTION OF RECORD 3 (TYPE 8) WILL BE SUPPLIED
C  BY THE PROCESSING PROGRAM FROM THE INFO CONTAINED IN RECORD 6
C  AS READ BY QUANT
C
	WRITE(IRUN,1310)
1310	FORMAT(128(' '))
	NREC=NREC+2
C
C  RETURN TO TOP FOR NEXT LINE
C
	GOTO 200
C
C======================================================================
C
C  RUN FILE HAS BEEN WRITTEN TO DISK. WRITE AN END OF FILE AND CLOSE
C
400	ENDFILE IRUN
	CLOSE(UNIT=IRUN)
C
C  PRINT THE SUMMARY MESSAGE
C
	WRITE(ITYP,420) (NMRUN(I),I=1,14),NREC
420	FORMAT(/,'  RUN FILE ',14A1,' CONTAINS ',I3,' RECORDS.')
	GOTO 9999
C
C======================================================================
C
9900	WRITE(ITYP,9904)
9904	FORMAT(' File building aborted.')
	CLOSE(UNIT=IRUN,DISPOSE='DELETE')
C
9999	RETURN
	END
