      DOUBLE PRECISION FUNCTION C05NCT(N,X)
C     MARK 9 RELEASE.  NAG COPYRIGHT 1981
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     **********
C
C     FUNCTION C05NCT
C
C     GIVEN AN N-VECTOR X, THIS FUNCTION CALCULATES THE
C     EUCLIDEAN NORM OF X.
C
C     THE EUCLIDEAN NORM IS COMPUTED BY ACCUMULATING THE SUM OF
C     SQUARES IN THREE DIFFERENT SUMS. THE SUMS OF SQUARES FOR THE
C     SMALL AND LARGE COMPONENTS ARE SCALED SO THAT NO OVERFLOWS
C     OCCUR. NON-DESTRUCTIVE UNDERFLOWS ARE PERMITTED. UNDERFLOWS
C     AND OVERFLOWS DO NOT OCCUR IN THE COMPUTATION OF THE UNSCALED
C     SUM OF SQUARES FOR THE INTERMEDIATE COMPONENTS.
C     THE DEFINITIONS OF SMALL, INTERMEDIATE AND LARGE COMPONENTS
C     DEPEND ON TWO CONSTANTS, RDWARF AND RGIANT. THE MAIN
C     RESTRICTIONS ON THESE CONSTANTS ARE THAT RDWARF**2 NOT
C     UNDERFLOW AND RGIANT**2 NOT OVERFLOW. THE CONSTANTS
C     GIVEN HERE ARE SUITABLE FOR EVERY KNOWN COMPUTER.
C
C     THE FUNCTION STATEMENT IS
C
C     REAL FUNCTION C05NCT(N,X)
C
C     WHERE
C
C     N IS A POSITIVE INTEGER INPUT VARIABLE.
C
C     X IS AN INPUT ARRAY OF LENGTH N.
C
C     ARGONNE NATIONAL LABORATORY. MINPACK PROJECT. MARCH 1980.
C     BURTON S. GARBOW, KENNETH E. HILLSTROM, JORGE J. MORE
C
C     **********
C     .. Scalar Arguments ..
      INTEGER                          N
C     .. Array Arguments ..
      DOUBLE PRECISION                 X(N)
C     .. Local Scalars ..
      DOUBLE PRECISION                 AGIANT, FLOATN, ONE, RDWARF,
     *                                 RGIANT, S1, S2, S3, X1MAX, X3MAX,
     *                                 XABS, ZERO
      INTEGER                          I
C     .. Intrinsic Functions ..
      INTRINSIC                        ABS, SQRT
C     .. Data statements ..
      DATA                             ONE, ZERO, RDWARF, RGIANT/1.0D0,
     *                                 0.0D0, 1.0D-19, 1.304D19/
C     .. Executable Statements ..
      S1 = ZERO
      S2 = ZERO
      S3 = ZERO
      X1MAX = ZERO
      X3MAX = ZERO
      FLOATN = N
      AGIANT = RGIANT/FLOATN
      DO 180 I = 1, N
         XABS = ABS(X(I))
         IF (XABS.GT.RDWARF .AND. XABS.LT.AGIANT) GO TO 140
         IF (XABS.LE.RDWARF) GO TO 60
C
C        SUM FOR LARGE COMPONENTS.
C
         IF (XABS.LE.X1MAX) GO TO 20
         S1 = ONE + S1*(X1MAX/XABS)**2
         X1MAX = XABS
         GO TO 40
   20    CONTINUE
         S1 = S1 + (XABS/X1MAX)**2
   40    CONTINUE
         GO TO 120
   60    CONTINUE
C
C        SUM FOR SMALL COMPONENTS.
C
         IF (XABS.LE.X3MAX) GO TO 80
         S3 = ONE + S3*(X3MAX/XABS)**2
         X3MAX = XABS
         GO TO 100
   80    CONTINUE
         IF (XABS.NE.ZERO) S3 = S3 + (XABS/X3MAX)**2
  100    CONTINUE
  120    CONTINUE
         GO TO 160
  140    CONTINUE
C
C        SUM FOR INTERMEDIATE COMPONENTS.
C
         S2 = S2 + XABS**2
  160    CONTINUE
  180 CONTINUE
C
C     CALCULATION OF NORM.
C
      IF (S1.EQ.ZERO) GO TO 200
      C05NCT = X1MAX*SQRT(S1+(S2/X1MAX)/X1MAX)
      GO TO 260
  200 CONTINUE
      IF (S2.EQ.ZERO) GO TO 220
      IF (S2.GE.X3MAX) C05NCT = SQRT(S2*(ONE+(X3MAX/S2)*(X3MAX*S3)))
      IF (S2.LT.X3MAX) C05NCT = SQRT(X3MAX*((S2/X3MAX)+(X3MAX*S3)))
      GO TO 240
  220 CONTINUE
      C05NCT = X3MAX*SQRT(S3)
  240 CONTINUE
  260 CONTINUE
      RETURN
      END
