C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zgesvj.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 doublecomplex c_b1 = {0.,0.};
516 static doublecomplex c_b2 = {1.,0.};
517 static integer c__1 = 1;
518 static integer c__0 = 0;
519 static doublereal c_b42 = 1.;
520 static integer c__2 = 2;
521
522 /* > \brief <b> ZGESVJ </b> */
523
524 /*  =========== DOCUMENTATION =========== */
525
526 /* Online html documentation available at */
527 /*            http://www.netlib.org/lapack/explore-html/ */
528
529 /* > \htmlonly */
530 /* > Download ZGESVJ + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgesvj.
532 f"> */
533 /* > [TGZ]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgesvj.
535 f"> */
536 /* > [ZIP]</a> */
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgesvj.
538 f"> */
539 /* > [TXT]</a> */
540 /* > \endhtmlonly */
541
542 /*  Definition: */
543 /*  =========== */
544
545 /*       SUBROUTINE ZGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V, */
546 /*                          LDV, CWORK, LWORK, RWORK, LRWORK, INFO ) */
547
548 /*       INTEGER            INFO, LDA, LDV, LWORK, LRWORK, M, MV, N */
549 /*       CHARACTER*1        JOBA, JOBU, JOBV */
550 /*       COMPLEX*16         A( LDA, * ),  V( LDV, * ), CWORK( LWORK ) */
551 /*       DOUBLE PRECISION   RWORK( LRWORK ),  SVA( N ) */
552
553
554 /* > \par Purpose: */
555 /*  ============= */
556 /* > */
557 /* > \verbatim */
558 /* > */
559 /* > ZGESVJ computes the singular value decomposition (SVD) of a complex */
560 /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
561 /* >                                    [++]   [xx]   [x0]   [xx] */
562 /* >              A = U * SIGMA * V^*,  [++] = [xx] * [ox] * [xx] */
563 /* >                                    [++]   [xx] */
564 /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
565 /* > matrix, and V is an N-by-N unitary matrix. The diagonal elements */
566 /* > of SIGMA are the singular values of A. The columns of U and V are the */
567 /* > left and the right singular vectors of A, respectively. */
568 /* > \endverbatim */
569
570 /*  Arguments: */
571 /*  ========== */
572
573 /* > \param[in] JOBA */
574 /* > \verbatim */
575 /* >          JOBA is CHARACTER*1 */
576 /* >          Specifies the structure of A. */
577 /* >          = 'L': The input matrix A is lower triangular; */
578 /* >          = 'U': The input matrix A is upper triangular; */
579 /* >          = 'G': The input matrix A is general M-by-N matrix, M >= N. */
580 /* > \endverbatim */
581 /* > */
582 /* > \param[in] JOBU */
583 /* > \verbatim */
584 /* >          JOBU is CHARACTER*1 */
585 /* >          Specifies whether to compute the left singular vectors */
586 /* >          (columns of U): */
587 /* >          = 'U' or 'F': The left singular vectors corresponding to the nonzero */
588 /* >                 singular values are computed and returned in the leading */
589 /* >                 columns of A. See more details in the description of A. */
590 /* >                 The default numerical orthogonality threshold is set to */
591 /* >                 approximately TOL=CTOL*EPS, CTOL=SQRT(M), EPS=DLAMCH('E'). */
592 /* >          = 'C': Analogous to JOBU='U', except that user can control the */
593 /* >                 level of numerical orthogonality of the computed left */
594 /* >                 singular vectors. TOL can be set to TOL = CTOL*EPS, where */
595 /* >                 CTOL is given on input in the array WORK. */
596 /* >                 No CTOL smaller than ONE is allowed. CTOL greater */
597 /* >                 than 1 / EPS is meaningless. The option 'C' */
598 /* >                 can be used if M*EPS is satisfactory orthogonality */
599 /* >                 of the computed left singular vectors, so CTOL=M could */
600 /* >                 save few sweeps of Jacobi rotations. */
601 /* >                 See the descriptions of A and WORK(1). */
602 /* >          = 'N': The matrix U is not computed. However, see the */
603 /* >                 description of A. */
604 /* > \endverbatim */
605 /* > */
606 /* > \param[in] JOBV */
607 /* > \verbatim */
608 /* >          JOBV is CHARACTER*1 */
609 /* >          Specifies whether to compute the right singular vectors, that */
610 /* >          is, the matrix V: */
611 /* >          = 'V' or 'J': the matrix V is computed and returned in the array V */
612 /* >          = 'A':  the Jacobi rotations are applied to the MV-by-N */
613 /* >                  array V. In other words, the right singular vector */
614 /* >                  matrix V is not computed explicitly; instead it is */
615 /* >                  applied to an MV-by-N matrix initially stored in the */
616 /* >                  first MV rows of V. */
617 /* >          = 'N':  the matrix V is not computed and the array V is not */
618 /* >                  referenced */
619 /* > \endverbatim */
620 /* > */
621 /* > \param[in] M */
622 /* > \verbatim */
623 /* >          M is INTEGER */
624 /* >          The number of rows of the input matrix A. 1/DLAMCH('E') > M >= 0. */
625 /* > \endverbatim */
626 /* > */
627 /* > \param[in] N */
628 /* > \verbatim */
629 /* >          N is INTEGER */
630 /* >          The number of columns of the input matrix A. */
631 /* >          M >= N >= 0. */
632 /* > \endverbatim */
633 /* > */
634 /* > \param[in,out] A */
635 /* > \verbatim */
636 /* >          A is COMPLEX*16 array, dimension (LDA,N) */
637 /* >          On entry, the M-by-N matrix A. */
638 /* >          On exit, */
639 /* >          If JOBU = 'U' .OR. JOBU = 'C': */
640 /* >                 If INFO = 0 : */
641 /* >                 RANKA orthonormal columns of U are returned in the */
642 /* >                 leading RANKA columns of the array A. Here RANKA <= N */
643 /* >                 is the number of computed singular values of A that are */
644 /* >                 above the underflow threshold DLAMCH('S'). The singular */
645 /* >                 vectors corresponding to underflowed or zero singular */
646 /* >                 values are not computed. The value of RANKA is returned */
647 /* >                 in the array RWORK as RANKA=NINT(RWORK(2)). Also see the */
648 /* >                 descriptions of SVA and RWORK. The computed columns of U */
649 /* >                 are mutually numerically orthogonal up to approximately */
650 /* >                 TOL=SQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU = 'C'), */
651 /* >                 see the description of JOBU. */
652 /* >                 If INFO > 0, */
653 /* >                 the procedure ZGESVJ did not converge in the given number */
654 /* >                 of iterations (sweeps). In that case, the computed */
655 /* >                 columns of U may not be orthogonal up to TOL. The output */
656 /* >                 U (stored in A), SIGMA (given by the computed singular */
657 /* >                 values in SVA(1:N)) and V is still a decomposition of the */
658 /* >                 input matrix A in the sense that the residual */
659 /* >                 || A - SCALE * U * SIGMA * V^* ||_2 / ||A||_2 is small. */
660 /* >          If JOBU = 'N': */
661 /* >                 If INFO = 0 : */
662 /* >                 Note that the left singular vectors are 'for free' in the */
663 /* >                 one-sided Jacobi SVD algorithm. However, if only the */
664 /* >                 singular values are needed, the level of numerical */
665 /* >                 orthogonality of U is not an issue and iterations are */
666 /* >                 stopped when the columns of the iterated matrix are */
667 /* >                 numerically orthogonal up to approximately M*EPS. Thus, */
668 /* >                 on exit, A contains the columns of U scaled with the */
669 /* >                 corresponding singular values. */
670 /* >                 If INFO > 0: */
671 /* >                 the procedure ZGESVJ did not converge in the given number */
672 /* >                 of iterations (sweeps). */
673 /* > \endverbatim */
674 /* > */
675 /* > \param[in] LDA */
676 /* > \verbatim */
677 /* >          LDA is INTEGER */
678 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,M). */
679 /* > \endverbatim */
680 /* > */
681 /* > \param[out] SVA */
682 /* > \verbatim */
683 /* >          SVA is DOUBLE PRECISION array, dimension (N) */
684 /* >          On exit, */
685 /* >          If INFO = 0 : */
686 /* >          depending on the value SCALE = RWORK(1), we have: */
687 /* >                 If SCALE = ONE: */
688 /* >                 SVA(1:N) contains the computed singular values of A. */
689 /* >                 During the computation SVA contains the Euclidean column */
690 /* >                 norms of the iterated matrices in the array A. */
691 /* >                 If SCALE .NE. ONE: */
692 /* >                 The singular values of A are SCALE*SVA(1:N), and this */
693 /* >                 factored representation is due to the fact that some of the */
694 /* >                 singular values of A might underflow or overflow. */
695 /* > */
696 /* >          If INFO > 0: */
697 /* >          the procedure ZGESVJ did not converge in the given number of */
698 /* >          iterations (sweeps) and SCALE*SVA(1:N) may not be accurate. */
699 /* > \endverbatim */
700 /* > */
701 /* > \param[in] MV */
702 /* > \verbatim */
703 /* >          MV is INTEGER */
704 /* >          If JOBV = 'A', then the product of Jacobi rotations in ZGESVJ */
705 /* >          is applied to the first MV rows of V. See the description of JOBV. */
706 /* > \endverbatim */
707 /* > */
708 /* > \param[in,out] V */
709 /* > \verbatim */
710 /* >          V is COMPLEX*16 array, dimension (LDV,N) */
711 /* >          If JOBV = 'V', then V contains on exit the N-by-N matrix of */
712 /* >                         the right singular vectors; */
713 /* >          If JOBV = 'A', then V contains the product of the computed right */
714 /* >                         singular vector matrix and the initial matrix in */
715 /* >                         the array V. */
716 /* >          If JOBV = 'N', then V is not referenced. */
717 /* > \endverbatim */
718 /* > */
719 /* > \param[in] LDV */
720 /* > \verbatim */
721 /* >          LDV is INTEGER */
722 /* >          The leading dimension of the array V, LDV >= 1. */
723 /* >          If JOBV = 'V', then LDV >= f2cmax(1,N). */
724 /* >          If JOBV = 'A', then LDV >= f2cmax(1,MV) . */
725 /* > \endverbatim */
726 /* > */
727 /* > \param[in,out] CWORK */
728 /* > \verbatim */
729 /* >          CWORK is COMPLEX*16 array, dimension (f2cmax(1,LWORK)) */
730 /* >          Used as workspace. */
731 /* >          If on entry LWORK = -1, then a workspace query is assumed and */
732 /* >          no computation is done; CWORK(1) is set to the minial (and optimal) */
733 /* >          length of CWORK. */
734 /* > \endverbatim */
735 /* > */
736 /* > \param[in] LWORK */
737 /* > \verbatim */
738 /* >          LWORK is INTEGER. */
739 /* >          Length of CWORK, LWORK >= M+N. */
740 /* > \endverbatim */
741 /* > */
742 /* > \param[in,out] RWORK */
743 /* > \verbatim */
744 /* >          RWORK is DOUBLE PRECISION array, dimension (f2cmax(6,LRWORK)) */
745 /* >          On entry, */
746 /* >          If JOBU = 'C' : */
747 /* >          RWORK(1) = CTOL, where CTOL defines the threshold for convergence. */
748 /* >                    The process stops if all columns of A are mutually */
749 /* >                    orthogonal up to CTOL*EPS, EPS=DLAMCH('E'). */
750 /* >                    It is required that CTOL >= ONE, i.e. it is not */
751 /* >                    allowed to force the routine to obtain orthogonality */
752 /* >                    below EPSILON. */
753 /* >          On exit, */
754 /* >          RWORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N) */
755 /* >                    are the computed singular values of A. */
756 /* >                    (See description of SVA().) */
757 /* >          RWORK(2) = NINT(RWORK(2)) is the number of the computed nonzero */
758 /* >                    singular values. */
759 /* >          RWORK(3) = NINT(RWORK(3)) is the number of the computed singular */
760 /* >                    values that are larger than the underflow threshold. */
761 /* >          RWORK(4) = NINT(RWORK(4)) is the number of sweeps of Jacobi */
762 /* >                    rotations needed for numerical convergence. */
763 /* >          RWORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep. */
764 /* >                    This is useful information in cases when ZGESVJ did */
765 /* >                    not converge, as it can be used to estimate whether */
766 /* >                    the output is still useful and for post festum analysis. */
767 /* >          RWORK(6) = the largest absolute value over all sines of the */
768 /* >                    Jacobi rotation angles in the last sweep. It can be */
769 /* >                    useful for a post festum analysis. */
770 /* >         If on entry LRWORK = -1, then a workspace query is assumed and */
771 /* >         no computation is done; RWORK(1) is set to the minial (and optimal) */
772 /* >         length of RWORK. */
773 /* > \endverbatim */
774 /* > */
775 /* > \param[in] LRWORK */
776 /* > \verbatim */
777 /* >         LRWORK is INTEGER */
778 /* >         Length of RWORK, LRWORK >= MAX(6,N). */
779 /* > \endverbatim */
780 /* > */
781 /* > \param[out] INFO */
782 /* > \verbatim */
783 /* >          INFO is INTEGER */
784 /* >          = 0:  successful exit. */
785 /* >          < 0:  if INFO = -i, then the i-th argument had an illegal value */
786 /* >          > 0:  ZGESVJ did not converge in the maximal allowed number */
787 /* >                (NSWEEP=30) of sweeps. The output may still be useful. */
788 /* >                See the description of RWORK. */
789 /* > \endverbatim */
790 /* > */
791 /*  Authors: */
792 /*  ======== */
793
794 /* > \author Univ. of Tennessee */
795 /* > \author Univ. of California Berkeley */
796 /* > \author Univ. of Colorado Denver */
797 /* > \author NAG Ltd. */
798
799 /* > \date June 2016 */
800
801 /* > \ingroup complex16GEcomputational */
802
803 /* > \par Further Details: */
804 /*  ===================== */
805 /* > */
806 /* > \verbatim */
807 /* > */
808 /* > The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane */
809 /* > rotations. In the case of underflow of the tangent of the Jacobi angle, a */
810 /* > modified Jacobi transformation of Drmac [3] is used. Pivot strategy uses */
811 /* > column interchanges of de Rijk [1]. The relative accuracy of the computed */
812 /* > singular values and the accuracy of the computed singular vectors (in */
813 /* > angle metric) is as guaranteed by the theory of Demmel and Veselic [2]. */
814 /* > The condition number that determines the accuracy in the full rank case */
815 /* > is essentially min_{D=diag} kappa(A*D), where kappa(.) is the */
816 /* > spectral condition number. The best performance of this Jacobi SVD */
817 /* > procedure is achieved if used in an  accelerated version of Drmac and */
818 /* > Veselic [4,5], and it is the kernel routine in the SIGMA library [6]. */
819 /* > Some tunning parameters (marked with [TP]) are available for the */
820 /* > implementer. */
821 /* > The computational range for the nonzero singular values is the  machine */
822 /* > number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even */
823 /* > denormalized singular values can be computed with the corresponding */
824 /* > gradual loss of accurate digits. */
825 /* > \endverbatim */
826
827 /* > \par Contributor: */
828 /*  ================== */
829 /* > */
830 /* > \verbatim */
831 /* > */
832 /* >  ============ */
833 /* > */
834 /* >  Zlatko Drmac (Zagreb, Croatia) */
835 /* > */
836 /* > \endverbatim */
837
838 /* > \par References: */
839 /*  ================ */
840 /* > */
841 /* > \verbatim */
842 /* > */
843 /* > [1] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the */
844 /* >    singular value decomposition on a vector computer. */
845 /* >    SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371. */
846 /* > [2] J. Demmel and K. Veselic: Jacobi method is more accurate than QR. */
847 /* > [3] Z. Drmac: Implementation of Jacobi rotations for accurate singular */
848 /* >    value computation in floating point arithmetic. */
849 /* >    SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222. */
850 /* > [4] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. */
851 /* >    SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. */
852 /* >    LAPACK Working note 169. */
853 /* > [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. */
854 /* >    SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. */
855 /* >    LAPACK Working note 170. */
856 /* > [6] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV, */
857 /* >    QSVD, (H,K)-SVD computations. */
858 /* >    Department of Mathematics, University of Zagreb, 2008, 2015. */
859 /* > \endverbatim */
860
861 /* > \par Bugs, examples and comments: */
862 /*  ================================= */
863 /* > */
864 /* > \verbatim */
865 /* >  =========================== */
866 /* >  Please report all bugs and send interesting test examples and comments to */
867 /* >  drmac@math.hr. Thank you. */
868 /* > \endverbatim */
869 /* > */
870 /*  ===================================================================== */
871 /* Subroutine */ int zgesvj_(char *joba, char *jobu, char *jobv, integer *m, 
872         integer *n, doublecomplex *a, integer *lda, doublereal *sva, integer *
873         mv, doublecomplex *v, integer *ldv, doublecomplex *cwork, integer *
874         lwork, doublereal *rwork, integer *lrwork, integer *info)
875 {
876     /* System generated locals */
877     integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5, 
878             i__6;
879     doublereal d__1, d__2;
880     doublecomplex z__1, z__2, z__3;
881
882     /* Local variables */
883     doublereal aapp;
884     doublecomplex aapq;
885     doublereal aaqq, ctol;
886     integer ierr;
887     doublereal bigtheta;
888     doublecomplex ompq;
889     integer pskipped;
890     extern /* Subroutine */ int zrot_(integer *, doublecomplex *, integer *, 
891             doublecomplex *, integer *, doublereal *, doublecomplex *);
892     doublereal aapp0, aapq1, temp1;
893     integer i__, p, q;
894     doublereal t, apoaq, aqoap;
895     extern logical lsame_(char *, char *);
896     doublereal theta, small, sfmin;
897     logical lsvec;
898     doublereal epsln;
899     logical applv, rsvec, uctol;
900     extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *, 
901             doublecomplex *, integer *, doublecomplex *, integer *);
902     logical lower, upper, rotok;
903     integer n2, n4;
904     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
905             doublecomplex *, integer *), zswap_(integer *, doublecomplex *, 
906             integer *, doublecomplex *, integer *), zaxpy_(integer *, 
907             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
908             integer *);
909     doublereal rootsfmin;
910     extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
911     extern /* Subroutine */ int zgsvj0_(char *, integer *, integer *, 
912             doublecomplex *, integer *, doublecomplex *, doublereal *, 
913             integer *, doublecomplex *, integer *, doublereal *, doublereal *,
914              doublereal *, integer *, doublecomplex *, integer *, integer *), zgsvj1_(char *, integer *, integer *, integer *, 
915             doublecomplex *, integer *, doublecomplex *, doublereal *, 
916             integer *, doublecomplex *, integer *, doublereal *, doublereal *,
917              doublereal *, integer *, doublecomplex *, integer *, integer *);
918     integer n34;
919     doublereal cs;
920     extern doublereal dlamch_(char *);
921     doublereal sn;
922     extern /* Subroutine */ int dlascl_(char *, integer *, integer *, 
923             doublereal *, doublereal *, integer *, integer *, doublereal *, 
924             integer *, integer *);
925     extern integer idamax_(integer *, doublereal *, integer *);
926     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
927     integer ijblsk, swband;
928     extern /* Subroutine */ int zdscal_(integer *, doublereal *, 
929             doublecomplex *, integer *);
930     integer blskip;
931     doublereal mxaapq;
932     extern /* Subroutine */ int zlascl_(char *, integer *, integer *, 
933             doublereal *, doublereal *, integer *, integer *, doublecomplex *,
934              integer *, integer *);
935     doublereal thsign;
936     extern /* Subroutine */ int zlaset_(char *, integer *, integer *, 
937             doublecomplex *, doublecomplex *, doublecomplex *, integer *);
938     doublereal mxsinj;
939     integer ir1;
940     extern /* Subroutine */ int zlassq_(integer *, doublecomplex *, integer *,
941              doublereal *, doublereal *);
942     integer emptsw;
943     logical lquery;
944     integer notrot, iswrot, jbc;
945     doublereal big;
946     integer kbl, lkahead, igl, ibr, jgl, nbl;
947     doublereal skl;
948     logical goscale;
949     doublereal tol;
950     integer mvl;
951     logical noscale;
952     doublereal rootbig, rooteps;
953     integer rowskip;
954     doublereal roottol;
955
956
957 /*  -- LAPACK computational routine (version 3.8.0) -- */
958 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
959 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
960 /*     June 2016 */
961
962
963 /*  ===================================================================== */
964
965 /*     from BLAS */
966 /*     from LAPACK */
967 /*     from BLAS */
968 /*     from LAPACK */
969
970 /*     Test the input arguments */
971
972     /* Parameter adjustments */
973     --sva;
974     a_dim1 = *lda;
975     a_offset = 1 + a_dim1 * 1;
976     a -= a_offset;
977     v_dim1 = *ldv;
978     v_offset = 1 + v_dim1 * 1;
979     v -= v_offset;
980     --cwork;
981     --rwork;
982
983     /* Function Body */
984     lsvec = lsame_(jobu, "U") || lsame_(jobu, "F");
985     uctol = lsame_(jobu, "C");
986     rsvec = lsame_(jobv, "V") || lsame_(jobv, "J");
987     applv = lsame_(jobv, "A");
988     upper = lsame_(joba, "U");
989     lower = lsame_(joba, "L");
990
991     lquery = *lwork == -1 || *lrwork == -1;
992     if (! (upper || lower || lsame_(joba, "G"))) {
993         *info = -1;
994     } else if (! (lsvec || uctol || lsame_(jobu, "N"))) 
995             {
996         *info = -2;
997     } else if (! (rsvec || applv || lsame_(jobv, "N"))) 
998             {
999         *info = -3;
1000     } else if (*m < 0) {
1001         *info = -4;
1002     } else if (*n < 0 || *n > *m) {
1003         *info = -5;
1004     } else if (*lda < *m) {
1005         *info = -7;
1006     } else if (*mv < 0) {
1007         *info = -9;
1008     } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
1009         *info = -11;
1010     } else if (uctol && rwork[1] <= 1.) {
1011         *info = -12;
1012     } else if (*lwork < *m + *n && ! lquery) {
1013         *info = -13;
1014     } else if (*lrwork < f2cmax(*n,6) && ! lquery) {
1015         *info = -15;
1016     } else {
1017         *info = 0;
1018     }
1019
1020 /*     #:( */
1021     if (*info != 0) {
1022         i__1 = -(*info);
1023         xerbla_("ZGESVJ", &i__1, (ftnlen)6);
1024         return 0;
1025     } else if (lquery) {
1026         i__1 = *m + *n;
1027         cwork[1].r = (doublereal) i__1, cwork[1].i = 0.;
1028         rwork[1] = (doublereal) f2cmax(*n,6);
1029         return 0;
1030     }
1031
1032 /* #:) Quick return for void matrix */
1033
1034     if (*m == 0 || *n == 0) {
1035         return 0;
1036     }
1037
1038 /*     Set numerical parameters */
1039 /*     The stopping criterion for Jacobi rotations is */
1040
1041 /*     max_{i<>j}|A(:,i)^* * A(:,j)| / (||A(:,i)||*||A(:,j)||) < CTOL*EPS */
1042
1043 /*     where EPS is the round-off and CTOL is defined as follows: */
1044
1045     if (uctol) {
1046 /*        ... user controlled */
1047         ctol = rwork[1];
1048     } else {
1049 /*        ... default */
1050         if (lsvec || rsvec || applv) {
1051             ctol = sqrt((doublereal) (*m));
1052         } else {
1053             ctol = (doublereal) (*m);
1054         }
1055     }
1056 /*     ... and the machine dependent parameters are */
1057 /* [!]  (Make sure that SLAMCH() works properly on the target machine.) */
1058
1059     epsln = dlamch_("Epsilon");
1060     rooteps = sqrt(epsln);
1061     sfmin = dlamch_("SafeMinimum");
1062     rootsfmin = sqrt(sfmin);
1063     small = sfmin / epsln;
1064     big = dlamch_("Overflow");
1065 /*     BIG         = ONE    / SFMIN */
1066     rootbig = 1. / rootsfmin;
1067 /*      LARGE = BIG / SQRT( DBLE( M*N ) ) */
1068     bigtheta = 1. / rooteps;
1069
1070     tol = ctol * epsln;
1071     roottol = sqrt(tol);
1072
1073     if ((doublereal) (*m) * epsln >= 1.) {
1074         *info = -4;
1075         i__1 = -(*info);
1076         xerbla_("ZGESVJ", &i__1, (ftnlen)6);
1077         return 0;
1078     }
1079
1080 /*     Initialize the right singular vector matrix. */
1081
1082     if (rsvec) {
1083         mvl = *n;
1084         zlaset_("A", &mvl, n, &c_b1, &c_b2, &v[v_offset], ldv);
1085     } else if (applv) {
1086         mvl = *mv;
1087     }
1088     rsvec = rsvec || applv;
1089
1090 /*     Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N ) */
1091 /* (!)  If necessary, scale A to protect the largest singular value */
1092 /*     from overflow. It is possible that saving the largest singular */
1093 /*     value destroys the information about the small ones. */
1094 /*     This initial scaling is almost minimal in the sense that the */
1095 /*     goal is to make sure that no column norm overflows, and that */
1096 /*     SQRT(N)*max_i SVA(i) does not overflow. If INFinite entries */
1097 /*     in A are detected, the procedure returns with INFO=-6. */
1098
1099     skl = 1. / sqrt((doublereal) (*m) * (doublereal) (*n));
1100     noscale = TRUE_;
1101     goscale = TRUE_;
1102
1103     if (lower) {
1104 /*        the input matrix is M-by-N lower triangular (trapezoidal) */
1105         i__1 = *n;
1106         for (p = 1; p <= i__1; ++p) {
1107             aapp = 0.;
1108             aaqq = 1.;
1109             i__2 = *m - p + 1;
1110             zlassq_(&i__2, &a[p + p * a_dim1], &c__1, &aapp, &aaqq);
1111             if (aapp > big) {
1112                 *info = -6;
1113                 i__2 = -(*info);
1114                 xerbla_("ZGESVJ", &i__2, (ftnlen)6);
1115                 return 0;
1116             }
1117             aaqq = sqrt(aaqq);
1118             if (aapp < big / aaqq && noscale) {
1119                 sva[p] = aapp * aaqq;
1120             } else {
1121                 noscale = FALSE_;
1122                 sva[p] = aapp * (aaqq * skl);
1123                 if (goscale) {
1124                     goscale = FALSE_;
1125                     i__2 = p - 1;
1126                     for (q = 1; q <= i__2; ++q) {
1127                         sva[q] *= skl;
1128 /* L1873: */
1129                     }
1130                 }
1131             }
1132 /* L1874: */
1133         }
1134     } else if (upper) {
1135 /*        the input matrix is M-by-N upper triangular (trapezoidal) */
1136         i__1 = *n;
1137         for (p = 1; p <= i__1; ++p) {
1138             aapp = 0.;
1139             aaqq = 1.;
1140             zlassq_(&p, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
1141             if (aapp > big) {
1142                 *info = -6;
1143                 i__2 = -(*info);
1144                 xerbla_("ZGESVJ", &i__2, (ftnlen)6);
1145                 return 0;
1146             }
1147             aaqq = sqrt(aaqq);
1148             if (aapp < big / aaqq && noscale) {
1149                 sva[p] = aapp * aaqq;
1150             } else {
1151                 noscale = FALSE_;
1152                 sva[p] = aapp * (aaqq * skl);
1153                 if (goscale) {
1154                     goscale = FALSE_;
1155                     i__2 = p - 1;
1156                     for (q = 1; q <= i__2; ++q) {
1157                         sva[q] *= skl;
1158 /* L2873: */
1159                     }
1160                 }
1161             }
1162 /* L2874: */
1163         }
1164     } else {
1165 /*        the input matrix is M-by-N general dense */
1166         i__1 = *n;
1167         for (p = 1; p <= i__1; ++p) {
1168             aapp = 0.;
1169             aaqq = 1.;
1170             zlassq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
1171             if (aapp > big) {
1172                 *info = -6;
1173                 i__2 = -(*info);
1174                 xerbla_("ZGESVJ", &i__2, (ftnlen)6);
1175                 return 0;
1176             }
1177             aaqq = sqrt(aaqq);
1178             if (aapp < big / aaqq && noscale) {
1179                 sva[p] = aapp * aaqq;
1180             } else {
1181                 noscale = FALSE_;
1182                 sva[p] = aapp * (aaqq * skl);
1183                 if (goscale) {
1184                     goscale = FALSE_;
1185                     i__2 = p - 1;
1186                     for (q = 1; q <= i__2; ++q) {
1187                         sva[q] *= skl;
1188 /* L3873: */
1189                     }
1190                 }
1191             }
1192 /* L3874: */
1193         }
1194     }
1195
1196     if (noscale) {
1197         skl = 1.;
1198     }
1199
1200 /*     Move the smaller part of the spectrum from the underflow threshold */
1201 /* (!)  Start by determining the position of the nonzero entries of the */
1202 /*     array SVA() relative to ( SFMIN, BIG ). */
1203
1204     aapp = 0.;
1205     aaqq = big;
1206     i__1 = *n;
1207     for (p = 1; p <= i__1; ++p) {
1208         if (sva[p] != 0.) {
1209 /* Computing MIN */
1210             d__1 = aaqq, d__2 = sva[p];
1211             aaqq = f2cmin(d__1,d__2);
1212         }
1213 /* Computing MAX */
1214         d__1 = aapp, d__2 = sva[p];
1215         aapp = f2cmax(d__1,d__2);
1216 /* L4781: */
1217     }
1218
1219 /* #:) Quick return for zero matrix */
1220
1221     if (aapp == 0.) {
1222         if (lsvec) {
1223             zlaset_("G", m, n, &c_b1, &c_b2, &a[a_offset], lda);
1224         }
1225         rwork[1] = 1.;
1226         rwork[2] = 0.;
1227         rwork[3] = 0.;
1228         rwork[4] = 0.;
1229         rwork[5] = 0.;
1230         rwork[6] = 0.;
1231         return 0;
1232     }
1233
1234 /* #:) Quick return for one-column matrix */
1235
1236     if (*n == 1) {
1237         if (lsvec) {
1238             zlascl_("G", &c__0, &c__0, &sva[1], &skl, m, &c__1, &a[a_dim1 + 1]
1239                     , lda, &ierr);
1240         }
1241         rwork[1] = 1. / skl;
1242         if (sva[1] >= sfmin) {
1243             rwork[2] = 1.;
1244         } else {
1245             rwork[2] = 0.;
1246         }
1247         rwork[3] = 0.;
1248         rwork[4] = 0.;
1249         rwork[5] = 0.;
1250         rwork[6] = 0.;
1251         return 0;
1252     }
1253
1254 /*     Protect small singular values from underflow, and try to */
1255 /*     avoid underflows/overflows in computing Jacobi rotations. */
1256
1257     sn = sqrt(sfmin / epsln);
1258     temp1 = sqrt(big / (doublereal) (*n));
1259     if (aapp <= sn || aaqq >= temp1 || sn <= aaqq && aapp <= temp1) {
1260 /* Computing MIN */
1261         d__1 = big, d__2 = temp1 / aapp;
1262         temp1 = f2cmin(d__1,d__2);
1263 /*         AAQQ  = AAQQ*TEMP1 */
1264 /*         AAPP  = AAPP*TEMP1 */
1265     } else if (aaqq <= sn && aapp <= temp1) {
1266 /* Computing MIN */
1267         d__1 = sn / aaqq, d__2 = big / (aapp * sqrt((doublereal) (*n)));
1268         temp1 = f2cmin(d__1,d__2);
1269 /*         AAQQ  = AAQQ*TEMP1 */
1270 /*         AAPP  = AAPP*TEMP1 */
1271     } else if (aaqq >= sn && aapp >= temp1) {
1272 /* Computing MAX */
1273         d__1 = sn / aaqq, d__2 = temp1 / aapp;
1274         temp1 = f2cmax(d__1,d__2);
1275 /*         AAQQ  = AAQQ*TEMP1 */
1276 /*         AAPP  = AAPP*TEMP1 */
1277     } else if (aaqq <= sn && aapp >= temp1) {
1278 /* Computing MIN */
1279         d__1 = sn / aaqq, d__2 = big / (sqrt((doublereal) (*n)) * aapp);
1280         temp1 = f2cmin(d__1,d__2);
1281 /*         AAQQ  = AAQQ*TEMP1 */
1282 /*         AAPP  = AAPP*TEMP1 */
1283     } else {
1284         temp1 = 1.;
1285     }
1286
1287 /*     Scale, if necessary */
1288
1289     if (temp1 != 1.) {
1290         dlascl_("G", &c__0, &c__0, &c_b42, &temp1, n, &c__1, &sva[1], n, &
1291                 ierr);
1292     }
1293     skl = temp1 * skl;
1294     if (skl != 1.) {
1295         zlascl_(joba, &c__0, &c__0, &c_b42, &skl, m, n, &a[a_offset], lda, &
1296                 ierr);
1297         skl = 1. / skl;
1298     }
1299
1300 /*     Row-cyclic Jacobi SVD algorithm with column pivoting */
1301
1302     emptsw = *n * (*n - 1) / 2;
1303     notrot = 0;
1304     i__1 = *n;
1305     for (q = 1; q <= i__1; ++q) {
1306         i__2 = q;
1307         cwork[i__2].r = 1., cwork[i__2].i = 0.;
1308 /* L1868: */
1309     }
1310
1311
1312
1313     swband = 3;
1314 /* [TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective */
1315 /*     if ZGESVJ is used as a computational routine in the preconditioned */
1316 /*     Jacobi SVD algorithm ZGEJSV. For sweeps i=1:SWBAND the procedure */
1317 /*     works on pivots inside a band-like region around the diagonal. */
1318 /*     The boundaries are determined dynamically, based on the number of */
1319 /*     pivots above a threshold. */
1320
1321     kbl = f2cmin(8,*n);
1322 /* [TP] KBL is a tuning parameter that defines the tile size in the */
1323 /*     tiling of the p-q loops of pivot pairs. In general, an optimal */
1324 /*     value of KBL depends on the matrix dimensions and on the */
1325 /*     parameters of the computer's memory. */
1326
1327     nbl = *n / kbl;
1328     if (nbl * kbl != *n) {
1329         ++nbl;
1330     }
1331
1332 /* Computing 2nd power */
1333     i__1 = kbl;
1334     blskip = i__1 * i__1;
1335 /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
1336
1337     rowskip = f2cmin(5,kbl);
1338 /* [TP] ROWSKIP is a tuning parameter. */
1339
1340     lkahead = 1;
1341 /* [TP] LKAHEAD is a tuning parameter. */
1342
1343 /*     Quasi block transformations, using the lower (upper) triangular */
1344 /*     structure of the input matrix. The quasi-block-cycling usually */
1345 /*     invokes cubic convergence. Big part of this cycle is done inside */
1346 /*     canonical subspaces of dimensions less than M. */
1347
1348 /* Computing MAX */
1349     i__1 = 64, i__2 = kbl << 2;
1350     if ((lower || upper) && *n > f2cmax(i__1,i__2)) {
1351 /* [TP] The number of partition levels and the actual partition are */
1352 /*     tuning parameters. */
1353         n4 = *n / 4;
1354         n2 = *n / 2;
1355         n34 = n4 * 3;
1356         if (applv) {
1357             q = 0;
1358         } else {
1359             q = 1;
1360         }
1361
1362         if (lower) {
1363
1364 /*     This works very well on lower triangular matrices, in particular */
1365 /*     in the framework of the preconditioned Jacobi SVD (xGEJSV). */
1366 /*     The idea is simple: */
1367 /*     [+ 0 0 0]   Note that Jacobi transformations of [0 0] */
1368 /*     [+ + 0 0]                                       [0 0] */
1369 /*     [+ + x 0]   actually work on [x 0]              [x 0] */
1370 /*     [+ + x x]                    [x x].             [x x] */
1371
1372             i__1 = *m - n34;
1373             i__2 = *n - n34;
1374             i__3 = *lwork - *n;
1375             zgsvj0_(jobv, &i__1, &i__2, &a[n34 + 1 + (n34 + 1) * a_dim1], lda,
1376                      &cwork[n34 + 1], &sva[n34 + 1], &mvl, &v[n34 * q + 1 + (
1377                     n34 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &
1378                     cwork[*n + 1], &i__3, &ierr);
1379             i__1 = *m - n2;
1380             i__2 = n34 - n2;
1381             i__3 = *lwork - *n;
1382             zgsvj0_(jobv, &i__1, &i__2, &a[n2 + 1 + (n2 + 1) * a_dim1], lda, &
1383                     cwork[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 
1384                     1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &cwork[*n 
1385                     + 1], &i__3, &ierr);
1386             i__1 = *m - n2;
1387             i__2 = *n - n2;
1388             i__3 = *lwork - *n;
1389             zgsvj1_(jobv, &i__1, &i__2, &n4, &a[n2 + 1 + (n2 + 1) * a_dim1], 
1390                     lda, &cwork[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (
1391                     n2 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &
1392                     cwork[*n + 1], &i__3, &ierr);
1393             i__1 = *m - n4;
1394             i__2 = n2 - n4;
1395             i__3 = *lwork - *n;
1396             zgsvj0_(jobv, &i__1, &i__2, &a[n4 + 1 + (n4 + 1) * a_dim1], lda, &
1397                     cwork[n4 + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 
1398                     1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &cwork[*n 
1399                     + 1], &i__3, &ierr);
1400
1401             i__1 = *lwork - *n;
1402             zgsvj0_(jobv, m, &n4, &a[a_offset], lda, &cwork[1], &sva[1], &mvl,
1403                      &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &cwork[*
1404                     n + 1], &i__1, &ierr);
1405
1406             i__1 = *lwork - *n;
1407             zgsvj1_(jobv, m, &n2, &n4, &a[a_offset], lda, &cwork[1], &sva[1], 
1408                     &mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
1409                     cwork[*n + 1], &i__1, &ierr);
1410
1411
1412         } else if (upper) {
1413
1414
1415             i__1 = *lwork - *n;
1416             zgsvj0_(jobv, &n4, &n4, &a[a_offset], lda, &cwork[1], &sva[1], &
1417                     mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__2, &
1418                     cwork[*n + 1], &i__1, &ierr);
1419
1420             i__1 = *lwork - *n;
1421             zgsvj0_(jobv, &n2, &n4, &a[(n4 + 1) * a_dim1 + 1], lda, &cwork[n4 
1422                     + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1) * 
1423                     v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &cwork[*n + 1],
1424                      &i__1, &ierr);
1425
1426             i__1 = *lwork - *n;
1427             zgsvj1_(jobv, &n2, &n2, &n4, &a[a_offset], lda, &cwork[1], &sva[1]
1428                     , &mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
1429                     cwork[*n + 1], &i__1, &ierr);
1430
1431             i__1 = n2 + n4;
1432             i__2 = *lwork - *n;
1433             zgsvj0_(jobv, &i__1, &n4, &a[(n2 + 1) * a_dim1 + 1], lda, &cwork[
1434                     n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1) * 
1435                     v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &cwork[*n + 1],
1436                      &i__2, &ierr);
1437         }
1438
1439     }
1440
1441
1442     for (i__ = 1; i__ <= 30; ++i__) {
1443
1444
1445         mxaapq = 0.;
1446         mxsinj = 0.;
1447         iswrot = 0;
1448
1449         notrot = 0;
1450         pskipped = 0;
1451
1452 /*     Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs */
1453 /*     1 <= p < q <= N. This is the first step toward a blocked implementation */
1454 /*     of the rotations. New implementation, based on block transformations, */
1455 /*     is under development. */
1456
1457         i__1 = nbl;
1458         for (ibr = 1; ibr <= i__1; ++ibr) {
1459
1460             igl = (ibr - 1) * kbl + 1;
1461
1462 /* Computing MIN */
1463             i__3 = lkahead, i__4 = nbl - ibr;
1464             i__2 = f2cmin(i__3,i__4);
1465             for (ir1 = 0; ir1 <= i__2; ++ir1) {
1466
1467                 igl += ir1 * kbl;
1468
1469 /* Computing MIN */
1470                 i__4 = igl + kbl - 1, i__5 = *n - 1;
1471                 i__3 = f2cmin(i__4,i__5);
1472                 for (p = igl; p <= i__3; ++p) {
1473
1474
1475                     i__4 = *n - p + 1;
1476                     q = idamax_(&i__4, &sva[p], &c__1) + p - 1;
1477                     if (p != q) {
1478                         zswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 
1479                                 1], &c__1);
1480                         if (rsvec) {
1481                             zswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1482                                     v_dim1 + 1], &c__1);
1483                         }
1484                         temp1 = sva[p];
1485                         sva[p] = sva[q];
1486                         sva[q] = temp1;
1487                         i__4 = p;
1488                         aapq.r = cwork[i__4].r, aapq.i = cwork[i__4].i;
1489                         i__4 = p;
1490                         i__5 = q;
1491                         cwork[i__4].r = cwork[i__5].r, cwork[i__4].i = cwork[
1492                                 i__5].i;
1493                         i__4 = q;
1494                         cwork[i__4].r = aapq.r, cwork[i__4].i = aapq.i;
1495                     }
1496
1497                     if (ir1 == 0) {
1498
1499 /*        Column norms are periodically updated by explicit */
1500 /*        norm computation. */
1501 /* [!]     Caveat: */
1502 /*        Unfortunately, some BLAS implementations compute DZNRM2(M,A(1,p),1) */
1503 /*        as SQRT(S=CDOTC(M,A(1,p),1,A(1,p),1)), which may cause the result to */
1504 /*        overflow for ||A(:,p)||_2 > SQRT(overflow_threshold), and to */
1505 /*        underflow for ||A(:,p)||_2 < SQRT(underflow_threshold). */
1506 /*        Hence, DZNRM2 cannot be trusted, not even in the case when */
1507 /*        the true norm is far from the under(over)flow boundaries. */
1508 /*        If properly implemented SCNRM2 is available, the IF-THEN-ELSE-END IF */
1509 /*        below should be replaced with "AAPP = DZNRM2( M, A(1,p), 1 )". */
1510
1511                         if (sva[p] < rootbig && sva[p] > rootsfmin) {
1512                             sva[p] = dznrm2_(m, &a[p * a_dim1 + 1], &c__1);
1513                         } else {
1514                             temp1 = 0.;
1515                             aapp = 1.;
1516                             zlassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
1517                                     aapp);
1518                             sva[p] = temp1 * sqrt(aapp);
1519                         }
1520                         aapp = sva[p];
1521                     } else {
1522                         aapp = sva[p];
1523                     }
1524
1525                     if (aapp > 0.) {
1526
1527                         pskipped = 0;
1528
1529 /* Computing MIN */
1530                         i__5 = igl + kbl - 1;
1531                         i__4 = f2cmin(i__5,*n);
1532                         for (q = p + 1; q <= i__4; ++q) {
1533
1534                             aaqq = sva[q];
1535
1536                             if (aaqq > 0.) {
1537
1538                                 aapp0 = aapp;
1539                                 if (aaqq >= 1.) {
1540                                     rotok = small * aapp <= aaqq;
1541                                     if (aapp < big / aaqq) {
1542                                         zdotc_(&z__3, m, &a[p * a_dim1 + 1], &
1543                                                 c__1, &a[q * a_dim1 + 1], &
1544                                                 c__1);
1545                                         z__2.r = z__3.r / aaqq, z__2.i = 
1546                                                 z__3.i / aaqq;
1547                                         z__1.r = z__2.r / aapp, z__1.i = 
1548                                                 z__2.i / aapp;
1549                                         aapq.r = z__1.r, aapq.i = z__1.i;
1550                                     } else {
1551                                         zcopy_(m, &a[p * a_dim1 + 1], &c__1, &
1552                                                 cwork[*n + 1], &c__1);
1553                                         zlascl_("G", &c__0, &c__0, &aapp, &
1554                                                 c_b42, m, &c__1, &cwork[*n + 
1555                                                 1], lda, &ierr);
1556                                         zdotc_(&z__2, m, &cwork[*n + 1], &
1557                                                 c__1, &a[q * a_dim1 + 1], &
1558                                                 c__1);
1559                                         z__1.r = z__2.r / aaqq, z__1.i = 
1560                                                 z__2.i / aaqq;
1561                                         aapq.r = z__1.r, aapq.i = z__1.i;
1562                                     }
1563                                 } else {
1564                                     rotok = aapp <= aaqq / small;
1565                                     if (aapp > small / aaqq) {
1566                                         zdotc_(&z__3, m, &a[p * a_dim1 + 1], &
1567                                                 c__1, &a[q * a_dim1 + 1], &
1568                                                 c__1);
1569                                         z__2.r = z__3.r / aapp, z__2.i = 
1570                                                 z__3.i / aapp;
1571                                         z__1.r = z__2.r / aaqq, z__1.i = 
1572                                                 z__2.i / aaqq;
1573                                         aapq.r = z__1.r, aapq.i = z__1.i;
1574                                     } else {
1575                                         zcopy_(m, &a[q * a_dim1 + 1], &c__1, &
1576                                                 cwork[*n + 1], &c__1);
1577                                         zlascl_("G", &c__0, &c__0, &aaqq, &
1578                                                 c_b42, m, &c__1, &cwork[*n + 
1579                                                 1], lda, &ierr);
1580                                         zdotc_(&z__2, m, &a[p * a_dim1 + 1], &
1581                                                 c__1, &cwork[*n + 1], &c__1);
1582                                         z__1.r = z__2.r / aapp, z__1.i = 
1583                                                 z__2.i / aapp;
1584                                         aapq.r = z__1.r, aapq.i = z__1.i;
1585                                     }
1586                                 }
1587
1588 /*                           AAPQ = AAPQ * CONJG( CWORK(p) ) * CWORK(q) */
1589                                 aapq1 = -z_abs(&aapq);
1590 /* Computing MAX */
1591                                 d__1 = mxaapq, d__2 = -aapq1;
1592                                 mxaapq = f2cmax(d__1,d__2);
1593
1594 /*        TO rotate or NOT to rotate, THAT is the question ... */
1595
1596                                 if (abs(aapq1) > tol) {
1597                                     d__1 = z_abs(&aapq);
1598                                     z__1.r = aapq.r / d__1, z__1.i = aapq.i / 
1599                                             d__1;
1600                                     ompq.r = z__1.r, ompq.i = z__1.i;
1601
1602 /* [RTD]      ROTATED = ROTATED + ONE */
1603
1604                                     if (ir1 == 0) {
1605                                         notrot = 0;
1606                                         pskipped = 0;
1607                                         ++iswrot;
1608                                     }
1609
1610                                     if (rotok) {
1611
1612                                         aqoap = aaqq / aapp;
1613                                         apoaq = aapp / aaqq;
1614                                         theta = (d__1 = aqoap - apoaq, abs(
1615                                                 d__1)) * -.5 / aapq1;
1616
1617                                         if (abs(theta) > bigtheta) {
1618
1619                                             t = .5 / theta;
1620                                             cs = 1.;
1621                                             d_cnjg(&z__2, &ompq);
1622                                             z__1.r = t * z__2.r, z__1.i = t * 
1623                                                     z__2.i;
1624                                             zrot_(m, &a[p * a_dim1 + 1], &
1625                                                     c__1, &a[q * a_dim1 + 1], 
1626                                                     &c__1, &cs, &z__1);
1627                                             if (rsvec) {
1628                           d_cnjg(&z__2, &ompq);
1629                           z__1.r = t * z__2.r, z__1.i = t * z__2.i;
1630                           zrot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1631                                   v_dim1 + 1], &c__1, &cs, &z__1);
1632                                             }
1633 /* Computing MAX */
1634                                             d__1 = 0., d__2 = t * apoaq * 
1635                                                     aapq1 + 1.;
1636                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
1637                                                     d__2)));
1638 /* Computing MAX */
1639                                             d__1 = 0., d__2 = 1. - t * aqoap *
1640                                                      aapq1;
1641                                             aapp *= sqrt((f2cmax(d__1,d__2)));
1642 /* Computing MAX */
1643                                             d__1 = mxsinj, d__2 = abs(t);
1644                                             mxsinj = f2cmax(d__1,d__2);
1645
1646                                         } else {
1647
1648
1649                                             thsign = -d_sign(&c_b42, &aapq1);
1650                                             t = 1. / (theta + thsign * sqrt(
1651                                                     theta * theta + 1.));
1652                                             cs = sqrt(1. / (t * t + 1.));
1653                                             sn = t * cs;
1654
1655 /* Computing MAX */
1656                                             d__1 = mxsinj, d__2 = abs(sn);
1657                                             mxsinj = f2cmax(d__1,d__2);
1658 /* Computing MAX */
1659                                             d__1 = 0., d__2 = t * apoaq * 
1660                                                     aapq1 + 1.;
1661                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
1662                                                     d__2)));
1663 /* Computing MAX */
1664                                             d__1 = 0., d__2 = 1. - t * aqoap *
1665                                                      aapq1;
1666                                             aapp *= sqrt((f2cmax(d__1,d__2)));
1667
1668                                             d_cnjg(&z__2, &ompq);
1669                                             z__1.r = sn * z__2.r, z__1.i = sn 
1670                                                     * z__2.i;
1671                                             zrot_(m, &a[p * a_dim1 + 1], &
1672                                                     c__1, &a[q * a_dim1 + 1], 
1673                                                     &c__1, &cs, &z__1);
1674                                             if (rsvec) {
1675                           d_cnjg(&z__2, &ompq);
1676                           z__1.r = sn * z__2.r, z__1.i = sn * z__2.i;
1677                           zrot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1678                                   v_dim1 + 1], &c__1, &cs, &z__1);
1679                                             }
1680                                         }
1681                                         i__5 = p;
1682                                         i__6 = q;
1683                                         z__2.r = -cwork[i__6].r, z__2.i = 
1684                                                 -cwork[i__6].i;
1685                                         z__1.r = z__2.r * ompq.r - z__2.i * 
1686                                                 ompq.i, z__1.i = z__2.r * 
1687                                                 ompq.i + z__2.i * ompq.r;
1688                                         cwork[i__5].r = z__1.r, cwork[i__5].i 
1689                                                 = z__1.i;
1690
1691                                     } else {
1692                                         zcopy_(m, &a[p * a_dim1 + 1], &c__1, &
1693                                                 cwork[*n + 1], &c__1);
1694                                         zlascl_("G", &c__0, &c__0, &aapp, &
1695                                                 c_b42, m, &c__1, &cwork[*n + 
1696                                                 1], lda, &ierr);
1697                                         zlascl_("G", &c__0, &c__0, &aaqq, &
1698                                                 c_b42, m, &c__1, &a[q * 
1699                                                 a_dim1 + 1], lda, &ierr);
1700                                         z__1.r = -aapq.r, z__1.i = -aapq.i;
1701                                         zaxpy_(m, &z__1, &cwork[*n + 1], &
1702                                                 c__1, &a[q * a_dim1 + 1], &
1703                                                 c__1);
1704                                         zlascl_("G", &c__0, &c__0, &c_b42, &
1705                                                 aaqq, m, &c__1, &a[q * a_dim1 
1706                                                 + 1], lda, &ierr);
1707 /* Computing MAX */
1708                                         d__1 = 0., d__2 = 1. - aapq1 * aapq1;
1709                                         sva[q] = aaqq * sqrt((f2cmax(d__1,d__2)))
1710                                                 ;
1711                                         mxsinj = f2cmax(mxsinj,sfmin);
1712                                     }
1713 /*           END IF ROTOK THEN ... ELSE */
1714
1715 /*           In the case of cancellation in updating SVA(q), SVA(p) */
1716 /*           recompute SVA(q), SVA(p). */
1717
1718 /* Computing 2nd power */
1719                                     d__1 = sva[q] / aaqq;
1720                                     if (d__1 * d__1 <= rooteps) {
1721                                         if (aaqq < rootbig && aaqq > 
1722                                                 rootsfmin) {
1723                                             sva[q] = dznrm2_(m, &a[q * a_dim1 
1724                                                     + 1], &c__1);
1725                                         } else {
1726                                             t = 0.;
1727                                             aaqq = 1.;
1728                                             zlassq_(m, &a[q * a_dim1 + 1], &
1729                                                     c__1, &t, &aaqq);
1730                                             sva[q] = t * sqrt(aaqq);
1731                                         }
1732                                     }
1733                                     if (aapp / aapp0 <= rooteps) {
1734                                         if (aapp < rootbig && aapp > 
1735                                                 rootsfmin) {
1736                                             aapp = dznrm2_(m, &a[p * a_dim1 + 
1737                                                     1], &c__1);
1738                                         } else {
1739                                             t = 0.;
1740                                             aapp = 1.;
1741                                             zlassq_(m, &a[p * a_dim1 + 1], &
1742                                                     c__1, &t, &aapp);
1743                                             aapp = t * sqrt(aapp);
1744                                         }
1745                                         sva[p] = aapp;
1746                                     }
1747
1748                                 } else {
1749 /*                             A(:,p) and A(:,q) already numerically orthogonal */
1750                                     if (ir1 == 0) {
1751                                         ++notrot;
1752                                     }
1753 /* [RTD]      SKIPPED  = SKIPPED + 1 */
1754                                     ++pskipped;
1755                                 }
1756                             } else {
1757 /*                          A(:,q) is zero column */
1758                                 if (ir1 == 0) {
1759                                     ++notrot;
1760                                 }
1761                                 ++pskipped;
1762                             }
1763
1764                             if (i__ <= swband && pskipped > rowskip) {
1765                                 if (ir1 == 0) {
1766                                     aapp = -aapp;
1767                                 }
1768                                 notrot = 0;
1769                                 goto L2103;
1770                             }
1771
1772 /* L2002: */
1773                         }
1774 /*     END q-LOOP */
1775
1776 L2103:
1777 /*     bailed out of q-loop */
1778
1779                         sva[p] = aapp;
1780
1781                     } else {
1782                         sva[p] = aapp;
1783                         if (ir1 == 0 && aapp == 0.) {
1784 /* Computing MIN */
1785                             i__4 = igl + kbl - 1;
1786                             notrot = notrot + f2cmin(i__4,*n) - p;
1787                         }
1788                     }
1789
1790 /* L2001: */
1791                 }
1792 /*     end of the p-loop */
1793 /*     end of doing the block ( ibr, ibr ) */
1794 /* L1002: */
1795             }
1796 /*     end of ir1-loop */
1797
1798 /* ... go to the off diagonal blocks */
1799
1800             igl = (ibr - 1) * kbl + 1;
1801
1802             i__2 = nbl;
1803             for (jbc = ibr + 1; jbc <= i__2; ++jbc) {
1804
1805                 jgl = (jbc - 1) * kbl + 1;
1806
1807 /*        doing the block at ( ibr, jbc ) */
1808
1809                 ijblsk = 0;
1810 /* Computing MIN */
1811                 i__4 = igl + kbl - 1;
1812                 i__3 = f2cmin(i__4,*n);
1813                 for (p = igl; p <= i__3; ++p) {
1814
1815                     aapp = sva[p];
1816                     if (aapp > 0.) {
1817
1818                         pskipped = 0;
1819
1820 /* Computing MIN */
1821                         i__5 = jgl + kbl - 1;
1822                         i__4 = f2cmin(i__5,*n);
1823                         for (q = jgl; q <= i__4; ++q) {
1824
1825                             aaqq = sva[q];
1826                             if (aaqq > 0.) {
1827                                 aapp0 = aapp;
1828
1829
1830 /*        Safe Gram matrix computation */
1831
1832                                 if (aaqq >= 1.) {
1833                                     if (aapp >= aaqq) {
1834                                         rotok = small * aapp <= aaqq;
1835                                     } else {
1836                                         rotok = small * aaqq <= aapp;
1837                                     }
1838                                     if (aapp < big / aaqq) {
1839                                         zdotc_(&z__3, m, &a[p * a_dim1 + 1], &
1840                                                 c__1, &a[q * a_dim1 + 1], &
1841                                                 c__1);
1842                                         z__2.r = z__3.r / aaqq, z__2.i = 
1843                                                 z__3.i / aaqq;
1844                                         z__1.r = z__2.r / aapp, z__1.i = 
1845                                                 z__2.i / aapp;
1846                                         aapq.r = z__1.r, aapq.i = z__1.i;
1847                                     } else {
1848                                         zcopy_(m, &a[p * a_dim1 + 1], &c__1, &
1849                                                 cwork[*n + 1], &c__1);
1850                                         zlascl_("G", &c__0, &c__0, &aapp, &
1851                                                 c_b42, m, &c__1, &cwork[*n + 
1852                                                 1], lda, &ierr);
1853                                         zdotc_(&z__2, m, &cwork[*n + 1], &
1854                                                 c__1, &a[q * a_dim1 + 1], &
1855                                                 c__1);
1856                                         z__1.r = z__2.r / aaqq, z__1.i = 
1857                                                 z__2.i / aaqq;
1858                                         aapq.r = z__1.r, aapq.i = z__1.i;
1859                                     }
1860                                 } else {
1861                                     if (aapp >= aaqq) {
1862                                         rotok = aapp <= aaqq / small;
1863                                     } else {
1864                                         rotok = aaqq <= aapp / small;
1865                                     }
1866                                     if (aapp > small / aaqq) {
1867                                         zdotc_(&z__3, m, &a[p * a_dim1 + 1], &
1868                                                 c__1, &a[q * a_dim1 + 1], &
1869                                                 c__1);
1870                                         d__1 = f2cmax(aaqq,aapp);
1871                                         z__2.r = z__3.r / d__1, z__2.i = 
1872                                                 z__3.i / d__1;
1873                                         d__2 = f2cmin(aaqq,aapp);
1874                                         z__1.r = z__2.r / d__2, z__1.i = 
1875                                                 z__2.i / d__2;
1876                                         aapq.r = z__1.r, aapq.i = z__1.i;
1877                                     } else {
1878                                         zcopy_(m, &a[q * a_dim1 + 1], &c__1, &
1879                                                 cwork[*n + 1], &c__1);
1880                                         zlascl_("G", &c__0, &c__0, &aaqq, &
1881                                                 c_b42, m, &c__1, &cwork[*n + 
1882                                                 1], lda, &ierr);
1883                                         zdotc_(&z__2, m, &a[p * a_dim1 + 1], &
1884                                                 c__1, &cwork[*n + 1], &c__1);
1885                                         z__1.r = z__2.r / aapp, z__1.i = 
1886                                                 z__2.i / aapp;
1887                                         aapq.r = z__1.r, aapq.i = z__1.i;
1888                                     }
1889                                 }
1890
1891 /*                           AAPQ = AAPQ * CONJG(CWORK(p))*CWORK(q) */
1892                                 aapq1 = -z_abs(&aapq);
1893 /* Computing MAX */
1894                                 d__1 = mxaapq, d__2 = -aapq1;
1895                                 mxaapq = f2cmax(d__1,d__2);
1896
1897 /*        TO rotate or NOT to rotate, THAT is the question ... */
1898
1899                                 if (abs(aapq1) > tol) {
1900                                     d__1 = z_abs(&aapq);
1901                                     z__1.r = aapq.r / d__1, z__1.i = aapq.i / 
1902                                             d__1;
1903                                     ompq.r = z__1.r, ompq.i = z__1.i;
1904                                     notrot = 0;
1905 /* [RTD]      ROTATED  = ROTATED + 1 */
1906                                     pskipped = 0;
1907                                     ++iswrot;
1908
1909                                     if (rotok) {
1910
1911                                         aqoap = aaqq / aapp;
1912                                         apoaq = aapp / aaqq;
1913                                         theta = (d__1 = aqoap - apoaq, abs(
1914                                                 d__1)) * -.5 / aapq1;
1915                                         if (aaqq > aapp0) {
1916                                             theta = -theta;
1917                                         }
1918
1919                                         if (abs(theta) > bigtheta) {
1920                                             t = .5 / theta;
1921                                             cs = 1.;
1922                                             d_cnjg(&z__2, &ompq);
1923                                             z__1.r = t * z__2.r, z__1.i = t * 
1924                                                     z__2.i;
1925                                             zrot_(m, &a[p * a_dim1 + 1], &
1926                                                     c__1, &a[q * a_dim1 + 1], 
1927                                                     &c__1, &cs, &z__1);
1928                                             if (rsvec) {
1929                           d_cnjg(&z__2, &ompq);
1930                           z__1.r = t * z__2.r, z__1.i = t * z__2.i;
1931                           zrot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1932                                   v_dim1 + 1], &c__1, &cs, &z__1);
1933                                             }
1934 /* Computing MAX */
1935                                             d__1 = 0., d__2 = t * apoaq * 
1936                                                     aapq1 + 1.;
1937                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
1938                                                     d__2)));
1939 /* Computing MAX */
1940                                             d__1 = 0., d__2 = 1. - t * aqoap *
1941                                                      aapq1;
1942                                             aapp *= sqrt((f2cmax(d__1,d__2)));
1943 /* Computing MAX */
1944                                             d__1 = mxsinj, d__2 = abs(t);
1945                                             mxsinj = f2cmax(d__1,d__2);
1946                                         } else {
1947
1948
1949                                             thsign = -d_sign(&c_b42, &aapq1);
1950                                             if (aaqq > aapp0) {
1951                           thsign = -thsign;
1952                                             }
1953                                             t = 1. / (theta + thsign * sqrt(
1954                                                     theta * theta + 1.));
1955                                             cs = sqrt(1. / (t * t + 1.));
1956                                             sn = t * cs;
1957 /* Computing MAX */
1958                                             d__1 = mxsinj, d__2 = abs(sn);
1959                                             mxsinj = f2cmax(d__1,d__2);
1960 /* Computing MAX */
1961                                             d__1 = 0., d__2 = t * apoaq * 
1962                                                     aapq1 + 1.;
1963                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
1964                                                     d__2)));
1965 /* Computing MAX */
1966                                             d__1 = 0., d__2 = 1. - t * aqoap *
1967                                                      aapq1;
1968                                             aapp *= sqrt((f2cmax(d__1,d__2)));
1969
1970                                             d_cnjg(&z__2, &ompq);
1971                                             z__1.r = sn * z__2.r, z__1.i = sn 
1972                                                     * z__2.i;
1973                                             zrot_(m, &a[p * a_dim1 + 1], &
1974                                                     c__1, &a[q * a_dim1 + 1], 
1975                                                     &c__1, &cs, &z__1);
1976                                             if (rsvec) {
1977                           d_cnjg(&z__2, &ompq);
1978                           z__1.r = sn * z__2.r, z__1.i = sn * z__2.i;
1979                           zrot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1980                                   v_dim1 + 1], &c__1, &cs, &z__1);
1981                                             }
1982                                         }
1983                                         i__5 = p;
1984                                         i__6 = q;
1985                                         z__2.r = -cwork[i__6].r, z__2.i = 
1986                                                 -cwork[i__6].i;
1987                                         z__1.r = z__2.r * ompq.r - z__2.i * 
1988                                                 ompq.i, z__1.i = z__2.r * 
1989                                                 ompq.i + z__2.i * ompq.r;
1990                                         cwork[i__5].r = z__1.r, cwork[i__5].i 
1991                                                 = z__1.i;
1992
1993                                     } else {
1994                                         if (aapp > aaqq) {
1995                                             zcopy_(m, &a[p * a_dim1 + 1], &
1996                                                     c__1, &cwork[*n + 1], &
1997                                                     c__1);
1998                                             zlascl_("G", &c__0, &c__0, &aapp, 
1999                                                     &c_b42, m, &c__1, &cwork[*
2000                                                     n + 1], lda, &ierr);
2001                                             zlascl_("G", &c__0, &c__0, &aaqq, 
2002                                                     &c_b42, m, &c__1, &a[q * 
2003                                                     a_dim1 + 1], lda, &ierr);
2004                                             z__1.r = -aapq.r, z__1.i = 
2005                                                     -aapq.i;
2006                                             zaxpy_(m, &z__1, &cwork[*n + 1], &
2007                                                     c__1, &a[q * a_dim1 + 1], 
2008                                                     &c__1);
2009                                             zlascl_("G", &c__0, &c__0, &c_b42,
2010                                                      &aaqq, m, &c__1, &a[q * 
2011                                                     a_dim1 + 1], lda, &ierr);
2012 /* Computing MAX */
2013                                             d__1 = 0., d__2 = 1. - aapq1 * 
2014                                                     aapq1;
2015                                             sva[q] = aaqq * sqrt((f2cmax(d__1,
2016                                                     d__2)));
2017                                             mxsinj = f2cmax(mxsinj,sfmin);
2018                                         } else {
2019                                             zcopy_(m, &a[q * a_dim1 + 1], &
2020                                                     c__1, &cwork[*n + 1], &
2021                                                     c__1);
2022                                             zlascl_("G", &c__0, &c__0, &aaqq, 
2023                                                     &c_b42, m, &c__1, &cwork[*
2024                                                     n + 1], lda, &ierr);
2025                                             zlascl_("G", &c__0, &c__0, &aapp, 
2026                                                     &c_b42, m, &c__1, &a[p * 
2027                                                     a_dim1 + 1], lda, &ierr);
2028                                             d_cnjg(&z__2, &aapq);
2029                                             z__1.r = -z__2.r, z__1.i = 
2030                                                     -z__2.i;
2031                                             zaxpy_(m, &z__1, &cwork[*n + 1], &
2032                                                     c__1, &a[p * a_dim1 + 1], 
2033                                                     &c__1);
2034                                             zlascl_("G", &c__0, &c__0, &c_b42,
2035                                                      &aapp, m, &c__1, &a[p * 
2036                                                     a_dim1 + 1], lda, &ierr);
2037 /* Computing MAX */
2038                                             d__1 = 0., d__2 = 1. - aapq1 * 
2039                                                     aapq1;
2040                                             sva[p] = aapp * sqrt((f2cmax(d__1,
2041                                                     d__2)));
2042                                             mxsinj = f2cmax(mxsinj,sfmin);
2043                                         }
2044                                     }
2045 /*           END IF ROTOK THEN ... ELSE */
2046
2047 /*           In the case of cancellation in updating SVA(q), SVA(p) */
2048 /* Computing 2nd power */
2049                                     d__1 = sva[q] / aaqq;
2050                                     if (d__1 * d__1 <= rooteps) {
2051                                         if (aaqq < rootbig && aaqq > 
2052                                                 rootsfmin) {
2053                                             sva[q] = dznrm2_(m, &a[q * a_dim1 
2054                                                     + 1], &c__1);
2055                                         } else {
2056                                             t = 0.;
2057                                             aaqq = 1.;
2058                                             zlassq_(m, &a[q * a_dim1 + 1], &
2059                                                     c__1, &t, &aaqq);
2060                                             sva[q] = t * sqrt(aaqq);
2061                                         }
2062                                     }
2063 /* Computing 2nd power */
2064                                     d__1 = aapp / aapp0;
2065                                     if (d__1 * d__1 <= rooteps) {
2066                                         if (aapp < rootbig && aapp > 
2067                                                 rootsfmin) {
2068                                             aapp = dznrm2_(m, &a[p * a_dim1 + 
2069                                                     1], &c__1);
2070                                         } else {
2071                                             t = 0.;
2072                                             aapp = 1.;
2073                                             zlassq_(m, &a[p * a_dim1 + 1], &
2074                                                     c__1, &t, &aapp);
2075                                             aapp = t * sqrt(aapp);
2076                                         }
2077                                         sva[p] = aapp;
2078                                     }
2079 /*              end of OK rotation */
2080                                 } else {
2081                                     ++notrot;
2082 /* [RTD]      SKIPPED  = SKIPPED  + 1 */
2083                                     ++pskipped;
2084                                     ++ijblsk;
2085                                 }
2086                             } else {
2087                                 ++notrot;
2088                                 ++pskipped;
2089                                 ++ijblsk;
2090                             }
2091
2092                             if (i__ <= swband && ijblsk >= blskip) {
2093                                 sva[p] = aapp;
2094                                 notrot = 0;
2095                                 goto L2011;
2096                             }
2097                             if (i__ <= swband && pskipped > rowskip) {
2098                                 aapp = -aapp;
2099                                 notrot = 0;
2100                                 goto L2203;
2101                             }
2102
2103 /* L2200: */
2104                         }
2105 /*        end of the q-loop */
2106 L2203:
2107
2108                         sva[p] = aapp;
2109
2110                     } else {
2111
2112                         if (aapp == 0.) {
2113 /* Computing MIN */
2114                             i__4 = jgl + kbl - 1;
2115                             notrot = notrot + f2cmin(i__4,*n) - jgl + 1;
2116                         }
2117                         if (aapp < 0.) {
2118                             notrot = 0;
2119                         }
2120
2121                     }
2122
2123 /* L2100: */
2124                 }
2125 /*     end of the p-loop */
2126 /* L2010: */
2127             }
2128 /*     end of the jbc-loop */
2129 L2011:
2130 /* 2011 bailed out of the jbc-loop */
2131 /* Computing MIN */
2132             i__3 = igl + kbl - 1;
2133             i__2 = f2cmin(i__3,*n);
2134             for (p = igl; p <= i__2; ++p) {
2135                 sva[p] = (d__1 = sva[p], abs(d__1));
2136 /* L2012: */
2137             }
2138 /* ** */
2139 /* L2000: */
2140         }
2141 /* 2000 :: end of the ibr-loop */
2142
2143         if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
2144             sva[*n] = dznrm2_(m, &a[*n * a_dim1 + 1], &c__1);
2145         } else {
2146             t = 0.;
2147             aapp = 1.;
2148             zlassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
2149             sva[*n] = t * sqrt(aapp);
2150         }
2151
2152 /*     Additional steering devices */
2153
2154         if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
2155             swband = i__;
2156         }
2157
2158         if (i__ > swband + 1 && mxaapq < sqrt((doublereal) (*n)) * tol && (
2159                 doublereal) (*n) * mxaapq * mxsinj < tol) {
2160             goto L1994;
2161         }
2162
2163         if (notrot >= emptsw) {
2164             goto L1994;
2165         }
2166
2167 /* L1993: */
2168     }
2169 /*     end i=1:NSWEEP loop */
2170
2171 /* #:( Reaching this point means that the procedure has not converged. */
2172     *info = 29;
2173     goto L1995;
2174
2175 L1994:
2176 /* #:) Reaching this point means numerical convergence after the i-th */
2177 /*     sweep. */
2178
2179     *info = 0;
2180 /* #:) INFO = 0 confirms successful iterations. */
2181 L1995:
2182
2183 /*     Sort the singular values and find how many are above */
2184 /*     the underflow threshold. */
2185
2186     n2 = 0;
2187     n4 = 0;
2188     i__1 = *n - 1;
2189     for (p = 1; p <= i__1; ++p) {
2190         i__2 = *n - p + 1;
2191         q = idamax_(&i__2, &sva[p], &c__1) + p - 1;
2192         if (p != q) {
2193             temp1 = sva[p];
2194             sva[p] = sva[q];
2195             sva[q] = temp1;
2196             zswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
2197             if (rsvec) {
2198                 zswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
2199                         c__1);
2200             }
2201         }
2202         if (sva[p] != 0.) {
2203             ++n4;
2204             if (sva[p] * skl > sfmin) {
2205                 ++n2;
2206             }
2207         }
2208 /* L5991: */
2209     }
2210     if (sva[*n] != 0.) {
2211         ++n4;
2212         if (sva[*n] * skl > sfmin) {
2213             ++n2;
2214         }
2215     }
2216
2217 /*     Normalize the left singular vectors. */
2218
2219     if (lsvec || uctol) {
2220         i__1 = n4;
2221         for (p = 1; p <= i__1; ++p) {
2222 /*            CALL ZDSCAL( M, ONE / SVA( p ), A( 1, p ), 1 ) */
2223             zlascl_("G", &c__0, &c__0, &sva[p], &c_b42, m, &c__1, &a[p * 
2224                     a_dim1 + 1], m, &ierr);
2225 /* L1998: */
2226         }
2227     }
2228
2229 /*     Scale the product of Jacobi rotations. */
2230
2231     if (rsvec) {
2232         i__1 = *n;
2233         for (p = 1; p <= i__1; ++p) {
2234             temp1 = 1. / dznrm2_(&mvl, &v[p * v_dim1 + 1], &c__1);
2235             zdscal_(&mvl, &temp1, &v[p * v_dim1 + 1], &c__1);
2236 /* L2399: */
2237         }
2238     }
2239
2240 /*     Undo scaling, if necessary (and possible). */
2241     if (skl > 1. && sva[1] < big / skl || skl < 1. && sva[f2cmax(n2,1)] > sfmin /
2242              skl) {
2243         i__1 = *n;
2244         for (p = 1; p <= i__1; ++p) {
2245             sva[p] = skl * sva[p];
2246 /* L2400: */
2247         }
2248         skl = 1.;
2249     }
2250
2251     rwork[1] = skl;
2252 /*     The singular values of A are SKL*SVA(1:N). If SKL.NE.ONE */
2253 /*     then some of the singular values may overflow or underflow and */
2254 /*     the spectrum is given in this factored representation. */
2255
2256     rwork[2] = (doublereal) n4;
2257 /*     N4 is the number of computed nonzero singular values of A. */
2258
2259     rwork[3] = (doublereal) n2;
2260 /*     N2 is the number of singular values of A greater than SFMIN. */
2261 /*     If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers */
2262 /*     that may carry some information. */
2263
2264     rwork[4] = (doublereal) i__;
2265 /*     i is the index of the last sweep before declaring convergence. */
2266
2267     rwork[5] = mxaapq;
2268 /*     MXAAPQ is the largest absolute value of scaled pivots in the */
2269 /*     last sweep */
2270
2271     rwork[6] = mxsinj;
2272 /*     MXSINJ is the largest absolute value of the sines of Jacobi angles */
2273 /*     in the last sweep */
2274
2275     return 0;
2276 } /* zgesvj_ */
2277