C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / sorbdb.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 SORBDB */
518
519 /*  =========== DOCUMENTATION =========== */
520
521 /* Online html documentation available at */
522 /*            http://www.netlib.org/lapack/explore-html/ */
523
524 /* > \htmlonly */
525 /* > Download SORBDB + dependencies */
526 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sorbdb.
527 f"> */
528 /* > [TGZ]</a> */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sorbdb.
530 f"> */
531 /* > [ZIP]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sorbdb.
533 f"> */
534 /* > [TXT]</a> */
535 /* > \endhtmlonly */
536
537 /*  Definition: */
538 /*  =========== */
539
540 /*       SUBROUTINE SORBDB( 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 /*       REAL               PHI( * ), THETA( * ) */
548 /*       REAL               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 /* > SORBDB 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 SORCSD */
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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 realOTHERcomputational */
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 SORCSD for details. */
788 /* > */
789 /* >  P1, P2, Q1, and Q2 are represented as products of elementary */
790 /* >  reflectors. See SORCSD for details on generating P1, P2, Q1, and Q2 */
791 /* >  using SORGQR and SORGLQ. */
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 sorbdb_(char *trans, char *signs, integer *m, integer *p,
802          integer *q, real *x11, integer *ldx11, real *x12, integer *ldx12, 
803         real *x21, integer *ldx21, real *x22, integer *ldx22, real *theta, 
804         real *phi, real *taup1, real *taup2, real *tauq1, real *tauq2, real *
805         work, integer *lwork, integer *info)
806 {
807     /* System generated locals */
808     integer x11_dim1, x11_offset, x12_dim1, x12_offset, x21_dim1, x21_offset, 
809             x22_dim1, x22_offset, i__1, i__2, i__3;
810     real r__1;
811
812     /* Local variables */
813     logical colmajor;
814     integer lworkmin, lworkopt;
815     extern real snrm2_(integer *, real *, integer *);
816     integer i__;
817     extern logical lsame_(char *, char *);
818     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *), 
819             slarf_(char *, integer *, integer *, real *, integer *, real *, 
820             real *, integer *, real *), saxpy_(integer *, real *, 
821             real *, integer *, real *, integer *);
822     real z1, z2, z3, z4;
823     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
824     logical lquery;
825     extern /* Subroutine */ int slarfgp_(integer *, real *, real *, integer *,
826              real *);
827
828
829 /*  -- LAPACK computational routine (version 3.7.0) -- */
830 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
831 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
832 /*     December 2016 */
833
834
835 /*  ==================================================================== */
836
837
838 /*     Test input arguments */
839
840     /* Parameter adjustments */
841     x11_dim1 = *ldx11;
842     x11_offset = 1 + x11_dim1 * 1;
843     x11 -= x11_offset;
844     x12_dim1 = *ldx12;
845     x12_offset = 1 + x12_dim1 * 1;
846     x12 -= x12_offset;
847     x21_dim1 = *ldx21;
848     x21_offset = 1 + x21_dim1 * 1;
849     x21 -= x21_offset;
850     x22_dim1 = *ldx22;
851     x22_offset = 1 + x22_dim1 * 1;
852     x22 -= x22_offset;
853     --theta;
854     --phi;
855     --taup1;
856     --taup2;
857     --tauq1;
858     --tauq2;
859     --work;
860
861     /* Function Body */
862     *info = 0;
863     colmajor = ! lsame_(trans, "T");
864     if (! lsame_(signs, "O")) {
865         z1 = 1.f;
866         z2 = 1.f;
867         z3 = 1.f;
868         z4 = 1.f;
869     } else {
870         z1 = 1.f;
871         z2 = -1.f;
872         z3 = 1.f;
873         z4 = -1.f;
874     }
875     lquery = *lwork == -1;
876
877     if (*m < 0) {
878         *info = -3;
879     } else if (*p < 0 || *p > *m) {
880         *info = -4;
881     } else if (*q < 0 || *q > *p || *q > *m - *p || *q > *m - *q) {
882         *info = -5;
883     } else if (colmajor && *ldx11 < f2cmax(1,*p)) {
884         *info = -7;
885     } else if (! colmajor && *ldx11 < f2cmax(1,*q)) {
886         *info = -7;
887     } else if (colmajor && *ldx12 < f2cmax(1,*p)) {
888         *info = -9;
889     } else /* if(complicated condition) */ {
890 /* Computing MAX */
891         i__1 = 1, i__2 = *m - *q;
892         if (! colmajor && *ldx12 < f2cmax(i__1,i__2)) {
893             *info = -9;
894         } else /* if(complicated condition) */ {
895 /* Computing MAX */
896             i__1 = 1, i__2 = *m - *p;
897             if (colmajor && *ldx21 < f2cmax(i__1,i__2)) {
898                 *info = -11;
899             } else if (! colmajor && *ldx21 < f2cmax(1,*q)) {
900                 *info = -11;
901             } else /* if(complicated condition) */ {
902 /* Computing MAX */
903                 i__1 = 1, i__2 = *m - *p;
904                 if (colmajor && *ldx22 < f2cmax(i__1,i__2)) {
905                     *info = -13;
906                 } else /* if(complicated condition) */ {
907 /* Computing MAX */
908                     i__1 = 1, i__2 = *m - *q;
909                     if (! colmajor && *ldx22 < f2cmax(i__1,i__2)) {
910                         *info = -13;
911                     }
912                 }
913             }
914         }
915     }
916
917 /*     Compute workspace */
918
919     if (*info == 0) {
920         lworkopt = *m - *q;
921         lworkmin = *m - *q;
922         work[1] = (real) lworkopt;
923         if (*lwork < lworkmin && ! lquery) {
924             *info = -21;
925         }
926     }
927     if (*info != 0) {
928         i__1 = -(*info);
929         xerbla_("xORBDB", &i__1, (ftnlen)6);
930         return 0;
931     } else if (lquery) {
932         return 0;
933     }
934
935 /*     Handle column-major and row-major separately */
936
937     if (colmajor) {
938
939 /*        Reduce columns 1, ..., Q of X11, X12, X21, and X22 */
940
941         i__1 = *q;
942         for (i__ = 1; i__ <= i__1; ++i__) {
943
944             if (i__ == 1) {
945                 i__2 = *p - i__ + 1;
946                 sscal_(&i__2, &z1, &x11[i__ + i__ * x11_dim1], &c__1);
947             } else {
948                 i__2 = *p - i__ + 1;
949                 r__1 = z1 * cos(phi[i__ - 1]);
950                 sscal_(&i__2, &r__1, &x11[i__ + i__ * x11_dim1], &c__1);
951                 i__2 = *p - i__ + 1;
952                 r__1 = -z1 * z3 * z4 * sin(phi[i__ - 1]);
953                 saxpy_(&i__2, &r__1, &x12[i__ + (i__ - 1) * x12_dim1], &c__1, 
954                         &x11[i__ + i__ * x11_dim1], &c__1);
955             }
956             if (i__ == 1) {
957                 i__2 = *m - *p - i__ + 1;
958                 sscal_(&i__2, &z2, &x21[i__ + i__ * x21_dim1], &c__1);
959             } else {
960                 i__2 = *m - *p - i__ + 1;
961                 r__1 = z2 * cos(phi[i__ - 1]);
962                 sscal_(&i__2, &r__1, &x21[i__ + i__ * x21_dim1], &c__1);
963                 i__2 = *m - *p - i__ + 1;
964                 r__1 = -z2 * z3 * z4 * sin(phi[i__ - 1]);
965                 saxpy_(&i__2, &r__1, &x22[i__ + (i__ - 1) * x22_dim1], &c__1, 
966                         &x21[i__ + i__ * x21_dim1], &c__1);
967             }
968
969             i__2 = *m - *p - i__ + 1;
970             i__3 = *p - i__ + 1;
971             theta[i__] = atan2(snrm2_(&i__2, &x21[i__ + i__ * x21_dim1], &
972                     c__1), snrm2_(&i__3, &x11[i__ + i__ * x11_dim1], &c__1));
973
974             if (*p > i__) {
975                 i__2 = *p - i__ + 1;
976                 slarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + 1 + 
977                         i__ * x11_dim1], &c__1, &taup1[i__]);
978             } else if (*p == i__) {
979                 i__2 = *p - i__ + 1;
980                 slarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + i__ * 
981                         x11_dim1], &c__1, &taup1[i__]);
982             }
983             x11[i__ + i__ * x11_dim1] = 1.f;
984             if (*m - *p > i__) {
985                 i__2 = *m - *p - i__ + 1;
986                 slarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + 1 + 
987                         i__ * x21_dim1], &c__1, &taup2[i__]);
988             } else if (*m - *p == i__) {
989                 i__2 = *m - *p - i__ + 1;
990                 slarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + i__ * 
991                         x21_dim1], &c__1, &taup2[i__]);
992             }
993             x21[i__ + i__ * x21_dim1] = 1.f;
994
995             if (*q > i__) {
996                 i__2 = *p - i__ + 1;
997                 i__3 = *q - i__;
998                 slarf_("L", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], &c__1, &
999                         taup1[i__], &x11[i__ + (i__ + 1) * x11_dim1], ldx11, &
1000                         work[1]);
1001             }
1002             if (*m - *q + 1 > i__) {
1003                 i__2 = *p - i__ + 1;
1004                 i__3 = *m - *q - i__ + 1;
1005                 slarf_("L", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], &c__1, &
1006                         taup1[i__], &x12[i__ + i__ * x12_dim1], ldx12, &work[
1007                         1]);
1008             }
1009             if (*q > i__) {
1010                 i__2 = *m - *p - i__ + 1;
1011                 i__3 = *q - i__;
1012                 slarf_("L", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], &c__1, &
1013                         taup2[i__], &x21[i__ + (i__ + 1) * x21_dim1], ldx21, &
1014                         work[1]);
1015             }
1016             if (*m - *q + 1 > i__) {
1017                 i__2 = *m - *p - i__ + 1;
1018                 i__3 = *m - *q - i__ + 1;
1019                 slarf_("L", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], &c__1, &
1020                         taup2[i__], &x22[i__ + i__ * x22_dim1], ldx22, &work[
1021                         1]);
1022             }
1023
1024             if (i__ < *q) {
1025                 i__2 = *q - i__;
1026                 r__1 = -z1 * z3 * sin(theta[i__]);
1027                 sscal_(&i__2, &r__1, &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1028                 i__2 = *q - i__;
1029                 r__1 = z2 * z3 * cos(theta[i__]);
1030                 saxpy_(&i__2, &r__1, &x21[i__ + (i__ + 1) * x21_dim1], ldx21, 
1031                         &x11[i__ + (i__ + 1) * x11_dim1], ldx11);
1032             }
1033             i__2 = *m - *q - i__ + 1;
1034             r__1 = -z1 * z4 * sin(theta[i__]);
1035             sscal_(&i__2, &r__1, &x12[i__ + i__ * x12_dim1], ldx12);
1036             i__2 = *m - *q - i__ + 1;
1037             r__1 = z2 * z4 * cos(theta[i__]);
1038             saxpy_(&i__2, &r__1, &x22[i__ + i__ * x22_dim1], ldx22, &x12[i__ 
1039                     + i__ * x12_dim1], ldx12);
1040
1041             if (i__ < *q) {
1042                 i__2 = *q - i__;
1043                 i__3 = *m - *q - i__ + 1;
1044                 phi[i__] = atan2(snrm2_(&i__2, &x11[i__ + (i__ + 1) * 
1045                         x11_dim1], ldx11), snrm2_(&i__3, &x12[i__ + i__ * 
1046                         x12_dim1], ldx12));
1047             }
1048
1049             if (i__ < *q) {
1050                 if (*q - i__ == 1) {
1051                     i__2 = *q - i__;
1052                     slarfgp_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], &x11[
1053                             i__ + (i__ + 1) * x11_dim1], ldx11, &tauq1[i__]);
1054                 } else {
1055                     i__2 = *q - i__;
1056                     slarfgp_(&i__2, &x11[i__ + (i__ + 1) * x11_dim1], &x11[
1057                             i__ + (i__ + 2) * x11_dim1], ldx11, &tauq1[i__]);
1058                 }
1059                 x11[i__ + (i__ + 1) * x11_dim1] = 1.f;
1060             }
1061             if (*q + i__ - 1 < *m) {
1062                 if (*m - *q == i__) {
1063                     i__2 = *m - *q - i__ + 1;
1064                     slarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 
1065                             i__ * x12_dim1], ldx12, &tauq2[i__]);
1066                 } else {
1067                     i__2 = *m - *q - i__ + 1;
1068                     slarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + (
1069                             i__ + 1) * x12_dim1], ldx12, &tauq2[i__]);
1070                 }
1071             }
1072             x12[i__ + i__ * x12_dim1] = 1.f;
1073
1074             if (i__ < *q) {
1075                 i__2 = *p - i__;
1076                 i__3 = *q - i__;
1077                 slarf_("R", &i__2, &i__3, &x11[i__ + (i__ + 1) * x11_dim1], 
1078                         ldx11, &tauq1[i__], &x11[i__ + 1 + (i__ + 1) * 
1079                         x11_dim1], ldx11, &work[1]);
1080                 i__2 = *m - *p - i__;
1081                 i__3 = *q - i__;
1082                 slarf_("R", &i__2, &i__3, &x11[i__ + (i__ + 1) * x11_dim1], 
1083                         ldx11, &tauq1[i__], &x21[i__ + 1 + (i__ + 1) * 
1084                         x21_dim1], ldx21, &work[1]);
1085             }
1086             if (*p > i__) {
1087                 i__2 = *p - i__;
1088                 i__3 = *m - *q - i__ + 1;
1089                 slarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1090                         tauq2[i__], &x12[i__ + 1 + i__ * x12_dim1], ldx12, &
1091                         work[1]);
1092             }
1093             if (*m - *p > i__) {
1094                 i__2 = *m - *p - i__;
1095                 i__3 = *m - *q - i__ + 1;
1096                 slarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1097                         tauq2[i__], &x22[i__ + 1 + i__ * x22_dim1], ldx22, &
1098                         work[1]);
1099             }
1100
1101         }
1102
1103 /*        Reduce columns Q + 1, ..., P of X12, X22 */
1104
1105         i__1 = *p;
1106         for (i__ = *q + 1; i__ <= i__1; ++i__) {
1107
1108             i__2 = *m - *q - i__ + 1;
1109             r__1 = -z1 * z4;
1110             sscal_(&i__2, &r__1, &x12[i__ + i__ * x12_dim1], ldx12);
1111             if (i__ >= *m - *q) {
1112                 i__2 = *m - *q - i__ + 1;
1113                 slarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + i__ * 
1114                         x12_dim1], ldx12, &tauq2[i__]);
1115             } else {
1116                 i__2 = *m - *q - i__ + 1;
1117                 slarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + (i__ + 
1118                         1) * x12_dim1], ldx12, &tauq2[i__]);
1119             }
1120             x12[i__ + i__ * x12_dim1] = 1.f;
1121
1122             if (*p > i__) {
1123                 i__2 = *p - i__;
1124                 i__3 = *m - *q - i__ + 1;
1125                 slarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1126                         tauq2[i__], &x12[i__ + 1 + i__ * x12_dim1], ldx12, &
1127                         work[1]);
1128             }
1129             if (*m - *p - *q >= 1) {
1130                 i__2 = *m - *p - *q;
1131                 i__3 = *m - *q - i__ + 1;
1132                 slarf_("R", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], ldx12, &
1133                         tauq2[i__], &x22[*q + 1 + i__ * x22_dim1], ldx22, &
1134                         work[1]);
1135             }
1136
1137         }
1138
1139 /*        Reduce columns P + 1, ..., M - Q of X12, X22 */
1140
1141         i__1 = *m - *p - *q;
1142         for (i__ = 1; i__ <= i__1; ++i__) {
1143
1144             i__2 = *m - *p - *q - i__ + 1;
1145             r__1 = z2 * z4;
1146             sscal_(&i__2, &r__1, &x22[*q + i__ + (*p + i__) * x22_dim1], 
1147                     ldx22);
1148             if (i__ == *m - *p - *q) {
1149                 i__2 = *m - *p - *q - i__ + 1;
1150                 slarfgp_(&i__2, &x22[*q + i__ + (*p + i__) * x22_dim1], &x22[*
1151                         q + i__ + (*p + i__) * x22_dim1], ldx22, &tauq2[*p + 
1152                         i__]);
1153             } else {
1154                 i__2 = *m - *p - *q - i__ + 1;
1155                 slarfgp_(&i__2, &x22[*q + i__ + (*p + i__) * x22_dim1], &x22[*
1156                         q + i__ + (*p + i__ + 1) * x22_dim1], ldx22, &tauq2[*
1157                         p + i__]);
1158             }
1159             x22[*q + i__ + (*p + i__) * x22_dim1] = 1.f;
1160             if (i__ < *m - *p - *q) {
1161                 i__2 = *m - *p - *q - i__;
1162                 i__3 = *m - *p - *q - i__ + 1;
1163                 slarf_("R", &i__2, &i__3, &x22[*q + i__ + (*p + i__) * 
1164                         x22_dim1], ldx22, &tauq2[*p + i__], &x22[*q + i__ + 1 
1165                         + (*p + i__) * x22_dim1], ldx22, &work[1]);
1166             }
1167
1168         }
1169
1170     } else {
1171
1172 /*        Reduce columns 1, ..., Q of X11, X12, X21, X22 */
1173
1174         i__1 = *q;
1175         for (i__ = 1; i__ <= i__1; ++i__) {
1176
1177             if (i__ == 1) {
1178                 i__2 = *p - i__ + 1;
1179                 sscal_(&i__2, &z1, &x11[i__ + i__ * x11_dim1], ldx11);
1180             } else {
1181                 i__2 = *p - i__ + 1;
1182                 r__1 = z1 * cos(phi[i__ - 1]);
1183                 sscal_(&i__2, &r__1, &x11[i__ + i__ * x11_dim1], ldx11);
1184                 i__2 = *p - i__ + 1;
1185                 r__1 = -z1 * z3 * z4 * sin(phi[i__ - 1]);
1186                 saxpy_(&i__2, &r__1, &x12[i__ - 1 + i__ * x12_dim1], ldx12, &
1187                         x11[i__ + i__ * x11_dim1], ldx11);
1188             }
1189             if (i__ == 1) {
1190                 i__2 = *m - *p - i__ + 1;
1191                 sscal_(&i__2, &z2, &x21[i__ + i__ * x21_dim1], ldx21);
1192             } else {
1193                 i__2 = *m - *p - i__ + 1;
1194                 r__1 = z2 * cos(phi[i__ - 1]);
1195                 sscal_(&i__2, &r__1, &x21[i__ + i__ * x21_dim1], ldx21);
1196                 i__2 = *m - *p - i__ + 1;
1197                 r__1 = -z2 * z3 * z4 * sin(phi[i__ - 1]);
1198                 saxpy_(&i__2, &r__1, &x22[i__ - 1 + i__ * x22_dim1], ldx22, &
1199                         x21[i__ + i__ * x21_dim1], ldx21);
1200             }
1201
1202             i__2 = *m - *p - i__ + 1;
1203             i__3 = *p - i__ + 1;
1204             theta[i__] = atan2(snrm2_(&i__2, &x21[i__ + i__ * x21_dim1], 
1205                     ldx21), snrm2_(&i__3, &x11[i__ + i__ * x11_dim1], ldx11));
1206
1207             i__2 = *p - i__ + 1;
1208             slarfgp_(&i__2, &x11[i__ + i__ * x11_dim1], &x11[i__ + (i__ + 1) *
1209                      x11_dim1], ldx11, &taup1[i__]);
1210             x11[i__ + i__ * x11_dim1] = 1.f;
1211             if (i__ == *m - *p) {
1212                 i__2 = *m - *p - i__ + 1;
1213                 slarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + i__ * 
1214                         x21_dim1], ldx21, &taup2[i__]);
1215             } else {
1216                 i__2 = *m - *p - i__ + 1;
1217                 slarfgp_(&i__2, &x21[i__ + i__ * x21_dim1], &x21[i__ + (i__ + 
1218                         1) * x21_dim1], ldx21, &taup2[i__]);
1219             }
1220             x21[i__ + i__ * x21_dim1] = 1.f;
1221
1222             if (*q > i__) {
1223                 i__2 = *q - i__;
1224                 i__3 = *p - i__ + 1;
1225                 slarf_("R", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], ldx11, &
1226                         taup1[i__], &x11[i__ + 1 + i__ * x11_dim1], ldx11, &
1227                         work[1]);
1228             }
1229             if (*m - *q + 1 > i__) {
1230                 i__2 = *m - *q - i__ + 1;
1231                 i__3 = *p - i__ + 1;
1232                 slarf_("R", &i__2, &i__3, &x11[i__ + i__ * x11_dim1], ldx11, &
1233                         taup1[i__], &x12[i__ + i__ * x12_dim1], ldx12, &work[
1234                         1]);
1235             }
1236             if (*q > i__) {
1237                 i__2 = *q - i__;
1238                 i__3 = *m - *p - i__ + 1;
1239                 slarf_("R", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], ldx21, &
1240                         taup2[i__], &x21[i__ + 1 + i__ * x21_dim1], ldx21, &
1241                         work[1]);
1242             }
1243             if (*m - *q + 1 > i__) {
1244                 i__2 = *m - *q - i__ + 1;
1245                 i__3 = *m - *p - i__ + 1;
1246                 slarf_("R", &i__2, &i__3, &x21[i__ + i__ * x21_dim1], ldx21, &
1247                         taup2[i__], &x22[i__ + i__ * x22_dim1], ldx22, &work[
1248                         1]);
1249             }
1250
1251             if (i__ < *q) {
1252                 i__2 = *q - i__;
1253                 r__1 = -z1 * z3 * sin(theta[i__]);
1254                 sscal_(&i__2, &r__1, &x11[i__ + 1 + i__ * x11_dim1], &c__1);
1255                 i__2 = *q - i__;
1256                 r__1 = z2 * z3 * cos(theta[i__]);
1257                 saxpy_(&i__2, &r__1, &x21[i__ + 1 + i__ * x21_dim1], &c__1, &
1258                         x11[i__ + 1 + i__ * x11_dim1], &c__1);
1259             }
1260             i__2 = *m - *q - i__ + 1;
1261             r__1 = -z1 * z4 * sin(theta[i__]);
1262             sscal_(&i__2, &r__1, &x12[i__ + i__ * x12_dim1], &c__1);
1263             i__2 = *m - *q - i__ + 1;
1264             r__1 = z2 * z4 * cos(theta[i__]);
1265             saxpy_(&i__2, &r__1, &x22[i__ + i__ * x22_dim1], &c__1, &x12[i__ 
1266                     + i__ * x12_dim1], &c__1);
1267
1268             if (i__ < *q) {
1269                 i__2 = *q - i__;
1270                 i__3 = *m - *q - i__ + 1;
1271                 phi[i__] = atan2(snrm2_(&i__2, &x11[i__ + 1 + i__ * x11_dim1],
1272                          &c__1), snrm2_(&i__3, &x12[i__ + i__ * x12_dim1], &
1273                         c__1));
1274             }
1275
1276             if (i__ < *q) {
1277                 if (*q - i__ == 1) {
1278                     i__2 = *q - i__;
1279                     slarfgp_(&i__2, &x11[i__ + 1 + i__ * x11_dim1], &x11[i__ 
1280                             + 1 + i__ * x11_dim1], &c__1, &tauq1[i__]);
1281                 } else {
1282                     i__2 = *q - i__;
1283                     slarfgp_(&i__2, &x11[i__ + 1 + i__ * x11_dim1], &x11[i__ 
1284                             + 2 + i__ * x11_dim1], &c__1, &tauq1[i__]);
1285                 }
1286                 x11[i__ + 1 + i__ * x11_dim1] = 1.f;
1287             }
1288             if (*m - *q > i__) {
1289                 i__2 = *m - *q - i__ + 1;
1290                 slarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 1 + 
1291                         i__ * x12_dim1], &c__1, &tauq2[i__]);
1292             } else {
1293                 i__2 = *m - *q - i__ + 1;
1294                 slarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + i__ * 
1295                         x12_dim1], &c__1, &tauq2[i__]);
1296             }
1297             x12[i__ + i__ * x12_dim1] = 1.f;
1298
1299             if (i__ < *q) {
1300                 i__2 = *q - i__;
1301                 i__3 = *p - i__;
1302                 slarf_("L", &i__2, &i__3, &x11[i__ + 1 + i__ * x11_dim1], &
1303                         c__1, &tauq1[i__], &x11[i__ + 1 + (i__ + 1) * 
1304                         x11_dim1], ldx11, &work[1]);
1305                 i__2 = *q - i__;
1306                 i__3 = *m - *p - i__;
1307                 slarf_("L", &i__2, &i__3, &x11[i__ + 1 + i__ * x11_dim1], &
1308                         c__1, &tauq1[i__], &x21[i__ + 1 + (i__ + 1) * 
1309                         x21_dim1], ldx21, &work[1]);
1310             }
1311             i__2 = *m - *q - i__ + 1;
1312             i__3 = *p - i__;
1313             slarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1314                     tauq2[i__], &x12[i__ + (i__ + 1) * x12_dim1], ldx12, &
1315                     work[1]);
1316             if (*m - *p - i__ > 0) {
1317                 i__2 = *m - *q - i__ + 1;
1318                 i__3 = *m - *p - i__;
1319                 slarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1320                         tauq2[i__], &x22[i__ + (i__ + 1) * x22_dim1], ldx22, &
1321                         work[1]);
1322             }
1323
1324         }
1325
1326 /*        Reduce columns Q + 1, ..., P of X12, X22 */
1327
1328         i__1 = *p;
1329         for (i__ = *q + 1; i__ <= i__1; ++i__) {
1330
1331             i__2 = *m - *q - i__ + 1;
1332             r__1 = -z1 * z4;
1333             sscal_(&i__2, &r__1, &x12[i__ + i__ * x12_dim1], &c__1);
1334             i__2 = *m - *q - i__ + 1;
1335             slarfgp_(&i__2, &x12[i__ + i__ * x12_dim1], &x12[i__ + 1 + i__ * 
1336                     x12_dim1], &c__1, &tauq2[i__]);
1337             x12[i__ + i__ * x12_dim1] = 1.f;
1338
1339             if (*p > i__) {
1340                 i__2 = *m - *q - i__ + 1;
1341                 i__3 = *p - i__;
1342                 slarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1343                         tauq2[i__], &x12[i__ + (i__ + 1) * x12_dim1], ldx12, &
1344                         work[1]);
1345             }
1346             if (*m - *p - *q >= 1) {
1347                 i__2 = *m - *q - i__ + 1;
1348                 i__3 = *m - *p - *q;
1349                 slarf_("L", &i__2, &i__3, &x12[i__ + i__ * x12_dim1], &c__1, &
1350                         tauq2[i__], &x22[i__ + (*q + 1) * x22_dim1], ldx22, &
1351                         work[1]);
1352             }
1353
1354         }
1355
1356 /*        Reduce columns P + 1, ..., M - Q of X12, X22 */
1357
1358         i__1 = *m - *p - *q;
1359         for (i__ = 1; i__ <= i__1; ++i__) {
1360
1361             i__2 = *m - *p - *q - i__ + 1;
1362             r__1 = z2 * z4;
1363             sscal_(&i__2, &r__1, &x22[*p + i__ + (*q + i__) * x22_dim1], &
1364                     c__1);
1365             if (*m - *p - *q == i__) {
1366                 i__2 = *m - *p - *q - i__ + 1;
1367                 slarfgp_(&i__2, &x22[*p + i__ + (*q + i__) * x22_dim1], &x22[*
1368                         p + i__ + (*q + i__) * x22_dim1], &c__1, &tauq2[*p + 
1369                         i__]);
1370                 x22[*p + i__ + (*q + i__) * x22_dim1] = 1.f;
1371             } else {
1372                 i__2 = *m - *p - *q - i__ + 1;
1373                 slarfgp_(&i__2, &x22[*p + i__ + (*q + i__) * x22_dim1], &x22[*
1374                         p + i__ + 1 + (*q + i__) * x22_dim1], &c__1, &tauq2[*
1375                         p + i__]);
1376                 x22[*p + i__ + (*q + i__) * x22_dim1] = 1.f;
1377                 i__2 = *m - *p - *q - i__ + 1;
1378                 i__3 = *m - *p - *q - i__;
1379                 slarf_("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
1384
1385         }
1386
1387     }
1388
1389     return 0;
1390
1391 /*     End of SORBDB */
1392
1393 } /* sorbdb_ */
1394