        SUBROUTINE CDCLIN (
*
*  inputs
*
     :                          X, Y, NPTS,
*
*  outputs
*
     :                          COEFF, NCOEFF, NVAR, STATUS)
*
*  Module number:
*
*  Module name:
*
*  Keyphrase:
*  ----------
*  Get initial coefficients for circle least square fitting.
*
*  Description:
*  ------------
*
*  FORTRAN name: CDCLIN.FOR
*
*  Keywords of accessed files and tables:
*  --------------------------------------
*  Name                         I/O     Description / Comments
*       None
*
*  Subroutines Called:
*  -------------------
*  CDBS:
*       None
*  SDAS:
*       UMSPUT
*  Others:
*       None
*
*  History:
*  --------
*  Version      Date        Author          Description
*     1       01-20-87     J.-C. HSU        design and coding
*     2       05-20-87     J.-C. HSU        f77 SDAS
*-------------------------------------------------------------------------------
*
*== inputs:
*                                       --X and Y arrays
        REAL                    X(1), Y(1)
*                                       --total number of input data points
        INTEGER                 NPTS
*
*== outputs:
*                                       --(initial) coefficients
        DOUBLE PRECISION        COEFF(*)
*                                       --number of coefficients and variables
        INTEGER                 NCOEFF, NVAR,
*                                       --error status
     :                          STATUS
*
*== local:
*                                       --maximum and minimum of X and Y
        REAL                    XMIN, XMAX, YMIN, YMAX
*                                       --loop index
        INTEGER                 I,
*                                       --error status
     :                          STATOK
*                                       --error message context
        CHARACTER*130           CONTXT, MESS
*=========================begin hsp.inc=========================================
*                                       --status return code
        INTEGER         OK, ERRNUM(20)
        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/
*                                       --message destination and priority
        DATA DEST, PRIO /1, 0/
*=========================end hsp.inc===========================================
*------------------------------------------------------------------------------
*
*  initialize
*
        NVAR = 2
        NCOEFF = 3
*
*  check if there is enough data points
*
        IF (NPTS .LE. NCOEFF) THEN
            STATUS = ERRNUM(1)
            CONTXT = 'number is input data points is no more than '
     :                  // 'the number of coefficients'
            GO TO 999
        END IF
*
*  find maximum and minimum of X and Y
*
        XMIN = X(1)
        XMAX = X(1)
        YMIN = Y(1)
        YMAX = Y(1)
*
        DO 10 I = 2, NPTS
            IF (X(I) .LT. XMIN) THEN
                XMIN = X(I)
            ELSE IF (X(I) .GT. XMAX) THEN
                XMAX = X(I)
            END IF
*
            IF (Y(I) .LT. YMIN) THEN
                YMIN = Y(I)
            ELSE IF (Y(I) .GT. YMAX) THEN
                YMAX = Y(I)
            END IF
   10   CONTINUE
*
*  take the geometric mean of maximum extensions of X and Y as initial value
*  of DIAMETER, this will NOT work well for arcs
*
        COEFF(3) = DBLE(SQRT((YMAX - YMIN) * (XMAX - XMIN)) / 2.)
*
*  set initial center coordinate at (0, 0), this is OK if the points have
*  been shifted to the origin of mean coordinates
*
        COEFF(1) = 0.D0
        COEFF(2) = 0.D0
*
        STATUS = OK
        GO TO 1000
*
  999   MESS = 'CDCLIN: ' // CONTXT
        CALL UMSPUT (MESS, DEST, PRIO,    STATOK)
*
 1000   RETURN
        END
