C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dorbdb.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__1 = 1;
516
517 /* > \brief \b DORBDB */
518
519 /*  =========== DOCUMENTATION =========== */
520
521 /* Online html documentation available at */
522 /*            http://www.netlib.org/lapack/explore-html/ */
523
524 /* > \htmlonly */
525 /* > Download DORBDB + dependencies */
526 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dorbdb.
527 f"> */
528 /* > [TGZ]</a> */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dorbdb.
530 f"> */
531 /* > [ZIP]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dorbdb.
533 f"> */
534 /* > [TXT]</a> */
535 /* > \endhtmlonly */
536
537 /*  Definition: */
538 /*  =========== */
539
540 /*       SUBROUTINE DORBDB( 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 /*       DOUBLE PRECISION   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 /* > DORBDB simultaneously bidiagonalizes the blocks of an M-by-M */
559 /* > partitioned orthogonal matrix X: */
560 /* > */
561 /* >                                 [ B11 | B12 0  0 ] */
562 /* >     [ X11 | X12 ]   [ P1 |    ] [  0  |  0 -I  0 ] [ Q1 |    ]**T */
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 DORCSD */
570 /* > for details.) */
571 /* > */
572 /* > The orthogonal 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 DOUBLE PRECISION array, dimension (LDX11,Q) */
623 /* >          On entry, the top-left block of the orthogonal 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 DOUBLE PRECISION array, dimension (LDX12,M-Q) */
643 /* >          On entry, the top-right block of the orthogonal 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 DOUBLE PRECISION array, dimension (LDX21,Q) */
663 /* >          On entry, the bottom-left block of the orthogonal 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 DOUBLE PRECISION array, dimension (LDX22,M-Q) */
681 /* >          On entry, the bottom-right block of the orthogonal 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 doubleOTHERcomputational */
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 DORCSD for details. */
788 /* > */
789 /* >  P1, P2, Q1, and Q2 are represented as products of elementary */
790 /* >  reflectors. See DORCSD for details on generating P1, P2, Q1, and Q2 */
791 /* >  using DORGQR and DORGLQ. */
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 dorbdb_(char *trans, char *signs, integer *m, integer *p,
802          integer *q, doublereal *x11, integer *ldx11, doublereal *x12, 
803         integer *ldx12, doublereal *x21, integer *ldx21, doublereal *x22, 
804         integer *ldx22, doublereal *theta, doublereal *phi, doublereal *taup1,
805          doublereal *taup2, doublereal *tauq1, doublereal *tauq2, doublereal *
806         work, integer *lwork, integer *info)
807 {
808     /* System generated locals */
809     integer x11_dim1, x11_offset, x12_dim1, x12_offset, x21_dim1, x21_offset, 
810             x22_dim1, x22_offset, i__1, i__2, i__3;
811     doublereal d__1;
812
813     /* Local variables */
814     logical colmajor;
815     integer lworkmin;
816     extern doublereal dnrm2_(integer *, doublereal *, integer *);
817     integer lworkopt, i__;
818     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
819             integer *), dlarf_(char *, integer *, integer *, doublereal *, 
820             integer *, doublereal *, doublereal *, integer *, doublereal *);
821     extern logical lsame_(char *, char *);
822     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
823             integer *, doublereal *, integer *);
824     doublereal z1, z2, z3, z4;
825     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
826     logical lquery;
827     extern /* Subroutine */ int dlarfgp_(integer *, doublereal *, doublereal *
828             , integer *, doublereal *);
829
830
831 /*  -- LAPACK computational routine (version 3.7.0) -- */
832 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
833 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
834 /*     December 2016 */
835
836
837 /*  ==================================================================== */
838
839
840 /*     Test input arguments */
841
842     /* Parameter adjustments */
843     x11_dim1 = *ldx11;
844     x11_offset = 1 + x11_dim1 * 1;
845     x11 -= x11_offset;
846     x12_dim1 = *ldx12;
847     x12_offset = 1 + x12_dim1 * 1;
848     x12 -= x12_offset;
849     x21_dim1 = *ldx21;
850     x21_offset = 1 + x21_dim1 * 1;
851     x21 -= x21_offset;
852     x22_dim1 = *ldx22;
853     x22_offset = 1 + x22_dim1 * 1;
854     x22 -= x22_offset;
855     --theta;
856     --phi;
857     --taup1;
858     --taup2;
859     --tauq1;
860     --tauq2;
861     --work;
862
863     /* Function Body */
864     *info = 0;
865     colmajor = ! lsame_(trans, "T");
866     if (! lsame_(signs, "O")) {
867         z1 = 1.;
868         z2 = 1.;
869         z3 = 1.;
870         z4 = 1.;
871     } else {
872         z1 = 1.;
873         z2 = -1.;
874         z3 = 1.;
875         z4 = -1.;
876     }
877     lquery = *lwork == -1;
878
879     if (*m < 0) {
880         *info = -3;
881     } else if (*p < 0 || *p > *m) {
882         *info = -4;
883     } else if (*q < 0 || *q > *p || *q > *m - *p || *q > *m - *q) {
884         *info = -5;
885     } else if (colmajor && *ldx11 < f2cmax(1,*p)) {
886         *info = -7;
887     } else if (! colmajor && *ldx11 < f2cmax(1,*q)) {
888         *info = -7;
889     } else if (colmajor && *ldx12 < f2cmax(1,*p)) {
890         *info = -9;
891     } else /* if(complicated condition) */ {
892 /* Computing MAX */
893         i__1 = 1, i__2 = *m - *q;
894         if (! colmajor && *ldx12 < f2cmax(i__1,i__2)) {
895             *info = -9;
896         } else /* if(complicated condition) */ {
897 /* Computing MAX */
898             i__1 = 1, i__2 = *m - *p;
899             if (colmajor && *ldx21 < f2cmax(i__1,i__2)) {
900                 *info = -11;
901             } else if (! colmajor && *ldx21 < f2cmax(1,*q)) {
902                 *info = -11;
903             } else /* if(complicated condition) */ {
904 /* Computing MAX */
905                 i__1 = 1, i__2 = *m - *p;
906                 if (colmajor && *ldx22 < f2cmax(i__1,i__2)) {
907                     *info = -13;
908                 } else /* if(complicated condition) */ {
909 /* Computing MAX */
910                     i__1 = 1, i__2 = *m - *q;
911                     if (! colmajor && *ldx22 < f2cmax(i__1,i__2)) {
912                         *info = -13;
913                     }
914                 }
915             }
916         }
917     }
918
919 /*     Compute workspace */
920
921     if (*info == 0) {
922         lworkopt = *m - *q;
923         lworkmin = *m - *q;
924         work[1] = (doublereal) lworkopt;
925         if (*lwork < lworkmin && ! lquery) {
926             *info = -21;
927         }
928     }
929     if (*info != 0) {
930         i__1 = -(*info);
931         xerbla_("xORBDB", &i__1, (ftnlen)6);
932         return 0;
933     } else if (lquery) {
934         return 0;
935     }
936
937 /*     Handle column-major and row-major separately */
938
939     if (colmajor) {
940
941 /*        Reduce columns 1, ..., Q of X11, X12, X21, and X22 */
942
943         i__1 = *q;
944         for (i__ = 1; i__ <= i__1; ++i__) {
945
946             if (i__ == 1) {
947                 i__2 = *p - i__ + 1;
948                 dscal_(&i__2, &z1, &x11[i__ + i__ * x11_dim1], &c__1);
949             } else {
950                 i__2 = *p - i__ + 1;
951                 d__1 = z1 * cos(phi[i__ - 1]);
952                 dscal_(&i__2, &d__1, &x11[i__ + i__ * x11_dim1], &c__1);
953                 i__2 = *p - i__ + 1;
954                 d__1 = -z1 * z3 * z4 * sin(phi[i__ - 1]);
955                 daxpy_(&i__2, &d__1, &x12[i__ + (i__ - 1) * x12_dim1], &c__1, 
956                         &x11[i__ + i__ * x11_dim1], &c__1);
957             }
958             if (i__ == 1) {
959                 i__2 = *m - *p - i__ + 1;
960                 dscal_(&i__2, &z2, &x21[i__ + i__ * x21_dim1], &c__1);
961             } else {
962                 i__2 = *m - *p - i__ + 1;
963                 d__1 = z2 * cos(phi[i__ - 1]);
964                 dscal_(&i__2, &d__1, &x21[i__ + i__ * x21_dim1], &c__1);
965                 i__2 = *m - *p - i__ + 1;
966                 d__1 = -z2 * z3 * z4 * sin(phi[i__ - 1]);
967                 daxpy_(&i__2, &d__1, &x22[i__ + (i__ - 1) * x22_dim1], &c__1, 
968                         &x21[i__ + i__ * x21_dim1], &c__1);
969             }
970
971             i__2 = *m - *p - i__ + 1;
972             i__3 = *p - i__ + 1;
973             theta[i__] = atan2(dnrm2_(&i__2, &x21[i__ + i__ * x21_dim1], &
974                     c__1), dnrm2_(&i__3, &x11[i__ + i__ * x11_dim1], &c__1));
975
976             if (*p > i__) {
977                 i__2 = *p - i__ + 1;
978                 dlarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + 1 + 
979                         i__ * x11_dim1], &c__1, &taup1[i__]);
980             } else if (*p == i__) {
981                 i__2 = *p - i__ + 1;
982                 dlarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + i__ * 
983                         x11_dim1], &c__1, &taup1[i__]);
984             }
985             x11[i__ + i__ * x11_dim1] = 1.;
986             if (*m - *p > i__) {
987                 i__2 = *m - *p - i__ + 1;
988                 dlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + 1 + 
989                         i__ * x21_dim1], &c__1, &taup2[i__]);
990             } else if (*m - *p == i__) {
991                 i__2 = *m - *p - i__ + 1;
992                 dlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + i__ * 
993                         x21_dim1], &c__1, &taup2[i__]);
994             }
995             x21[i__ + i__ * x21_dim1] = 1.;
996
997             if (*q > i__) {
998                 i__2 = *p - i__ + 1;
999                 i__3 = *q - i__;
1000                 dlarf_("L", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], &c__1, &
1001                         taup1[i__], &x11[i__ + (i__ + 1) * x11_dim1], ldx11, &
1002                         work[1]);
1003             }
1004             if (*m - *q + 1 > i__) {
1005                 i__2 = *p - i__ + 1;
1006                 i__3 = *m - *q - i__ + 1;
1007                 dlarf_("L", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], &c__1, &
1008                         taup1[i__], &x12[i__ + i__ * x12_dim1], ldx12, &work[
1009                         1]);
1010             }
1011             if (*q > i__) {
1012                 i__2 = *m - *p - i__ + 1;
1013                 i__3 = *q - i__;
1014                 dlarf_("L", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], &c__1, &
1015                         taup2[i__], &x21[i__ + (i__ + 1) * x21_dim1], ldx21, &
1016                         work[1]);
1017             }
1018             if (*m - *q + 1 > i__) {
1019                 i__2 = *m - *p - i__ + 1;
1020                 i__3 = *m - *q - i__ + 1;
1021                 dlarf_("L", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], &c__1, &
1022                         taup2[i__], &x22[i__ + i__ * x22_dim1], ldx22, &work[
1023                         1]);
1024             }
1025
1026             if (i__ < *q) {
1027                 i__2 = *q - i__;
1028                 d__1 = -z1 * z3 * sin(theta[i__]);
1029                 dscal_(&i__2, &d__1, &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1030                 i__2 = *q - i__;
1031                 d__1 = z2 * z3 * cos(theta[i__]);
1032                 daxpy_(&i__2, &d__1, &x21[i__ + (i__ + 1) * x21_dim1], ldx21, 
1033                         &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1034             }
1035             i__2 = *m - *q - i__ + 1;
1036             d__1 = -z1 * z4 * sin(theta[i__]);
1037             dscal_(&i__2, &d__1, &x12[i__ + i__ * x12_dim1], ldx12);
1038             i__2 = *m - *q - i__ + 1;
1039             d__1 = z2 * z4 * cos(theta[i__]);
1040             daxpy_(&i__2, &d__1, &x22[i__ + i__ * x22_dim1], ldx22, &x12[i__ 
1041                     + i__ * x12_dim1], ldx12);
1042
1043             if (i__ < *q) {
1044                 i__2 = *q - i__;
1045                 i__3 = *m - *q - i__ + 1;
1046                 phi[i__] = atan2(dnrm2_(&i__2, &x11[i__ + (i__ + 1) * 
1047                         x11_dim1], ldx11), dnrm2_(&i__3, &x12[i__ + i__ * 
1048                         x12_dim1], ldx12));
1049             }
1050
1051             if (i__ < *q) {
1052                 if (*q - i__ == 1) {
1053                     i__2 = *q - i__;
1054                     dlarfgp_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], &x11[
1055                             i__ + (i__ + 1) * x11_dim1], ldx11, &tauq1[i__]);
1056                 } else {
1057                     i__2 = *q - i__;
1058                     dlarfgp_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], &x11[
1059                             i__ + (i__ + 2) * x11_dim1], ldx11, &tauq1[i__]);
1060                 }
1061                 x11[i__ + (i__ + 1) * x11_dim1] = 1.;
1062             }
1063             if (*q + i__ - 1 < *m) {
1064                 if (*m - *q == i__) {
1065                     i__2 = *m - *q - i__ + 1;
1066                     dlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 
1067                             i__ * x12_dim1], ldx12, &tauq2[i__]);
1068                 } else {
1069                     i__2 = *m - *q - i__ + 1;
1070                     dlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + (
1071                             i__ + 1) * x12_dim1], ldx12, &tauq2[i__]);
1072                 }
1073             }
1074             x12[i__ + i__ * x12_dim1] = 1.;
1075
1076             if (i__ < *q) {
1077                 i__2 = *p - i__;
1078                 i__3 = *q - i__;
1079                 dlarf_("R", &i__2, &i__3, &x11[i__ + (i__ + 1) * x11_dim1], 
1080                         ldx11, &tauq1[i__], &x11[i__ + 1 + (i__ + 1) * 
1081                         x11_dim1], ldx11, &work[1]);
1082                 i__2 = *m - *p - i__;
1083                 i__3 = *q - i__;
1084                 dlarf_("R", &i__2, &i__3, &x11[i__ + (i__ + 1) * x11_dim1], 
1085                         ldx11, &tauq1[i__], &x21[i__ + 1 + (i__ + 1) * 
1086                         x21_dim1], ldx21, &work[1]);
1087             }
1088             if (*p > i__) {
1089                 i__2 = *p - i__;
1090                 i__3 = *m - *q - i__ + 1;
1091                 dlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1092                         tauq2[i__], &x12[i__ + 1 + i__ * x12_dim1], ldx12, &
1093                         work[1]);
1094             }
1095             if (*m - *p > i__) {
1096                 i__2 = *m - *p - i__;
1097                 i__3 = *m - *q - i__ + 1;
1098                 dlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1099                         tauq2[i__], &x22[i__ + 1 + i__ * x22_dim1], ldx22, &
1100                         work[1]);
1101             }
1102
1103         }
1104
1105 /*        Reduce columns Q + 1, ..., P of X12, X22 */
1106
1107         i__1 = *p;
1108         for (i__ = *q + 1; i__ <= i__1; ++i__) {
1109
1110             i__2 = *m - *q - i__ + 1;
1111             d__1 = -z1 * z4;
1112             dscal_(&i__2, &d__1, &x12[i__ + i__ * x12_dim1], ldx12);
1113             if (i__ >= *m - *q) {
1114                 i__2 = *m - *q - i__ + 1;
1115                 dlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + i__ * 
1116                         x12_dim1], ldx12, &tauq2[i__]);
1117             } else {
1118                 i__2 = *m - *q - i__ + 1;
1119                 dlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + (i__ + 
1120                         1) * x12_dim1], ldx12, &tauq2[i__]);
1121             }
1122             x12[i__ + i__ * x12_dim1] = 1.;
1123
1124             if (*p > i__) {
1125                 i__2 = *p - i__;
1126                 i__3 = *m - *q - i__ + 1;
1127                 dlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1128                         tauq2[i__], &x12[i__ + 1 + i__ * x12_dim1], ldx12, &
1129                         work[1]);
1130             }
1131             if (*m - *p - *q >= 1) {
1132                 i__2 = *m - *p - *q;
1133                 i__3 = *m - *q - i__ + 1;
1134                 dlarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1135                         tauq2[i__], &x22[*q + 1 + i__ * x22_dim1], ldx22, &
1136                         work[1]);
1137             }
1138
1139         }
1140
1141 /*        Reduce columns P + 1, ..., M - Q of X12, X22 */
1142
1143         i__1 = *m - *p - *q;
1144         for (i__ = 1; i__ <= i__1; ++i__) {
1145
1146             i__2 = *m - *p - *q - i__ + 1;
1147             d__1 = z2 * z4;
1148             dscal_(&i__2, &d__1, &x22[*q + i__ + (*p + i__) * x22_dim1], 
1149                     ldx22);
1150             if (i__ == *m - *p - *q) {
1151                 i__2 = *m - *p - *q - i__ + 1;
1152                 dlarfgp_(&i__2, &x22[*q + i__ + (*p + i__) * x22_dim1], &x22[*
1153                         q + i__ + (*p + i__) * x22_dim1], ldx22, &tauq2[*p + 
1154                         i__]);
1155             } else {
1156                 i__2 = *m - *p - *q - i__ + 1;
1157                 dlarfgp_(&i__2, &x22[*q + i__ + (*p + i__) * x22_dim1], &x22[*
1158                         q + i__ + (*p + i__ + 1) * x22_dim1], ldx22, &tauq2[*
1159                         p + i__]);
1160             }
1161             x22[*q + i__ + (*p + i__) * x22_dim1] = 1.;
1162             if (i__ < *m - *p - *q) {
1163                 i__2 = *m - *p - *q - i__;
1164                 i__3 = *m - *p - *q - i__ + 1;
1165                 dlarf_("R", &i__2, &i__3, &x22[*q + i__ + (*p + i__) * 
1166                         x22_dim1], ldx22, &tauq2[*p + i__], &x22[*q + i__ + 1 
1167                         + (*p + i__) * x22_dim1], ldx22, &work[1]);
1168             }
1169
1170         }
1171
1172     } else {
1173
1174 /*        Reduce columns 1, ..., Q of X11, X12, X21, X22 */
1175
1176         i__1 = *q;
1177         for (i__ = 1; i__ <= i__1; ++i__) {
1178
1179             if (i__ == 1) {
1180                 i__2 = *p - i__ + 1;
1181                 dscal_(&i__2, &z1, &x11[i__ + i__ * x11_dim1], ldx11);
1182             } else {
1183                 i__2 = *p - i__ + 1;
1184                 d__1 = z1 * cos(phi[i__ - 1]);
1185                 dscal_(&i__2, &d__1, &x11[i__ + i__ * x11_dim1], ldx11);
1186                 i__2 = *p - i__ + 1;
1187                 d__1 = -z1 * z3 * z4 * sin(phi[i__ - 1]);
1188                 daxpy_(&i__2, &d__1, &x12[i__ - 1 + i__ * x12_dim1], ldx12, &
1189                         x11[i__ + i__ * x11_dim1], ldx11);
1190             }
1191             if (i__ == 1) {
1192                 i__2 = *m - *p - i__ + 1;
1193                 dscal_(&i__2, &z2, &x21[i__ + i__ * x21_dim1], ldx21);
1194             } else {
1195                 i__2 = *m - *p - i__ + 1;
1196                 d__1 = z2 * cos(phi[i__ - 1]);
1197                 dscal_(&i__2, &d__1, &x21[i__ + i__ * x21_dim1], ldx21);
1198                 i__2 = *m - *p - i__ + 1;
1199                 d__1 = -z2 * z3 * z4 * sin(phi[i__ - 1]);
1200                 daxpy_(&i__2, &d__1, &x22[i__ - 1 + i__ * x22_dim1], ldx22, &
1201                         x21[i__ + i__ * x21_dim1], ldx21);
1202             }
1203
1204             i__2 = *m - *p - i__ + 1;
1205             i__3 = *p - i__ + 1;
1206             theta[i__] = atan2(dnrm2_(&i__2, &x21[i__ + i__ * x21_dim1], 
1207                     ldx21), dnrm2_(&i__3, &x11[i__ + i__ * x11_dim1], ldx11));
1208
1209             i__2 = *p - i__ + 1;
1210             dlarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + (i__ + 1) *
1211                      x11_dim1], ldx11, &taup1[i__]);
1212             x11[i__ + i__ * x11_dim1] = 1.;
1213             if (i__ == *m - *p) {
1214                 i__2 = *m - *p - i__ + 1;
1215                 dlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + i__ * 
1216                         x21_dim1], ldx21, &taup2[i__]);
1217             } else {
1218                 i__2 = *m - *p - i__ + 1;
1219                 dlarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + (i__ + 
1220                         1) * x21_dim1], ldx21, &taup2[i__]);
1221             }
1222             x21[i__ + i__ * x21_dim1] = 1.;
1223
1224             if (*q > i__) {
1225                 i__2 = *q - i__;
1226                 i__3 = *p - i__ + 1;
1227                 dlarf_("R", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], ldx11, &
1228                         taup1[i__], &x11[i__ + 1 + i__ * x11_dim1], ldx11, &
1229                         work[1]);
1230             }
1231             if (*m - *q + 1 > i__) {
1232                 i__2 = *m - *q - i__ + 1;
1233                 i__3 = *p - i__ + 1;
1234                 dlarf_("R", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], ldx11, &
1235                         taup1[i__], &x12[i__ + i__ * x12_dim1], ldx12, &work[
1236                         1]);
1237             }
1238             if (*q > i__) {
1239                 i__2 = *q - i__;
1240                 i__3 = *m - *p - i__ + 1;
1241                 dlarf_("R", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], ldx21, &
1242                         taup2[i__], &x21[i__ + 1 + i__ * x21_dim1], ldx21, &
1243                         work[1]);
1244             }
1245             if (*m - *q + 1 > i__) {
1246                 i__2 = *m - *q - i__ + 1;
1247                 i__3 = *m - *p - i__ + 1;
1248                 dlarf_("R", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], ldx21, &
1249                         taup2[i__], &x22[i__ + i__ * x22_dim1], ldx22, &work[
1250                         1]);
1251             }
1252
1253             if (i__ < *q) {
1254                 i__2 = *q - i__;
1255                 d__1 = -z1 * z3 * sin(theta[i__]);
1256                 dscal_(&i__2, &d__1, &x11[i__ + 1 + i__ * x11_dim1], &c__1);
1257                 i__2 = *q - i__;
1258                 d__1 = z2 * z3 * cos(theta[i__]);
1259                 daxpy_(&i__2, &d__1, &x21[i__ + 1 + i__ * x21_dim1], &c__1, &
1260                         x11[i__ + 1 + i__ * x11_dim1], &c__1);
1261             }
1262             i__2 = *m - *q - i__ + 1;
1263             d__1 = -z1 * z4 * sin(theta[i__]);
1264             dscal_(&i__2, &d__1, &x12[i__ + i__ * x12_dim1], &c__1);
1265             i__2 = *m - *q - i__ + 1;
1266             d__1 = z2 * z4 * cos(theta[i__]);
1267             daxpy_(&i__2, &d__1, &x22[i__ + i__ * x22_dim1], &c__1, &x12[i__ 
1268                     + i__ * x12_dim1], &c__1);
1269
1270             if (i__ < *q) {
1271                 i__2 = *q - i__;
1272                 i__3 = *m - *q - i__ + 1;
1273                 phi[i__] = atan2(dnrm2_(&i__2, &x11[i__ + 1 + i__ * x11_dim1],
1274                          &c__1), dnrm2_(&i__3, &x12[i__ + i__ * x12_dim1], &
1275                         c__1));
1276             }
1277
1278             if (i__ < *q) {
1279                 if (*q - i__ == 1) {
1280                     i__2 = *q - i__;
1281                     dlarfgp_(&i__2, &x11[i__ + 1 + i__ * x11_dim1], &x11[i__ 
1282                             + 1 + i__ * x11_dim1], &c__1, &tauq1[i__]);
1283                 } else {
1284                     i__2 = *q - i__;
1285                     dlarfgp_(&i__2, &x11[i__ + 1 + i__ * x11_dim1], &x11[i__ 
1286                             + 2 + i__ * x11_dim1], &c__1, &tauq1[i__]);
1287                 }
1288                 x11[i__ + 1 + i__ * x11_dim1] = 1.;
1289             }
1290             if (*m - *q > i__) {
1291                 i__2 = *m - *q - i__ + 1;
1292                 dlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 1 + 
1293                         i__ * x12_dim1], &c__1, &tauq2[i__]);
1294             } else {
1295                 i__2 = *m - *q - i__ + 1;
1296                 dlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + i__ * 
1297                         x12_dim1], &c__1, &tauq2[i__]);
1298             }
1299             x12[i__ + i__ * x12_dim1] = 1.;
1300
1301             if (i__ < *q) {
1302                 i__2 = *q - i__;
1303                 i__3 = *p - i__;
1304                 dlarf_("L", &i__2, &i__3, &x11[i__ + 1 + i__ * x11_dim1], &
1305                         c__1, &tauq1[i__], &x11[i__ + 1 + (i__ + 1) * 
1306                         x11_dim1], ldx11, &work[1]);
1307                 i__2 = *q - i__;
1308                 i__3 = *m - *p - i__;
1309                 dlarf_("L", &i__2, &i__3, &x11[i__ + 1 + i__ * x11_dim1], &
1310                         c__1, &tauq1[i__], &x21[i__ + 1 + (i__ + 1) * 
1311                         x21_dim1], ldx21, &work[1]);
1312             }
1313             i__2 = *m - *q - i__ + 1;
1314             i__3 = *p - i__;
1315             dlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1316                     tauq2[i__], &x12[i__ + (i__ + 1) * x12_dim1], ldx12, &
1317                     work[1]);
1318             if (*m - *p - i__ > 0) {
1319                 i__2 = *m - *q - i__ + 1;
1320                 i__3 = *m - *p - i__;
1321                 dlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1322                         tauq2[i__], &x22[i__ + (i__ + 1) * x22_dim1], ldx22, &
1323                         work[1]);
1324             }
1325
1326         }
1327
1328 /*        Reduce columns Q + 1, ..., P of X12, X22 */
1329
1330         i__1 = *p;
1331         for (i__ = *q + 1; i__ <= i__1; ++i__) {
1332
1333             i__2 = *m - *q - i__ + 1;
1334             d__1 = -z1 * z4;
1335             dscal_(&i__2, &d__1, &x12[i__ + i__ * x12_dim1], &c__1);
1336             i__2 = *m - *q - i__ + 1;
1337             dlarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 1 + i__ * 
1338                     x12_dim1], &c__1, &tauq2[i__]);
1339             x12[i__ + i__ * x12_dim1] = 1.;
1340
1341             if (*p > i__) {
1342                 i__2 = *m - *q - i__ + 1;
1343                 i__3 = *p - i__;
1344                 dlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1345                         tauq2[i__], &x12[i__ + (i__ + 1) * x12_dim1], ldx12, &
1346                         work[1]);
1347             }
1348             if (*m - *p - *q >= 1) {
1349                 i__2 = *m - *q - i__ + 1;
1350                 i__3 = *m - *p - *q;
1351                 dlarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1352                         tauq2[i__], &x22[i__ + (*q + 1) * x22_dim1], ldx22, &
1353                         work[1]);
1354             }
1355
1356         }
1357
1358 /*        Reduce columns P + 1, ..., M - Q of X12, X22 */
1359
1360         i__1 = *m - *p - *q;
1361         for (i__ = 1; i__ <= i__1; ++i__) {
1362
1363             i__2 = *m - *p - *q - i__ + 1;
1364             d__1 = z2 * z4;
1365             dscal_(&i__2, &d__1, &x22[*p + i__ + (*q + i__) * x22_dim1], &
1366                     c__1);
1367             if (*m - *p - *q == i__) {
1368                 i__2 = *m - *p - *q - i__ + 1;
1369                 dlarfgp_(&i__2, &x22[*p + i__ + (*q + i__) * x22_dim1], &x22[*
1370                         p + i__ + (*q + i__) * x22_dim1], &c__1, &tauq2[*p + 
1371                         i__]);
1372             } else {
1373                 i__2 = *m - *p - *q - i__ + 1;
1374                 dlarfgp_(&i__2, &x22[*p + i__ + (*q + i__) * x22_dim1], &x22[*
1375                         p + i__ + 1 + (*q + i__) * x22_dim1], &c__1, &tauq2[*
1376                         p + i__]);
1377                 i__2 = *m - *p - *q - i__ + 1;
1378                 i__3 = *m - *p - *q - i__;
1379                 dlarf_("L", &i__2, &i__3, &x22[*p + i__ + (*q + i__) * 
1380                         x22_dim1], &c__1, &tauq2[*p + i__], &x22[*p + i__ + (*
1381                         q + i__ + 1) * x22_dim1], ldx22, &work[1]);
1382             }
1383             x22[*p + i__ + (*q + i__) * x22_dim1] = 1.;
1384
1385         }
1386
1387     }
1388
1389     return 0;
1390
1391 /*     End of DORBDB */
1392
1393 } /* dorbdb_ */
1394