C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / zunbdb.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 /* Table of constant values */
514
515 static integer c__1 = 1;
516
517 /* > \brief \b ZUNBDB */
518
519 /*  =========== DOCUMENTATION =========== */
520
521 /* Online html documentation available at */
522 /*            http://www.netlib.org/lapack/explore-html/ */
523
524 /* > \htmlonly */
525 /* > Download ZUNBDB + dependencies */
526 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zunbdb.
527 f"> */
528 /* > [TGZ]</a> */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zunbdb.
530 f"> */
531 /* > [ZIP]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zunbdb.
533 f"> */
534 /* > [TXT]</a> */
535 /* > \endhtmlonly */
536
537 /*  Definition: */
538 /*  =========== */
539
540 /*       SUBROUTINE ZUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, */
541 /*                          X21, LDX21, X22, LDX22, THETA, PHI, TAUP1, */
542 /*                          TAUP2, TAUQ1, TAUQ2, WORK, LWORK, INFO ) */
543
544 /*       CHARACTER          SIGNS, TRANS */
545 /*       INTEGER            INFO, LDX11, LDX12, LDX21, LDX22, LWORK, M, P, */
546 /*      $                   Q */
547 /*       DOUBLE PRECISION   PHI( * ), THETA( * ) */
548 /*       COMPLEX*16         TAUP1( * ), TAUP2( * ), TAUQ1( * ), TAUQ2( * ), */
549 /*      $                   WORK( * ), X11( LDX11, * ), X12( LDX12, * ), */
550 /*      $                   X21( LDX21, * ), X22( LDX22, * ) */
551
552
553 /* > \par Purpose: */
554 /*  ============= */
555 /* > */
556 /* > \verbatim */
557 /* > */
558 /* > ZUNBDB simultaneously bidiagonalizes the blocks of an M-by-M */
559 /* > partitioned unitary matrix X: */
560 /* > */
561 /* >                                 [ B11 | B12 0  0 ] */
562 /* >     [ X11 | X12 ]   [ P1 |    ] [  0  |  0 -I  0 ] [ Q1 |    ]**H */
563 /* > X = [-----------] = [---------] [----------------] [---------]   . */
564 /* >     [ X21 | X22 ]   [    | P2 ] [ B21 | B22 0  0 ] [    | Q2 ] */
565 /* >                                 [  0  |  0  0  I ] */
566 /* > */
567 /* > X11 is P-by-Q. Q must be no larger than P, M-P, or M-Q. (If this is */
568 /* > not the case, then X must be transposed and/or permuted. This can be */
569 /* > done in constant time using the TRANS and SIGNS options. See ZUNCSD */
570 /* > for details.) */
571 /* > */
572 /* > The unitary matrices P1, P2, Q1, and Q2 are P-by-P, (M-P)-by- */
573 /* > (M-P), Q-by-Q, and (M-Q)-by-(M-Q), respectively. They are */
574 /* > represented implicitly by Householder vectors. */
575 /* > */
576 /* > B11, B12, B21, and B22 are Q-by-Q bidiagonal matrices represented */
577 /* > implicitly by angles THETA, PHI. */
578 /* > \endverbatim */
579
580 /*  Arguments: */
581 /*  ========== */
582
583 /* > \param[in] TRANS */
584 /* > \verbatim */
585 /* >          TRANS is CHARACTER */
586 /* >          = 'T':      X, U1, U2, V1T, and V2T are stored in row-major */
587 /* >                      order; */
588 /* >          otherwise:  X, U1, U2, V1T, and V2T are stored in column- */
589 /* >                      major order. */
590 /* > \endverbatim */
591 /* > */
592 /* > \param[in] SIGNS */
593 /* > \verbatim */
594 /* >          SIGNS is CHARACTER */
595 /* >          = 'O':      The lower-left block is made nonpositive (the */
596 /* >                      "other" convention); */
597 /* >          otherwise:  The upper-right block is made nonpositive (the */
598 /* >                      "default" convention). */
599 /* > \endverbatim */
600 /* > */
601 /* > \param[in] M */
602 /* > \verbatim */
603 /* >          M is INTEGER */
604 /* >          The number of rows and columns in X. */
605 /* > \endverbatim */
606 /* > */
607 /* > \param[in] P */
608 /* > \verbatim */
609 /* >          P is INTEGER */
610 /* >          The number of rows in X11 and X12. 0 <= P <= M. */
611 /* > \endverbatim */
612 /* > */
613 /* > \param[in] Q */
614 /* > \verbatim */
615 /* >          Q is INTEGER */
616 /* >          The number of columns in X11 and X21. 0 <= Q <= */
617 /* >          MIN(P,M-P,M-Q). */
618 /* > \endverbatim */
619 /* > */
620 /* > \param[in,out] X11 */
621 /* > \verbatim */
622 /* >          X11 is COMPLEX*16 array, dimension (LDX11,Q) */
623 /* >          On entry, the top-left block of the unitary matrix to be */
624 /* >          reduced. On exit, the form depends on TRANS: */
625 /* >          If TRANS = 'N', then */
626 /* >             the columns of tril(X11) specify reflectors for P1, */
627 /* >             the rows of triu(X11,1) specify reflectors for Q1; */
628 /* >          else TRANS = 'T', and */
629 /* >             the rows of triu(X11) specify reflectors for P1, */
630 /* >             the columns of tril(X11,-1) specify reflectors for Q1. */
631 /* > \endverbatim */
632 /* > */
633 /* > \param[in] LDX11 */
634 /* > \verbatim */
635 /* >          LDX11 is INTEGER */
636 /* >          The leading dimension of X11. If TRANS = 'N', then LDX11 >= */
637 /* >          P; else LDX11 >= Q. */
638 /* > \endverbatim */
639 /* > */
640 /* > \param[in,out] X12 */
641 /* > \verbatim */
642 /* >          X12 is COMPLEX*16 array, dimension (LDX12,M-Q) */
643 /* >          On entry, the top-right block of the unitary matrix to */
644 /* >          be reduced. On exit, the form depends on TRANS: */
645 /* >          If TRANS = 'N', then */
646 /* >             the rows of triu(X12) specify the first P reflectors for */
647 /* >             Q2; */
648 /* >          else TRANS = 'T', and */
649 /* >             the columns of tril(X12) specify the first P reflectors */
650 /* >             for Q2. */
651 /* > \endverbatim */
652 /* > */
653 /* > \param[in] LDX12 */
654 /* > \verbatim */
655 /* >          LDX12 is INTEGER */
656 /* >          The leading dimension of X12. If TRANS = 'N', then LDX12 >= */
657 /* >          P; else LDX11 >= M-Q. */
658 /* > \endverbatim */
659 /* > */
660 /* > \param[in,out] X21 */
661 /* > \verbatim */
662 /* >          X21 is COMPLEX*16 array, dimension (LDX21,Q) */
663 /* >          On entry, the bottom-left block of the unitary matrix to */
664 /* >          be reduced. On exit, the form depends on TRANS: */
665 /* >          If TRANS = 'N', then */
666 /* >             the columns of tril(X21) specify reflectors for P2; */
667 /* >          else TRANS = 'T', and */
668 /* >             the rows of triu(X21) specify reflectors for P2. */
669 /* > \endverbatim */
670 /* > */
671 /* > \param[in] LDX21 */
672 /* > \verbatim */
673 /* >          LDX21 is INTEGER */
674 /* >          The leading dimension of X21. If TRANS = 'N', then LDX21 >= */
675 /* >          M-P; else LDX21 >= Q. */
676 /* > \endverbatim */
677 /* > */
678 /* > \param[in,out] X22 */
679 /* > \verbatim */
680 /* >          X22 is COMPLEX*16 array, dimension (LDX22,M-Q) */
681 /* >          On entry, the bottom-right block of the unitary matrix to */
682 /* >          be reduced. On exit, the form depends on TRANS: */
683 /* >          If TRANS = 'N', then */
684 /* >             the rows of triu(X22(Q+1:M-P,P+1:M-Q)) specify the last */
685 /* >             M-P-Q reflectors for Q2, */
686 /* >          else TRANS = 'T', and */
687 /* >             the columns of tril(X22(P+1:M-Q,Q+1:M-P)) specify the last */
688 /* >             M-P-Q reflectors for P2. */
689 /* > \endverbatim */
690 /* > */
691 /* > \param[in] LDX22 */
692 /* > \verbatim */
693 /* >          LDX22 is INTEGER */
694 /* >          The leading dimension of X22. If TRANS = 'N', then LDX22 >= */
695 /* >          M-P; else LDX22 >= M-Q. */
696 /* > \endverbatim */
697 /* > */
698 /* > \param[out] THETA */
699 /* > \verbatim */
700 /* >          THETA is DOUBLE PRECISION array, dimension (Q) */
701 /* >          The entries of the bidiagonal blocks B11, B12, B21, B22 can */
702 /* >          be computed from the angles THETA and PHI. See Further */
703 /* >          Details. */
704 /* > \endverbatim */
705 /* > */
706 /* > \param[out] PHI */
707 /* > \verbatim */
708 /* >          PHI is DOUBLE PRECISION array, dimension (Q-1) */
709 /* >          The entries of the bidiagonal blocks B11, B12, B21, B22 can */
710 /* >          be computed from the angles THETA and PHI. See Further */
711 /* >          Details. */
712 /* > \endverbatim */
713 /* > */
714 /* > \param[out] TAUP1 */
715 /* > \verbatim */
716 /* >          TAUP1 is COMPLEX*16 array, dimension (P) */
717 /* >          The scalar factors of the elementary reflectors that define */
718 /* >          P1. */
719 /* > \endverbatim */
720 /* > */
721 /* > \param[out] TAUP2 */
722 /* > \verbatim */
723 /* >          TAUP2 is COMPLEX*16 array, dimension (M-P) */
724 /* >          The scalar factors of the elementary reflectors that define */
725 /* >          P2. */
726 /* > \endverbatim */
727 /* > */
728 /* > \param[out] TAUQ1 */
729 /* > \verbatim */
730 /* >          TAUQ1 is COMPLEX*16 array, dimension (Q) */
731 /* >          The scalar factors of the elementary reflectors that define */
732 /* >          Q1. */
733 /* > \endverbatim */
734 /* > */
735 /* > \param[out] TAUQ2 */
736 /* > \verbatim */
737 /* >          TAUQ2 is COMPLEX*16 array, dimension (M-Q) */
738 /* >          The scalar factors of the elementary reflectors that define */
739 /* >          Q2. */
740 /* > \endverbatim */
741 /* > */
742 /* > \param[out] WORK */
743 /* > \verbatim */
744 /* >          WORK is COMPLEX*16 array, dimension (LWORK) */
745 /* > \endverbatim */
746 /* > */
747 /* > \param[in] LWORK */
748 /* > \verbatim */
749 /* >          LWORK is INTEGER */
750 /* >          The dimension of the array WORK. LWORK >= M-Q. */
751 /* > */
752 /* >          If LWORK = -1, then a workspace query is assumed; the routine */
753 /* >          only calculates the optimal size of the WORK array, returns */
754 /* >          this value as the first entry of the WORK array, and no error */
755 /* >          message related to LWORK is issued by XERBLA. */
756 /* > \endverbatim */
757 /* > */
758 /* > \param[out] INFO */
759 /* > \verbatim */
760 /* >          INFO is INTEGER */
761 /* >          = 0:  successful exit. */
762 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
763 /* > \endverbatim */
764
765 /*  Authors: */
766 /*  ======== */
767
768 /* > \author Univ. of Tennessee */
769 /* > \author Univ. of California Berkeley */
770 /* > \author Univ. of Colorado Denver */
771 /* > \author NAG Ltd. */
772
773 /* > \date December 2016 */
774
775 /* > \ingroup complex16OTHERcomputational */
776
777 /* > \par Further Details: */
778 /*  ===================== */
779 /* > */
780 /* > \verbatim */
781 /* > */
782 /* >  The bidiagonal blocks B11, B12, B21, and B22 are represented */
783 /* >  implicitly by angles THETA(1), ..., THETA(Q) and PHI(1), ..., */
784 /* >  PHI(Q-1). B11 and B21 are upper bidiagonal, while B21 and B22 are */
785 /* >  lower bidiagonal. Every entry in each bidiagonal band is a product */
786 /* >  of a sine or cosine of a THETA with a sine or cosine of a PHI. See */
787 /* >  [1] or ZUNCSD for details. */
788 /* > */
789 /* >  P1, P2, Q1, and Q2 are represented as products of elementary */
790 /* >  reflectors. See ZUNCSD for details on generating P1, P2, Q1, and Q2 */
791 /* >  using ZUNGQR and ZUNGLQ. */
792 /* > \endverbatim */
793
794 /* > \par References: */
795 /*  ================ */
796 /* > */
797 /* >  [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
798 /* >      Algorithms, 50(1):33-65, 2009. */
799 /* > */
800 /*  ===================================================================== */
801 /* Subroutine */ int zunbdb_(char *trans, char *signs, integer *m, integer *p,
802          integer *q, doublecomplex *x11, integer *ldx11, doublecomplex *x12, 
803         integer *ldx12, doublecomplex *x21, integer *ldx21, doublecomplex *
804         x22, integer *ldx22, doublereal *theta, doublereal *phi, 
805         doublecomplex *taup1, doublecomplex *taup2, doublecomplex *tauq1, 
806         doublecomplex *tauq2, doublecomplex *work, integer *lwork, integer *
807         info)
808 {
809     /* System generated locals */
810     integer x11_dim1, x11_offset, x12_dim1, x12_offset, x21_dim1, x21_offset, 
811             x22_dim1, x22_offset, i__1, i__2, i__3;
812     doublereal d__1;
813     doublecomplex z__1;
814
815     /* Local variables */
816     logical colmajor;
817     integer lworkmin, lworkopt, i__;
818     extern logical lsame_(char *, char *);
819     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
820             doublecomplex *, integer *), zlarf_(char *, integer *, integer *, 
821             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
822             integer *, doublecomplex *);
823     doublereal z1, z2, z3, z4;
824     extern /* Subroutine */ int zaxpy_(integer *, doublecomplex *, 
825             doublecomplex *, integer *, doublecomplex *, integer *);
826     extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
827     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zlacgv_(
828             integer *, doublecomplex *, integer *);
829     logical lquery;
830     extern /* Subroutine */ int zlarfgp_(integer *, doublecomplex *, 
831             doublecomplex *, integer *, doublecomplex *);
832
833
834 /*  -- LAPACK computational routine (version 3.7.0) -- */
835 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
836 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
837 /*     December 2016 */
838
839
840 /*  ==================================================================== */
841
842
843
844 /*     Test input arguments */
845
846     /* Parameter adjustments */
847     x11_dim1 = *ldx11;
848     x11_offset = 1 + x11_dim1 * 1;
849     x11 -= x11_offset;
850     x12_dim1 = *ldx12;
851     x12_offset = 1 + x12_dim1 * 1;
852     x12 -= x12_offset;
853     x21_dim1 = *ldx21;
854     x21_offset = 1 + x21_dim1 * 1;
855     x21 -= x21_offset;
856     x22_dim1 = *ldx22;
857     x22_offset = 1 + x22_dim1 * 1;
858     x22 -= x22_offset;
859     --theta;
860     --phi;
861     --taup1;
862     --taup2;
863     --tauq1;
864     --tauq2;
865     --work;
866
867     /* Function Body */
868     *info = 0;
869     colmajor = ! lsame_(trans, "T");
870     if (! lsame_(signs, "O")) {
871         z1 = 1.;
872         z2 = 1.;
873         z3 = 1.;
874         z4 = 1.;
875     } else {
876         z1 = 1.;
877         z2 = -1.;
878         z3 = 1.;
879         z4 = -1.;
880     }
881     lquery = *lwork == -1;
882
883     if (*m < 0) {
884         *info = -3;
885     } else if (*p < 0 || *p > *m) {
886         *info = -4;
887     } else if (*q < 0 || *q > *p || *q > *m - *p || *q > *m - *q) {
888         *info = -5;
889     } else if (colmajor && *ldx11 < f2cmax(1,*p)) {
890         *info = -7;
891     } else if (! colmajor && *ldx11 < f2cmax(1,*q)) {
892         *info = -7;
893     } else if (colmajor && *ldx12 < f2cmax(1,*p)) {
894         *info = -9;
895     } else /* if(complicated condition) */ {
896 /* Computing MAX */
897         i__1 = 1, i__2 = *m - *q;
898         if (! colmajor && *ldx12 < f2cmax(i__1,i__2)) {
899             *info = -9;
900         } else /* if(complicated condition) */ {
901 /* Computing MAX */
902             i__1 = 1, i__2 = *m - *p;
903             if (colmajor && *ldx21 < f2cmax(i__1,i__2)) {
904                 *info = -11;
905             } else if (! colmajor && *ldx21 < f2cmax(1,*q)) {
906                 *info = -11;
907             } else /* if(complicated condition) */ {
908 /* Computing MAX */
909                 i__1 = 1, i__2 = *m - *p;
910                 if (colmajor && *ldx22 < f2cmax(i__1,i__2)) {
911                     *info = -13;
912                 } else /* if(complicated condition) */ {
913 /* Computing MAX */
914                     i__1 = 1, i__2 = *m - *q;
915                     if (! colmajor && *ldx22 < f2cmax(i__1,i__2)) {
916                         *info = -13;
917                     }
918                 }
919             }
920         }
921     }
922
923 /*     Compute workspace */
924
925     if (*info == 0) {
926         lworkopt = *m - *q;
927         lworkmin = *m - *q;
928         work[1].r = (doublereal) lworkopt, work[1].i = 0.;
929         if (*lwork < lworkmin && ! lquery) {
930             *info = -21;
931         }
932     }
933     if (*info != 0) {
934         i__1 = -(*info);
935         xerbla_("xORBDB", &i__1, (ftnlen)6);
936         return 0;
937     } else if (lquery) {
938         return 0;
939     }
940
941 /*     Handle column-major and row-major separately */
942
943     if (colmajor) {
944
945 /*        Reduce columns 1, ..., Q of X11, X12, X21, and X22 */
946
947         i__1 = *q;
948         for (i__ = 1; i__ <= i__1; ++i__) {
949
950             if (i__ == 1) {
951                 i__2 = *p - i__ + 1;
952                 z__1.r = z1, z__1.i = 0.;
953                 zscal_(&i__2, &z__1, &x11[i__ + i__ * x11_dim1], &c__1);
954             } else {
955                 i__2 = *p - i__ + 1;
956                 d__1 = z1 * cos(phi[i__ - 1]);
957                 z__1.r = d__1, z__1.i = 0.;
958                 zscal_(&i__2, &z__1, &x11[i__ + i__ * x11_dim1], &c__1);
959                 i__2 = *p - i__ + 1;
960                 d__1 = -z1 * z3 * z4 * sin(phi[i__ - 1]);
961                 z__1.r = d__1, z__1.i = 0.;
962                 zaxpy_(&i__2, &z__1, &x12[i__ + (i__ - 1) * x12_dim1], &c__1, 
963                         &x11[i__ + i__ * x11_dim1], &c__1);
964             }
965             if (i__ == 1) {
966                 i__2 = *m - *p - i__ + 1;
967                 z__1.r = z2, z__1.i = 0.;
968                 zscal_(&i__2, &z__1, &x21[i__ + i__ * x21_dim1], &c__1);
969             } else {
970                 i__2 = *m - *p - i__ + 1;
971                 d__1 = z2 * cos(phi[i__ - 1]);
972                 z__1.r = d__1, z__1.i = 0.;
973                 zscal_(&i__2, &z__1, &x21[i__ + i__ * x21_dim1], &c__1);
974                 i__2 = *m - *p - i__ + 1;
975                 d__1 = -z2 * z3 * z4 * sin(phi[i__ - 1]);
976                 z__1.r = d__1, z__1.i = 0.;
977                 zaxpy_(&i__2, &z__1, &x22[i__ + (i__ - 1) * x22_dim1], &c__1, 
978                         &x21[i__ + i__ * x21_dim1], &c__1);
979             }
980
981             i__2 = *m - *p - i__ + 1;
982             i__3 = *p - i__ + 1;
983             theta[i__] = atan2(dznrm2_(&i__2, &x21[i__ + i__ * x21_dim1], &
984                     c__1), dznrm2_(&i__3, &x11[i__ + i__ * x11_dim1], &c__1));
985
986             if (*p > i__) {
987                 i__2 = *p - i__ + 1;
988                 zlarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + 1 + 
989                         i__ * x11_dim1], &c__1, &taup1[i__]);
990             } else if (*p == i__) {
991                 i__2 = *p - i__ + 1;
992                 zlarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + i__ * 
993                         x11_dim1], &c__1, &taup1[i__]);
994             }
995             i__2 = i__ + i__ * x11_dim1;
996             x11[i__2].r = 1., x11[i__2].i = 0.;
997             if (*m - *p > i__) {
998                 i__2 = *m - *p - i__ + 1;
999                 zlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + 1 + 
1000                         i__ * x21_dim1], &c__1, &taup2[i__]);
1001             } else if (*m - *p == i__) {
1002                 i__2 = *m - *p - i__ + 1;
1003                 zlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + i__ * 
1004                         x21_dim1], &c__1, &taup2[i__]);
1005             }
1006             i__2 = i__ + i__ * x21_dim1;
1007             x21[i__2].r = 1., x21[i__2].i = 0.;
1008
1009             if (*q > i__) {
1010                 i__2 = *p - i__ + 1;
1011                 i__3 = *q - i__;
1012                 d_cnjg(&z__1, &taup1[i__]);
1013                 zlarf_("L", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], &c__1, &
1014                         z__1, &x11[i__ + (i__ + 1) * x11_dim1], ldx11, &work[
1015                         1]);
1016                 i__2 = *m - *p - i__ + 1;
1017                 i__3 = *q - i__;
1018                 d_cnjg(&z__1, &taup2[i__]);
1019                 zlarf_("L", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], &c__1, &
1020                         z__1, &x21[i__ + (i__ + 1) * x21_dim1], ldx21, &work[
1021                         1]);
1022             }
1023             if (*m - *q + 1 > i__) {
1024                 i__2 = *p - i__ + 1;
1025                 i__3 = *m - *q - i__ + 1;
1026                 d_cnjg(&z__1, &taup1[i__]);
1027                 zlarf_("L", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], &c__1, &
1028                         z__1, &x12[i__ + i__ * x12_dim1], ldx12, &work[1]);
1029                 i__2 = *m - *p - i__ + 1;
1030                 i__3 = *m - *q - i__ + 1;
1031                 d_cnjg(&z__1, &taup2[i__]);
1032                 zlarf_("L", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], &c__1, &
1033                         z__1, &x22[i__ + i__ * x22_dim1], ldx22, &work[1]);
1034             }
1035
1036             if (i__ < *q) {
1037                 i__2 = *q - i__;
1038                 d__1 = -z1 * z3 * sin(theta[i__]);
1039                 z__1.r = d__1, z__1.i = 0.;
1040                 zscal_(&i__2, &z__1, &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1041                 i__2 = *q - i__;
1042                 d__1 = z2 * z3 * cos(theta[i__]);
1043                 z__1.r = d__1, z__1.i = 0.;
1044                 zaxpy_(&i__2, &z__1, &x21[i__ + (i__ + 1) * x21_dim1], ldx21, 
1045                         &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1046             }
1047             i__2 = *m - *q - i__ + 1;
1048             d__1 = -z1 * z4 * sin(theta[i__]);
1049             z__1.r = d__1, z__1.i = 0.;
1050             zscal_(&i__2, &z__1, &x12[i__ + i__ * x12_dim1], ldx12);
1051             i__2 = *m - *q - i__ + 1;
1052             d__1 = z2 * z4 * cos(theta[i__]);
1053             z__1.r = d__1, z__1.i = 0.;
1054             zaxpy_(&i__2, &z__1, &x22[i__ + i__ * x22_dim1], ldx22, &x12[i__ 
1055                     + i__ * x12_dim1], ldx12);
1056
1057             if (i__ < *q) {
1058                 i__2 = *q - i__;
1059                 i__3 = *m - *q - i__ + 1;
1060                 phi[i__] = atan2(dznrm2_(&i__2, &x11[i__ + (i__ + 1) * 
1061                         x11_dim1], ldx11), dznrm2_(&i__3, &x12[i__ + i__ * 
1062                         x12_dim1], ldx12));
1063             }
1064
1065             if (i__ < *q) {
1066                 i__2 = *q - i__;
1067                 zlacgv_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1068                 if (i__ == *q - 1) {
1069                     i__2 = *q - i__;
1070                     zlarfgp_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], &x11[
1071                             i__ + (i__ + 1) * x11_dim1], ldx11, &tauq1[i__]);
1072                 } else {
1073                     i__2 = *q - i__;
1074                     zlarfgp_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], &x11[
1075                             i__ + (i__ + 2) * x11_dim1], ldx11, &tauq1[i__]);
1076                 }
1077                 i__2 = i__ + (i__ + 1) * x11_dim1;
1078                 x11[i__2].r = 1., x11[i__2].i = 0.;
1079             }
1080             if (*m - *q + 1 > i__) {
1081                 i__2 = *m - *q - i__ + 1;
1082                 zlacgv_(&i__2, &x12[i__ + i__ * x12_dim1], ldx12);
1083                 if (*m - *q == i__) {
1084                     i__2 = *m - *q - i__ + 1;
1085                     zlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 
1086                             i__ * x12_dim1], ldx12, &tauq2[i__]);
1087                 } else {
1088                     i__2 = *m - *q - i__ + 1;
1089                     zlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + (
1090                             i__ + 1) * x12_dim1], ldx12, &tauq2[i__]);
1091                 }
1092             }
1093             i__2 = i__ + i__ * x12_dim1;
1094             x12[i__2].r = 1., x12[i__2].i = 0.;
1095
1096             if (i__ < *q) {
1097                 i__2 = *p - i__;
1098                 i__3 = *q - i__;
1099                 zlarf_("R", &i__2, &i__3, &x11[i__ + (i__ + 1) * x11_dim1], 
1100                         ldx11, &tauq1[i__], &x11[i__ + 1 + (i__ + 1) * 
1101                         x11_dim1], ldx11, &work[1]);
1102                 i__2 = *m - *p - i__;
1103                 i__3 = *q - i__;
1104                 zlarf_("R", &i__2, &i__3, &x11[i__ + (i__ + 1) * x11_dim1], 
1105                         ldx11, &tauq1[i__], &x21[i__ + 1 + (i__ + 1) * 
1106                         x21_dim1], ldx21, &work[1]);
1107             }
1108             if (*p > i__) {
1109                 i__2 = *p - i__;
1110                 i__3 = *m - *q - i__ + 1;
1111                 zlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1112                         tauq2[i__], &x12[i__ + 1 + i__ * x12_dim1], ldx12, &
1113                         work[1]);
1114             }
1115             if (*m - *p > i__) {
1116                 i__2 = *m - *p - i__;
1117                 i__3 = *m - *q - i__ + 1;
1118                 zlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1119                         tauq2[i__], &x22[i__ + 1 + i__ * x22_dim1], ldx22, &
1120                         work[1]);
1121             }
1122
1123             if (i__ < *q) {
1124                 i__2 = *q - i__;
1125                 zlacgv_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1126             }
1127             i__2 = *m - *q - i__ + 1;
1128             zlacgv_(&i__2, &x12[i__ + i__ * x12_dim1], ldx12);
1129
1130         }
1131
1132 /*        Reduce columns Q + 1, ..., P of X12, X22 */
1133
1134         i__1 = *p;
1135         for (i__ = *q + 1; i__ <= i__1; ++i__) {
1136
1137             i__2 = *m - *q - i__ + 1;
1138             d__1 = -z1 * z4;
1139             z__1.r = d__1, z__1.i = 0.;
1140             zscal_(&i__2, &z__1, &x12[i__ + i__ * x12_dim1], ldx12);
1141             i__2 = *m - *q - i__ + 1;
1142             zlacgv_(&i__2, &x12[i__ + i__ * x12_dim1], ldx12);
1143             if (i__ >= *m - *q) {
1144                 i__2 = *m - *q - i__ + 1;
1145                 zlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + i__ * 
1146                         x12_dim1], ldx12, &tauq2[i__]);
1147             } else {
1148                 i__2 = *m - *q - i__ + 1;
1149                 zlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + (i__ + 
1150                         1) * x12_dim1], ldx12, &tauq2[i__]);
1151             }
1152             i__2 = i__ + i__ * x12_dim1;
1153             x12[i__2].r = 1., x12[i__2].i = 0.;
1154
1155             if (*p > i__) {
1156                 i__2 = *p - i__;
1157                 i__3 = *m - *q - i__ + 1;
1158                 zlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1159                         tauq2[i__], &x12[i__ + 1 + i__ * x12_dim1], ldx12, &
1160                         work[1]);
1161             }
1162             if (*m - *p - *q >= 1) {
1163                 i__2 = *m - *p - *q;
1164                 i__3 = *m - *q - i__ + 1;
1165                 zlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1166                         tauq2[i__], &x22[*q + 1 + i__ * x22_dim1], ldx22, &
1167                         work[1]);
1168             }
1169
1170             i__2 = *m - *q - i__ + 1;
1171             zlacgv_(&i__2, &x12[i__ + i__ * x12_dim1], ldx12);
1172
1173         }
1174
1175 /*        Reduce columns P + 1, ..., M - Q of X12, X22 */
1176
1177         i__1 = *m - *p - *q;
1178         for (i__ = 1; i__ <= i__1; ++i__) {
1179
1180             i__2 = *m - *p - *q - i__ + 1;
1181             d__1 = z2 * z4;
1182             z__1.r = d__1, z__1.i = 0.;
1183             zscal_(&i__2, &z__1, &x22[*q + i__ + (*p + i__) * x22_dim1], 
1184                     ldx22);
1185             i__2 = *m - *p - *q - i__ + 1;
1186             zlacgv_(&i__2, &x22[*q + i__ + (*p + i__) * x22_dim1], ldx22);
1187             i__2 = *m - *p - *q - i__ + 1;
1188             zlarfgp_(&i__2, &x22[*q + i__ + (*p + i__) * x22_dim1], &x22[*q + 
1189                     i__ + (*p + i__ + 1) * x22_dim1], ldx22, &tauq2[*p + i__])
1190                     ;
1191             i__2 = *q + i__ + (*p + i__) * x22_dim1;
1192             x22[i__2].r = 1., x22[i__2].i = 0.;
1193             i__2 = *m - *p - *q - i__;
1194             i__3 = *m - *p - *q - i__ + 1;
1195             zlarf_("R", &i__2, &i__3, &x22[*q + i__ + (*p + i__) * x22_dim1], 
1196                     ldx22, &tauq2[*p + i__], &x22[*q + i__ + 1 + (*p + i__) * 
1197                     x22_dim1], ldx22, &work[1]);
1198
1199             i__2 = *m - *p - *q - i__ + 1;
1200             zlacgv_(&i__2, &x22[*q + i__ + (*p + i__) * x22_dim1], ldx22);
1201
1202         }
1203
1204     } else {
1205
1206 /*        Reduce columns 1, ..., Q of X11, X12, X21, X22 */
1207
1208         i__1 = *q;
1209         for (i__ = 1; i__ <= i__1; ++i__) {
1210
1211             if (i__ == 1) {
1212                 i__2 = *p - i__ + 1;
1213                 z__1.r = z1, z__1.i = 0.;
1214                 zscal_(&i__2, &z__1, &x11[i__ + i__ * x11_dim1], ldx11);
1215             } else {
1216                 i__2 = *p - i__ + 1;
1217                 d__1 = z1 * cos(phi[i__ - 1]);
1218                 z__1.r = d__1, z__1.i = 0.;
1219                 zscal_(&i__2, &z__1, &x11[i__ + i__ * x11_dim1], ldx11);
1220                 i__2 = *p - i__ + 1;
1221                 d__1 = -z1 * z3 * z4 * sin(phi[i__ - 1]);
1222                 z__1.r = d__1, z__1.i = 0.;
1223                 zaxpy_(&i__2, &z__1, &x12[i__ - 1 + i__ * x12_dim1], ldx12, &
1224                         x11[i__ + i__ * x11_dim1], ldx11);
1225             }
1226             if (i__ == 1) {
1227                 i__2 = *m - *p - i__ + 1;
1228                 z__1.r = z2, z__1.i = 0.;
1229                 zscal_(&i__2, &z__1, &x21[i__ + i__ * x21_dim1], ldx21);
1230             } else {
1231                 i__2 = *m - *p - i__ + 1;
1232                 d__1 = z2 * cos(phi[i__ - 1]);
1233                 z__1.r = d__1, z__1.i = 0.;
1234                 zscal_(&i__2, &z__1, &x21[i__ + i__ * x21_dim1], ldx21);
1235                 i__2 = *m - *p - i__ + 1;
1236                 d__1 = -z2 * z3 * z4 * sin(phi[i__ - 1]);
1237                 z__1.r = d__1, z__1.i = 0.;
1238                 zaxpy_(&i__2, &z__1, &x22[i__ - 1 + i__ * x22_dim1], ldx22, &
1239                         x21[i__ + i__ * x21_dim1], ldx21);
1240             }
1241
1242             i__2 = *m - *p - i__ + 1;
1243             i__3 = *p - i__ + 1;
1244             theta[i__] = atan2(dznrm2_(&i__2, &x21[i__ + i__ * x21_dim1], 
1245                     ldx21), dznrm2_(&i__3, &x11[i__ + i__ * x11_dim1], ldx11))
1246                     ;
1247
1248             i__2 = *p - i__ + 1;
1249             zlacgv_(&i__2, &x11[i__ + i__ * x11_dim1], ldx11);
1250             i__2 = *m - *p - i__ + 1;
1251             zlacgv_(&i__2, &x21[i__ + i__ * x21_dim1], ldx21);
1252
1253             i__2 = *p - i__ + 1;
1254             zlarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + (i__ + 1) *
1255                      x11_dim1], ldx11, &taup1[i__]);
1256             i__2 = i__ + i__ * x11_dim1;
1257             x11[i__2].r = 1., x11[i__2].i = 0.;
1258             if (i__ == *m - *p) {
1259                 i__2 = *m - *p - i__ + 1;
1260                 zlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + i__ * 
1261                         x21_dim1], ldx21, &taup2[i__]);
1262             } else {
1263                 i__2 = *m - *p - i__ + 1;
1264                 zlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + (i__ + 
1265                         1) * x21_dim1], ldx21, &taup2[i__]);
1266             }
1267             i__2 = i__ + i__ * x21_dim1;
1268             x21[i__2].r = 1., x21[i__2].i = 0.;
1269
1270             i__2 = *q - i__;
1271             i__3 = *p - i__ + 1;
1272             zlarf_("R", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], ldx11, &
1273                     taup1[i__], &x11[i__ + 1 + i__ * x11_dim1], ldx11, &work[
1274                     1]);
1275             i__2 = *m - *q - i__ + 1;
1276             i__3 = *p - i__ + 1;
1277             zlarf_("R", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], ldx11, &
1278                     taup1[i__], &x12[i__ + i__ * x12_dim1], ldx12, &work[1]);
1279             i__2 = *q - i__;
1280             i__3 = *m - *p - i__ + 1;
1281             zlarf_("R", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], ldx21, &
1282                     taup2[i__], &x21[i__ + 1 + i__ * x21_dim1], ldx21, &work[
1283                     1]);
1284             i__2 = *m - *q - i__ + 1;
1285             i__3 = *m - *p - i__ + 1;
1286             zlarf_("R", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], ldx21, &
1287                     taup2[i__], &x22[i__ + i__ * x22_dim1], ldx22, &work[1]);
1288
1289             i__2 = *p - i__ + 1;
1290             zlacgv_(&i__2, &x11[i__ + i__ * x11_dim1], ldx11);
1291             i__2 = *m - *p - i__ + 1;
1292             zlacgv_(&i__2, &x21[i__ + i__ * x21_dim1], ldx21);
1293
1294             if (i__ < *q) {
1295                 i__2 = *q - i__;
1296                 d__1 = -z1 * z3 * sin(theta[i__]);
1297                 z__1.r = d__1, z__1.i = 0.;
1298                 zscal_(&i__2, &z__1, &x11[i__ + 1 + i__ * x11_dim1], &c__1);
1299                 i__2 = *q - i__;
1300                 d__1 = z2 * z3 * cos(theta[i__]);
1301                 z__1.r = d__1, z__1.i = 0.;
1302                 zaxpy_(&i__2, &z__1, &x21[i__ + 1 + i__ * x21_dim1], &c__1, &
1303                         x11[i__ + 1 + i__ * x11_dim1], &c__1);
1304             }
1305             i__2 = *m - *q - i__ + 1;
1306             d__1 = -z1 * z4 * sin(theta[i__]);
1307             z__1.r = d__1, z__1.i = 0.;
1308             zscal_(&i__2, &z__1, &x12[i__ + i__ * x12_dim1], &c__1);
1309             i__2 = *m - *q - i__ + 1;
1310             d__1 = z2 * z4 * cos(theta[i__]);
1311             z__1.r = d__1, z__1.i = 0.;
1312             zaxpy_(&i__2, &z__1, &x22[i__ + i__ * x22_dim1], &c__1, &x12[i__ 
1313                     + i__ * x12_dim1], &c__1);
1314
1315             if (i__ < *q) {
1316                 i__2 = *q - i__;
1317                 i__3 = *m - *q - i__ + 1;
1318                 phi[i__] = atan2(dznrm2_(&i__2, &x11[i__ + 1 + i__ * x11_dim1]
1319                         , &c__1), dznrm2_(&i__3, &x12[i__ + i__ * x12_dim1], &
1320                         c__1));
1321             }
1322
1323             if (i__ < *q) {
1324                 i__2 = *q - i__;
1325                 zlarfgp_(&i__2, &x11[i__ + 1 + i__ * x11_dim1], &x11[i__ + 2 
1326                         + i__ * x11_dim1], &c__1, &tauq1[i__]);
1327                 i__2 = i__ + 1 + i__ * x11_dim1;
1328                 x11[i__2].r = 1., x11[i__2].i = 0.;
1329             }
1330             i__2 = *m - *q - i__ + 1;
1331             zlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 1 + i__ * 
1332                     x12_dim1], &c__1, &tauq2[i__]);
1333             i__2 = i__ + i__ * x12_dim1;
1334             x12[i__2].r = 1., x12[i__2].i = 0.;
1335
1336             if (i__ < *q) {
1337                 i__2 = *q - i__;
1338                 i__3 = *p - i__;
1339                 d_cnjg(&z__1, &tauq1[i__]);
1340                 zlarf_("L", &i__2, &i__3, &x11[i__ + 1 + i__ * x11_dim1], &
1341                         c__1, &z__1, &x11[i__ + 1 + (i__ + 1) * x11_dim1], 
1342                         ldx11, &work[1]);
1343                 i__2 = *q - i__;
1344                 i__3 = *m - *p - i__;
1345                 d_cnjg(&z__1, &tauq1[i__]);
1346                 zlarf_("L", &i__2, &i__3, &x11[i__ + 1 + i__ * x11_dim1], &
1347                         c__1, &z__1, &x21[i__ + 1 + (i__ + 1) * x21_dim1], 
1348                         ldx21, &work[1]);
1349             }
1350             i__2 = *m - *q - i__ + 1;
1351             i__3 = *p - i__;
1352             d_cnjg(&z__1, &tauq2[i__]);
1353             zlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1354                     z__1, &x12[i__ + (i__ + 1) * x12_dim1], ldx12, &work[1]);
1355             if (*m - *p > i__) {
1356                 i__2 = *m - *q - i__ + 1;
1357                 i__3 = *m - *p - i__;
1358                 d_cnjg(&z__1, &tauq2[i__]);
1359                 zlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1360                         z__1, &x22[i__ + (i__ + 1) * x22_dim1], ldx22, &work[
1361                         1]);
1362             }
1363
1364         }
1365
1366 /*        Reduce columns Q + 1, ..., P of X12, X22 */
1367
1368         i__1 = *p;
1369         for (i__ = *q + 1; i__ <= i__1; ++i__) {
1370
1371             i__2 = *m - *q - i__ + 1;
1372             d__1 = -z1 * z4;
1373             z__1.r = d__1, z__1.i = 0.;
1374             zscal_(&i__2, &z__1, &x12[i__ + i__ * x12_dim1], &c__1);
1375             i__2 = *m - *q - i__ + 1;
1376             zlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 1 + i__ * 
1377                     x12_dim1], &c__1, &tauq2[i__]);
1378             i__2 = i__ + i__ * x12_dim1;
1379             x12[i__2].r = 1., x12[i__2].i = 0.;
1380
1381             if (*p > i__) {
1382                 i__2 = *m - *q - i__ + 1;
1383                 i__3 = *p - i__;
1384                 d_cnjg(&z__1, &tauq2[i__]);
1385                 zlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1386                         z__1, &x12[i__ + (i__ + 1) * x12_dim1], ldx12, &work[
1387                         1]);
1388             }
1389             if (*m - *p - *q >= 1) {
1390                 i__2 = *m - *q - i__ + 1;
1391                 i__3 = *m - *p - *q;
1392                 d_cnjg(&z__1, &tauq2[i__]);
1393                 zlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1394                         z__1, &x22[i__ + (*q + 1) * x22_dim1], ldx22, &work[1]
1395                         );
1396             }
1397
1398         }
1399
1400 /*        Reduce columns P + 1, ..., M - Q of X12, X22 */
1401
1402         i__1 = *m - *p - *q;
1403         for (i__ = 1; i__ <= i__1; ++i__) {
1404
1405             i__2 = *m - *p - *q - i__ + 1;
1406             d__1 = z2 * z4;
1407             z__1.r = d__1, z__1.i = 0.;
1408             zscal_(&i__2, &z__1, &x22[*p + i__ + (*q + i__) * x22_dim1], &
1409                     c__1);
1410             i__2 = *m - *p - *q - i__ + 1;
1411             zlarfgp_(&i__2, &x22[*p + i__ + (*q + i__) * x22_dim1], &x22[*p + 
1412                     i__ + 1 + (*q + i__) * x22_dim1], &c__1, &tauq2[*p + i__])
1413                     ;
1414             i__2 = *p + i__ + (*q + i__) * x22_dim1;
1415             x22[i__2].r = 1., x22[i__2].i = 0.;
1416
1417             if (*m - *p - *q != i__) {
1418                 i__2 = *m - *p - *q - i__ + 1;
1419                 i__3 = *m - *p - *q - i__;
1420                 d_cnjg(&z__1, &tauq2[*p + i__]);
1421                 zlarf_("L", &i__2, &i__3, &x22[*p + i__ + (*q + i__) * 
1422                         x22_dim1], &c__1, &z__1, &x22[*p + i__ + (*q + i__ + 
1423                         1) * x22_dim1], ldx22, &work[1]);
1424             }
1425
1426         }
1427
1428     }
1429
1430     return 0;
1431
1432 /*     End of ZUNBDB */
1433
1434 } /* zunbdb_ */
1435