C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / cgsvj0.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__1 = 1;
516 static integer c__0 = 0;
517 static real c_b27 = 1.f;
518
519 /* > \brief \b CGSVJ0 pre-processor for the routine cgesvj. */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download CGSVJ0 + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgsvj0.
529 f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgsvj0.
532 f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgsvj0.
535 f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE CGSVJ0( JOBV, M, N, A, LDA, D, SVA, MV, V, LDV, EPS, */
543 /*                          SFMIN, TOL, NSWEEP, WORK, LWORK, INFO ) */
544
545 /*       INTEGER            INFO, LDA, LDV, LWORK, M, MV, N, NSWEEP */
546 /*       REAL               EPS, SFMIN, TOL */
547 /*       CHARACTER*1        JOBV */
548 /*       COMPLEX            A( LDA, * ), D( N ), V( LDV, * ), WORK( LWORK ) */
549 /*       REAL               SVA( N ) */
550
551
552 /* > \par Purpose: */
553 /*  ============= */
554 /* > */
555 /* > \verbatim */
556 /* > */
557 /* > CGSVJ0 is called from CGESVJ as a pre-processor and that is its main */
558 /* > purpose. It applies Jacobi rotations in the same way as CGESVJ does, but */
559 /* > it does not check convergence (stopping criterion). Few tuning */
560 /* > parameters (marked by [TP]) are available for the implementer. */
561 /* > \endverbatim */
562
563 /*  Arguments: */
564 /*  ========== */
565
566 /* > \param[in] JOBV */
567 /* > \verbatim */
568 /* >          JOBV is CHARACTER*1 */
569 /* >          Specifies whether the output from this procedure is used */
570 /* >          to compute the matrix V: */
571 /* >          = 'V': the product of the Jacobi rotations is accumulated */
572 /* >                 by postmulyiplying the N-by-N array V. */
573 /* >                (See the description of V.) */
574 /* >          = 'A': the product of the Jacobi rotations is accumulated */
575 /* >                 by postmulyiplying the MV-by-N array V. */
576 /* >                (See the descriptions of MV and V.) */
577 /* >          = 'N': the Jacobi rotations are not accumulated. */
578 /* > \endverbatim */
579 /* > */
580 /* > \param[in] M */
581 /* > \verbatim */
582 /* >          M is INTEGER */
583 /* >          The number of rows of the input matrix A.  M >= 0. */
584 /* > \endverbatim */
585 /* > */
586 /* > \param[in] N */
587 /* > \verbatim */
588 /* >          N is INTEGER */
589 /* >          The number of columns of the input matrix A. */
590 /* >          M >= N >= 0. */
591 /* > \endverbatim */
592 /* > */
593 /* > \param[in,out] A */
594 /* > \verbatim */
595 /* >          A is COMPLEX array, dimension (LDA,N) */
596 /* >          On entry, M-by-N matrix A, such that A*diag(D) represents */
597 /* >          the input matrix. */
598 /* >          On exit, */
599 /* >          A_onexit * diag(D_onexit) represents the input matrix A*diag(D) */
600 /* >          post-multiplied by a sequence of Jacobi rotations, where the */
601 /* >          rotation threshold and the total number of sweeps are given in */
602 /* >          TOL and NSWEEP, respectively. */
603 /* >          (See the descriptions of D, TOL and NSWEEP.) */
604 /* > \endverbatim */
605 /* > */
606 /* > \param[in] LDA */
607 /* > \verbatim */
608 /* >          LDA is INTEGER */
609 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,M). */
610 /* > \endverbatim */
611 /* > */
612 /* > \param[in,out] D */
613 /* > \verbatim */
614 /* >          D is COMPLEX array, dimension (N) */
615 /* >          The array D accumulates the scaling factors from the complex scaled */
616 /* >          Jacobi rotations. */
617 /* >          On entry, A*diag(D) represents the input matrix. */
618 /* >          On exit, A_onexit*diag(D_onexit) represents the input matrix */
619 /* >          post-multiplied by a sequence of Jacobi rotations, where the */
620 /* >          rotation threshold and the total number of sweeps are given in */
621 /* >          TOL and NSWEEP, respectively. */
622 /* >          (See the descriptions of A, TOL and NSWEEP.) */
623 /* > \endverbatim */
624 /* > */
625 /* > \param[in,out] SVA */
626 /* > \verbatim */
627 /* >          SVA is REAL array, dimension (N) */
628 /* >          On entry, SVA contains the Euclidean norms of the columns of */
629 /* >          the matrix A*diag(D). */
630 /* >          On exit, SVA contains the Euclidean norms of the columns of */
631 /* >          the matrix A_onexit*diag(D_onexit). */
632 /* > \endverbatim */
633 /* > */
634 /* > \param[in] MV */
635 /* > \verbatim */
636 /* >          MV is INTEGER */
637 /* >          If JOBV = 'A', then MV rows of V are post-multipled by a */
638 /* >                           sequence of Jacobi rotations. */
639 /* >          If JOBV = 'N',   then MV is not referenced. */
640 /* > \endverbatim */
641 /* > */
642 /* > \param[in,out] V */
643 /* > \verbatim */
644 /* >          V is COMPLEX array, dimension (LDV,N) */
645 /* >          If JOBV = 'V' then N rows of V are post-multipled by a */
646 /* >                           sequence of Jacobi rotations. */
647 /* >          If JOBV = 'A' then MV rows of V are post-multipled by a */
648 /* >                           sequence of Jacobi rotations. */
649 /* >          If JOBV = 'N',   then V is not referenced. */
650 /* > \endverbatim */
651 /* > */
652 /* > \param[in] LDV */
653 /* > \verbatim */
654 /* >          LDV is INTEGER */
655 /* >          The leading dimension of the array V,  LDV >= 1. */
656 /* >          If JOBV = 'V', LDV >= N. */
657 /* >          If JOBV = 'A', LDV >= MV. */
658 /* > \endverbatim */
659 /* > */
660 /* > \param[in] EPS */
661 /* > \verbatim */
662 /* >          EPS is REAL */
663 /* >          EPS = SLAMCH('Epsilon') */
664 /* > \endverbatim */
665 /* > */
666 /* > \param[in] SFMIN */
667 /* > \verbatim */
668 /* >          SFMIN is REAL */
669 /* >          SFMIN = SLAMCH('Safe Minimum') */
670 /* > \endverbatim */
671 /* > */
672 /* > \param[in] TOL */
673 /* > \verbatim */
674 /* >          TOL is REAL */
675 /* >          TOL is the threshold for Jacobi rotations. For a pair */
676 /* >          A(:,p), A(:,q) of pivot columns, the Jacobi rotation is */
677 /* >          applied only if ABS(COS(angle(A(:,p),A(:,q)))) > TOL. */
678 /* > \endverbatim */
679 /* > */
680 /* > \param[in] NSWEEP */
681 /* > \verbatim */
682 /* >          NSWEEP is INTEGER */
683 /* >          NSWEEP is the number of sweeps of Jacobi rotations to be */
684 /* >          performed. */
685 /* > \endverbatim */
686 /* > */
687 /* > \param[out] WORK */
688 /* > \verbatim */
689 /* >          WORK is COMPLEX array, dimension (LWORK) */
690 /* > \endverbatim */
691 /* > */
692 /* > \param[in] LWORK */
693 /* > \verbatim */
694 /* >          LWORK is INTEGER */
695 /* >          LWORK is the dimension of WORK. LWORK >= M. */
696 /* > \endverbatim */
697 /* > */
698 /* > \param[out] INFO */
699 /* > \verbatim */
700 /* >          INFO is INTEGER */
701 /* >          = 0:  successful exit. */
702 /* >          < 0:  if INFO = -i, then the i-th argument had an illegal value */
703 /* > \endverbatim */
704
705 /*  Authors: */
706 /*  ======== */
707
708 /* > \author Univ. of Tennessee */
709 /* > \author Univ. of California Berkeley */
710 /* > \author Univ. of Colorado Denver */
711 /* > \author NAG Ltd. */
712
713 /* > \date June 2016 */
714
715 /* > \ingroup complexOTHERcomputational */
716
717 /* > \par Further Details: */
718 /*  ===================== */
719 /* > */
720 /* > CGSVJ0 is used just to enable CGESVJ to call a simplified version of */
721 /* > itself to work on a submatrix of the original matrix. */
722 /* > */
723 /* > \par Contributor: */
724 /*  ================== */
725 /* > */
726 /* > Zlatko Drmac (Zagreb, Croatia) */
727 /* > */
728 /* > \par Bugs, Examples and Comments: */
729 /*  ================================= */
730 /* > */
731 /* > Please report all bugs and send interesting test examples and comments to */
732 /* > drmac@math.hr. Thank you. */
733
734 /*  ===================================================================== */
735 /* Subroutine */ int cgsvj0_(char *jobv, integer *m, integer *n, complex *a, 
736         integer *lda, complex *d__, real *sva, integer *mv, complex *v, 
737         integer *ldv, real *eps, real *sfmin, real *tol, integer *nsweep, 
738         complex *work, integer *lwork, integer *info)
739 {
740     /* System generated locals */
741     integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5, 
742             i__6, i__7;
743     real r__1, r__2;
744     complex q__1, q__2, q__3;
745
746     /* Local variables */
747     real aapp;
748     complex aapq;
749     real aaqq;
750     integer ierr;
751     real bigtheta;
752     extern /* Subroutine */ int crot_(integer *, complex *, integer *, 
753             complex *, integer *, real *, complex *);
754     complex ompq;
755     integer pskipped;
756     real aapp0, aapq1, temp1;
757     integer i__, p, q;
758     real t;
759     extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer 
760             *, complex *, integer *);
761     real apoaq, aqoap;
762     extern logical lsame_(char *, char *);
763     real theta, small;
764     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
765             complex *, integer *), cswap_(integer *, complex *, integer *, 
766             complex *, integer *);
767     logical applv, rsvec;
768     extern /* Subroutine */ int caxpy_(integer *, complex *, complex *, 
769             integer *, complex *, integer *);
770     logical rotok;
771     real rootsfmin;
772     extern real scnrm2_(integer *, complex *, integer *);
773     real cs, sn;
774     extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *, 
775             real *, integer *, integer *, complex *, integer *, integer *), xerbla_(char *, integer *, ftnlen);
776     integer ijblsk, swband;
777     extern integer isamax_(integer *, real *, integer *);
778     integer blskip;
779     extern /* Subroutine */ int classq_(integer *, complex *, integer *, real 
780             *, real *);
781     real mxaapq, thsign, mxsinj;
782     integer ir1, emptsw, notrot, iswrot, jbc;
783     real big;
784     integer kbl, lkahead, igl, ibr, jgl, nbl, mvl;
785     real rootbig, rooteps;
786     integer rowskip;
787     real roottol;
788
789
790 /*  -- LAPACK computational routine (version 3.8.0) -- */
791 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
792 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
793 /*     June 2016 */
794
795
796 /*  ===================================================================== */
797
798 /*     from BLAS */
799 /*     from LAPACK */
800
801 /*     Test the input parameters. */
802
803     /* Parameter adjustments */
804     --sva;
805     --d__;
806     a_dim1 = *lda;
807     a_offset = 1 + a_dim1 * 1;
808     a -= a_offset;
809     v_dim1 = *ldv;
810     v_offset = 1 + v_dim1 * 1;
811     v -= v_offset;
812     --work;
813
814     /* Function Body */
815     applv = lsame_(jobv, "A");
816     rsvec = lsame_(jobv, "V");
817     if (! (rsvec || applv || lsame_(jobv, "N"))) {
818         *info = -1;
819     } else if (*m < 0) {
820         *info = -2;
821     } else if (*n < 0 || *n > *m) {
822         *info = -3;
823     } else if (*lda < *m) {
824         *info = -5;
825     } else if ((rsvec || applv) && *mv < 0) {
826         *info = -8;
827     } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
828         *info = -10;
829     } else if (*tol <= *eps) {
830         *info = -13;
831     } else if (*nsweep < 0) {
832         *info = -14;
833     } else if (*lwork < *m) {
834         *info = -16;
835     } else {
836         *info = 0;
837     }
838
839 /*     #:( */
840     if (*info != 0) {
841         i__1 = -(*info);
842         xerbla_("CGSVJ0", &i__1, (ftnlen)6);
843         return 0;
844     }
845
846     if (rsvec) {
847         mvl = *n;
848     } else if (applv) {
849         mvl = *mv;
850     }
851     rsvec = rsvec || applv;
852     rooteps = sqrt(*eps);
853     rootsfmin = sqrt(*sfmin);
854     small = *sfmin / *eps;
855     big = 1.f / *sfmin;
856     rootbig = 1.f / rootsfmin;
857     bigtheta = 1.f / rooteps;
858     roottol = sqrt(*tol);
859
860
861     emptsw = *n * (*n - 1) / 2;
862     notrot = 0;
863
864
865     swband = 0;
866 /* [TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective */
867 /*     if CGESVJ is used as a computational routine in the preconditioned */
868 /*     Jacobi SVD algorithm CGEJSV. For sweeps i=1:SWBAND the procedure */
869 /*     works on pivots inside a band-like region around the diagonal. */
870 /*     The boundaries are determined dynamically, based on the number of */
871 /*     pivots above a threshold. */
872
873     kbl = f2cmin(8,*n);
874 /* [TP] KBL is a tuning parameter that defines the tile size in the */
875 /*     tiling of the p-q loops of pivot pairs. In general, an optimal */
876 /*     value of KBL depends on the matrix dimensions and on the */
877 /*     parameters of the computer's memory. */
878
879     nbl = *n / kbl;
880     if (nbl * kbl != *n) {
881         ++nbl;
882     }
883
884 /* Computing 2nd power */
885     i__1 = kbl;
886     blskip = i__1 * i__1;
887 /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
888
889     rowskip = f2cmin(5,kbl);
890 /* [TP] ROWSKIP is a tuning parameter. */
891
892     lkahead = 1;
893 /* [TP] LKAHEAD is a tuning parameter. */
894
895 /*     Quasi block transformations, using the lower (upper) triangular */
896 /*     structure of the input matrix. The quasi-block-cycling usually */
897 /*     invokes cubic convergence. Big part of this cycle is done inside */
898 /*     canonical subspaces of dimensions less than M. */
899
900
901
902     i__1 = *nsweep;
903     for (i__ = 1; i__ <= i__1; ++i__) {
904
905
906         mxaapq = 0.f;
907         mxsinj = 0.f;
908         iswrot = 0;
909
910         notrot = 0;
911         pskipped = 0;
912
913 /*     Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs */
914 /*     1 <= p < q <= N. This is the first step toward a blocked implementation */
915 /*     of the rotations. New implementation, based on block transformations, */
916 /*     is under development. */
917
918         i__2 = nbl;
919         for (ibr = 1; ibr <= i__2; ++ibr) {
920
921             igl = (ibr - 1) * kbl + 1;
922
923 /* Computing MIN */
924             i__4 = lkahead, i__5 = nbl - ibr;
925             i__3 = f2cmin(i__4,i__5);
926             for (ir1 = 0; ir1 <= i__3; ++ir1) {
927
928                 igl += ir1 * kbl;
929
930 /* Computing MIN */
931                 i__5 = igl + kbl - 1, i__6 = *n - 1;
932                 i__4 = f2cmin(i__5,i__6);
933                 for (p = igl; p <= i__4; ++p) {
934
935
936                     i__5 = *n - p + 1;
937                     q = isamax_(&i__5, &sva[p], &c__1) + p - 1;
938                     if (p != q) {
939                         cswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 
940                                 1], &c__1);
941                         if (rsvec) {
942                             cswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
943                                     v_dim1 + 1], &c__1);
944                         }
945                         temp1 = sva[p];
946                         sva[p] = sva[q];
947                         sva[q] = temp1;
948                         i__5 = p;
949                         aapq.r = d__[i__5].r, aapq.i = d__[i__5].i;
950                         i__5 = p;
951                         i__6 = q;
952                         d__[i__5].r = d__[i__6].r, d__[i__5].i = d__[i__6].i;
953                         i__5 = q;
954                         d__[i__5].r = aapq.r, d__[i__5].i = aapq.i;
955                     }
956
957                     if (ir1 == 0) {
958
959 /*        Column norms are periodically updated by explicit */
960 /*        norm computation. */
961 /*        Caveat: */
962 /*        Unfortunately, some BLAS implementations compute SNCRM2(M,A(1,p),1) */
963 /*        as SQRT(S=CDOTC(M,A(1,p),1,A(1,p),1)), which may cause the result to */
964 /*        overflow for ||A(:,p)||_2 > SQRT(overflow_threshold), and to */
965 /*        underflow for ||A(:,p)||_2 < SQRT(underflow_threshold). */
966 /*        Hence, SCNRM2 cannot be trusted, not even in the case when */
967 /*        the true norm is far from the under(over)flow boundaries. */
968 /*        If properly implemented SCNRM2 is available, the IF-THEN-ELSE-END IF */
969 /*        below should be replaced with "AAPP = SCNRM2( M, A(1,p), 1 )". */
970
971                         if (sva[p] < rootbig && sva[p] > rootsfmin) {
972                             sva[p] = scnrm2_(m, &a[p * a_dim1 + 1], &c__1);
973                         } else {
974                             temp1 = 0.f;
975                             aapp = 1.f;
976                             classq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
977                                     aapp);
978                             sva[p] = temp1 * sqrt(aapp);
979                         }
980                         aapp = sva[p];
981                     } else {
982                         aapp = sva[p];
983                     }
984
985                     if (aapp > 0.f) {
986
987                         pskipped = 0;
988
989 /* Computing MIN */
990                         i__6 = igl + kbl - 1;
991                         i__5 = f2cmin(i__6,*n);
992                         for (q = p + 1; q <= i__5; ++q) {
993
994                             aaqq = sva[q];
995
996                             if (aaqq > 0.f) {
997
998                                 aapp0 = aapp;
999                                 if (aaqq >= 1.f) {
1000                                     rotok = small * aapp <= aaqq;
1001                                     if (aapp < big / aaqq) {
1002                                         cdotc_(&q__3, m, &a[p * a_dim1 + 1], &
1003                                                 c__1, &a[q * a_dim1 + 1], &
1004                                                 c__1);
1005                                         q__2.r = q__3.r / aaqq, q__2.i = 
1006                                                 q__3.i / aaqq;
1007                                         q__1.r = q__2.r / aapp, q__1.i = 
1008                                                 q__2.i / aapp;
1009                                         aapq.r = q__1.r, aapq.i = q__1.i;
1010                                     } else {
1011                                         ccopy_(m, &a[p * a_dim1 + 1], &c__1, &
1012                                                 work[1], &c__1);
1013                                         clascl_("G", &c__0, &c__0, &aapp, &
1014                                                 c_b27, m, &c__1, &work[1], 
1015                                                 lda, &ierr);
1016                                         cdotc_(&q__2, m, &work[1], &c__1, &a[
1017                                                 q * a_dim1 + 1], &c__1);
1018                                         q__1.r = q__2.r / aaqq, q__1.i = 
1019                                                 q__2.i / aaqq;
1020                                         aapq.r = q__1.r, aapq.i = q__1.i;
1021                                     }
1022                                 } else {
1023                                     rotok = aapp <= aaqq / small;
1024                                     if (aapp > small / aaqq) {
1025                                         cdotc_(&q__3, m, &a[p * a_dim1 + 1], &
1026                                                 c__1, &a[q * a_dim1 + 1], &
1027                                                 c__1);
1028                                         q__2.r = q__3.r / aapp, q__2.i = 
1029                                                 q__3.i / aapp;
1030                                         q__1.r = q__2.r / aaqq, q__1.i = 
1031                                                 q__2.i / aaqq;
1032                                         aapq.r = q__1.r, aapq.i = q__1.i;
1033                                     } else {
1034                                         ccopy_(m, &a[q * a_dim1 + 1], &c__1, &
1035                                                 work[1], &c__1);
1036                                         clascl_("G", &c__0, &c__0, &aaqq, &
1037                                                 c_b27, m, &c__1, &work[1], 
1038                                                 lda, &ierr);
1039                                         cdotc_(&q__2, m, &a[p * a_dim1 + 1], &
1040                                                 c__1, &work[1], &c__1);
1041                                         q__1.r = q__2.r / aapp, q__1.i = 
1042                                                 q__2.i / aapp;
1043                                         aapq.r = q__1.r, aapq.i = q__1.i;
1044                                     }
1045                                 }
1046
1047 /*                           AAPQ = AAPQ * CONJG( CWORK(p) ) * CWORK(q) */
1048                                 aapq1 = -c_abs(&aapq);
1049 /* Computing MAX */
1050                                 r__1 = mxaapq, r__2 = -aapq1;
1051                                 mxaapq = f2cmax(r__1,r__2);
1052
1053 /*        TO rotate or NOT to rotate, THAT is the question ... */
1054
1055                                 if (abs(aapq1) > *tol) {
1056                                     r__1 = c_abs(&aapq);
1057                                     q__1.r = aapq.r / r__1, q__1.i = aapq.i / 
1058                                             r__1;
1059                                     ompq.r = q__1.r, ompq.i = q__1.i;
1060
1061 /* [RTD]      ROTATED = ROTATED + ONE */
1062
1063                                     if (ir1 == 0) {
1064                                         notrot = 0;
1065                                         pskipped = 0;
1066                                         ++iswrot;
1067                                     }
1068
1069                                     if (rotok) {
1070
1071                                         aqoap = aaqq / aapp;
1072                                         apoaq = aapp / aaqq;
1073                                         theta = (r__1 = aqoap - apoaq, abs(
1074                                                 r__1)) * -.5f / aapq1;
1075
1076                                         if (abs(theta) > bigtheta) {
1077
1078                                             t = .5f / theta;
1079                                             cs = 1.f;
1080                                             r_cnjg(&q__2, &ompq);
1081                                             q__1.r = t * q__2.r, q__1.i = t * 
1082                                                     q__2.i;
1083                                             crot_(m, &a[p * a_dim1 + 1], &
1084                                                     c__1, &a[q * a_dim1 + 1], 
1085                                                     &c__1, &cs, &q__1);
1086                                             if (rsvec) {
1087                           r_cnjg(&q__2, &ompq);
1088                           q__1.r = t * q__2.r, q__1.i = t * q__2.i;
1089                           crot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1090                                   v_dim1 + 1], &c__1, &cs, &q__1);
1091                                             }
1092 /* Computing MAX */
1093                                             r__1 = 0.f, r__2 = t * apoaq * 
1094                                                     aapq1 + 1.f;
1095                                             sva[q] = aaqq * sqrt((f2cmax(r__1,
1096                                                     r__2)));
1097 /* Computing MAX */
1098                                             r__1 = 0.f, r__2 = 1.f - t * 
1099                                                     aqoap * aapq1;
1100                                             aapp *= sqrt((f2cmax(r__1,r__2)));
1101 /* Computing MAX */
1102                                             r__1 = mxsinj, r__2 = abs(t);
1103                                             mxsinj = f2cmax(r__1,r__2);
1104
1105                                         } else {
1106
1107
1108                                             thsign = -r_sign(&c_b27, &aapq1);
1109                                             t = 1.f / (theta + thsign * sqrt(
1110                                                     theta * theta + 1.f));
1111                                             cs = sqrt(1.f / (t * t + 1.f));
1112                                             sn = t * cs;
1113
1114 /* Computing MAX */
1115                                             r__1 = mxsinj, r__2 = abs(sn);
1116                                             mxsinj = f2cmax(r__1,r__2);
1117 /* Computing MAX */
1118                                             r__1 = 0.f, r__2 = t * apoaq * 
1119                                                     aapq1 + 1.f;
1120                                             sva[q] = aaqq * sqrt((f2cmax(r__1,
1121                                                     r__2)));
1122 /* Computing MAX */
1123                                             r__1 = 0.f, r__2 = 1.f - t * 
1124                                                     aqoap * aapq1;
1125                                             aapp *= sqrt((f2cmax(r__1,r__2)));
1126
1127                                             r_cnjg(&q__2, &ompq);
1128                                             q__1.r = sn * q__2.r, q__1.i = sn 
1129                                                     * q__2.i;
1130                                             crot_(m, &a[p * a_dim1 + 1], &
1131                                                     c__1, &a[q * a_dim1 + 1], 
1132                                                     &c__1, &cs, &q__1);
1133                                             if (rsvec) {
1134                           r_cnjg(&q__2, &ompq);
1135                           q__1.r = sn * q__2.r, q__1.i = sn * q__2.i;
1136                           crot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1137                                   v_dim1 + 1], &c__1, &cs, &q__1);
1138                                             }
1139                                         }
1140                                         i__6 = p;
1141                                         i__7 = q;
1142                                         q__2.r = -d__[i__7].r, q__2.i = -d__[
1143                                                 i__7].i;
1144                                         q__1.r = q__2.r * ompq.r - q__2.i * 
1145                                                 ompq.i, q__1.i = q__2.r * 
1146                                                 ompq.i + q__2.i * ompq.r;
1147                                         d__[i__6].r = q__1.r, d__[i__6].i = 
1148                                                 q__1.i;
1149
1150                                     } else {
1151                                         ccopy_(m, &a[p * a_dim1 + 1], &c__1, &
1152                                                 work[1], &c__1);
1153                                         clascl_("G", &c__0, &c__0, &aapp, &
1154                                                 c_b27, m, &c__1, &work[1], 
1155                                                 lda, &ierr);
1156                                         clascl_("G", &c__0, &c__0, &aaqq, &
1157                                                 c_b27, m, &c__1, &a[q * 
1158                                                 a_dim1 + 1], lda, &ierr);
1159                                         q__1.r = -aapq.r, q__1.i = -aapq.i;
1160                                         caxpy_(m, &q__1, &work[1], &c__1, &a[
1161                                                 q * a_dim1 + 1], &c__1);
1162                                         clascl_("G", &c__0, &c__0, &c_b27, &
1163                                                 aaqq, m, &c__1, &a[q * a_dim1 
1164                                                 + 1], lda, &ierr);
1165 /* Computing MAX */
1166                                         r__1 = 0.f, r__2 = 1.f - aapq1 * 
1167                                                 aapq1;
1168                                         sva[q] = aaqq * sqrt((f2cmax(r__1,r__2)))
1169                                                 ;
1170                                         mxsinj = f2cmax(mxsinj,*sfmin);
1171                                     }
1172 /*           END IF ROTOK THEN ... ELSE */
1173
1174 /*           In the case of cancellation in updating SVA(q), SVA(p) */
1175 /*           recompute SVA(q), SVA(p). */
1176
1177 /* Computing 2nd power */
1178                                     r__1 = sva[q] / aaqq;
1179                                     if (r__1 * r__1 <= rooteps) {
1180                                         if (aaqq < rootbig && aaqq > 
1181                                                 rootsfmin) {
1182                                             sva[q] = scnrm2_(m, &a[q * a_dim1 
1183                                                     + 1], &c__1);
1184                                         } else {
1185                                             t = 0.f;
1186                                             aaqq = 1.f;
1187                                             classq_(m, &a[q * a_dim1 + 1], &
1188                                                     c__1, &t, &aaqq);
1189                                             sva[q] = t * sqrt(aaqq);
1190                                         }
1191                                     }
1192                                     if (aapp / aapp0 <= rooteps) {
1193                                         if (aapp < rootbig && aapp > 
1194                                                 rootsfmin) {
1195                                             aapp = scnrm2_(m, &a[p * a_dim1 + 
1196                                                     1], &c__1);
1197                                         } else {
1198                                             t = 0.f;
1199                                             aapp = 1.f;
1200                                             classq_(m, &a[p * a_dim1 + 1], &
1201                                                     c__1, &t, &aapp);
1202                                             aapp = t * sqrt(aapp);
1203                                         }
1204                                         sva[p] = aapp;
1205                                     }
1206
1207                                 } else {
1208 /*        A(:,p) and A(:,q) already numerically orthogonal */
1209                                     if (ir1 == 0) {
1210                                         ++notrot;
1211                                     }
1212 /* [RTD]      SKIPPED  = SKIPPED  + 1 */
1213                                     ++pskipped;
1214                                 }
1215                             } else {
1216 /*        A(:,q) is zero column */
1217                                 if (ir1 == 0) {
1218                                     ++notrot;
1219                                 }
1220                                 ++pskipped;
1221                             }
1222
1223                             if (i__ <= swband && pskipped > rowskip) {
1224                                 if (ir1 == 0) {
1225                                     aapp = -aapp;
1226                                 }
1227                                 notrot = 0;
1228                                 goto L2103;
1229                             }
1230
1231 /* L2002: */
1232                         }
1233 /*     END q-LOOP */
1234
1235 L2103:
1236 /*     bailed out of q-loop */
1237
1238                         sva[p] = aapp;
1239
1240                     } else {
1241                         sva[p] = aapp;
1242                         if (ir1 == 0 && aapp == 0.f) {
1243 /* Computing MIN */
1244                             i__5 = igl + kbl - 1;
1245                             notrot = notrot + f2cmin(i__5,*n) - p;
1246                         }
1247                     }
1248
1249 /* L2001: */
1250                 }
1251 /*     end of the p-loop */
1252 /*     end of doing the block ( ibr, ibr ) */
1253 /* L1002: */
1254             }
1255 /*     end of ir1-loop */
1256
1257 /* ... go to the off diagonal blocks */
1258
1259             igl = (ibr - 1) * kbl + 1;
1260
1261             i__3 = nbl;
1262             for (jbc = ibr + 1; jbc <= i__3; ++jbc) {
1263
1264                 jgl = (jbc - 1) * kbl + 1;
1265
1266 /*        doing the block at ( ibr, jbc ) */
1267
1268                 ijblsk = 0;
1269 /* Computing MIN */
1270                 i__5 = igl + kbl - 1;
1271                 i__4 = f2cmin(i__5,*n);
1272                 for (p = igl; p <= i__4; ++p) {
1273
1274                     aapp = sva[p];
1275                     if (aapp > 0.f) {
1276
1277                         pskipped = 0;
1278
1279 /* Computing MIN */
1280                         i__6 = jgl + kbl - 1;
1281                         i__5 = f2cmin(i__6,*n);
1282                         for (q = jgl; q <= i__5; ++q) {
1283
1284                             aaqq = sva[q];
1285                             if (aaqq > 0.f) {
1286                                 aapp0 = aapp;
1287
1288
1289 /*        Safe Gram matrix computation */
1290
1291                                 if (aaqq >= 1.f) {
1292                                     if (aapp >= aaqq) {
1293                                         rotok = small * aapp <= aaqq;
1294                                     } else {
1295                                         rotok = small * aaqq <= aapp;
1296                                     }
1297                                     if (aapp < big / aaqq) {
1298                                         cdotc_(&q__3, m, &a[p * a_dim1 + 1], &
1299                                                 c__1, &a[q * a_dim1 + 1], &
1300                                                 c__1);
1301                                         q__2.r = q__3.r / aaqq, q__2.i = 
1302                                                 q__3.i / aaqq;
1303                                         q__1.r = q__2.r / aapp, q__1.i = 
1304                                                 q__2.i / aapp;
1305                                         aapq.r = q__1.r, aapq.i = q__1.i;
1306                                     } else {
1307                                         ccopy_(m, &a[p * a_dim1 + 1], &c__1, &
1308                                                 work[1], &c__1);
1309                                         clascl_("G", &c__0, &c__0, &aapp, &
1310                                                 c_b27, m, &c__1, &work[1], 
1311                                                 lda, &ierr);
1312                                         cdotc_(&q__2, m, &work[1], &c__1, &a[
1313                                                 q * a_dim1 + 1], &c__1);
1314                                         q__1.r = q__2.r / aaqq, q__1.i = 
1315                                                 q__2.i / aaqq;
1316                                         aapq.r = q__1.r, aapq.i = q__1.i;
1317                                     }
1318                                 } else {
1319                                     if (aapp >= aaqq) {
1320                                         rotok = aapp <= aaqq / small;
1321                                     } else {
1322                                         rotok = aaqq <= aapp / small;
1323                                     }
1324                                     if (aapp > small / aaqq) {
1325                                         cdotc_(&q__3, m, &a[p * a_dim1 + 1], &
1326                                                 c__1, &a[q * a_dim1 + 1], &
1327                                                 c__1);
1328                                         r__1 = f2cmax(aaqq,aapp);
1329                                         q__2.r = q__3.r / r__1, q__2.i = 
1330                                                 q__3.i / r__1;
1331                                         r__2 = f2cmin(aaqq,aapp);
1332                                         q__1.r = q__2.r / r__2, q__1.i = 
1333                                                 q__2.i / r__2;
1334                                         aapq.r = q__1.r, aapq.i = q__1.i;
1335                                     } else {
1336                                         ccopy_(m, &a[q * a_dim1 + 1], &c__1, &
1337                                                 work[1], &c__1);
1338                                         clascl_("G", &c__0, &c__0, &aaqq, &
1339                                                 c_b27, m, &c__1, &work[1], 
1340                                                 lda, &ierr);
1341                                         cdotc_(&q__2, m, &a[p * a_dim1 + 1], &
1342                                                 c__1, &work[1], &c__1);
1343                                         q__1.r = q__2.r / aapp, q__1.i = 
1344                                                 q__2.i / aapp;
1345                                         aapq.r = q__1.r, aapq.i = q__1.i;
1346                                     }
1347                                 }
1348
1349 /*                           AAPQ = AAPQ * CONJG(CWORK(p))*CWORK(q) */
1350                                 aapq1 = -c_abs(&aapq);
1351 /* Computing MAX */
1352                                 r__1 = mxaapq, r__2 = -aapq1;
1353                                 mxaapq = f2cmax(r__1,r__2);
1354
1355 /*        TO rotate or NOT to rotate, THAT is the question ... */
1356
1357                                 if (abs(aapq1) > *tol) {
1358                                     r__1 = c_abs(&aapq);
1359                                     q__1.r = aapq.r / r__1, q__1.i = aapq.i / 
1360                                             r__1;
1361                                     ompq.r = q__1.r, ompq.i = q__1.i;
1362                                     notrot = 0;
1363 /* [RTD]      ROTATED  = ROTATED + 1 */
1364                                     pskipped = 0;
1365                                     ++iswrot;
1366
1367                                     if (rotok) {
1368
1369                                         aqoap = aaqq / aapp;
1370                                         apoaq = aapp / aaqq;
1371                                         theta = (r__1 = aqoap - apoaq, abs(
1372                                                 r__1)) * -.5f / aapq1;
1373                                         if (aaqq > aapp0) {
1374                                             theta = -theta;
1375                                         }
1376
1377                                         if (abs(theta) > bigtheta) {
1378                                             t = .5f / theta;
1379                                             cs = 1.f;
1380                                             r_cnjg(&q__2, &ompq);
1381                                             q__1.r = t * q__2.r, q__1.i = t * 
1382                                                     q__2.i;
1383                                             crot_(m, &a[p * a_dim1 + 1], &
1384                                                     c__1, &a[q * a_dim1 + 1], 
1385                                                     &c__1, &cs, &q__1);
1386                                             if (rsvec) {
1387                           r_cnjg(&q__2, &ompq);
1388                           q__1.r = t * q__2.r, q__1.i = t * q__2.i;
1389                           crot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1390                                   v_dim1 + 1], &c__1, &cs, &q__1);
1391                                             }
1392 /* Computing MAX */
1393                                             r__1 = 0.f, r__2 = t * apoaq * 
1394                                                     aapq1 + 1.f;
1395                                             sva[q] = aaqq * sqrt((f2cmax(r__1,
1396                                                     r__2)));
1397 /* Computing MAX */
1398                                             r__1 = 0.f, r__2 = 1.f - t * 
1399                                                     aqoap * aapq1;
1400                                             aapp *= sqrt((f2cmax(r__1,r__2)));
1401 /* Computing MAX */
1402                                             r__1 = mxsinj, r__2 = abs(t);
1403                                             mxsinj = f2cmax(r__1,r__2);
1404                                         } else {
1405
1406
1407                                             thsign = -r_sign(&c_b27, &aapq1);
1408                                             if (aaqq > aapp0) {
1409                           thsign = -thsign;
1410                                             }
1411                                             t = 1.f / (theta + thsign * sqrt(
1412                                                     theta * theta + 1.f));
1413                                             cs = sqrt(1.f / (t * t + 1.f));
1414                                             sn = t * cs;
1415 /* Computing MAX */
1416                                             r__1 = mxsinj, r__2 = abs(sn);
1417                                             mxsinj = f2cmax(r__1,r__2);
1418 /* Computing MAX */
1419                                             r__1 = 0.f, r__2 = t * apoaq * 
1420                                                     aapq1 + 1.f;
1421                                             sva[q] = aaqq * sqrt((f2cmax(r__1,
1422                                                     r__2)));
1423 /* Computing MAX */
1424                                             r__1 = 0.f, r__2 = 1.f - t * 
1425                                                     aqoap * aapq1;
1426                                             aapp *= sqrt((f2cmax(r__1,r__2)));
1427
1428                                             r_cnjg(&q__2, &ompq);
1429                                             q__1.r = sn * q__2.r, q__1.i = sn 
1430                                                     * q__2.i;
1431                                             crot_(m, &a[p * a_dim1 + 1], &
1432                                                     c__1, &a[q * a_dim1 + 1], 
1433                                                     &c__1, &cs, &q__1);
1434                                             if (rsvec) {
1435                           r_cnjg(&q__2, &ompq);
1436                           q__1.r = sn * q__2.r, q__1.i = sn * q__2.i;
1437                           crot_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * 
1438                                   v_dim1 + 1], &c__1, &cs, &q__1);
1439                                             }
1440                                         }
1441                                         i__6 = p;
1442                                         i__7 = q;
1443                                         q__2.r = -d__[i__7].r, q__2.i = -d__[
1444                                                 i__7].i;
1445                                         q__1.r = q__2.r * ompq.r - q__2.i * 
1446                                                 ompq.i, q__1.i = q__2.r * 
1447                                                 ompq.i + q__2.i * ompq.r;
1448                                         d__[i__6].r = q__1.r, d__[i__6].i = 
1449                                                 q__1.i;
1450
1451                                     } else {
1452                                         if (aapp > aaqq) {
1453                                             ccopy_(m, &a[p * a_dim1 + 1], &
1454                                                     c__1, &work[1], &c__1);
1455                                             clascl_("G", &c__0, &c__0, &aapp, 
1456                                                     &c_b27, m, &c__1, &work[1]
1457                                                     , lda, &ierr);
1458                                             clascl_("G", &c__0, &c__0, &aaqq, 
1459                                                     &c_b27, m, &c__1, &a[q * 
1460                                                     a_dim1 + 1], lda, &ierr);
1461                                             q__1.r = -aapq.r, q__1.i = 
1462                                                     -aapq.i;
1463                                             caxpy_(m, &q__1, &work[1], &c__1, 
1464                                                     &a[q * a_dim1 + 1], &c__1)
1465                                                     ;
1466                                             clascl_("G", &c__0, &c__0, &c_b27,
1467                                                      &aaqq, m, &c__1, &a[q * 
1468                                                     a_dim1 + 1], lda, &ierr);
1469 /* Computing MAX */
1470                                             r__1 = 0.f, r__2 = 1.f - aapq1 * 
1471                                                     aapq1;
1472                                             sva[q] = aaqq * sqrt((f2cmax(r__1,
1473                                                     r__2)));
1474                                             mxsinj = f2cmax(mxsinj,*sfmin);
1475                                         } else {
1476                                             ccopy_(m, &a[q * a_dim1 + 1], &
1477                                                     c__1, &work[1], &c__1);
1478                                             clascl_("G", &c__0, &c__0, &aaqq, 
1479                                                     &c_b27, m, &c__1, &work[1]
1480                                                     , lda, &ierr);
1481                                             clascl_("G", &c__0, &c__0, &aapp, 
1482                                                     &c_b27, m, &c__1, &a[p * 
1483                                                     a_dim1 + 1], lda, &ierr);
1484                                             r_cnjg(&q__2, &aapq);
1485                                             q__1.r = -q__2.r, q__1.i = 
1486                                                     -q__2.i;
1487                                             caxpy_(m, &q__1, &work[1], &c__1, 
1488                                                     &a[p * a_dim1 + 1], &c__1)
1489                                                     ;
1490                                             clascl_("G", &c__0, &c__0, &c_b27,
1491                                                      &aapp, m, &c__1, &a[p * 
1492                                                     a_dim1 + 1], lda, &ierr);
1493 /* Computing MAX */
1494                                             r__1 = 0.f, r__2 = 1.f - aapq1 * 
1495                                                     aapq1;
1496                                             sva[p] = aapp * sqrt((f2cmax(r__1,
1497                                                     r__2)));
1498                                             mxsinj = f2cmax(mxsinj,*sfmin);
1499                                         }
1500                                     }
1501 /*           END IF ROTOK THEN ... ELSE */
1502
1503 /*           In the case of cancellation in updating SVA(q), SVA(p) */
1504 /* Computing 2nd power */
1505                                     r__1 = sva[q] / aaqq;
1506                                     if (r__1 * r__1 <= rooteps) {
1507                                         if (aaqq < rootbig && aaqq > 
1508                                                 rootsfmin) {
1509                                             sva[q] = scnrm2_(m, &a[q * a_dim1 
1510                                                     + 1], &c__1);
1511                                         } else {
1512                                             t = 0.f;
1513                                             aaqq = 1.f;
1514                                             classq_(m, &a[q * a_dim1 + 1], &
1515                                                     c__1, &t, &aaqq);
1516                                             sva[q] = t * sqrt(aaqq);
1517                                         }
1518                                     }
1519 /* Computing 2nd power */
1520                                     r__1 = aapp / aapp0;
1521                                     if (r__1 * r__1 <= rooteps) {
1522                                         if (aapp < rootbig && aapp > 
1523                                                 rootsfmin) {
1524                                             aapp = scnrm2_(m, &a[p * a_dim1 + 
1525                                                     1], &c__1);
1526                                         } else {
1527                                             t = 0.f;
1528                                             aapp = 1.f;
1529                                             classq_(m, &a[p * a_dim1 + 1], &
1530                                                     c__1, &t, &aapp);
1531                                             aapp = t * sqrt(aapp);
1532                                         }
1533                                         sva[p] = aapp;
1534                                     }
1535 /*              end of OK rotation */
1536                                 } else {
1537                                     ++notrot;
1538 /* [RTD]      SKIPPED  = SKIPPED  + 1 */
1539                                     ++pskipped;
1540                                     ++ijblsk;
1541                                 }
1542                             } else {
1543                                 ++notrot;
1544                                 ++pskipped;
1545                                 ++ijblsk;
1546                             }
1547
1548                             if (i__ <= swband && ijblsk >= blskip) {
1549                                 sva[p] = aapp;
1550                                 notrot = 0;
1551                                 goto L2011;
1552                             }
1553                             if (i__ <= swband && pskipped > rowskip) {
1554                                 aapp = -aapp;
1555                                 notrot = 0;
1556                                 goto L2203;
1557                             }
1558
1559 /* L2200: */
1560                         }
1561 /*        end of the q-loop */
1562 L2203:
1563
1564                         sva[p] = aapp;
1565
1566                     } else {
1567
1568                         if (aapp == 0.f) {
1569 /* Computing MIN */
1570                             i__5 = jgl + kbl - 1;
1571                             notrot = notrot + f2cmin(i__5,*n) - jgl + 1;
1572                         }
1573                         if (aapp < 0.f) {
1574                             notrot = 0;
1575                         }
1576
1577                     }
1578
1579 /* L2100: */
1580                 }
1581 /*     end of the p-loop */
1582 /* L2010: */
1583             }
1584 /*     end of the jbc-loop */
1585 L2011:
1586 /* 2011 bailed out of the jbc-loop */
1587 /* Computing MIN */
1588             i__4 = igl + kbl - 1;
1589             i__3 = f2cmin(i__4,*n);
1590             for (p = igl; p <= i__3; ++p) {
1591                 sva[p] = (r__1 = sva[p], abs(r__1));
1592 /* L2012: */
1593             }
1594 /* ** */
1595 /* L2000: */
1596         }
1597 /* 2000 :: end of the ibr-loop */
1598
1599         if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
1600             sva[*n] = scnrm2_(m, &a[*n * a_dim1 + 1], &c__1);
1601         } else {
1602             t = 0.f;
1603             aapp = 1.f;
1604             classq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
1605             sva[*n] = t * sqrt(aapp);
1606         }
1607
1608 /*     Additional steering devices */
1609
1610         if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
1611             swband = i__;
1612         }
1613
1614         if (i__ > swband + 1 && mxaapq < sqrt((real) (*n)) * *tol && (real) (*
1615                 n) * mxaapq * mxsinj < *tol) {
1616             goto L1994;
1617         }
1618
1619         if (notrot >= emptsw) {
1620             goto L1994;
1621         }
1622
1623 /* L1993: */
1624     }
1625 /*     end i=1:NSWEEP loop */
1626
1627 /* #:( Reaching this point means that the procedure has not converged. */
1628     *info = *nsweep - 1;
1629     goto L1995;
1630
1631 L1994:
1632 /* #:) Reaching this point means numerical convergence after the i-th */
1633 /*     sweep. */
1634
1635     *info = 0;
1636 /* #:) INFO = 0 confirms successful iterations. */
1637 L1995:
1638
1639 /*     Sort the vector SVA() of column norms. */
1640     i__1 = *n - 1;
1641     for (p = 1; p <= i__1; ++p) {
1642         i__2 = *n - p + 1;
1643         q = isamax_(&i__2, &sva[p], &c__1) + p - 1;
1644         if (p != q) {
1645             temp1 = sva[p];
1646             sva[p] = sva[q];
1647             sva[q] = temp1;
1648             i__2 = p;
1649             aapq.r = d__[i__2].r, aapq.i = d__[i__2].i;
1650             i__2 = p;
1651             i__3 = q;
1652             d__[i__2].r = d__[i__3].r, d__[i__2].i = d__[i__3].i;
1653             i__2 = q;
1654             d__[i__2].r = aapq.r, d__[i__2].i = aapq.i;
1655             cswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
1656             if (rsvec) {
1657                 cswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
1658                         c__1);
1659             }
1660         }
1661 /* L5991: */
1662     }
1663
1664     return 0;
1665 } /* cgsvj0_ */
1666