C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / ctgsja.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]/Cd(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
514 /* Table of constant values */
515
516 static complex c_b1 = {0.f,0.f};
517 static complex c_b2 = {1.f,0.f};
518 static real c_b3 = 0.f;
519 static integer c__1 = 1;
520 static real c_b40 = -1.f;
521 static real c_b43 = 1.f;
522
523 /* > \brief \b CTGSJA */
524
525 /*  =========== DOCUMENTATION =========== */
526
527 /* Online html documentation available at */
528 /*            http://www.netlib.org/lapack/explore-html/ */
529
530 /* > \htmlonly */
531 /* > Download CTGSJA + dependencies */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctgsja.
533 f"> */
534 /* > [TGZ]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctgsja.
536 f"> */
537 /* > [ZIP]</a> */
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctgsja.
539 f"> */
540 /* > [TXT]</a> */
541 /* > \endhtmlonly */
542
543 /*  Definition: */
544 /*  =========== */
545
546 /*       SUBROUTINE CTGSJA( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B, */
547 /*                          LDB, TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV, */
548 /*                          Q, LDQ, WORK, NCALL MYCYCLE, INFO ) */
549
550 /*       CHARACTER          JOBQ, JOBU, JOBV */
551 /*       INTEGER            INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, */
552 /*      $                   NCALL MYCYCLE, P */
553 /*       REAL               TOLA, TOLB */
554 /*       REAL               ALPHA( * ), BETA( * ) */
555 /*       COMPLEX            A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
556 /*      $                   U( LDU, * ), V( LDV, * ), WORK( * ) */
557
558
559 /* > \par Purpose: */
560 /*  ============= */
561 /* > */
562 /* > \verbatim */
563 /* > */
564 /* > CTGSJA computes the generalized singular value decomposition (GSVD) */
565 /* > of two complex upper triangular (or trapezoidal) matrices A and B. */
566 /* > */
567 /* > On entry, it is assumed that matrices A and B have the following */
568 /* > forms, which may be obtained by the preprocessing subroutine CGGSVP */
569 /* > from a general M-by-N matrix A and P-by-N matrix B: */
570 /* > */
571 /* >              N-K-L  K    L */
572 /* >    A =    K ( 0    A12  A13 ) if M-K-L >= 0; */
573 /* >           L ( 0     0   A23 ) */
574 /* >       M-K-L ( 0     0    0  ) */
575 /* > */
576 /* >            N-K-L  K    L */
577 /* >    A =  K ( 0    A12  A13 ) if M-K-L < 0; */
578 /* >       M-K ( 0     0   A23 ) */
579 /* > */
580 /* >            N-K-L  K    L */
581 /* >    B =  L ( 0     0   B13 ) */
582 /* >       P-L ( 0     0    0  ) */
583 /* > */
584 /* > where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */
585 /* > upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */
586 /* > otherwise A23 is (M-K)-by-L upper trapezoidal. */
587 /* > */
588 /* > On exit, */
589 /* > */
590 /* >        U**H *A*Q = D1*( 0 R ),    V**H *B*Q = D2*( 0 R ), */
591 /* > */
592 /* > where U, V and Q are unitary matrices. */
593 /* > R is a nonsingular upper triangular matrix, and D1 */
594 /* > and D2 are ``diagonal'' matrices, which are of the following */
595 /* > structures: */
596 /* > */
597 /* > If M-K-L >= 0, */
598 /* > */
599 /* >                     K  L */
600 /* >        D1 =     K ( I  0 ) */
601 /* >                 L ( 0  C ) */
602 /* >             M-K-L ( 0  0 ) */
603 /* > */
604 /* >                    K  L */
605 /* >        D2 = L   ( 0  S ) */
606 /* >             P-L ( 0  0 ) */
607 /* > */
608 /* >                N-K-L  K    L */
609 /* >   ( 0 R ) = K (  0   R11  R12 ) K */
610 /* >             L (  0    0   R22 ) L */
611 /* > */
612 /* > where */
613 /* > */
614 /* >   C = diag( ALPHA(K+1), ... , ALPHA(K+L) ), */
615 /* >   S = diag( BETA(K+1),  ... , BETA(K+L) ), */
616 /* >   C**2 + S**2 = I. */
617 /* > */
618 /* >   R is stored in A(1:K+L,N-K-L+1:N) on exit. */
619 /* > */
620 /* > If M-K-L < 0, */
621 /* > */
622 /* >                K M-K K+L-M */
623 /* >     D1 =   K ( I  0    0   ) */
624 /* >          M-K ( 0  C    0   ) */
625 /* > */
626 /* >                  K M-K K+L-M */
627 /* >     D2 =   M-K ( 0  S    0   ) */
628 /* >          K+L-M ( 0  0    I   ) */
629 /* >            P-L ( 0  0    0   ) */
630 /* > */
631 /* >                N-K-L  K   M-K  K+L-M */
632 /* > ( 0 R ) =    K ( 0    R11  R12  R13  ) */
633 /* >           M-K ( 0     0   R22  R23  ) */
634 /* >         K+L-M ( 0     0    0   R33  ) */
635 /* > */
636 /* > where */
637 /* > C = diag( ALPHA(K+1), ... , ALPHA(M) ), */
638 /* > S = diag( BETA(K+1),  ... , BETA(M) ), */
639 /* > C**2 + S**2 = I. */
640 /* > */
641 /* > R = ( R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N) and R33 is stored */
642 /* >     (  0  R22 R23 ) */
643 /* > in B(M-K+1:L,N+M-K-L+1:N) on exit. */
644 /* > */
645 /* > The computation of the unitary transformation matrices U, V or Q */
646 /* > is optional.  These matrices may either be formed explicitly, or they */
647 /* > may be postmultiplied into input matrices U1, V1, or Q1. */
648 /* > \endverbatim */
649
650 /*  Arguments: */
651 /*  ========== */
652
653 /* > \param[in] JOBU */
654 /* > \verbatim */
655 /* >          JOBU is CHARACTER*1 */
656 /* >          = 'U':  U must contain a unitary matrix U1 on entry, and */
657 /* >                  the product U1*U is returned; */
658 /* >          = 'I':  U is initialized to the unit matrix, and the */
659 /* >                  unitary matrix U is returned; */
660 /* >          = 'N':  U is not computed. */
661 /* > \endverbatim */
662 /* > */
663 /* > \param[in] JOBV */
664 /* > \verbatim */
665 /* >          JOBV is CHARACTER*1 */
666 /* >          = 'V':  V must contain a unitary matrix V1 on entry, and */
667 /* >                  the product V1*V is returned; */
668 /* >          = 'I':  V is initialized to the unit matrix, and the */
669 /* >                  unitary matrix V is returned; */
670 /* >          = 'N':  V is not computed. */
671 /* > \endverbatim */
672 /* > */
673 /* > \param[in] JOBQ */
674 /* > \verbatim */
675 /* >          JOBQ is CHARACTER*1 */
676 /* >          = 'Q':  Q must contain a unitary matrix Q1 on entry, and */
677 /* >                  the product Q1*Q is returned; */
678 /* >          = 'I':  Q is initialized to the unit matrix, and the */
679 /* >                  unitary matrix Q is returned; */
680 /* >          = 'N':  Q is not computed. */
681 /* > \endverbatim */
682 /* > */
683 /* > \param[in] M */
684 /* > \verbatim */
685 /* >          M is INTEGER */
686 /* >          The number of rows of the matrix A.  M >= 0. */
687 /* > \endverbatim */
688 /* > */
689 /* > \param[in] P */
690 /* > \verbatim */
691 /* >          P is INTEGER */
692 /* >          The number of rows of the matrix B.  P >= 0. */
693 /* > \endverbatim */
694 /* > */
695 /* > \param[in] N */
696 /* > \verbatim */
697 /* >          N is INTEGER */
698 /* >          The number of columns of the matrices A and B.  N >= 0. */
699 /* > \endverbatim */
700 /* > */
701 /* > \param[in] K */
702 /* > \verbatim */
703 /* >          K is INTEGER */
704 /* > \endverbatim */
705 /* > */
706 /* > \param[in] L */
707 /* > \verbatim */
708 /* >          L is INTEGER */
709 /* > */
710 /* >          K and L specify the subblocks in the input matrices A and B: */
711 /* >          A23 = A(K+1:MIN(K+L,M),N-L+1:N) and B13 = B(1:L,,N-L+1:N) */
712 /* >          of A and B, whose GSVD is going to be computed by CTGSJA. */
713 /* >          See Further Details. */
714 /* > \endverbatim */
715 /* > */
716 /* > \param[in,out] A */
717 /* > \verbatim */
718 /* >          A is COMPLEX array, dimension (LDA,N) */
719 /* >          On entry, the M-by-N matrix A. */
720 /* >          On exit, A(N-K+1:N,1:MIN(K+L,M) ) contains the triangular */
721 /* >          matrix R or part of R.  See Purpose for details. */
722 /* > \endverbatim */
723 /* > */
724 /* > \param[in] LDA */
725 /* > \verbatim */
726 /* >          LDA is INTEGER */
727 /* >          The leading dimension of the array A. LDA >= f2cmax(1,M). */
728 /* > \endverbatim */
729 /* > */
730 /* > \param[in,out] B */
731 /* > \verbatim */
732 /* >          B is COMPLEX array, dimension (LDB,N) */
733 /* >          On entry, the P-by-N matrix B. */
734 /* >          On exit, if necessary, B(M-K+1:L,N+M-K-L+1:N) contains */
735 /* >          a part of R.  See Purpose for details. */
736 /* > \endverbatim */
737 /* > */
738 /* > \param[in] LDB */
739 /* > \verbatim */
740 /* >          LDB is INTEGER */
741 /* >          The leading dimension of the array B. LDB >= f2cmax(1,P). */
742 /* > \endverbatim */
743 /* > */
744 /* > \param[in] TOLA */
745 /* > \verbatim */
746 /* >          TOLA is REAL */
747 /* > \endverbatim */
748 /* > */
749 /* > \param[in] TOLB */
750 /* > \verbatim */
751 /* >          TOLB is REAL */
752 /* > */
753 /* >          TOLA and TOLB are the convergence criteria for the Jacobi- */
754 /* >          Kogbetliantz iteration procedure. Generally, they are the */
755 /* >          same as used in the preprocessing step, say */
756 /* >              TOLA = MAX(M,N)*norm(A)*MACHEPS, */
757 /* >              TOLB = MAX(P,N)*norm(B)*MACHEPS. */
758 /* > \endverbatim */
759 /* > */
760 /* > \param[out] ALPHA */
761 /* > \verbatim */
762 /* >          ALPHA is REAL array, dimension (N) */
763 /* > \endverbatim */
764 /* > */
765 /* > \param[out] BETA */
766 /* > \verbatim */
767 /* >          BETA is REAL array, dimension (N) */
768 /* > */
769 /* >          On exit, ALPHA and BETA contain the generalized singular */
770 /* >          value pairs of A and B; */
771 /* >            ALPHA(1:K) = 1, */
772 /* >            BETA(1:K)  = 0, */
773 /* >          and if M-K-L >= 0, */
774 /* >            ALPHA(K+1:K+L) = diag(C), */
775 /* >            BETA(K+1:K+L)  = diag(S), */
776 /* >          or if M-K-L < 0, */
777 /* >            ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0 */
778 /* >            BETA(K+1:M) = S, BETA(M+1:K+L) = 1. */
779 /* >          Furthermore, if K+L < N, */
780 /* >            ALPHA(K+L+1:N) = 0 */
781 /* >            BETA(K+L+1:N)  = 0. */
782 /* > \endverbatim */
783 /* > */
784 /* > \param[in,out] U */
785 /* > \verbatim */
786 /* >          U is COMPLEX array, dimension (LDU,M) */
787 /* >          On entry, if JOBU = 'U', U must contain a matrix U1 (usually */
788 /* >          the unitary matrix returned by CGGSVP). */
789 /* >          On exit, */
790 /* >          if JOBU = 'I', U contains the unitary matrix U; */
791 /* >          if JOBU = 'U', U contains the product U1*U. */
792 /* >          If JOBU = 'N', U is not referenced. */
793 /* > \endverbatim */
794 /* > */
795 /* > \param[in] LDU */
796 /* > \verbatim */
797 /* >          LDU is INTEGER */
798 /* >          The leading dimension of the array U. LDU >= f2cmax(1,M) if */
799 /* >          JOBU = 'U'; LDU >= 1 otherwise. */
800 /* > \endverbatim */
801 /* > */
802 /* > \param[in,out] V */
803 /* > \verbatim */
804 /* >          V is COMPLEX array, dimension (LDV,P) */
805 /* >          On entry, if JOBV = 'V', V must contain a matrix V1 (usually */
806 /* >          the unitary matrix returned by CGGSVP). */
807 /* >          On exit, */
808 /* >          if JOBV = 'I', V contains the unitary matrix V; */
809 /* >          if JOBV = 'V', V contains the product V1*V. */
810 /* >          If JOBV = 'N', V is not referenced. */
811 /* > \endverbatim */
812 /* > */
813 /* > \param[in] LDV */
814 /* > \verbatim */
815 /* >          LDV is INTEGER */
816 /* >          The leading dimension of the array V. LDV >= f2cmax(1,P) if */
817 /* >          JOBV = 'V'; LDV >= 1 otherwise. */
818 /* > \endverbatim */
819 /* > */
820 /* > \param[in,out] Q */
821 /* > \verbatim */
822 /* >          Q is COMPLEX array, dimension (LDQ,N) */
823 /* >          On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually */
824 /* >          the unitary matrix returned by CGGSVP). */
825 /* >          On exit, */
826 /* >          if JOBQ = 'I', Q contains the unitary matrix Q; */
827 /* >          if JOBQ = 'Q', Q contains the product Q1*Q. */
828 /* >          If JOBQ = 'N', Q is not referenced. */
829 /* > \endverbatim */
830 /* > */
831 /* > \param[in] LDQ */
832 /* > \verbatim */
833 /* >          LDQ is INTEGER */
834 /* >          The leading dimension of the array Q. LDQ >= f2cmax(1,N) if */
835 /* >          JOBQ = 'Q'; LDQ >= 1 otherwise. */
836 /* > \endverbatim */
837 /* > */
838 /* > \param[out] WORK */
839 /* > \verbatim */
840 /* >          WORK is COMPLEX array, dimension (2*N) */
841 /* > \endverbatim */
842 /* > */
843 /* > \param[out] NCALL MYCYCLE */
844 /* > \verbatim */
845 /* >          NCALL MYCYCLE is INTEGER */
846 /* >          The number of cycles required for convergence. */
847 /* > \endverbatim */
848 /* > */
849 /* > \param[out] INFO */
850 /* > \verbatim */
851 /* >          INFO is INTEGER */
852 /* >          = 0:  successful exit */
853 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
854 /* >          = 1:  the procedure does not converge after MAXIT cycles. */
855 /* > \endverbatim */
856
857 /* > \par Internal Parameters: */
858 /*  ========================= */
859 /* > */
860 /* > \verbatim */
861 /* >  MAXIT   INTEGER */
862 /* >          MAXIT specifies the total loops that the iterative procedure */
863 /* >          may take. If after MAXIT cycles, the routine fails to */
864 /* >          converge, we return INFO = 1. */
865 /* > \endverbatim */
866
867 /*  Authors: */
868 /*  ======== */
869
870 /* > \author Univ. of Tennessee */
871 /* > \author Univ. of California Berkeley */
872 /* > \author Univ. of Colorado Denver */
873 /* > \author NAG Ltd. */
874
875 /* > \date December 2016 */
876
877 /* > \ingroup complexOTHERcomputational */
878
879 /* > \par Further Details: */
880 /*  ===================== */
881 /* > */
882 /* > \verbatim */
883 /* > */
884 /* >  CTGSJA essentially uses a variant of Kogbetliantz algorithm to reduce */
885 /* >  f2cmin(L,M-K)-by-L triangular (or trapezoidal) matrix A23 and L-by-L */
886 /* >  matrix B13 to the form: */
887 /* > */
888 /* >           U1**H *A13*Q1 = C1*R1; V1**H *B13*Q1 = S1*R1, */
889 /* > */
890 /* >  where U1, V1 and Q1 are unitary matrix. */
891 /* >  C1 and S1 are diagonal matrices satisfying */
892 /* > */
893 /* >                C1**2 + S1**2 = I, */
894 /* > */
895 /* >  and R1 is an L-by-L nonsingular upper triangular matrix. */
896 /* > \endverbatim */
897 /* > */
898 /*  ===================================================================== */
899 /* Subroutine */ int ctgsja_(char *jobu, char *jobv, char *jobq, integer *m, 
900         integer *p, integer *n, integer *k, integer *l, complex *a, integer *
901         lda, complex *b, integer *ldb, real *tola, real *tolb, real *alpha, 
902         real *beta, complex *u, integer *ldu, complex *v, integer *ldv, 
903         complex *q, integer *ldq, complex *work, integer *ncallmycycle, 
904         integer *info)
905 {
906     /* System generated locals */
907     integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1, 
908             u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
909     real r__1;
910     complex q__1;
911
912     /* Local variables */
913     extern /* Subroutine */ int crot_(integer *, complex *, integer *, 
914             complex *, integer *, real *, complex *);
915     integer kcallmycycle, i__, j;
916     real gamma;
917     extern logical lsame_(char *, char *);
918     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
919             complex *, integer *);
920     logical initq;
921     real a1, a3, b1;
922     logical initu, initv, wantq, upper;
923     real b3, error;
924     logical wantu, wantv;
925     real ssmin;
926     complex a2, b2;
927     extern /* Subroutine */ int clags2_(logical *, real *, complex *, real *, 
928             real *, complex *, real *, real *, complex *, real *, complex *, 
929             real *, complex *), clapll_(integer *, complex *, integer *, 
930             complex *, integer *, real *), csscal_(integer *, real *, complex 
931             *, integer *), claset_(char *, integer *, integer *, complex *, 
932             complex *, complex *, integer *), xerbla_(char *, integer 
933             *, ftnlen), slartg_(real *, real *, real *, real *, real *);
934 //    extern integer myhuge_(real *);
935     real csq, csu, csv;
936     complex snq;
937     real rwk;
938     complex snu, snv;
939
940
941 /*  -- LAPACK computational routine (version 3.7.0) -- */
942 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
943 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
944 /*     December 2016 */
945
946
947 /*  ===================================================================== */
948
949
950
951 /*     Decode and test the input parameters */
952
953     /* Parameter adjustments */
954     a_dim1 = *lda;
955     a_offset = 1 + a_dim1 * 1;
956     a -= a_offset;
957     b_dim1 = *ldb;
958     b_offset = 1 + b_dim1 * 1;
959     b -= b_offset;
960     --alpha;
961     --beta;
962     u_dim1 = *ldu;
963     u_offset = 1 + u_dim1 * 1;
964     u -= u_offset;
965     v_dim1 = *ldv;
966     v_offset = 1 + v_dim1 * 1;
967     v -= v_offset;
968     q_dim1 = *ldq;
969     q_offset = 1 + q_dim1 * 1;
970     q -= q_offset;
971     --work;
972
973     /* Function Body */
974     initu = lsame_(jobu, "I");
975     wantu = initu || lsame_(jobu, "U");
976
977     initv = lsame_(jobv, "I");
978     wantv = initv || lsame_(jobv, "V");
979
980     initq = lsame_(jobq, "I");
981     wantq = initq || lsame_(jobq, "Q");
982
983     *info = 0;
984     if (! (initu || wantu || lsame_(jobu, "N"))) {
985         *info = -1;
986     } else if (! (initv || wantv || lsame_(jobv, "N"))) 
987             {
988         *info = -2;
989     } else if (! (initq || wantq || lsame_(jobq, "N"))) 
990             {
991         *info = -3;
992     } else if (*m < 0) {
993         *info = -4;
994     } else if (*p < 0) {
995         *info = -5;
996     } else if (*n < 0) {
997         *info = -6;
998     } else if (*lda < f2cmax(1,*m)) {
999         *info = -10;
1000     } else if (*ldb < f2cmax(1,*p)) {
1001         *info = -12;
1002     } else if (*ldu < 1 || wantu && *ldu < *m) {
1003         *info = -18;
1004     } else if (*ldv < 1 || wantv && *ldv < *p) {
1005         *info = -20;
1006     } else if (*ldq < 1 || wantq && *ldq < *n) {
1007         *info = -22;
1008     }
1009     if (*info != 0) {
1010         i__1 = -(*info);
1011         xerbla_("CTGSJA", &i__1, (ftnlen)6);
1012         return 0;
1013     }
1014
1015 /*     Initialize U, V and Q, if necessary */
1016
1017     if (initu) {
1018         claset_("Full", m, m, &c_b1, &c_b2, &u[u_offset], ldu);
1019     }
1020     if (initv) {
1021         claset_("Full", p, p, &c_b1, &c_b2, &v[v_offset], ldv);
1022     }
1023     if (initq) {
1024         claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
1025     }
1026
1027 /*     Loop until convergence */
1028
1029     upper = FALSE_;
1030     for (kcallmycycle = 1; kcallmycycle <= 40; ++kcallmycycle) {
1031
1032         upper = ! upper;
1033
1034         i__1 = *l - 1;
1035         for (i__ = 1; i__ <= i__1; ++i__) {
1036             i__2 = *l;
1037             for (j = i__ + 1; j <= i__2; ++j) {
1038
1039                 a1 = 0.f;
1040                 a2.r = 0.f, a2.i = 0.f;
1041                 a3 = 0.f;
1042                 if (*k + i__ <= *m) {
1043                     i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
1044                     a1 = a[i__3].r;
1045                 }
1046                 if (*k + j <= *m) {
1047                     i__3 = *k + j + (*n - *l + j) * a_dim1;
1048                     a3 = a[i__3].r;
1049                 }
1050
1051                 i__3 = i__ + (*n - *l + i__) * b_dim1;
1052                 b1 = b[i__3].r;
1053                 i__3 = j + (*n - *l + j) * b_dim1;
1054                 b3 = b[i__3].r;
1055
1056                 if (upper) {
1057                     if (*k + i__ <= *m) {
1058                         i__3 = *k + i__ + (*n - *l + j) * a_dim1;
1059                         a2.r = a[i__3].r, a2.i = a[i__3].i;
1060                     }
1061                     i__3 = i__ + (*n - *l + j) * b_dim1;
1062                     b2.r = b[i__3].r, b2.i = b[i__3].i;
1063                 } else {
1064                     if (*k + j <= *m) {
1065                         i__3 = *k + j + (*n - *l + i__) * a_dim1;
1066                         a2.r = a[i__3].r, a2.i = a[i__3].i;
1067                     }
1068                     i__3 = j + (*n - *l + i__) * b_dim1;
1069                     b2.r = b[i__3].r, b2.i = b[i__3].i;
1070                 }
1071
1072                 clags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, &
1073                         csv, &snv, &csq, &snq);
1074
1075 /*              Update (K+I)-th and (K+J)-th rows of matrix A: U**H *A */
1076
1077                 if (*k + j <= *m) {
1078                     r_cnjg(&q__1, &snu);
1079                     crot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k 
1080                             + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &q__1)
1081                             ;
1082                 }
1083
1084 /*              Update I-th and J-th rows of matrix B: V**H *B */
1085
1086                 r_cnjg(&q__1, &snv);
1087                 crot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - *
1088                         l + 1) * b_dim1], ldb, &csv, &q__1);
1089
1090 /*              Update (N-L+I)-th and (N-L+J)-th columns of matrices */
1091 /*              A and B: A*Q and B*Q */
1092
1093 /* Computing MIN */
1094                 i__4 = *k + *l;
1095                 i__3 = f2cmin(i__4,*m);
1096                 crot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - *
1097                         l + i__) * a_dim1 + 1], &c__1, &csq, &snq);
1098
1099                 crot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l + 
1100                         i__) * b_dim1 + 1], &c__1, &csq, &snq);
1101
1102                 if (upper) {
1103                     if (*k + i__ <= *m) {
1104                         i__3 = *k + i__ + (*n - *l + j) * a_dim1;
1105                         a[i__3].r = 0.f, a[i__3].i = 0.f;
1106                     }
1107                     i__3 = i__ + (*n - *l + j) * b_dim1;
1108                     b[i__3].r = 0.f, b[i__3].i = 0.f;
1109                 } else {
1110                     if (*k + j <= *m) {
1111                         i__3 = *k + j + (*n - *l + i__) * a_dim1;
1112                         a[i__3].r = 0.f, a[i__3].i = 0.f;
1113                     }
1114                     i__3 = j + (*n - *l + i__) * b_dim1;
1115                     b[i__3].r = 0.f, b[i__3].i = 0.f;
1116                 }
1117
1118 /*              Ensure that the diagonal elements of A and B are real. */
1119
1120                 if (*k + i__ <= *m) {
1121                     i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
1122                     i__4 = *k + i__ + (*n - *l + i__) * a_dim1;
1123                     r__1 = a[i__4].r;
1124                     a[i__3].r = r__1, a[i__3].i = 0.f;
1125                 }
1126                 if (*k + j <= *m) {
1127                     i__3 = *k + j + (*n - *l + j) * a_dim1;
1128                     i__4 = *k + j + (*n - *l + j) * a_dim1;
1129                     r__1 = a[i__4].r;
1130                     a[i__3].r = r__1, a[i__3].i = 0.f;
1131                 }
1132                 i__3 = i__ + (*n - *l + i__) * b_dim1;
1133                 i__4 = i__ + (*n - *l + i__) * b_dim1;
1134                 r__1 = b[i__4].r;
1135                 b[i__3].r = r__1, b[i__3].i = 0.f;
1136                 i__3 = j + (*n - *l + j) * b_dim1;
1137                 i__4 = j + (*n - *l + j) * b_dim1;
1138                 r__1 = b[i__4].r;
1139                 b[i__3].r = r__1, b[i__3].i = 0.f;
1140
1141 /*              Update unitary matrices U, V, Q, if desired. */
1142
1143                 if (wantu && *k + j <= *m) {
1144                     crot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) *
1145                              u_dim1 + 1], &c__1, &csu, &snu);
1146                 }
1147
1148                 if (wantv) {
1149                     crot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1], 
1150                             &c__1, &csv, &snv);
1151                 }
1152
1153                 if (wantq) {
1154                     crot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - *
1155                             l + i__) * q_dim1 + 1], &c__1, &csq, &snq);
1156                 }
1157
1158 /* L10: */
1159             }
1160 /* L20: */
1161         }
1162
1163         if (! upper) {
1164
1165 /*           The matrices A13 and B13 were lower triangular at the start */
1166 /*           of the cycle, and are now upper triangular. */
1167
1168 /*           Convergence test: test the parallelism of the corresponding */
1169 /*           rows of A and B. */
1170
1171             error = 0.f;
1172 /* Computing MIN */
1173             i__2 = *l, i__3 = *m - *k;
1174             i__1 = f2cmin(i__2,i__3);
1175             for (i__ = 1; i__ <= i__1; ++i__) {
1176                 i__2 = *l - i__ + 1;
1177                 ccopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, &
1178                         work[1], &c__1);
1179                 i__2 = *l - i__ + 1;
1180                 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[*
1181                         l + 1], &c__1);
1182                 i__2 = *l - i__ + 1;
1183                 clapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin);
1184                 error = f2cmax(error,ssmin);
1185 /* L30: */
1186             }
1187
1188             if (abs(error) <= f2cmin(*tola,*tolb)) {
1189                 goto L50;
1190             }
1191         }
1192
1193 /*        End of cycle loop */
1194
1195 /* L40: */
1196     }
1197
1198 /*     The algorithm has not converged after MAXIT cycles. */
1199
1200     *info = 1;
1201     goto L100;
1202
1203 L50:
1204
1205 /*     If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged. */
1206 /*     Compute the generalized singular value pairs (ALPHA, BETA), and */
1207 /*     set the triangular matrix R to array A. */
1208
1209     i__1 = *k;
1210     for (i__ = 1; i__ <= i__1; ++i__) {
1211         alpha[i__] = 1.f;
1212         beta[i__] = 0.f;
1213 /* L60: */
1214     }
1215
1216 /* Computing MIN */
1217     i__2 = *l, i__3 = *m - *k;
1218     i__1 = f2cmin(i__2,i__3);
1219     for (i__ = 1; i__ <= i__1; ++i__) {
1220
1221         i__2 = *k + i__ + (*n - *l + i__) * a_dim1;
1222         a1 = a[i__2].r;
1223         i__2 = i__ + (*n - *l + i__) * b_dim1;
1224         b1 = b[i__2].r;
1225         gamma = b1 / a1;
1226
1227         if (gamma <= (real) myhuge_(&c_b3) && gamma >= -((real) myhuge_(&c_b3)
1228                 )) {
1229
1230             if (gamma < 0.f) {
1231                 i__2 = *l - i__ + 1;
1232                 csscal_(&i__2, &c_b40, &b[i__ + (*n - *l + i__) * b_dim1], 
1233                         ldb);
1234                 if (wantv) {
1235                     csscal_(p, &c_b40, &v[i__ * v_dim1 + 1], &c__1);
1236                 }
1237             }
1238
1239             r__1 = abs(gamma);
1240             slartg_(&r__1, &c_b43, &beta[*k + i__], &alpha[*k + i__], &rwk);
1241
1242             if (alpha[*k + i__] >= beta[*k + i__]) {
1243                 i__2 = *l - i__ + 1;
1244                 r__1 = 1.f / alpha[*k + i__];
1245                 csscal_(&i__2, &r__1, &a[*k + i__ + (*n - *l + i__) * a_dim1],
1246                          lda);
1247             } else {
1248                 i__2 = *l - i__ + 1;
1249                 r__1 = 1.f / beta[*k + i__];
1250                 csscal_(&i__2, &r__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb)
1251                         ;
1252                 i__2 = *l - i__ + 1;
1253                 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k 
1254                         + i__ + (*n - *l + i__) * a_dim1], lda);
1255             }
1256
1257         } else {
1258             alpha[*k + i__] = 0.f;
1259             beta[*k + i__] = 1.f;
1260             i__2 = *l - i__ + 1;
1261             ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k + 
1262                     i__ + (*n - *l + i__) * a_dim1], lda);
1263         }
1264 /* L70: */
1265     }
1266
1267 /*     Post-assignment */
1268
1269     i__1 = *k + *l;
1270     for (i__ = *m + 1; i__ <= i__1; ++i__) {
1271         alpha[i__] = 0.f;
1272         beta[i__] = 1.f;
1273 /* L80: */
1274     }
1275
1276     if (*k + *l < *n) {
1277         i__1 = *n;
1278         for (i__ = *k + *l + 1; i__ <= i__1; ++i__) {
1279             alpha[i__] = 0.f;
1280             beta[i__] = 0.f;
1281 /* L90: */
1282         }
1283     }
1284
1285 L100:
1286     *ncallmycycle = kcallmycycle;
1287
1288     return 0;
1289
1290 /*     End of CTGSJA */
1291
1292 } /* ctgsja_ */
1293