File: slartg.c

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,652 kB
  • sloc: cpp: 458,133; ansic: 196,223; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 430; csh: 220; perl: 193; xml: 20
file content (281 lines) | stat: -rw-r--r-- 8,455 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* lapack/single/slartg.f -- translated by f2c (version 20050501).
   You must link the resulting object file with libf2c:
        on Microsoft Windows system, link with libf2c.lib;
        on Linux or Unix systems, link with .../path/to/libf2c.a -lm
        or, if you install libf2c.a in a standard place, with -lf2c -lm
        -- in that order, at the end of the command line, as in
                cc *.o -lf2c -lm
        Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,

                http://www.netlib.org/f2c/libf2c.zip
*/

#ifdef __cplusplus
extern "C" {
#endif
#include "v3p_netlib.h"

/* Initialization function just calls the function once so that its
   runtime-initialized constants are initialized.  After the first
   call it is safe to call the function from multiple threads at
   once.  */
void v3p_netlib_slartg_init()
{
  real f=0, g=0, cs=0, sn=0, r=0;
  slartg_(&f, &g, &cs, &sn, &r);
}

/*<       SUBROUTINE SLARTG( F, G, CS, SN, R ) >*/
/* Subroutine */ int slartg_(real *f, real *g, real *cs, real *sn, real *r__)
{
    /* Initialized data */

    static logical first = TRUE_; /* runtime-initialized constant */

    /* System generated locals */
    integer i__1;
    real r__1, r__2;

    /* Builtin functions */
    double log(doublereal), pow_ri(real *, integer *), sqrt(doublereal);

    /* Local variables */
    integer i__;
    real f1, g1, eps, scale;
    integer count;
    static real safmn2, safmx2; /* runtime-initialized constant */
    extern doublereal slamch_(char *, ftnlen);
    static real safmin; /* runtime-initialized constant */


/*  -- LAPACK auxiliary routine (version 3.0) -- */
/*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
/*     Courant Institute, Argonne National Lab, and Rice University */
/*     September 30, 1994 */

/*     .. Scalar Arguments .. */
/*<       REAL               CS, F, G, R, SN >*/
/*     .. */

/*  Purpose */
/*  ======= */

/*  SLARTG generate a plane rotation so that */

/*     [  CS  SN  ]  .  [ F ]  =  [ R ]   where CS**2 + SN**2 = 1. */
/*     [ -SN  CS  ]     [ G ]     [ 0 ] */

/*  This is a slower, more accurate version of the BLAS1 routine SROTG, */
/*  with the following other differences: */
/*     F and G are unchanged on return. */
/*     If G=0, then CS=1 and SN=0. */
/*     If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any */
/*        floating point operations (saves work in SBDSQR when */
/*        there are zeros on the diagonal). */

/*  If F exceeds G in magnitude, CS will be positive. */

/*  Arguments */
/*  ========= */

/*  F       (input) REAL */
/*          The first component of vector to be rotated. */

/*  G       (input) REAL */
/*          The second component of vector to be rotated. */

/*  CS      (output) REAL */
/*          The cosine of the rotation. */

/*  SN      (output) REAL */
/*          The sine of the rotation. */

/*  R       (output) REAL */
/*          The nonzero component of the rotated vector. */

/*  ===================================================================== */

/*     .. Parameters .. */
/*<       REAL               ZERO >*/
/*<       PARAMETER          ( ZERO = 0.0E0 ) >*/
/*<       REAL               ONE >*/
/*<       PARAMETER          ( ONE = 1.0E0 ) >*/
/*<       REAL               TWO >*/
/*<       PARAMETER          ( TWO = 2.0E0 ) >*/
/*     .. */
/*     .. Local Scalars .. */
/*<       LOGICAL            FIRST >*/
/*<       INTEGER            COUNT, I >*/
/*<       REAL               EPS, F1, G1, SAFMIN, SAFMN2, SAFMX2, SCALE >*/
/*     .. */
/*     .. External Functions .. */
/*<       REAL               SLAMCH >*/
/*<       EXTERNAL           SLAMCH >*/
/*     .. */
/*     .. Intrinsic Functions .. */
/*<       INTRINSIC          ABS, INT, LOG, MAX, SQRT >*/
/*     .. */
/*     .. Save statement .. */
/*<       SAVE               FIRST, SAFMX2, SAFMIN, SAFMN2 >*/
/*     .. */
/*     .. Data statements .. */
/*<       DATA               FIRST / .TRUE. / >*/
/*     .. */
/*     .. Executable Statements .. */

/*<       IF( FIRST ) THEN >*/
    if (first) {
/*<          FIRST = .FALSE. >*/
        first = FALSE_;
/*<          SAFMIN = SLAMCH( 'S' ) >*/
        safmin = slamch_("S", (ftnlen)1);
/*<          EPS = SLAMCH( 'E' ) >*/
        eps = slamch_("E", (ftnlen)1);
/*<    >*/
        r__1 = slamch_("B", (ftnlen)1);
        i__1 = (integer) (log(safmin / eps) / log(slamch_("B", (ftnlen)1)) / (
                float)2.);
        safmn2 = pow_ri(&r__1, &i__1);
/*<          SAFMX2 = ONE / SAFMN2 >*/
        safmx2 = (float)1. / safmn2;
/*<       END IF >*/
    }
/*<       IF( G.EQ.ZERO ) THEN >*/
    if (*g == (float)0.) {
/*<          CS = ONE >*/
        *cs = (float)1.;
/*<          SN = ZERO >*/
        *sn = (float)0.;
/*<          R = F >*/
        *r__ = *f;
/*<       ELSE IF( F.EQ.ZERO ) THEN >*/
    } else if (*f == (float)0.) {
/*<          CS = ZERO >*/
        *cs = (float)0.;
/*<          SN = ONE >*/
        *sn = (float)1.;
/*<          R = G >*/
        *r__ = *g;
/*<       ELSE >*/
    } else {
/*<          F1 = F >*/
        f1 = *f;
/*<          G1 = G >*/
        g1 = *g;
/*<          SCALE = MAX( ABS( F1 ), ABS( G1 ) ) >*/
/* Computing MAX */
        r__1 = dabs(f1), r__2 = dabs(g1);
        scale = dmax(r__1,r__2);
/*<          IF( SCALE.GE.SAFMX2 ) THEN >*/
        if (scale >= safmx2) {
/*<             COUNT = 0 >*/
            count = 0;
/*<    10       CONTINUE >*/
L10:
/*<             COUNT = COUNT + 1 >*/
            ++count;
/*<             F1 = F1*SAFMN2 >*/
            f1 *= safmn2;
/*<             G1 = G1*SAFMN2 >*/
            g1 *= safmn2;
/*<             SCALE = MAX( ABS( F1 ), ABS( G1 ) ) >*/
/* Computing MAX */
            r__1 = dabs(f1), r__2 = dabs(g1);
            scale = dmax(r__1,r__2);
/*<    >*/
            if (scale >= safmx2) {
                goto L10;
            }
/*<             R = SQRT( F1**2+G1**2 ) >*/
/* Computing 2nd power */
            r__1 = f1;
/* Computing 2nd power */
            r__2 = g1;
            *r__ = sqrt(r__1 * r__1 + r__2 * r__2);
/*<             CS = F1 / R >*/
            *cs = f1 / *r__;
/*<             SN = G1 / R >*/
            *sn = g1 / *r__;
/*<             DO 20 I = 1, COUNT >*/
            i__1 = count;
            for (i__ = 1; i__ <= i__1; ++i__) {
/*<                R = R*SAFMX2 >*/
                *r__ *= safmx2;
/*<    20       CONTINUE >*/
/* L20: */
            }
/*<          ELSE IF( SCALE.LE.SAFMN2 ) THEN >*/
        } else if (scale <= safmn2) {
/*<             COUNT = 0 >*/
            count = 0;
/*<    30       CONTINUE >*/
L30:
/*<             COUNT = COUNT + 1 >*/
            ++count;
/*<             F1 = F1*SAFMX2 >*/
            f1 *= safmx2;
/*<             G1 = G1*SAFMX2 >*/
            g1 *= safmx2;
/*<             SCALE = MAX( ABS( F1 ), ABS( G1 ) ) >*/
/* Computing MAX */
            r__1 = dabs(f1), r__2 = dabs(g1);
            scale = dmax(r__1,r__2);
/*<    >*/
            if (scale <= safmn2) {
                goto L30;
            }
/*<             R = SQRT( F1**2+G1**2 ) >*/
/* Computing 2nd power */
            r__1 = f1;
/* Computing 2nd power */
            r__2 = g1;
            *r__ = sqrt(r__1 * r__1 + r__2 * r__2);
/*<             CS = F1 / R >*/
            *cs = f1 / *r__;
/*<             SN = G1 / R >*/
            *sn = g1 / *r__;
/*<             DO 40 I = 1, COUNT >*/
            i__1 = count;
            for (i__ = 1; i__ <= i__1; ++i__) {
/*<                R = R*SAFMN2 >*/
                *r__ *= safmn2;
/*<    40       CONTINUE >*/
/* L40: */
            }
/*<          ELSE >*/
        } else {
/*<             R = SQRT( F1**2+G1**2 ) >*/
/* Computing 2nd power */
            r__1 = f1;
/* Computing 2nd power */
            r__2 = g1;
            *r__ = sqrt(r__1 * r__1 + r__2 * r__2);
/*<             CS = F1 / R >*/
            *cs = f1 / *r__;
/*<             SN = G1 / R >*/
            *sn = g1 / *r__;
/*<          END IF >*/
        }
/*<          IF( ABS( F ).GT.ABS( G ) .AND. CS.LT.ZERO ) THEN >*/
        if (dabs(*f) > dabs(*g) && *cs < (float)0.) {
/*<             CS = -CS >*/
            *cs = -(*cs);
/*<             SN = -SN >*/
            *sn = -(*sn);
/*<             R = -R >*/
            *r__ = -(*r__);
/*<          END IF >*/
        }
/*<       END IF >*/
    }
/*<       RETURN >*/
    return 0;

/*     End of SLARTG */

/*<       END >*/
} /* slartg_ */

#ifdef __cplusplus
        }
#endif