C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dgsvj1.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__1 = 1;
516 static integer c__0 = 0;
517 static doublereal c_b35 = 1.;
518
519 /* > \brief \b DGSVJ1 pre-processor for the routine dgesvj, applies Jacobi rotations targeting only particular
520  pivots. */
521
522 /*  =========== DOCUMENTATION =========== */
523
524 /* Online html documentation available at */
525 /*            http://www.netlib.org/lapack/explore-html/ */
526
527 /* > \htmlonly */
528 /* > Download DGSVJ1 + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgsvj1.
530 f"> */
531 /* > [TGZ]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgsvj1.
533 f"> */
534 /* > [ZIP]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgsvj1.
536 f"> */
537 /* > [TXT]</a> */
538 /* > \endhtmlonly */
539
540 /*  Definition: */
541 /*  =========== */
542
543 /*       SUBROUTINE DGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV, */
544 /*                          EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO ) */
545
546 /*       DOUBLE PRECISION   EPS, SFMIN, TOL */
547 /*       INTEGER            INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP */
548 /*       CHARACTER*1        JOBV */
549 /*       DOUBLE PRECISION   A( LDA, * ), D( N ), SVA( N ), V( LDV, * ), */
550 /*      $                   WORK( LWORK ) */
551
552
553 /* > \par Purpose: */
554 /*  ============= */
555 /* > */
556 /* > \verbatim */
557 /* > */
558 /* > DGSVJ1 is called from DGESVJ as a pre-processor and that is its main */
559 /* > purpose. It applies Jacobi rotations in the same way as DGESVJ does, but */
560 /* > it targets only particular pivots and it does not check convergence */
561 /* > (stopping criterion). Few tunning parameters (marked by [TP]) are */
562 /* > available for the implementer. */
563 /* > */
564 /* > Further Details */
565 /* > ~~~~~~~~~~~~~~~ */
566 /* > DGSVJ1 applies few sweeps of Jacobi rotations in the column space of */
567 /* > the input M-by-N matrix A. The pivot pairs are taken from the (1,2) */
568 /* > off-diagonal block in the corresponding N-by-N Gram matrix A^T * A. The */
569 /* > block-entries (tiles) of the (1,2) off-diagonal block are marked by the */
570 /* > [x]'s in the following scheme: */
571 /* > */
572 /* >    | *  *  * [x] [x] [x]| */
573 /* >    | *  *  * [x] [x] [x]|    Row-cycling in the nblr-by-nblc [x] blocks. */
574 /* >    | *  *  * [x] [x] [x]|    Row-cyclic pivoting inside each [x] block. */
575 /* >    |[x] [x] [x] *  *  * | */
576 /* >    |[x] [x] [x] *  *  * | */
577 /* >    |[x] [x] [x] *  *  * | */
578 /* > */
579 /* > In terms of the columns of A, the first N1 columns are rotated 'against' */
580 /* > the remaining N-N1 columns, trying to increase the angle between the */
581 /* > corresponding subspaces. The off-diagonal block is N1-by(N-N1) and it is */
582 /* > tiled using quadratic tiles of side KBL. Here, KBL is a tunning parameter. */
583 /* > The number of sweeps is given in NSWEEP and the orthogonality threshold */
584 /* > is given in TOL. */
585 /* > \endverbatim */
586
587 /*  Arguments: */
588 /*  ========== */
589
590 /* > \param[in] JOBV */
591 /* > \verbatim */
592 /* >          JOBV is CHARACTER*1 */
593 /* >          Specifies whether the output from this procedure is used */
594 /* >          to compute the matrix V: */
595 /* >          = 'V': the product of the Jacobi rotations is accumulated */
596 /* >                 by postmulyiplying the N-by-N array V. */
597 /* >                (See the description of V.) */
598 /* >          = 'A': the product of the Jacobi rotations is accumulated */
599 /* >                 by postmulyiplying the MV-by-N array V. */
600 /* >                (See the descriptions of MV and V.) */
601 /* >          = 'N': the Jacobi rotations are not accumulated. */
602 /* > \endverbatim */
603 /* > */
604 /* > \param[in] M */
605 /* > \verbatim */
606 /* >          M is INTEGER */
607 /* >          The number of rows of the input matrix A.  M >= 0. */
608 /* > \endverbatim */
609 /* > */
610 /* > \param[in] N */
611 /* > \verbatim */
612 /* >          N is INTEGER */
613 /* >          The number of columns of the input matrix A. */
614 /* >          M >= N >= 0. */
615 /* > \endverbatim */
616 /* > */
617 /* > \param[in] N1 */
618 /* > \verbatim */
619 /* >          N1 is INTEGER */
620 /* >          N1 specifies the 2 x 2 block partition, the first N1 columns are */
621 /* >          rotated 'against' the remaining N-N1 columns of A. */
622 /* > \endverbatim */
623 /* > */
624 /* > \param[in,out] A */
625 /* > \verbatim */
626 /* >          A is DOUBLE PRECISION array, dimension (LDA,N) */
627 /* >          On entry, M-by-N matrix A, such that A*diag(D) represents */
628 /* >          the input matrix. */
629 /* >          On exit, */
630 /* >          A_onexit * D_onexit represents the input matrix A*diag(D) */
631 /* >          post-multiplied by a sequence of Jacobi rotations, where the */
632 /* >          rotation threshold and the total number of sweeps are given in */
633 /* >          TOL and NSWEEP, respectively. */
634 /* >          (See the descriptions of N1, D, TOL and NSWEEP.) */
635 /* > \endverbatim */
636 /* > */
637 /* > \param[in] LDA */
638 /* > \verbatim */
639 /* >          LDA is INTEGER */
640 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,M). */
641 /* > \endverbatim */
642 /* > */
643 /* > \param[in,out] D */
644 /* > \verbatim */
645 /* >          D is DOUBLE PRECISION array, dimension (N) */
646 /* >          The array D accumulates the scaling factors from the fast scaled */
647 /* >          Jacobi rotations. */
648 /* >          On entry, A*diag(D) represents the input matrix. */
649 /* >          On exit, A_onexit*diag(D_onexit) represents the input matrix */
650 /* >          post-multiplied by a sequence of Jacobi rotations, where the */
651 /* >          rotation threshold and the total number of sweeps are given in */
652 /* >          TOL and NSWEEP, respectively. */
653 /* >          (See the descriptions of N1, A, TOL and NSWEEP.) */
654 /* > \endverbatim */
655 /* > */
656 /* > \param[in,out] SVA */
657 /* > \verbatim */
658 /* >          SVA is DOUBLE PRECISION array, dimension (N) */
659 /* >          On entry, SVA contains the Euclidean norms of the columns of */
660 /* >          the matrix A*diag(D). */
661 /* >          On exit, SVA contains the Euclidean norms of the columns of */
662 /* >          the matrix onexit*diag(D_onexit). */
663 /* > \endverbatim */
664 /* > */
665 /* > \param[in] MV */
666 /* > \verbatim */
667 /* >          MV is INTEGER */
668 /* >          If JOBV = 'A', then MV rows of V are post-multipled by a */
669 /* >                         sequence of Jacobi rotations. */
670 /* >          If JOBV = 'N', then MV is not referenced. */
671 /* > \endverbatim */
672 /* > */
673 /* > \param[in,out] V */
674 /* > \verbatim */
675 /* >          V is DOUBLE PRECISION array, dimension (LDV,N) */
676 /* >          If JOBV = 'V', then N rows of V are post-multipled by a */
677 /* >                         sequence of Jacobi rotations. */
678 /* >          If JOBV = 'A', then MV rows of V are post-multipled by a */
679 /* >                         sequence of Jacobi rotations. */
680 /* >          If JOBV = 'N', then V is not referenced. */
681 /* > \endverbatim */
682 /* > */
683 /* > \param[in] LDV */
684 /* > \verbatim */
685 /* >          LDV is INTEGER */
686 /* >          The leading dimension of the array V,  LDV >= 1. */
687 /* >          If JOBV = 'V', LDV >= N. */
688 /* >          If JOBV = 'A', LDV >= MV. */
689 /* > \endverbatim */
690 /* > */
691 /* > \param[in] EPS */
692 /* > \verbatim */
693 /* >          EPS is DOUBLE PRECISION */
694 /* >          EPS = DLAMCH('Epsilon') */
695 /* > \endverbatim */
696 /* > */
697 /* > \param[in] SFMIN */
698 /* > \verbatim */
699 /* >          SFMIN is DOUBLE PRECISION */
700 /* >          SFMIN = DLAMCH('Safe Minimum') */
701 /* > \endverbatim */
702 /* > */
703 /* > \param[in] TOL */
704 /* > \verbatim */
705 /* >          TOL is DOUBLE PRECISION */
706 /* >          TOL is the threshold for Jacobi rotations. For a pair */
707 /* >          A(:,p), A(:,q) of pivot columns, the Jacobi rotation is */
708 /* >          applied only if DABS(COS(angle(A(:,p),A(:,q)))) > TOL. */
709 /* > \endverbatim */
710 /* > */
711 /* > \param[in] NSWEEP */
712 /* > \verbatim */
713 /* >          NSWEEP is INTEGER */
714 /* >          NSWEEP is the number of sweeps of Jacobi rotations to be */
715 /* >          performed. */
716 /* > \endverbatim */
717 /* > */
718 /* > \param[out] WORK */
719 /* > \verbatim */
720 /* >          WORK is DOUBLE PRECISION array, dimension (LWORK) */
721 /* > \endverbatim */
722 /* > */
723 /* > \param[in] LWORK */
724 /* > \verbatim */
725 /* >          LWORK is INTEGER */
726 /* >          LWORK is the dimension of WORK. LWORK >= M. */
727 /* > \endverbatim */
728 /* > */
729 /* > \param[out] INFO */
730 /* > \verbatim */
731 /* >          INFO is INTEGER */
732 /* >          = 0:  successful exit. */
733 /* >          < 0:  if INFO = -i, then the i-th argument had an illegal value */
734 /* > \endverbatim */
735
736 /*  Authors: */
737 /*  ======== */
738
739 /* > \author Univ. of Tennessee */
740 /* > \author Univ. of California Berkeley */
741 /* > \author Univ. of Colorado Denver */
742 /* > \author NAG Ltd. */
743
744 /* > \date June 2016 */
745
746 /* > \ingroup doubleOTHERcomputational */
747
748 /* > \par Contributors: */
749 /*  ================== */
750 /* > */
751 /* > Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
752
753 /*  ===================================================================== */
754 /* Subroutine */ int dgsvj1_(char *jobv, integer *m, integer *n, integer *n1, 
755         doublereal *a, integer *lda, doublereal *d__, doublereal *sva, 
756         integer *mv, doublereal *v, integer *ldv, doublereal *eps, doublereal 
757         *sfmin, doublereal *tol, integer *nsweep, doublereal *work, integer *
758         lwork, integer *info)
759 {
760     /* System generated locals */
761     integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5, 
762             i__6;
763     doublereal d__1, d__2;
764
765     /* Local variables */
766     integer nblc;
767     doublereal aapp, aapq, aaqq;
768     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
769             integer *);
770     integer nblr, ierr;
771     doublereal bigtheta;
772     integer pskipped;
773     doublereal aapp0;
774     extern doublereal dnrm2_(integer *, doublereal *, integer *);
775     doublereal temp1;
776     integer i__, p, q;
777     doublereal t, large, apoaq, aqoap;
778     extern logical lsame_(char *, char *);
779     doublereal theta, small;
780     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
781             doublereal *, integer *);
782     doublereal fastr[5];
783     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *, 
784             doublereal *, integer *);
785     logical applv, rsvec;
786     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
787             integer *, doublereal *, integer *), drotm_(integer *, doublereal 
788             *, integer *, doublereal *, integer *, doublereal *);
789     logical rotok;
790     doublereal rootsfmin, cs, sn;
791     extern /* Subroutine */ int dlascl_(char *, integer *, integer *, 
792             doublereal *, doublereal *, integer *, integer *, doublereal *, 
793             integer *, integer *);
794     extern integer idamax_(integer *, doublereal *, integer *);
795     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
796     integer ijblsk, swband, blskip;
797     doublereal mxaapq;
798     extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *, 
799             doublereal *, doublereal *);
800     doublereal thsign, mxsinj;
801     integer emptsw, notrot, iswrot, jbc;
802     doublereal big;
803     integer kbl, igl, ibr, jgl, mvl;
804     doublereal rootbig, rooteps;
805     integer rowskip;
806     doublereal roottol;
807
808
809 /*  -- LAPACK computational routine (version 3.8.0) -- */
810 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
811 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
812 /*     June 2016 */
813
814
815 /*  ===================================================================== */
816
817
818 /*     Test the input parameters. */
819
820     /* Parameter adjustments */
821     --sva;
822     --d__;
823     a_dim1 = *lda;
824     a_offset = 1 + a_dim1 * 1;
825     a -= a_offset;
826     v_dim1 = *ldv;
827     v_offset = 1 + v_dim1 * 1;
828     v -= v_offset;
829     --work;
830
831     /* Function Body */
832     applv = lsame_(jobv, "A");
833     rsvec = lsame_(jobv, "V");
834     if (! (rsvec || applv || lsame_(jobv, "N"))) {
835         *info = -1;
836     } else if (*m < 0) {
837         *info = -2;
838     } else if (*n < 0 || *n > *m) {
839         *info = -3;
840     } else if (*n1 < 0) {
841         *info = -4;
842     } else if (*lda < *m) {
843         *info = -6;
844     } else if ((rsvec || applv) && *mv < 0) {
845         *info = -9;
846     } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
847         *info = -11;
848     } else if (*tol <= *eps) {
849         *info = -14;
850     } else if (*nsweep < 0) {
851         *info = -15;
852     } else if (*lwork < *m) {
853         *info = -17;
854     } else {
855         *info = 0;
856     }
857
858 /*     #:( */
859     if (*info != 0) {
860         i__1 = -(*info);
861         xerbla_("DGSVJ1", &i__1, (ftnlen)6);
862         return 0;
863     }
864
865     if (rsvec) {
866         mvl = *n;
867     } else if (applv) {
868         mvl = *mv;
869     }
870     rsvec = rsvec || applv;
871     rooteps = sqrt(*eps);
872     rootsfmin = sqrt(*sfmin);
873     small = *sfmin / *eps;
874     big = 1. / *sfmin;
875     rootbig = 1. / rootsfmin;
876     large = big / sqrt((doublereal) (*m * *n));
877     bigtheta = 1. / rooteps;
878     roottol = sqrt(*tol);
879
880
881 /*     RSVEC = LSAME( JOBV, 'Y' ) */
882
883     emptsw = *n1 * (*n - *n1);
884     notrot = 0;
885     fastr[0] = 0.;
886
887
888     kbl = f2cmin(8,*n);
889     nblr = *n1 / kbl;
890     if (nblr * kbl != *n1) {
891         ++nblr;
892     }
893     nblc = (*n - *n1) / kbl;
894     if (nblc * kbl != *n - *n1) {
895         ++nblc;
896     }
897 /* Computing 2nd power */
898     i__1 = kbl;
899     blskip = i__1 * i__1 + 1;
900 /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
901     rowskip = f2cmin(5,kbl);
902 /* [TP] ROWSKIP is a tuning parameter. */
903     swband = 0;
904 /* [TP] SWBAND is a tuning parameter. It is meaningful and effective */
905 /*     if SGESVJ is used as a computational routine in the preconditioned */
906 /*     Jacobi SVD algorithm SGESVJ. */
907
908
909 /*     | *   *   * [x] [x] [x]| */
910 /*     | *   *   * [x] [x] [x]|    Row-cycling in the nblr-by-nblc [x] blocks. */
911 /*     | *   *   * [x] [x] [x]|    Row-cyclic pivoting inside each [x] block. */
912 /*     |[x] [x] [x] *   *   * | */
913 /*     |[x] [x] [x] *   *   * | */
914 /*     |[x] [x] [x] *   *   * | */
915
916
917     i__1 = *nsweep;
918     for (i__ = 1; i__ <= i__1; ++i__) {
919
920         mxaapq = 0.;
921         mxsinj = 0.;
922         iswrot = 0;
923
924         notrot = 0;
925         pskipped = 0;
926
927         i__2 = nblr;
928         for (ibr = 1; ibr <= i__2; ++ibr) {
929             igl = (ibr - 1) * kbl + 1;
930
931
932 /* ........................................................ */
933 /* ... go to the off diagonal blocks */
934             igl = (ibr - 1) * kbl + 1;
935             i__3 = nblc;
936             for (jbc = 1; jbc <= i__3; ++jbc) {
937                 jgl = *n1 + (jbc - 1) * kbl + 1;
938 /*        doing the block at ( ibr, jbc ) */
939                 ijblsk = 0;
940 /* Computing MIN */
941                 i__5 = igl + kbl - 1;
942                 i__4 = f2cmin(i__5,*n1);
943                 for (p = igl; p <= i__4; ++p) {
944                     aapp = sva[p];
945                     if (aapp > 0.) {
946                         pskipped = 0;
947 /* Computing MIN */
948                         i__6 = jgl + kbl - 1;
949                         i__5 = f2cmin(i__6,*n);
950                         for (q = jgl; q <= i__5; ++q) {
951
952                             aaqq = sva[q];
953                             if (aaqq > 0.) {
954                                 aapp0 = aapp;
955
956
957
958                                 if (aaqq >= 1.) {
959                                     if (aapp >= aaqq) {
960                                         rotok = small * aapp <= aaqq;
961                                     } else {
962                                         rotok = small * aaqq <= aapp;
963                                     }
964                                     if (aapp < big / aaqq) {
965                                         aapq = ddot_(m, &a[p * a_dim1 + 1], &
966                                                 c__1, &a[q * a_dim1 + 1], &
967                                                 c__1) * d__[p] * d__[q] / 
968                                                 aaqq / aapp;
969                                     } else {
970                                         dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
971                                                 work[1], &c__1);
972                                         dlascl_("G", &c__0, &c__0, &aapp, &
973                                                 d__[p], m, &c__1, &work[1], 
974                                                 lda, &ierr);
975                                         aapq = ddot_(m, &work[1], &c__1, &a[q 
976                                                 * a_dim1 + 1], &c__1) * d__[q]
977                                                  / aaqq;
978                                     }
979                                 } else {
980                                     if (aapp >= aaqq) {
981                                         rotok = aapp <= aaqq / small;
982                                     } else {
983                                         rotok = aaqq <= aapp / small;
984                                     }
985                                     if (aapp > small / aaqq) {
986                                         aapq = ddot_(m, &a[p * a_dim1 + 1], &
987                                                 c__1, &a[q * a_dim1 + 1], &
988                                                 c__1) * d__[p] * d__[q] / 
989                                                 aaqq / aapp;
990                                     } else {
991                                         dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
992                                                 work[1], &c__1);
993                                         dlascl_("G", &c__0, &c__0, &aaqq, &
994                                                 d__[q], m, &c__1, &work[1], 
995                                                 lda, &ierr);
996                                         aapq = ddot_(m, &work[1], &c__1, &a[p 
997                                                 * a_dim1 + 1], &c__1) * d__[p]
998                                                  / aapp;
999                                     }
1000                                 }
1001 /* Computing MAX */
1002                                 d__1 = mxaapq, d__2 = abs(aapq);
1003                                 mxaapq = f2cmax(d__1,d__2);
1004 /*        TO rotate or NOT to rotate, THAT is the question ... */
1005
1006                                 if (abs(aapq) > *tol) {
1007                                     notrot = 0;
1008 /*           ROTATED  = ROTATED + 1 */
1009                                     pskipped = 0;
1010                                     ++iswrot;
1011
1012                                     if (rotok) {
1013
1014                                         aqoap = aaqq / aapp;
1015                                         apoaq = aapp / aaqq;
1016                                         theta = (d__1 = aqoap - apoaq, abs(
1017                                                 d__1)) * -.5 / aapq;
1018                                         if (aaqq > aapp0) {
1019                                             theta = -theta;
1020                                         }
1021                                         if (abs(theta) > bigtheta) {
1022                                             t = .5 / theta;
1023                                             fastr[2] = t * d__[p] / d__[q];
1024                                             fastr[3] = -t * d__[q] / d__[p];
1025                                             drotm_(m, &a[p * a_dim1 + 1], &
1026                                                     c__1, &a[q * a_dim1 + 1], 
1027                                                     &c__1, fastr);
1028                                             if (rsvec) {
1029                           drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1030                                   v_dim1 + 1], &c__1, fastr);
1031                                             }
1032 /* Computing MAX */
1033                                             d__1 = 0., d__2 = t * apoaq * 
1034                                                     aapq + 1.;
1035                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
1036                                                     d__2)));
1037 /* Computing MAX */
1038                                             d__1 = 0., d__2 = 1. - t * aqoap *
1039                                                      aapq;
1040                                             aapp *= sqrt((f2cmax(d__1,d__2)));
1041 /* Computing MAX */
1042                                             d__1 = mxsinj, d__2 = abs(t);
1043                                             mxsinj = f2cmax(d__1,d__2);
1044                                         } else {
1045
1046
1047                                             thsign = -d_sign(&c_b35, &aapq);
1048                                             if (aaqq > aapp0) {
1049                           thsign = -thsign;
1050                                             }
1051                                             t = 1. / (theta + thsign * sqrt(
1052                                                     theta * theta + 1.));
1053                                             cs = sqrt(1. / (t * t + 1.));
1054                                             sn = t * cs;
1055 /* Computing MAX */
1056                                             d__1 = mxsinj, d__2 = abs(sn);
1057                                             mxsinj = f2cmax(d__1,d__2);
1058 /* Computing MAX */
1059                                             d__1 = 0., d__2 = t * apoaq * 
1060                                                     aapq + 1.;
1061                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
1062                                                     d__2)));
1063 /* Computing MAX */
1064                                             d__1 = 0., d__2 = 1. - t * aqoap *
1065                                                      aapq;
1066                                             aapp *= sqrt((f2cmax(d__1,d__2)));
1067                                             apoaq = d__[p] / d__[q];
1068                                             aqoap = d__[q] / d__[p];
1069                                             if (d__[p] >= 1.) {
1070
1071                           if (d__[q] >= 1.) {
1072                               fastr[2] = t * apoaq;
1073                               fastr[3] = -t * aqoap;
1074                               d__[p] *= cs;
1075                               d__[q] *= cs;
1076                               drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q * 
1077                                       a_dim1 + 1], &c__1, fastr);
1078                               if (rsvec) {
1079                                   drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
1080                                           q * v_dim1 + 1], &c__1, fastr);
1081                               }
1082                           } else {
1083                               d__1 = -t * aqoap;
1084                               daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
1085                                       p * a_dim1 + 1], &c__1);
1086                               d__1 = cs * sn * apoaq;
1087                               daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
1088                                       q * a_dim1 + 1], &c__1);
1089                               if (rsvec) {
1090                                   d__1 = -t * aqoap;
1091                                   daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
1092                                           c__1, &v[p * v_dim1 + 1], &c__1);
1093                                   d__1 = cs * sn * apoaq;
1094                                   daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
1095                                           c__1, &v[q * v_dim1 + 1], &c__1);
1096                               }
1097                               d__[p] *= cs;
1098                               d__[q] /= cs;
1099                           }
1100                                             } else {
1101                           if (d__[q] >= 1.) {
1102                               d__1 = t * apoaq;
1103                               daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
1104                                       q * a_dim1 + 1], &c__1);
1105                               d__1 = -cs * sn * aqoap;
1106                               daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
1107                                       p * a_dim1 + 1], &c__1);
1108                               if (rsvec) {
1109                                   d__1 = t * apoaq;
1110                                   daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
1111                                           c__1, &v[q * v_dim1 + 1], &c__1);
1112                                   d__1 = -cs * sn * aqoap;
1113                                   daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
1114                                           c__1, &v[p * v_dim1 + 1], &c__1);
1115                               }
1116                               d__[p] /= cs;
1117                               d__[q] *= cs;
1118                           } else {
1119                               if (d__[p] >= d__[q]) {
1120                                   d__1 = -t * aqoap;
1121                                   daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, 
1122                                           &a[p * a_dim1 + 1], &c__1);
1123                                   d__1 = cs * sn * apoaq;
1124                                   daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, 
1125                                           &a[q * a_dim1 + 1], &c__1);
1126                                   d__[p] *= cs;
1127                                   d__[q] /= cs;
1128                                   if (rsvec) {
1129                                       d__1 = -t * aqoap;
1130                                       daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], 
1131                                               &c__1, &v[p * v_dim1 + 1], &
1132                                               c__1);
1133                                       d__1 = cs * sn * apoaq;
1134                                       daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], 
1135                                               &c__1, &v[q * v_dim1 + 1], &
1136                                               c__1);
1137                                   }
1138                               } else {
1139                                   d__1 = t * apoaq;
1140                                   daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, 
1141                                           &a[q * a_dim1 + 1], &c__1);
1142                                   d__1 = -cs * sn * aqoap;
1143                                   daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, 
1144                                           &a[p * a_dim1 + 1], &c__1);
1145                                   d__[p] /= cs;
1146                                   d__[q] *= cs;
1147                                   if (rsvec) {
1148                                       d__1 = t * apoaq;
1149                                       daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], 
1150                                               &c__1, &v[q * v_dim1 + 1], &
1151                                               c__1);
1152                                       d__1 = -cs * sn * aqoap;
1153                                       daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], 
1154                                               &c__1, &v[p * v_dim1 + 1], &
1155                                               c__1);
1156                                   }
1157                               }
1158                           }
1159                                             }
1160                                         }
1161                                     } else {
1162                                         if (aapp > aaqq) {
1163                                             dcopy_(m, &a[p * a_dim1 + 1], &
1164                                                     c__1, &work[1], &c__1);
1165                                             dlascl_("G", &c__0, &c__0, &aapp, 
1166                                                     &c_b35, m, &c__1, &work[1]
1167                                                     , lda, &ierr);
1168                                             dlascl_("G", &c__0, &c__0, &aaqq, 
1169                                                     &c_b35, m, &c__1, &a[q * 
1170                                                     a_dim1 + 1], lda, &ierr);
1171                                             temp1 = -aapq * d__[p] / d__[q];
1172                                             daxpy_(m, &temp1, &work[1], &c__1,
1173                                                      &a[q * a_dim1 + 1], &
1174                                                     c__1);
1175                                             dlascl_("G", &c__0, &c__0, &c_b35,
1176                                                      &aaqq, m, &c__1, &a[q * 
1177                                                     a_dim1 + 1], lda, &ierr);
1178 /* Computing MAX */
1179                                             d__1 = 0., d__2 = 1. - aapq * 
1180                                                     aapq;
1181                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
1182                                                     d__2)));
1183                                             mxsinj = f2cmax(mxsinj,*sfmin);
1184                                         } else {
1185                                             dcopy_(m, &a[q * a_dim1 + 1], &
1186                                                     c__1, &work[1], &c__1);
1187                                             dlascl_("G", &c__0, &c__0, &aaqq, 
1188                                                     &c_b35, m, &c__1, &work[1]
1189                                                     , lda, &ierr);
1190                                             dlascl_("G", &c__0, &c__0, &aapp, 
1191                                                     &c_b35, m, &c__1, &a[p * 
1192                                                     a_dim1 + 1], lda, &ierr);
1193                                             temp1 = -aapq * d__[q] / d__[p];
1194                                             daxpy_(m, &temp1, &work[1], &c__1,
1195                                                      &a[p * a_dim1 + 1], &
1196                                                     c__1);
1197                                             dlascl_("G", &c__0, &c__0, &c_b35,
1198                                                      &aapp, m, &c__1, &a[p * 
1199                                                     a_dim1 + 1], lda, &ierr);
1200 /* Computing MAX */
1201                                             d__1 = 0., d__2 = 1. - aapq * 
1202                                                     aapq;
1203                                             sva[p] = aapp * sqrt((f2cmax(d__1,
1204                                                     d__2)));
1205                                             mxsinj = f2cmax(mxsinj,*sfmin);
1206                                         }
1207                                     }
1208 /*           END IF ROTOK THEN ... ELSE */
1209
1210 /*           In the case of cancellation in updating SVA(q) */
1211 /* Computing 2nd power */
1212                                     d__1 = sva[q] / aaqq;
1213                                     if (d__1 * d__1 <= rooteps) {
1214                                         if (aaqq < rootbig && aaqq > 
1215                                                 rootsfmin) {
1216                                             sva[q] = dnrm2_(m, &a[q * a_dim1 
1217                                                     + 1], &c__1) * d__[q];
1218                                         } else {
1219                                             t = 0.;
1220                                             aaqq = 1.;
1221                                             dlassq_(m, &a[q * a_dim1 + 1], &
1222                                                     c__1, &t, &aaqq);
1223                                             sva[q] = t * sqrt(aaqq) * d__[q];
1224                                         }
1225                                     }
1226 /* Computing 2nd power */
1227                                     d__1 = aapp / aapp0;
1228                                     if (d__1 * d__1 <= rooteps) {
1229                                         if (aapp < rootbig && aapp > 
1230                                                 rootsfmin) {
1231                                             aapp = dnrm2_(m, &a[p * a_dim1 + 
1232                                                     1], &c__1) * d__[p];
1233                                         } else {
1234                                             t = 0.;
1235                                             aapp = 1.;
1236                                             dlassq_(m, &a[p * a_dim1 + 1], &
1237                                                     c__1, &t, &aapp);
1238                                             aapp = t * sqrt(aapp) * d__[p];
1239                                         }
1240                                         sva[p] = aapp;
1241                                     }
1242 /*              end of OK rotation */
1243                                 } else {
1244                                     ++notrot;
1245 /*           SKIPPED  = SKIPPED  + 1 */
1246                                     ++pskipped;
1247                                     ++ijblsk;
1248                                 }
1249                             } else {
1250                                 ++notrot;
1251                                 ++pskipped;
1252                                 ++ijblsk;
1253                             }
1254 /*      IF ( NOTROT .GE. EMPTSW )  GO TO 2011 */
1255                             if (i__ <= swband && ijblsk >= blskip) {
1256                                 sva[p] = aapp;
1257                                 notrot = 0;
1258                                 goto L2011;
1259                             }
1260                             if (i__ <= swband && pskipped > rowskip) {
1261                                 aapp = -aapp;
1262                                 notrot = 0;
1263                                 goto L2203;
1264                             }
1265
1266 /* L2200: */
1267                         }
1268 /*        end of the q-loop */
1269 L2203:
1270                         sva[p] = aapp;
1271
1272                     } else {
1273                         if (aapp == 0.) {
1274 /* Computing MIN */
1275                             i__5 = jgl + kbl - 1;
1276                             notrot = notrot + f2cmin(i__5,*n) - jgl + 1;
1277                         }
1278                         if (aapp < 0.) {
1279                             notrot = 0;
1280                         }
1281 /* **      IF ( NOTROT .GE. EMPTSW )  GO TO 2011 */
1282                     }
1283 /* L2100: */
1284                 }
1285 /*     end of the p-loop */
1286 /* L2010: */
1287             }
1288 /*     end of the jbc-loop */
1289 L2011:
1290 /* 2011 bailed out of the jbc-loop */
1291 /* Computing MIN */
1292             i__4 = igl + kbl - 1;
1293             i__3 = f2cmin(i__4,*n);
1294             for (p = igl; p <= i__3; ++p) {
1295                 sva[p] = (d__1 = sva[p], abs(d__1));
1296 /* L2012: */
1297             }
1298 /* **   IF ( NOTROT .GE. EMPTSW ) GO TO 1994 */
1299 /* L2000: */
1300         }
1301 /* 2000 :: end of the ibr-loop */
1302
1303         if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
1304             sva[*n] = dnrm2_(m, &a[*n * a_dim1 + 1], &c__1) * d__[*n];
1305         } else {
1306             t = 0.;
1307             aapp = 1.;
1308             dlassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
1309             sva[*n] = t * sqrt(aapp) * d__[*n];
1310         }
1311
1312 /*     Additional steering devices */
1313
1314         if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
1315             swband = i__;
1316         }
1317         if (i__ > swband + 1 && mxaapq < (doublereal) (*n) * *tol && (
1318                 doublereal) (*n) * mxaapq * mxsinj < *tol) {
1319             goto L1994;
1320         }
1321
1322         if (notrot >= emptsw) {
1323             goto L1994;
1324         }
1325 /* L1993: */
1326     }
1327 /*     end i=1:NSWEEP loop */
1328 /* #:) Reaching this point means that the procedure has completed the given */
1329 /*     number of sweeps. */
1330     *info = *nsweep - 1;
1331     goto L1995;
1332 L1994:
1333 /* #:) Reaching this point means that during the i-th sweep all pivots were */
1334 /*     below the given threshold, causing early exit. */
1335     *info = 0;
1336 /* #:) INFO = 0 confirms successful iterations. */
1337 L1995:
1338
1339 /*     Sort the vector D */
1340
1341     i__1 = *n - 1;
1342     for (p = 1; p <= i__1; ++p) {
1343         i__2 = *n - p + 1;
1344         q = idamax_(&i__2, &sva[p], &c__1) + p - 1;
1345         if (p != q) {
1346             temp1 = sva[p];
1347             sva[p] = sva[q];
1348             sva[q] = temp1;
1349             temp1 = d__[p];
1350             d__[p] = d__[q];
1351             d__[q] = temp1;
1352             dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
1353             if (rsvec) {
1354                 dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
1355                         c__1);
1356             }
1357         }
1358 /* L5991: */
1359     }
1360
1361     return 0;
1362 } /* dgsvj1_ */
1363