kusano 7d535a
#include "f2c.h"
kusano 7d535a
kusano 7d535a
/* Subroutine */ int slartg_(real *f, real *g, real *cs, real *sn, real *r)
kusano 7d535a
{
kusano 7d535a
/*  -- LAPACK auxiliary routine (version 2.0) --   
kusano 7d535a
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
kusano 7d535a
       Courant Institute, Argonne National Lab, and Rice University   
kusano 7d535a
       September 30, 1994   
kusano 7d535a
kusano 7d535a
kusano 7d535a
    Purpose   
kusano 7d535a
    =======   
kusano 7d535a
kusano 7d535a
    SLARTG generate a plane rotation so that   
kusano 7d535a
kusano 7d535a
       [  CS  SN  ]  .  [ F ]  =  [ R ]   where CS**2 + SN**2 = 1.   
kusano 7d535a
       [ -SN  CS  ]     [ G ]     [ 0 ]   
kusano 7d535a
kusano 7d535a
    This is a slower, more accurate version of the BLAS1 routine SROTG,   
kusano 7d535a
    with the following other differences:   
kusano 7d535a
       F and G are unchanged on return.   
kusano 7d535a
       If G=0, then CS=1 and SN=0.   
kusano 7d535a
       If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any   
kusano 7d535a
          floating point operations (saves work in SBDSQR when   
kusano 7d535a
          there are zeros on the diagonal).   
kusano 7d535a
kusano 7d535a
    If F exceeds G in magnitude, CS will be positive.   
kusano 7d535a
kusano 7d535a
    Arguments   
kusano 7d535a
    =========   
kusano 7d535a
kusano 7d535a
    F       (input) REAL   
kusano 7d535a
            The first component of vector to be rotated.   
kusano 7d535a
kusano 7d535a
    G       (input) REAL   
kusano 7d535a
            The second component of vector to be rotated.   
kusano 7d535a
kusano 7d535a
    CS      (output) REAL   
kusano 7d535a
            The cosine of the rotation.   
kusano 7d535a
kusano 7d535a
    SN      (output) REAL   
kusano 7d535a
            The sine of the rotation.   
kusano 7d535a
kusano 7d535a
    R       (output) REAL   
kusano 7d535a
            The nonzero component of the rotated vector.   
kusano 7d535a
kusano 7d535a
    ===================================================================== 
kusano 7d535a
*/
kusano 7d535a
    /* Initialized data */
kusano 7d535a
    static logical first = TRUE_;
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    integer i__1;
kusano 7d535a
    real r__1, r__2;
kusano 7d535a
    /* Builtin functions */
kusano 7d535a
    double log(doublereal), pow_ri(real *, integer *), sqrt(doublereal);
kusano 7d535a
    /* Local variables */
kusano 7d535a
    static integer i;
kusano 7d535a
    static real scale;
kusano 7d535a
    static integer count;
kusano 7d535a
    static real f1, g1, safmn2, safmx2;
kusano 7d535a
    extern float slamch_(char *);
kusano 7d535a
    static real safmin, eps;
kusano 7d535a
kusano 7d535a
kusano 7d535a
    if (first) {
kusano 7d535a
	first = FALSE_;
kusano 7d535a
	safmin = slamch_("S");
kusano 7d535a
	eps = slamch_("E");
kusano 7d535a
	r__1 = slamch_("B");
kusano 7d535a
	i__1 = (integer) (log(safmin / eps) / log(slamch_("B")) / 2.f);
kusano 7d535a
	safmn2 = pow_ri(&r__1, &i__1);
kusano 7d535a
	safmx2 = 1.f / safmn2;
kusano 7d535a
    }
kusano 7d535a
    if (*g == 0.f) {
kusano 7d535a
	*cs = 1.f;
kusano 7d535a
	*sn = 0.f;
kusano 7d535a
	*r = *f;
kusano 7d535a
    } else if (*f == 0.f) {
kusano 7d535a
	*cs = 0.f;
kusano 7d535a
	*sn = 1.f;
kusano 7d535a
	*r = *g;
kusano 7d535a
    } else {
kusano 7d535a
	f1 = *f;
kusano 7d535a
	g1 = *g;
kusano 7d535a
/* Computing MAX */
kusano 7d535a
	r__1 = dabs(f1), r__2 = dabs(g1);
kusano 7d535a
	scale = dmax(r__1,r__2);
kusano 7d535a
	if (scale >= safmx2) {
kusano 7d535a
	    count = 0;
kusano 7d535a
L10:
kusano 7d535a
	    ++count;
kusano 7d535a
	    f1 *= safmn2;
kusano 7d535a
	    g1 *= safmn2;
kusano 7d535a
/* Computing MAX */
kusano 7d535a
	    r__1 = dabs(f1), r__2 = dabs(g1);
kusano 7d535a
	    scale = dmax(r__1,r__2);
kusano 7d535a
	    if (scale >= safmx2) {
kusano 7d535a
		goto L10;
kusano 7d535a
	    }
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
	    r__1 = f1;
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
	    r__2 = g1;
kusano 7d535a
	    *r = sqrt(r__1 * r__1 + r__2 * r__2);
kusano 7d535a
	    *cs = f1 / *r;
kusano 7d535a
	    *sn = g1 / *r;
kusano 7d535a
	    i__1 = count;
kusano 7d535a
	    for (i = 1; i <= count; ++i) {
kusano 7d535a
		*r *= safmx2;
kusano 7d535a
/* L20: */
kusano 7d535a
	    }
kusano 7d535a
	} else if (scale <= safmn2) {
kusano 7d535a
	    count = 0;
kusano 7d535a
L30:
kusano 7d535a
	    ++count;
kusano 7d535a
	    f1 *= safmx2;
kusano 7d535a
	    g1 *= safmx2;
kusano 7d535a
/* Computing MAX */
kusano 7d535a
	    r__1 = dabs(f1), r__2 = dabs(g1);
kusano 7d535a
	    scale = dmax(r__1,r__2);
kusano 7d535a
	    if (scale <= safmn2) {
kusano 7d535a
		goto L30;
kusano 7d535a
	    }
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
	    r__1 = f1;
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
	    r__2 = g1;
kusano 7d535a
	    *r = sqrt(r__1 * r__1 + r__2 * r__2);
kusano 7d535a
	    *cs = f1 / *r;
kusano 7d535a
	    *sn = g1 / *r;
kusano 7d535a
	    i__1 = count;
kusano 7d535a
	    for (i = 1; i <= count; ++i) {
kusano 7d535a
		*r *= safmn2;
kusano 7d535a
/* L40: */
kusano 7d535a
	    }
kusano 7d535a
	} else {
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
	    r__1 = f1;
kusano 7d535a
/* Computing 2nd power */
kusano 7d535a
	    r__2 = g1;
kusano 7d535a
	    *r = sqrt(r__1 * r__1 + r__2 * r__2);
kusano 7d535a
	    *cs = f1 / *r;
kusano 7d535a
	    *sn = g1 / *r;
kusano 7d535a
	}
kusano 7d535a
	if (dabs(*f) > dabs(*g) && *cs < 0.f) {
kusano 7d535a
	    *cs = -(doublereal)(*cs);
kusano 7d535a
	    *sn = -(doublereal)(*sn);
kusano 7d535a
	    *r = -(doublereal)(*r);
kusano 7d535a
	}
kusano 7d535a
    }
kusano 7d535a
    return 0;
kusano 7d535a
kusano 7d535a
/*     End of SLARTG */
kusano 7d535a
kusano 7d535a
} /* slartg_ */
kusano 7d535a