C**********************************************************************
C
	SUBROUTINE QUANT
C
C	MAIN ROUTINE FOR COLLECTING QUANTITIVE DATA.
C
      INCLUDE 'COMMON.FTN'
C Uses IPEAK, MPEAK, IRUN, ITYP, MOUNT, NMOUNT, IREP, NREP.
C Calls QBEGIN, IFLOAD, PASS0, PKSCAN, SYTIME, FINISH
C
C======================================================================
C
C	GET READY TO DO A RUN
C
C   Initialize the interface, Input any last minute information, open files.
C
	CALL QBEGIN( IQUIT)
	IF(NBUG(2).NE.0) CALL STATUS
C
C   User may abort run before it even starts
	IF( IQUIT.NE.0) GOTO 9999
C
C======================================================================
C
C	MAKE THE MEASUREMENTS FOR HOWEVER MANY MOUNTINGS WE ARE SUPPOSED TO
C
	DO 6000, MOUNT=1,NMOUNT
C
C   Start the mounting by rewinding the runfile and skipping the first record.
	 REWIND IRUN
	 READ(IRUN,1004) JUNK
1004	 FORMAT(A1)
C
C   WE NEED A SAMPLE FOR EACH MOUNTING
C
C   Prompt for sample
	WRITE(ITYP,1014) MOUNT, NMOUNT
1014	FORMAT(' READY FOR MOUNTING',I2,' OF',I2)
C
C   Move to a convienient angle and wait for the user to type S to start.
	CALL IFLOAD( IQUIT)
C
C   User may have said E or ^Z to Exit early.
	IF( IQUIT.NE.0) GOTO 9900
C
C  Do preliminary measurements to find peaks and optimize times
C  that will be used for all repitions
	IF(NBUG(2).NE.0) CALL STATUS
	IREP = 0
	CALL PASS0
C
C======================================================================
C
C  LOOP FOR THE REPETITIONS
C
	DO 5000, IREP=1,NREP
	IF(NBUG(2).NE.0) CALL STATUS
C
C   Start the repetition by rewinding the runfile and skipping the first record.
	 REWIND IRUN
	 READ(IRUN,3004) JUNK
3004	 FORMAT(A1)
C
C   Loop to measure peaks.
	 IPEAK=0
4000	  IPEAK = IPEAK + 1
	  IF(IPEAK.GT.MPEAK) GOTO 4900
	  CALL PKSCAN( IEND)
	IF(NBUG(2).NE.0) CALL STATUS
	  IF( IEND.EQ.0) GOTO 4000
C
C======================================================================
C
C  END OF REPETITION, PRINT TIME
4900	CALL SYTIME
	WRITE(ITYP,4904) IREP,NREP,ITIM,IDAT
4904	FORMAT(' END OF REPETITION',I3,' OF',I3,' AT',
     &    I3,':',I2,':',I2,' ON',I3,'/',I2,'/',I2)
C     &    I3,':',I2.2,':',I2.2,' ON',I3,'/',I2,'/',I2.2)
5000	CONTINUE
C
C  END OF MOUNTING
6000	CONTINUE
C
	GOTO 9900
C
C======================================================================
C
C	DATA COLLECTION COMPLETE.  CLEAN UP.
C
9900	CALL FINISH
C
9999	RETURN
	END
