C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dgbbrd.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 doublereal c_b8 = 0.;
516 static doublereal c_b9 = 1.;
517 static integer c__1 = 1;
518
519 /* > \brief \b DGBBRD */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download DGBBRD + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgbbrd.
529 f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgbbrd.
532 f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgbbrd.
535 f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE DGBBRD( VECT, M, N, NCC, KL, KU, AB, LDAB, D, E, Q, */
543 /*                          LDQ, PT, LDPT, C, LDC, WORK, INFO ) */
544
545 /*       CHARACTER          VECT */
546 /*       INTEGER            INFO, KL, KU, LDAB, LDC, LDPT, LDQ, M, N, NCC */
547 /*       DOUBLE PRECISION   AB( LDAB, * ), C( LDC, * ), D( * ), E( * ), */
548 /*      $                   PT( LDPT, * ), Q( LDQ, * ), WORK( * ) */
549
550
551 /* > \par Purpose: */
552 /*  ============= */
553 /* > */
554 /* > \verbatim */
555 /* > */
556 /* > DGBBRD reduces a real general m-by-n band matrix A to upper */
557 /* > bidiagonal form B by an orthogonal transformation: Q**T * A * P = B. */
558 /* > */
559 /* > The routine computes B, and optionally forms Q or P**T, or computes */
560 /* > Q**T*C for a given matrix C. */
561 /* > \endverbatim */
562
563 /*  Arguments: */
564 /*  ========== */
565
566 /* > \param[in] VECT */
567 /* > \verbatim */
568 /* >          VECT is CHARACTER*1 */
569 /* >          Specifies whether or not the matrices Q and P**T are to be */
570 /* >          formed. */
571 /* >          = 'N': do not form Q or P**T; */
572 /* >          = 'Q': form Q only; */
573 /* >          = 'P': form P**T only; */
574 /* >          = 'B': form both. */
575 /* > \endverbatim */
576 /* > */
577 /* > \param[in] M */
578 /* > \verbatim */
579 /* >          M is INTEGER */
580 /* >          The number of rows of the matrix A.  M >= 0. */
581 /* > \endverbatim */
582 /* > */
583 /* > \param[in] N */
584 /* > \verbatim */
585 /* >          N is INTEGER */
586 /* >          The number of columns of the matrix A.  N >= 0. */
587 /* > \endverbatim */
588 /* > */
589 /* > \param[in] NCC */
590 /* > \verbatim */
591 /* >          NCC is INTEGER */
592 /* >          The number of columns of the matrix C.  NCC >= 0. */
593 /* > \endverbatim */
594 /* > */
595 /* > \param[in] KL */
596 /* > \verbatim */
597 /* >          KL is INTEGER */
598 /* >          The number of subdiagonals of the matrix A. KL >= 0. */
599 /* > \endverbatim */
600 /* > */
601 /* > \param[in] KU */
602 /* > \verbatim */
603 /* >          KU is INTEGER */
604 /* >          The number of superdiagonals of the matrix A. KU >= 0. */
605 /* > \endverbatim */
606 /* > */
607 /* > \param[in,out] AB */
608 /* > \verbatim */
609 /* >          AB is DOUBLE PRECISION array, dimension (LDAB,N) */
610 /* >          On entry, the m-by-n band matrix A, stored in rows 1 to */
611 /* >          KL+KU+1. The j-th column of A is stored in the j-th column of */
612 /* >          the array AB as follows: */
613 /* >          AB(ku+1+i-j,j) = A(i,j) for f2cmax(1,j-ku)<=i<=f2cmin(m,j+kl). */
614 /* >          On exit, A is overwritten by values generated during the */
615 /* >          reduction. */
616 /* > \endverbatim */
617 /* > */
618 /* > \param[in] LDAB */
619 /* > \verbatim */
620 /* >          LDAB is INTEGER */
621 /* >          The leading dimension of the array A. LDAB >= KL+KU+1. */
622 /* > \endverbatim */
623 /* > */
624 /* > \param[out] D */
625 /* > \verbatim */
626 /* >          D is DOUBLE PRECISION array, dimension (f2cmin(M,N)) */
627 /* >          The diagonal elements of the bidiagonal matrix B. */
628 /* > \endverbatim */
629 /* > */
630 /* > \param[out] E */
631 /* > \verbatim */
632 /* >          E is DOUBLE PRECISION array, dimension (f2cmin(M,N)-1) */
633 /* >          The superdiagonal elements of the bidiagonal matrix B. */
634 /* > \endverbatim */
635 /* > */
636 /* > \param[out] Q */
637 /* > \verbatim */
638 /* >          Q is DOUBLE PRECISION array, dimension (LDQ,M) */
639 /* >          If VECT = 'Q' or 'B', the m-by-m orthogonal matrix Q. */
640 /* >          If VECT = 'N' or 'P', the array Q is not referenced. */
641 /* > \endverbatim */
642 /* > */
643 /* > \param[in] LDQ */
644 /* > \verbatim */
645 /* >          LDQ is INTEGER */
646 /* >          The leading dimension of the array Q. */
647 /* >          LDQ >= f2cmax(1,M) if VECT = 'Q' or 'B'; LDQ >= 1 otherwise. */
648 /* > \endverbatim */
649 /* > */
650 /* > \param[out] PT */
651 /* > \verbatim */
652 /* >          PT is DOUBLE PRECISION array, dimension (LDPT,N) */
653 /* >          If VECT = 'P' or 'B', the n-by-n orthogonal matrix P'. */
654 /* >          If VECT = 'N' or 'Q', the array PT is not referenced. */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in] LDPT */
658 /* > \verbatim */
659 /* >          LDPT is INTEGER */
660 /* >          The leading dimension of the array PT. */
661 /* >          LDPT >= f2cmax(1,N) if VECT = 'P' or 'B'; LDPT >= 1 otherwise. */
662 /* > \endverbatim */
663 /* > */
664 /* > \param[in,out] C */
665 /* > \verbatim */
666 /* >          C is DOUBLE PRECISION array, dimension (LDC,NCC) */
667 /* >          On entry, an m-by-ncc matrix C. */
668 /* >          On exit, C is overwritten by Q**T*C. */
669 /* >          C is not referenced if NCC = 0. */
670 /* > \endverbatim */
671 /* > */
672 /* > \param[in] LDC */
673 /* > \verbatim */
674 /* >          LDC is INTEGER */
675 /* >          The leading dimension of the array C. */
676 /* >          LDC >= f2cmax(1,M) if NCC > 0; LDC >= 1 if NCC = 0. */
677 /* > \endverbatim */
678 /* > */
679 /* > \param[out] WORK */
680 /* > \verbatim */
681 /* >          WORK is DOUBLE PRECISION array, dimension (2*f2cmax(M,N)) */
682 /* > \endverbatim */
683 /* > */
684 /* > \param[out] INFO */
685 /* > \verbatim */
686 /* >          INFO is INTEGER */
687 /* >          = 0:  successful exit. */
688 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
689 /* > \endverbatim */
690
691 /*  Authors: */
692 /*  ======== */
693
694 /* > \author Univ. of Tennessee */
695 /* > \author Univ. of California Berkeley */
696 /* > \author Univ. of Colorado Denver */
697 /* > \author NAG Ltd. */
698
699 /* > \date December 2016 */
700
701 /* > \ingroup doubleGBcomputational */
702
703 /*  ===================================================================== */
704 /* Subroutine */ int dgbbrd_(char *vect, integer *m, integer *n, integer *ncc,
705          integer *kl, integer *ku, doublereal *ab, integer *ldab, doublereal *
706         d__, doublereal *e, doublereal *q, integer *ldq, doublereal *pt, 
707         integer *ldpt, doublereal *c__, integer *ldc, doublereal *work, 
708         integer *info)
709 {
710     /* System generated locals */
711     integer ab_dim1, ab_offset, c_dim1, c_offset, pt_dim1, pt_offset, q_dim1, 
712             q_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7;
713
714     /* Local variables */
715     integer inca;
716     extern /* Subroutine */ int drot_(integer *, doublereal *, integer *, 
717             doublereal *, integer *, doublereal *, doublereal *);
718     integer i__, j, l;
719     extern logical lsame_(char *, char *);
720     logical wantb, wantc;
721     integer minmn;
722     logical wantq;
723     integer j1, j2, kb;
724     doublereal ra, rb;
725     integer kk;
726     doublereal rc;
727     integer ml, mn, nr, mu;
728     doublereal rs;
729     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
730             doublereal *, doublereal *, doublereal *, integer *), 
731             dlartg_(doublereal *, doublereal *, doublereal *, doublereal *, 
732             doublereal *), xerbla_(char *, integer *, ftnlen), dlargv_(
733             integer *, doublereal *, integer *, doublereal *, integer *, 
734             doublereal *, integer *), dlartv_(integer *, doublereal *, 
735             integer *, doublereal *, integer *, doublereal *, doublereal *, 
736             integer *);
737     integer kb1, ml0;
738     logical wantpt;
739     integer mu0, klm, kun, nrt, klu1;
740
741
742 /*  -- LAPACK computational routine (version 3.7.0) -- */
743 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
744 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
745 /*     December 2016 */
746
747
748 /*  ===================================================================== */
749
750
751 /*     Test the input parameters */
752
753     /* Parameter adjustments */
754     ab_dim1 = *ldab;
755     ab_offset = 1 + ab_dim1 * 1;
756     ab -= ab_offset;
757     --d__;
758     --e;
759     q_dim1 = *ldq;
760     q_offset = 1 + q_dim1 * 1;
761     q -= q_offset;
762     pt_dim1 = *ldpt;
763     pt_offset = 1 + pt_dim1 * 1;
764     pt -= pt_offset;
765     c_dim1 = *ldc;
766     c_offset = 1 + c_dim1 * 1;
767     c__ -= c_offset;
768     --work;
769
770     /* Function Body */
771     wantb = lsame_(vect, "B");
772     wantq = lsame_(vect, "Q") || wantb;
773     wantpt = lsame_(vect, "P") || wantb;
774     wantc = *ncc > 0;
775     klu1 = *kl + *ku + 1;
776     *info = 0;
777     if (! wantq && ! wantpt && ! lsame_(vect, "N")) {
778         *info = -1;
779     } else if (*m < 0) {
780         *info = -2;
781     } else if (*n < 0) {
782         *info = -3;
783     } else if (*ncc < 0) {
784         *info = -4;
785     } else if (*kl < 0) {
786         *info = -5;
787     } else if (*ku < 0) {
788         *info = -6;
789     } else if (*ldab < klu1) {
790         *info = -8;
791     } else if (*ldq < 1 || wantq && *ldq < f2cmax(1,*m)) {
792         *info = -12;
793     } else if (*ldpt < 1 || wantpt && *ldpt < f2cmax(1,*n)) {
794         *info = -14;
795     } else if (*ldc < 1 || wantc && *ldc < f2cmax(1,*m)) {
796         *info = -16;
797     }
798     if (*info != 0) {
799         i__1 = -(*info);
800         xerbla_("DGBBRD", &i__1, (ftnlen)6);
801         return 0;
802     }
803
804 /*     Initialize Q and P**T to the unit matrix, if needed */
805
806     if (wantq) {
807         dlaset_("Full", m, m, &c_b8, &c_b9, &q[q_offset], ldq);
808     }
809     if (wantpt) {
810         dlaset_("Full", n, n, &c_b8, &c_b9, &pt[pt_offset], ldpt);
811     }
812
813 /*     Quick return if possible. */
814
815     if (*m == 0 || *n == 0) {
816         return 0;
817     }
818
819     minmn = f2cmin(*m,*n);
820
821     if (*kl + *ku > 1) {
822
823 /*        Reduce to upper bidiagonal form if KU > 0; if KU = 0, reduce */
824 /*        first to lower bidiagonal form and then transform to upper */
825 /*        bidiagonal */
826
827         if (*ku > 0) {
828             ml0 = 1;
829             mu0 = 2;
830         } else {
831             ml0 = 2;
832             mu0 = 1;
833         }
834
835 /*        Wherever possible, plane rotations are generated and applied in */
836 /*        vector operations of length NR over the index set J1:J2:KLU1. */
837
838 /*        The sines of the plane rotations are stored in WORK(1:f2cmax(m,n)) */
839 /*        and the cosines in WORK(f2cmax(m,n)+1:2*f2cmax(m,n)). */
840
841         mn = f2cmax(*m,*n);
842 /* Computing MIN */
843         i__1 = *m - 1;
844         klm = f2cmin(i__1,*kl);
845 /* Computing MIN */
846         i__1 = *n - 1;
847         kun = f2cmin(i__1,*ku);
848         kb = klm + kun;
849         kb1 = kb + 1;
850         inca = kb1 * *ldab;
851         nr = 0;
852         j1 = klm + 2;
853         j2 = 1 - kun;
854
855         i__1 = minmn;
856         for (i__ = 1; i__ <= i__1; ++i__) {
857
858 /*           Reduce i-th column and i-th row of matrix to bidiagonal form */
859
860             ml = klm + 1;
861             mu = kun + 1;
862             i__2 = kb;
863             for (kk = 1; kk <= i__2; ++kk) {
864                 j1 += kb;
865                 j2 += kb;
866
867 /*              generate plane rotations to annihilate nonzero elements */
868 /*              which have been created below the band */
869
870                 if (nr > 0) {
871                     dlargv_(&nr, &ab[klu1 + (j1 - klm - 1) * ab_dim1], &inca, 
872                             &work[j1], &kb1, &work[mn + j1], &kb1);
873                 }
874
875 /*              apply plane rotations from the left */
876
877                 i__3 = kb;
878                 for (l = 1; l <= i__3; ++l) {
879                     if (j2 - klm + l - 1 > *n) {
880                         nrt = nr - 1;
881                     } else {
882                         nrt = nr;
883                     }
884                     if (nrt > 0) {
885                         dlartv_(&nrt, &ab[klu1 - l + (j1 - klm + l - 1) * 
886                                 ab_dim1], &inca, &ab[klu1 - l + 1 + (j1 - klm 
887                                 + l - 1) * ab_dim1], &inca, &work[mn + j1], &
888                                 work[j1], &kb1);
889                     }
890 /* L10: */
891                 }
892
893                 if (ml > ml0) {
894                     if (ml <= *m - i__ + 1) {
895
896 /*                    generate plane rotation to annihilate a(i+ml-1,i) */
897 /*                    within the band, and apply rotation from the left */
898
899                         dlartg_(&ab[*ku + ml - 1 + i__ * ab_dim1], &ab[*ku + 
900                                 ml + i__ * ab_dim1], &work[mn + i__ + ml - 1],
901                                  &work[i__ + ml - 1], &ra);
902                         ab[*ku + ml - 1 + i__ * ab_dim1] = ra;
903                         if (i__ < *n) {
904 /* Computing MIN */
905                             i__4 = *ku + ml - 2, i__5 = *n - i__;
906                             i__3 = f2cmin(i__4,i__5);
907                             i__6 = *ldab - 1;
908                             i__7 = *ldab - 1;
909                             drot_(&i__3, &ab[*ku + ml - 2 + (i__ + 1) * 
910                                     ab_dim1], &i__6, &ab[*ku + ml - 1 + (i__ 
911                                     + 1) * ab_dim1], &i__7, &work[mn + i__ + 
912                                     ml - 1], &work[i__ + ml - 1]);
913                         }
914                     }
915                     ++nr;
916                     j1 -= kb1;
917                 }
918
919                 if (wantq) {
920
921 /*                 accumulate product of plane rotations in Q */
922
923                     i__3 = j2;
924                     i__4 = kb1;
925                     for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) 
926                             {
927                         drot_(m, &q[(j - 1) * q_dim1 + 1], &c__1, &q[j * 
928                                 q_dim1 + 1], &c__1, &work[mn + j], &work[j]);
929 /* L20: */
930                     }
931                 }
932
933                 if (wantc) {
934
935 /*                 apply plane rotations to C */
936
937                     i__4 = j2;
938                     i__3 = kb1;
939                     for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) 
940                             {
941                         drot_(ncc, &c__[j - 1 + c_dim1], ldc, &c__[j + c_dim1]
942                                 , ldc, &work[mn + j], &work[j]);
943 /* L30: */
944                     }
945                 }
946
947                 if (j2 + kun > *n) {
948
949 /*                 adjust J2 to keep within the bounds of the matrix */
950
951                     --nr;
952                     j2 -= kb1;
953                 }
954
955                 i__3 = j2;
956                 i__4 = kb1;
957                 for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
958
959 /*                 create nonzero element a(j-1,j+ku) above the band */
960 /*                 and store it in WORK(n+1:2*n) */
961
962                     work[j + kun] = work[j] * ab[(j + kun) * ab_dim1 + 1];
963                     ab[(j + kun) * ab_dim1 + 1] = work[mn + j] * ab[(j + kun) 
964                             * ab_dim1 + 1];
965 /* L40: */
966                 }
967
968 /*              generate plane rotations to annihilate nonzero elements */
969 /*              which have been generated above the band */
970
971                 if (nr > 0) {
972                     dlargv_(&nr, &ab[(j1 + kun - 1) * ab_dim1 + 1], &inca, &
973                             work[j1 + kun], &kb1, &work[mn + j1 + kun], &kb1);
974                 }
975
976 /*              apply plane rotations from the right */
977
978                 i__4 = kb;
979                 for (l = 1; l <= i__4; ++l) {
980                     if (j2 + l - 1 > *m) {
981                         nrt = nr - 1;
982                     } else {
983                         nrt = nr;
984                     }
985                     if (nrt > 0) {
986                         dlartv_(&nrt, &ab[l + 1 + (j1 + kun - 1) * ab_dim1], &
987                                 inca, &ab[l + (j1 + kun) * ab_dim1], &inca, &
988                                 work[mn + j1 + kun], &work[j1 + kun], &kb1);
989                     }
990 /* L50: */
991                 }
992
993                 if (ml == ml0 && mu > mu0) {
994                     if (mu <= *n - i__ + 1) {
995
996 /*                    generate plane rotation to annihilate a(i,i+mu-1) */
997 /*                    within the band, and apply rotation from the right */
998
999                         dlartg_(&ab[*ku - mu + 3 + (i__ + mu - 2) * ab_dim1], 
1000                                 &ab[*ku - mu + 2 + (i__ + mu - 1) * ab_dim1], 
1001                                 &work[mn + i__ + mu - 1], &work[i__ + mu - 1],
1002                                  &ra);
1003                         ab[*ku - mu + 3 + (i__ + mu - 2) * ab_dim1] = ra;
1004 /* Computing MIN */
1005                         i__3 = *kl + mu - 2, i__5 = *m - i__;
1006                         i__4 = f2cmin(i__3,i__5);
1007                         drot_(&i__4, &ab[*ku - mu + 4 + (i__ + mu - 2) * 
1008                                 ab_dim1], &c__1, &ab[*ku - mu + 3 + (i__ + mu 
1009                                 - 1) * ab_dim1], &c__1, &work[mn + i__ + mu - 
1010                                 1], &work[i__ + mu - 1]);
1011                     }
1012                     ++nr;
1013                     j1 -= kb1;
1014                 }
1015
1016                 if (wantpt) {
1017
1018 /*                 accumulate product of plane rotations in P**T */
1019
1020                     i__4 = j2;
1021                     i__3 = kb1;
1022                     for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) 
1023                             {
1024                         drot_(n, &pt[j + kun - 1 + pt_dim1], ldpt, &pt[j + 
1025                                 kun + pt_dim1], ldpt, &work[mn + j + kun], &
1026                                 work[j + kun]);
1027 /* L60: */
1028                     }
1029                 }
1030
1031                 if (j2 + kb > *m) {
1032
1033 /*                 adjust J2 to keep within the bounds of the matrix */
1034
1035                     --nr;
1036                     j2 -= kb1;
1037                 }
1038
1039                 i__3 = j2;
1040                 i__4 = kb1;
1041                 for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
1042
1043 /*                 create nonzero element a(j+kl+ku,j+ku-1) below the */
1044 /*                 band and store it in WORK(1:n) */
1045
1046                     work[j + kb] = work[j + kun] * ab[klu1 + (j + kun) * 
1047                             ab_dim1];
1048                     ab[klu1 + (j + kun) * ab_dim1] = work[mn + j + kun] * ab[
1049                             klu1 + (j + kun) * ab_dim1];
1050 /* L70: */
1051                 }
1052
1053                 if (ml > ml0) {
1054                     --ml;
1055                 } else {
1056                     --mu;
1057                 }
1058 /* L80: */
1059             }
1060 /* L90: */
1061         }
1062     }
1063
1064     if (*ku == 0 && *kl > 0) {
1065
1066 /*        A has been reduced to lower bidiagonal form */
1067
1068 /*        Transform lower bidiagonal form to upper bidiagonal by applying */
1069 /*        plane rotations from the left, storing diagonal elements in D */
1070 /*        and off-diagonal elements in E */
1071
1072 /* Computing MIN */
1073         i__2 = *m - 1;
1074         i__1 = f2cmin(i__2,*n);
1075         for (i__ = 1; i__ <= i__1; ++i__) {
1076             dlartg_(&ab[i__ * ab_dim1 + 1], &ab[i__ * ab_dim1 + 2], &rc, &rs, 
1077                     &ra);
1078             d__[i__] = ra;
1079             if (i__ < *n) {
1080                 e[i__] = rs * ab[(i__ + 1) * ab_dim1 + 1];
1081                 ab[(i__ + 1) * ab_dim1 + 1] = rc * ab[(i__ + 1) * ab_dim1 + 1]
1082                         ;
1083             }
1084             if (wantq) {
1085                 drot_(m, &q[i__ * q_dim1 + 1], &c__1, &q[(i__ + 1) * q_dim1 + 
1086                         1], &c__1, &rc, &rs);
1087             }
1088             if (wantc) {
1089                 drot_(ncc, &c__[i__ + c_dim1], ldc, &c__[i__ + 1 + c_dim1], 
1090                         ldc, &rc, &rs);
1091             }
1092 /* L100: */
1093         }
1094         if (*m <= *n) {
1095             d__[*m] = ab[*m * ab_dim1 + 1];
1096         }
1097     } else if (*ku > 0) {
1098
1099 /*        A has been reduced to upper bidiagonal form */
1100
1101         if (*m < *n) {
1102
1103 /*           Annihilate a(m,m+1) by applying plane rotations from the */
1104 /*           right, storing diagonal elements in D and off-diagonal */
1105 /*           elements in E */
1106
1107             rb = ab[*ku + (*m + 1) * ab_dim1];
1108             for (i__ = *m; i__ >= 1; --i__) {
1109                 dlartg_(&ab[*ku + 1 + i__ * ab_dim1], &rb, &rc, &rs, &ra);
1110                 d__[i__] = ra;
1111                 if (i__ > 1) {
1112                     rb = -rs * ab[*ku + i__ * ab_dim1];
1113                     e[i__ - 1] = rc * ab[*ku + i__ * ab_dim1];
1114                 }
1115                 if (wantpt) {
1116                     drot_(n, &pt[i__ + pt_dim1], ldpt, &pt[*m + 1 + pt_dim1], 
1117                             ldpt, &rc, &rs);
1118                 }
1119 /* L110: */
1120             }
1121         } else {
1122
1123 /*           Copy off-diagonal elements to E and diagonal elements to D */
1124
1125             i__1 = minmn - 1;
1126             for (i__ = 1; i__ <= i__1; ++i__) {
1127                 e[i__] = ab[*ku + (i__ + 1) * ab_dim1];
1128 /* L120: */
1129             }
1130             i__1 = minmn;
1131             for (i__ = 1; i__ <= i__1; ++i__) {
1132                 d__[i__] = ab[*ku + 1 + i__ * ab_dim1];
1133 /* L130: */
1134             }
1135         }
1136     } else {
1137
1138 /*        A is diagonal. Set elements of E to zero and copy diagonal */
1139 /*        elements to D. */
1140
1141         i__1 = minmn - 1;
1142         for (i__ = 1; i__ <= i__1; ++i__) {
1143             e[i__] = 0.;
1144 /* L140: */
1145         }
1146         i__1 = minmn;
1147         for (i__ = 1; i__ <= i__1; ++i__) {
1148             d__[i__] = ab[i__ * ab_dim1 + 1];
1149 /* L150: */
1150         }
1151     }
1152     return 0;
1153
1154 /*     End of DGBBRD */
1155
1156 } /* dgbbrd_ */
1157