        SUBROUTINE VDTGT (
*
*  outputs
*
     :                  X, Y, XERR, YERR, TEMP, EPOCH, NPTS,
     :                  WTFLAG, ITER, TOLERN, FRAC,
     :                  HIVOLT, DISCR, DETID,
     :                  OFILE, STATUS)
*
*  Module number: 15.5.2.1
*
*  Module name: deadtimev
*
*  Keyphrase:
*  ----------
*  Input parameters and data needed for dead time calibration
*
*  Description:
*  ------------
*
*  FORTRAN name: VDTGT.FOR
*
*  Keywords of accessed files and tables:
*  --------------------------------------
*  Name                         I/O     Description / Comments
*
*       CL parameters:
*
*  'intable'                     I      input table name
*  'outtable'                    I      output table name
*  'xweight'                     I      weighting scheme of X axis
*  'yweight'                     I      weighting scheme of Y axis
*  'itermax'                     I      maximum number of iterations
*  'tolern'                      I      tolerance of sigma-squared difference
*                                       during least square iterations
*  'frac'                        I      specified fraction applied to the
*                                       coefficients modification
*
*       input table column names:
*
*  'DOBJ'                        I      digital count rate 
*  'DOBJ_ERR'                    I      mean error of digital count rate
*  'AOBJ_C'                      I      analog count rate 
*  'AOBJ_ERR_C'                  I      mean error of analog count rate
*  'VOLTAGE'                     I      high voltage setting
*  'THRESH'                      I      discriminator threshold setting
*  'DET_TEMP'                    I      detector temperature
*  'DETECTOB'                    I      object detector
*  'EPOCH'                       I      epoch
*
*  Subroutines Called:
*  -------------------
*  CDBS:
*       CDTIN, VDTCR
*  SDAS:
*       UCLGSR, UCLGST, UTRGTR, UTRGTD, UTRGTT, UTTCLO, UMSPUT
*  Others:
*       None
*
*  History:
*  --------
*  Version      Date        Author          Description
*     1       11-15-85     J.-C. HSU        design and coding
*     2       08-20-87     J.-C. HSU        F77 standard
*     3       10-24-89     J.-C. HSU        error propagation
*-------------------------------------------------------------------------------
*
*== output:
*                                       --temperature of each observation
        REAL                    TEMP(1),
*                                       --weighting scheme
     :                          WTFLAG(*),
*                                       --tolerance of sigma-squared differnce
*                                       --during least square iterations
     :                          TOLERN,
*                                       --specified fraction applied to
*                                       --coefficients modification
     :                          FRAC,
*                                       --high voltage, gain setting, and
*                                       --discriminator threshold setting
     :                          HIVOLT, DISCR
*                                       --Y quantity (digital count rate) and
*                                       --its standard deviation
        DOUBLE PRECISION        Y(1), YERR(1),
*                                       --X quantity (analog count rate) and
*                                       --its standard deviation
     :                          X(1), XERR(1),
*                                       --epoch
     :                          EPOCH(1)
*                                       --output file name
        CHARACTER*(*)           OFILE
*                                       --total number of valid input data points
        INTEGER                 NPTS,
*                                       --maximum number of least square iteration
     :                          ITER,
*                                       --detector ID
     :                          DETID,
*                                       --error status
     :                          STATUS
*
*== local:
*                                       --number of input data points
        INTEGER                 NROWS,
*                                       --pointer of table descripter and column
*                                       --identifier
     :                          TP, COLIDN(20),
*                                       --loop indices, number of input columns
     :                          I, J, NCOLS,
*                                       --detector ID
     :                          DET,
*                                       --status
     :                          STAT(20), STATOK
*                                       --data buffer
        REAL                    COLBUF(20),
*                                       --high voltage setting and discriminator
*                                       --threshold setting
     :                          HV, DISC
*                                       --column names
        CHARACTER*16            COLNAM(20)
*                                       --null flag in UTRGTR
        LOGICAL                 NULMSK(20)
        CHARACTER*5             CHAR5
*                                       --input file name
        CHARACTER*128           IFILE
*                                       --error message context
        CHARACTER*130           CONTXT, MESS
*=========================begin hsp.inc=========================================
*                                       --status return code
        INTEGER         OK, ERRNUM(20)
*                                       --message destination and priority
        INTEGER         DEST, PRIO
        DATA OK /0/
        DATA ERRNUM /701, 702, 703, 704, 705, 706, 707, 708, 709, 710,
     :               711, 712, 713, 714, 715, 716, 717, 718, 719, 720/
        DATA DEST, PRIO /1, 0/
