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
real snrm2_(integer *n, real *x, integer *incx)
kusano 7d535a
{
kusano 7d535a
kusano 7d535a
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    integer i__1, i__2;
kusano 7d535a
    real ret_val, r__1;
kusano 7d535a
kusano 7d535a
    /* Builtin functions */
kusano 7d535a
    double sqrt(doublereal);
kusano 7d535a
kusano 7d535a
    /* Local variables */
kusano 7d535a
    static real norm, scale, absxi;
kusano 7d535a
    static integer ix;
kusano 7d535a
    static real ssq;
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*  SNRM2 returns the euclidean norm of a vector via the function   
kusano 7d535a
    name, so that   
kusano 7d535a
kusano 7d535a
       SNRM2 := 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 SLASSQ.   
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.f;
kusano 7d535a
    } else if (*n == 1) {
kusano 7d535a
	norm = dabs(X(1));
kusano 7d535a
    } else {
kusano 7d535a
	scale = 0.f;
kusano 7d535a
	ssq = 1.f;
kusano 7d535a
/*        The following loop is equivalent to this call to the LAPACK 
kusano 7d535a
  
kusano 7d535a
          auxiliary routine:   
kusano 7d535a
          CALL SLASSQ( 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.f) {
kusano 7d535a
		absxi = (r__1 = X(ix), dabs(r__1));
kusano 7d535a
		if (scale < absxi) {
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
		    r__1 = scale / absxi;
kusano 7d535a
		    ssq = ssq * (r__1 * r__1) + 1.f;
kusano 7d535a
		    scale = absxi;
kusano 7d535a
		} else {
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
		    r__1 = absxi / scale;
kusano 7d535a
		    ssq += r__1 * r__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 SNRM2. */
kusano 7d535a
kusano 7d535a
} /* snrm2_ */
kusano 7d535a