kusano 7d535a
kusano 7d535a
/*  -- translated by f2c (version 19940927).
kusano 7d535a
   You must link the resulting object file with the libraries:
kusano 7d535a
	-lf2c -lm   (in that order)
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
#include "f2c.h"
kusano 7d535a
kusano 7d535a
doublereal dnrm2_(integer *n, doublereal *x, integer *incx)
kusano 7d535a
{
kusano 7d535a
kusano 7d535a
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    integer i__1, i__2;
kusano 7d535a
    doublereal ret_val, d__1;
kusano 7d535a
kusano 7d535a
    /* Builtin functions */
kusano 7d535a
    double sqrt(doublereal);
kusano 7d535a
kusano 7d535a
    /* Local variables */
kusano 7d535a
    static doublereal norm, scale, absxi;
kusano 7d535a
    static integer ix;
kusano 7d535a
    static doublereal ssq;
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*  DNRM2 returns the euclidean norm of a vector via the function   
kusano 7d535a
    name, so that   
kusano 7d535a
kusano 7d535a
       DNRM2 := sqrt( x'*x )   
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
    -- This version written on 25-October-1982.   
kusano 7d535a
       Modified on 14-October-1993 to inline the call to DLASSQ.   
kusano 7d535a
       Sven Hammarling, Nag Ltd.   
kusano 7d535a
kusano 7d535a
kusano 7d535a
    
kusano 7d535a
   Parameter adjustments   
kusano 7d535a
       Function Body */
kusano 7d535a
#define X(I) x[(I)-1]
kusano 7d535a
kusano 7d535a
kusano 7d535a
    if (*n < 1 || *incx < 1) {
kusano 7d535a
	norm = 0.;
kusano 7d535a
    } else if (*n == 1) {
kusano 7d535a
	norm = abs(X(1));
kusano 7d535a
    } else {
kusano 7d535a
	scale = 0.;
kusano 7d535a
	ssq = 1.;
kusano 7d535a
/*        The following loop is equivalent to this call to the LAPACK 
kusano 7d535a
  
kusano 7d535a
          auxiliary routine:   
kusano 7d535a
          CALL DLASSQ( N, X, INCX, SCALE, SSQ ) */
kusano 7d535a
kusano 7d535a
	i__1 = (*n - 1) * *incx + 1;
kusano 7d535a
	i__2 = *incx;
kusano 7d535a
	for (ix = 1; *incx < 0 ? ix >= (*n-1)**incx+1 : ix <= (*n-1)**incx+1; ix += *incx) {
kusano 7d535a
	    if (X(ix) != 0.) {
kusano 7d535a
		absxi = (d__1 = X(ix), abs(d__1));
kusano 7d535a
		if (scale < absxi) {
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
		    d__1 = scale / absxi;
kusano 7d535a
		    ssq = ssq * (d__1 * d__1) + 1.;
kusano 7d535a
		    scale = absxi;
kusano 7d535a
		} else {
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
		    d__1 = absxi / scale;
kusano 7d535a
		    ssq += d__1 * d__1;
kusano 7d535a
		}
kusano 7d535a
	    }
kusano 7d535a
/* L10: */
kusano 7d535a
	}
kusano 7d535a
	norm = scale * sqrt(ssq);
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    ret_val = norm;
kusano 7d535a
    return ret_val;
kusano 7d535a
kusano 7d535a
/*     End of DNRM2. */
kusano 7d535a
kusano 7d535a
} /* dnrm2_ */
kusano 7d535a