*=========================end hsp.inc===========================================
*------------------------------------------------------------------------------
*
*  input CL parameters:
*
        CALL UCLGST ('intable',         IFILE, STAT(1))
        CALL UCLGST ('outtable',        OFILE, STAT(2))
        CALL UCLGSI ('itermax',         ITER, STAT(3))
        CALL UCLGSR ('tolern',          TOLERN, STAT(4))
        CALL UCLGSR ('frac',            FRAC, STAT(5))
        CALL UCLGSR ('xweight',         WTFLAG(1), STAT(6))
        CALL UCLGSR ('yweight',         WTFLAG(2), STAT(7))
*
        DO 10 I = 1, 7
            IF (STAT(I) .NE. OK) THEN
                STATUS = ERRNUM(1)
                CONTXT = 'can not get CL parameter(s)'
                GO TO 999
            END IF
   10   CONTINUE
*
*  set up input column names
*
        COLNAM(1) = 'DOBJ'
        COLNAM(2) = 'DOBJ_ERR'
        COLNAM(3) = 'AOBJ_C'
        COLNAM(4) = 'AOBJ_ERR_C'
        COLNAM(5) = 'VOLTAGE'
        COLNAM(6) = 'THRESH'
        COLNAM(7) = 'DET_TEMP'
        COLNAM(8) = 'DETECTOB'
        COLNAM(9) = 'EPOCH'
        NCOLS = 9
*
*  calculate corrected count rates
*
        CALL VDTCR (IFILE,     STATUS)
        IF (STATUS .NE. OK) THEN
            CONTXT = 'cannot calculate corrected count rates'
            GO TO 999
        END IF
*
*  set up the input table
*
        CALL CDTIN (IFILE, COLNAM, NCOLS,   TP, COLIDN, NROWS, STATUS)
        IF (STATUS .NE. OK) THEN
            CONTXT = 'error setting up input table'
            GO TO 999
        END IF
*
*  read data from the input table, row by row
*
        NPTS = 0
        DO 40 I = 1, NROWS
            CALL UTRGTR (TP, COLIDN(1), 7, I,   COLBUF(1), NULMSK(1), 
     :                   STAT(1))
            CALL UTRGTI (TP, COLIDN(8), 1, I,   DET, NULMSK(8), 
     :                   STAT(2))
            CALL UTRGTD (TP, COLIDN(9), 1, I,   EPOCH(I), NULMSK(9), 
     :                   STAT(3))
*
            STATOK = OK
            STATOK = ABS(STAT(1) - OK) + ABS(STAT(2) - OK) +
     :                  ABS(STAT(3) - OK) + OK
            DO 20 J = 1, NCOLS
                IF (NULMSK(J)) THEN
                    STATOK = ERRNUM(2)
                    GO TO 30
                END IF
   20       CONTINUE
*
*  if error in UTRGTR, put an error message and do NOT increment the data array
*  index
*
   30       WRITE(CHAR5, '(I5)') I
            IF (STATOK .NE. OK) THEN
                CONTXT = 'can not read input table row #' // CHAR5
                CALL UMSPUT (CONTXT, DEST, PRIO,     STATOK)
            ELSE
                NPTS = NPTS + 1
                Y(NPTS) = DBLE(COLBUF(1))
                YERR(NPTS) = DBLE(COLBUF(2))
                X(NPTS) = DBLE(COLBUF(3))
                XERR(NPTS) = DBLE(COLBUF(4))
                HV = COLBUF(5)
                DISC = COLBUF(6)
                TEMP(NPTS) = COLBUF(7)
                EPOCH(NPTS) = EPOCH(I)
                IF (NPTS .EQ. 1) THEN
                    DETID = DET
                    DISCR = DISC
                    HIVOLT = HV
                END IF
*
*  check attributes (high voltage, detector ID, discriminator threshold setting,
*  skip the data if they are different from the first data point
*
                IF (DET .NE. DETID   .OR.   DISC .NE. DISCR   .OR.
     :                  HV .NE. HIVOLT) THEN
                    CONTXT = 'different attribute(s) in row #' // CHAR5
                    CALL UMSPUT (CONTXT, DEST, PRIO,     STATOK)
                    NPTS = NPTS - 1
                END IF
            END IF
   40   CONTINUE
*
*  close input table
*
        CALL UTTCLO (TP,     STATUS)
        IF (STATUS .NE. OK) THEN
            CONTXT = 'cannot close input table'
            GO TO 999
        END IF
*
*  check if there is any valid data
*
        IF (NPTS .LE. 0) THEN
            STATUS = ERRNUM(3)
            CONTXT = 'no valid input data'
            GO TO 999
        END IF
*
        STATUS = OK
        GO TO 1000
*
*  write error message
*
  999   MESS = 'VDTGT: ' // CONTXT
        CALL UMSPUT (MESS, DEST, PRIO,     STATOK)
*
 1000   RETURN
        END
