C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dsbgst.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 static doublereal c_b20 = -1.;
519
520 /* > \brief \b DSBGST */
521
522 /*  =========== DOCUMENTATION =========== */
523
524 /* Online html documentation available at */
525 /*            http://www.netlib.org/lapack/explore-html/ */
526
527 /* > \htmlonly */
528 /* > Download DSBGST + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsbgst.
530 f"> */
531 /* > [TGZ]</a> */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsbgst.
533 f"> */
534 /* > [ZIP]</a> */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsbgst.
536 f"> */
537 /* > [TXT]</a> */
538 /* > \endhtmlonly */
539
540 /*  Definition: */
541 /*  =========== */
542
543 /*       SUBROUTINE DSBGST( VECT, UPLO, N, KA, KB, AB, LDAB, BB, LDBB, X, */
544 /*                          LDX, WORK, INFO ) */
545
546 /*       CHARACTER          UPLO, VECT */
547 /*       INTEGER            INFO, KA, KB, LDAB, LDBB, LDX, N */
548 /*       DOUBLE PRECISION   AB( LDAB, * ), BB( LDBB, * ), WORK( * ), */
549 /*      $                   X( LDX, * ) */
550
551
552 /* > \par Purpose: */
553 /*  ============= */
554 /* > */
555 /* > \verbatim */
556 /* > */
557 /* > DSBGST reduces a real symmetric-definite banded generalized */
558 /* > eigenproblem  A*x = lambda*B*x  to standard form  C*y = lambda*y, */
559 /* > such that C has the same bandwidth as A. */
560 /* > */
561 /* > B must have been previously factorized as S**T*S by DPBSTF, using a */
562 /* > split Cholesky factorization. A is overwritten by C = X**T*A*X, where */
563 /* > X = S**(-1)*Q and Q is an orthogonal matrix chosen to preserve the */
564 /* > bandwidth of A. */
565 /* > \endverbatim */
566
567 /*  Arguments: */
568 /*  ========== */
569
570 /* > \param[in] VECT */
571 /* > \verbatim */
572 /* >          VECT is CHARACTER*1 */
573 /* >          = 'N':  do not form the transformation matrix X; */
574 /* >          = 'V':  form X. */
575 /* > \endverbatim */
576 /* > */
577 /* > \param[in] UPLO */
578 /* > \verbatim */
579 /* >          UPLO is CHARACTER*1 */
580 /* >          = 'U':  Upper triangle of A is stored; */
581 /* >          = 'L':  Lower triangle of A is stored. */
582 /* > \endverbatim */
583 /* > */
584 /* > \param[in] N */
585 /* > \verbatim */
586 /* >          N is INTEGER */
587 /* >          The order of the matrices A and B.  N >= 0. */
588 /* > \endverbatim */
589 /* > */
590 /* > \param[in] KA */
591 /* > \verbatim */
592 /* >          KA is INTEGER */
593 /* >          The number of superdiagonals of the matrix A if UPLO = 'U', */
594 /* >          or the number of subdiagonals if UPLO = 'L'.  KA >= 0. */
595 /* > \endverbatim */
596 /* > */
597 /* > \param[in] KB */
598 /* > \verbatim */
599 /* >          KB is INTEGER */
600 /* >          The number of superdiagonals of the matrix B if UPLO = 'U', */
601 /* >          or the number of subdiagonals if UPLO = 'L'.  KA >= KB >= 0. */
602 /* > \endverbatim */
603 /* > */
604 /* > \param[in,out] AB */
605 /* > \verbatim */
606 /* >          AB is DOUBLE PRECISION array, dimension (LDAB,N) */
607 /* >          On entry, the upper or lower triangle of the symmetric band */
608 /* >          matrix A, stored in the first ka+1 rows of the array.  The */
609 /* >          j-th column of A is stored in the j-th column of the array AB */
610 /* >          as follows: */
611 /* >          if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for f2cmax(1,j-ka)<=i<=j; */
612 /* >          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=f2cmin(n,j+ka). */
613 /* > */
614 /* >          On exit, the transformed matrix X**T*A*X, stored in the same */
615 /* >          format as A. */
616 /* > \endverbatim */
617 /* > */
618 /* > \param[in] LDAB */
619 /* > \verbatim */
620 /* >          LDAB is INTEGER */
621 /* >          The leading dimension of the array AB.  LDAB >= KA+1. */
622 /* > \endverbatim */
623 /* > */
624 /* > \param[in] BB */
625 /* > \verbatim */
626 /* >          BB is DOUBLE PRECISION array, dimension (LDBB,N) */
627 /* >          The banded factor S from the split Cholesky factorization of */
628 /* >          B, as returned by DPBSTF, stored in the first KB+1 rows of */
629 /* >          the array. */
630 /* > \endverbatim */
631 /* > */
632 /* > \param[in] LDBB */
633 /* > \verbatim */
634 /* >          LDBB is INTEGER */
635 /* >          The leading dimension of the array BB.  LDBB >= KB+1. */
636 /* > \endverbatim */
637 /* > */
638 /* > \param[out] X */
639 /* > \verbatim */
640 /* >          X is DOUBLE PRECISION array, dimension (LDX,N) */
641 /* >          If VECT = 'V', the n-by-n matrix X. */
642 /* >          If VECT = 'N', the array X is not referenced. */
643 /* > \endverbatim */
644 /* > */
645 /* > \param[in] LDX */
646 /* > \verbatim */
647 /* >          LDX is INTEGER */
648 /* >          The leading dimension of the array X. */
649 /* >          LDX >= f2cmax(1,N) if VECT = 'V'; LDX >= 1 otherwise. */
650 /* > \endverbatim */
651 /* > */
652 /* > \param[out] WORK */
653 /* > \verbatim */
654 /* >          WORK is DOUBLE PRECISION array, dimension (2*N) */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[out] INFO */
658 /* > \verbatim */
659 /* >          INFO is INTEGER */
660 /* >          = 0:  successful exit */
661 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value. */
662 /* > \endverbatim */
663
664 /*  Authors: */
665 /*  ======== */
666
667 /* > \author Univ. of Tennessee */
668 /* > \author Univ. of California Berkeley */
669 /* > \author Univ. of Colorado Denver */
670 /* > \author NAG Ltd. */
671
672 /* > \date December 2016 */
673
674 /* > \ingroup doubleOTHERcomputational */
675
676 /*  ===================================================================== */
677 /* Subroutine */ int dsbgst_(char *vect, char *uplo, integer *n, integer *ka, 
678         integer *kb, doublereal *ab, integer *ldab, doublereal *bb, integer *
679         ldbb, doublereal *x, integer *ldx, doublereal *work, integer *info)
680 {
681     /* System generated locals */
682     integer ab_dim1, ab_offset, bb_dim1, bb_offset, x_dim1, x_offset, i__1, 
683             i__2, i__3, i__4;
684     doublereal d__1;
685
686     /* Local variables */
687     integer inca;
688     extern /* Subroutine */ int dger_(integer *, integer *, doublereal *, 
689             doublereal *, integer *, doublereal *, integer *, doublereal *, 
690             integer *), drot_(integer *, doublereal *, integer *, doublereal *
691             , integer *, doublereal *, doublereal *);
692     integer i__, j, k, l, m;
693     doublereal t;
694     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
695             integer *);
696     extern logical lsame_(char *, char *);
697     integer i0, i1;
698     logical upper;
699     integer i2, j1, j2;
700     logical wantx;
701     extern /* Subroutine */ int dlar2v_(integer *, doublereal *, doublereal *,
702              doublereal *, integer *, doublereal *, doublereal *, integer *);
703     doublereal ra;
704     integer nr, nx;
705     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
706             doublereal *, doublereal *, doublereal *, integer *), 
707             dlartg_(doublereal *, doublereal *, doublereal *, doublereal *, 
708             doublereal *), xerbla_(char *, integer *, ftnlen), dlargv_(
709             integer *, doublereal *, integer *, doublereal *, integer *, 
710             doublereal *, integer *);
711     logical update;
712     extern /* Subroutine */ int dlartv_(integer *, doublereal *, integer *, 
713             doublereal *, integer *, doublereal *, doublereal *, integer *);
714     integer ka1, kb1;
715     doublereal ra1;
716     integer j1t, j2t;
717     doublereal bii;
718     integer kbt, nrt;
719
720
721 /*  -- LAPACK computational routine (version 3.7.0) -- */
722 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
723 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
724 /*     December 2016 */
725
726
727 /*  ===================================================================== */
728
729
730 /*     Test the input parameters */
731
732     /* Parameter adjustments */
733     ab_dim1 = *ldab;
734     ab_offset = 1 + ab_dim1 * 1;
735     ab -= ab_offset;
736     bb_dim1 = *ldbb;
737     bb_offset = 1 + bb_dim1 * 1;
738     bb -= bb_offset;
739     x_dim1 = *ldx;
740     x_offset = 1 + x_dim1 * 1;
741     x -= x_offset;
742     --work;
743
744     /* Function Body */
745     wantx = lsame_(vect, "V");
746     upper = lsame_(uplo, "U");
747     ka1 = *ka + 1;
748     kb1 = *kb + 1;
749     *info = 0;
750     if (! wantx && ! lsame_(vect, "N")) {
751         *info = -1;
752     } else if (! upper && ! lsame_(uplo, "L")) {
753         *info = -2;
754     } else if (*n < 0) {
755         *info = -3;
756     } else if (*ka < 0) {
757         *info = -4;
758     } else if (*kb < 0 || *kb > *ka) {
759         *info = -5;
760     } else if (*ldab < *ka + 1) {
761         *info = -7;
762     } else if (*ldbb < *kb + 1) {
763         *info = -9;
764     } else if (*ldx < 1 || wantx && *ldx < f2cmax(1,*n)) {
765         *info = -11;
766     }
767     if (*info != 0) {
768         i__1 = -(*info);
769         xerbla_("DSBGST", &i__1, (ftnlen)6);
770         return 0;
771     }
772
773 /*     Quick return if possible */
774
775     if (*n == 0) {
776         return 0;
777     }
778
779     inca = *ldab * ka1;
780
781 /*     Initialize X to the unit matrix, if needed */
782
783     if (wantx) {
784         dlaset_("Full", n, n, &c_b8, &c_b9, &x[x_offset], ldx);
785     }
786
787 /*     Set M to the splitting point m. It must be the same value as is */
788 /*     used in DPBSTF. The chosen value allows the arrays WORK and RWORK */
789 /*     to be of dimension (N). */
790
791     m = (*n + *kb) / 2;
792
793 /*     The routine works in two phases, corresponding to the two halves */
794 /*     of the split Cholesky factorization of B as S**T*S where */
795
796 /*     S = ( U    ) */
797 /*         ( M  L ) */
798
799 /*     with U upper triangular of order m, and L lower triangular of */
800 /*     order n-m. S has the same bandwidth as B. */
801
802 /*     S is treated as a product of elementary matrices: */
803
804 /*     S = S(m)*S(m-1)*...*S(2)*S(1)*S(m+1)*S(m+2)*...*S(n-1)*S(n) */
805
806 /*     where S(i) is determined by the i-th row of S. */
807
808 /*     In phase 1, the index i takes the values n, n-1, ... , m+1; */
809 /*     in phase 2, it takes the values 1, 2, ... , m. */
810
811 /*     For each value of i, the current matrix A is updated by forming */
812 /*     inv(S(i))**T*A*inv(S(i)). This creates a triangular bulge outside */
813 /*     the band of A. The bulge is then pushed down toward the bottom of */
814 /*     A in phase 1, and up toward the top of A in phase 2, by applying */
815 /*     plane rotations. */
816
817 /*     There are kb*(kb+1)/2 elements in the bulge, but at most 2*kb-1 */
818 /*     of them are linearly independent, so annihilating a bulge requires */
819 /*     only 2*kb-1 plane rotations. The rotations are divided into a 1st */
820 /*     set of kb-1 rotations, and a 2nd set of kb rotations. */
821
822 /*     Wherever possible, rotations are generated and applied in vector */
823 /*     operations of length NR between the indices J1 and J2 (sometimes */
824 /*     replaced by modified values NRT, J1T or J2T). */
825
826 /*     The cosines and sines of the rotations are stored in the array */
827 /*     WORK. The cosines of the 1st set of rotations are stored in */
828 /*     elements n+2:n+m-kb-1 and the sines of the 1st set in elements */
829 /*     2:m-kb-1; the cosines of the 2nd set are stored in elements */
830 /*     n+m-kb+1:2*n and the sines of the second set in elements m-kb+1:n. */
831
832 /*     The bulges are not formed explicitly; nonzero elements outside the */
833 /*     band are created only when they are required for generating new */
834 /*     rotations; they are stored in the array WORK, in positions where */
835 /*     they are later overwritten by the sines of the rotations which */
836 /*     annihilate them. */
837
838 /*     **************************** Phase 1 ***************************** */
839
840 /*     The logical structure of this phase is: */
841
842 /*     UPDATE = .TRUE. */
843 /*     DO I = N, M + 1, -1 */
844 /*        use S(i) to update A and create a new bulge */
845 /*        apply rotations to push all bulges KA positions downward */
846 /*     END DO */
847 /*     UPDATE = .FALSE. */
848 /*     DO I = M + KA + 1, N - 1 */
849 /*        apply rotations to push all bulges KA positions downward */
850 /*     END DO */
851
852 /*     To avoid duplicating code, the two loops are merged. */
853
854     update = TRUE_;
855     i__ = *n + 1;
856 L10:
857     if (update) {
858         --i__;
859 /* Computing MIN */
860         i__1 = *kb, i__2 = i__ - 1;
861         kbt = f2cmin(i__1,i__2);
862         i0 = i__ - 1;
863 /* Computing MIN */
864         i__1 = *n, i__2 = i__ + *ka;
865         i1 = f2cmin(i__1,i__2);
866         i2 = i__ - kbt + ka1;
867         if (i__ < m + 1) {
868             update = FALSE_;
869             ++i__;
870             i0 = m;
871             if (*ka == 0) {
872                 goto L480;
873             }
874             goto L10;
875         }
876     } else {
877         i__ += *ka;
878         if (i__ > *n - 1) {
879             goto L480;
880         }
881     }
882
883     if (upper) {
884
885 /*        Transform A, working with the upper triangle */
886
887         if (update) {
888
889 /*           Form  inv(S(i))**T * A * inv(S(i)) */
890
891             bii = bb[kb1 + i__ * bb_dim1];
892             i__1 = i1;
893             for (j = i__; j <= i__1; ++j) {
894                 ab[i__ - j + ka1 + j * ab_dim1] /= bii;
895 /* L20: */
896             }
897 /* Computing MAX */
898             i__1 = 1, i__2 = i__ - *ka;
899             i__3 = i__;
900             for (j = f2cmax(i__1,i__2); j <= i__3; ++j) {
901                 ab[j - i__ + ka1 + i__ * ab_dim1] /= bii;
902 /* L30: */
903             }
904             i__3 = i__ - 1;
905             for (k = i__ - kbt; k <= i__3; ++k) {
906                 i__1 = k;
907                 for (j = i__ - kbt; j <= i__1; ++j) {
908                     ab[j - k + ka1 + k * ab_dim1] = ab[j - k + ka1 + k * 
909                             ab_dim1] - bb[j - i__ + kb1 + i__ * bb_dim1] * ab[
910                             k - i__ + ka1 + i__ * ab_dim1] - bb[k - i__ + kb1 
911                             + i__ * bb_dim1] * ab[j - i__ + ka1 + i__ * 
912                             ab_dim1] + ab[ka1 + i__ * ab_dim1] * bb[j - i__ + 
913                             kb1 + i__ * bb_dim1] * bb[k - i__ + kb1 + i__ * 
914                             bb_dim1];
915 /* L40: */
916                 }
917 /* Computing MAX */
918                 i__1 = 1, i__2 = i__ - *ka;
919                 i__4 = i__ - kbt - 1;
920                 for (j = f2cmax(i__1,i__2); j <= i__4; ++j) {
921                     ab[j - k + ka1 + k * ab_dim1] -= bb[k - i__ + kb1 + i__ * 
922                             bb_dim1] * ab[j - i__ + ka1 + i__ * ab_dim1];
923 /* L50: */
924                 }
925 /* L60: */
926             }
927             i__3 = i1;
928             for (j = i__; j <= i__3; ++j) {
929 /* Computing MAX */
930                 i__4 = j - *ka, i__1 = i__ - kbt;
931                 i__2 = i__ - 1;
932                 for (k = f2cmax(i__4,i__1); k <= i__2; ++k) {
933                     ab[k - j + ka1 + j * ab_dim1] -= bb[k - i__ + kb1 + i__ * 
934                             bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1];
935 /* L70: */
936                 }
937 /* L80: */
938             }
939
940             if (wantx) {
941
942 /*              post-multiply X by inv(S(i)) */
943
944                 i__3 = *n - m;
945                 d__1 = 1. / bii;
946                 dscal_(&i__3, &d__1, &x[m + 1 + i__ * x_dim1], &c__1);
947                 if (kbt > 0) {
948                     i__3 = *n - m;
949                     dger_(&i__3, &kbt, &c_b20, &x[m + 1 + i__ * x_dim1], &
950                             c__1, &bb[kb1 - kbt + i__ * bb_dim1], &c__1, &x[m 
951                             + 1 + (i__ - kbt) * x_dim1], ldx);
952                 }
953             }
954
955 /*           store a(i,i1) in RA1 for use in next loop over K */
956
957             ra1 = ab[i__ - i1 + ka1 + i1 * ab_dim1];
958         }
959
960 /*        Generate and apply vectors of rotations to chase all the */
961 /*        existing bulges KA positions down toward the bottom of the */
962 /*        band */
963
964         i__3 = *kb - 1;
965         for (k = 1; k <= i__3; ++k) {
966             if (update) {
967
968 /*              Determine the rotations which would annihilate the bulge */
969 /*              which has in theory just been created */
970
971                 if (i__ - k + *ka < *n && i__ - k > 1) {
972
973 /*                 generate rotation to annihilate a(i,i-k+ka+1) */
974
975                     dlartg_(&ab[k + 1 + (i__ - k + *ka) * ab_dim1], &ra1, &
976                             work[*n + i__ - k + *ka - m], &work[i__ - k + *ka 
977                             - m], &ra);
978
979 /*                 create nonzero element a(i-k,i-k+ka+1) outside the */
980 /*                 band and store it in WORK(i-k) */
981
982                     t = -bb[kb1 - k + i__ * bb_dim1] * ra1;
983                     work[i__ - k] = work[*n + i__ - k + *ka - m] * t - work[
984                             i__ - k + *ka - m] * ab[(i__ - k + *ka) * ab_dim1 
985                             + 1];
986                     ab[(i__ - k + *ka) * ab_dim1 + 1] = work[i__ - k + *ka - 
987                             m] * t + work[*n + i__ - k + *ka - m] * ab[(i__ - 
988                             k + *ka) * ab_dim1 + 1];
989                     ra1 = ra;
990                 }
991             }
992 /* Computing MAX */
993             i__2 = 1, i__4 = k - i0 + 2;
994             j2 = i__ - k - 1 + f2cmax(i__2,i__4) * ka1;
995             nr = (*n - j2 + *ka) / ka1;
996             j1 = j2 + (nr - 1) * ka1;
997             if (update) {
998 /* Computing MAX */
999                 i__2 = j2, i__4 = i__ + (*ka << 1) - k + 1;
1000                 j2t = f2cmax(i__2,i__4);
1001             } else {
1002                 j2t = j2;
1003             }
1004             nrt = (*n - j2t + *ka) / ka1;
1005             i__2 = j1;
1006             i__4 = ka1;
1007             for (j = j2t; i__4 < 0 ? j >= i__2 : j <= i__2; j += i__4) {
1008
1009 /*              create nonzero element a(j-ka,j+1) outside the band */
1010 /*              and store it in WORK(j-m) */
1011
1012                 work[j - m] *= ab[(j + 1) * ab_dim1 + 1];
1013                 ab[(j + 1) * ab_dim1 + 1] = work[*n + j - m] * ab[(j + 1) * 
1014                         ab_dim1 + 1];
1015 /* L90: */
1016             }
1017
1018 /*           generate rotations in 1st set to annihilate elements which */
1019 /*           have been created outside the band */
1020
1021             if (nrt > 0) {
1022                 dlargv_(&nrt, &ab[j2t * ab_dim1 + 1], &inca, &work[j2t - m], &
1023                         ka1, &work[*n + j2t - m], &ka1);
1024             }
1025             if (nr > 0) {
1026
1027 /*              apply rotations in 1st set from the right */
1028
1029                 i__4 = *ka - 1;
1030                 for (l = 1; l <= i__4; ++l) {
1031                     dlartv_(&nr, &ab[ka1 - l + j2 * ab_dim1], &inca, &ab[*ka 
1032                             - l + (j2 + 1) * ab_dim1], &inca, &work[*n + j2 - 
1033                             m], &work[j2 - m], &ka1);
1034 /* L100: */
1035                 }
1036
1037 /*              apply rotations in 1st set from both sides to diagonal */
1038 /*              blocks */
1039
1040                 dlar2v_(&nr, &ab[ka1 + j2 * ab_dim1], &ab[ka1 + (j2 + 1) * 
1041                         ab_dim1], &ab[*ka + (j2 + 1) * ab_dim1], &inca, &work[
1042                         *n + j2 - m], &work[j2 - m], &ka1);
1043
1044             }
1045
1046 /*           start applying rotations in 1st set from the left */
1047
1048             i__4 = *kb - k + 1;
1049             for (l = *ka - 1; l >= i__4; --l) {
1050                 nrt = (*n - j2 + l) / ka1;
1051                 if (nrt > 0) {
1052                     dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, &
1053                             ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, &
1054                             work[*n + j2 - m], &work[j2 - m], &ka1);
1055                 }
1056 /* L110: */
1057             }
1058
1059             if (wantx) {
1060
1061 /*              post-multiply X by product of rotations in 1st set */
1062
1063                 i__4 = j1;
1064                 i__2 = ka1;
1065                 for (j = j2; i__2 < 0 ? j >= i__4 : j <= i__4; j += i__2) {
1066                     i__1 = *n - m;
1067                     drot_(&i__1, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j 
1068                             + 1) * x_dim1], &c__1, &work[*n + j - m], &work[j 
1069                             - m]);
1070 /* L120: */
1071                 }
1072             }
1073 /* L130: */
1074         }
1075
1076         if (update) {
1077             if (i2 <= *n && kbt > 0) {
1078
1079 /*              create nonzero element a(i-kbt,i-kbt+ka+1) outside the */
1080 /*              band and store it in WORK(i-kbt) */
1081
1082                 work[i__ - kbt] = -bb[kb1 - kbt + i__ * bb_dim1] * ra1;
1083             }
1084         }
1085
1086         for (k = *kb; k >= 1; --k) {
1087             if (update) {
1088 /* Computing MAX */
1089                 i__3 = 2, i__2 = k - i0 + 1;
1090                 j2 = i__ - k - 1 + f2cmax(i__3,i__2) * ka1;
1091             } else {
1092 /* Computing MAX */
1093                 i__3 = 1, i__2 = k - i0 + 1;
1094                 j2 = i__ - k - 1 + f2cmax(i__3,i__2) * ka1;
1095             }
1096
1097 /*           finish applying rotations in 2nd set from the left */
1098
1099             for (l = *kb - k; l >= 1; --l) {
1100                 nrt = (*n - j2 + *ka + l) / ka1;
1101                 if (nrt > 0) {
1102                     dlartv_(&nrt, &ab[l + (j2 - l + 1) * ab_dim1], &inca, &ab[
1103                             l + 1 + (j2 - l + 1) * ab_dim1], &inca, &work[*n 
1104                             + j2 - *ka], &work[j2 - *ka], &ka1);
1105                 }
1106 /* L140: */
1107             }
1108             nr = (*n - j2 + *ka) / ka1;
1109             j1 = j2 + (nr - 1) * ka1;
1110             i__3 = j2;
1111             i__2 = -ka1;
1112             for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) {
1113                 work[j] = work[j - *ka];
1114                 work[*n + j] = work[*n + j - *ka];
1115 /* L150: */
1116             }
1117             i__2 = j1;
1118             i__3 = ka1;
1119             for (j = j2; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) {
1120
1121 /*              create nonzero element a(j-ka,j+1) outside the band */
1122 /*              and store it in WORK(j) */
1123
1124                 work[j] *= ab[(j + 1) * ab_dim1 + 1];
1125                 ab[(j + 1) * ab_dim1 + 1] = work[*n + j] * ab[(j + 1) * 
1126                         ab_dim1 + 1];
1127 /* L160: */
1128             }
1129             if (update) {
1130                 if (i__ - k < *n - *ka && k <= kbt) {
1131                     work[i__ - k + *ka] = work[i__ - k];
1132                 }
1133             }
1134 /* L170: */
1135         }
1136
1137         for (k = *kb; k >= 1; --k) {
1138 /* Computing MAX */
1139             i__3 = 1, i__2 = k - i0 + 1;
1140             j2 = i__ - k - 1 + f2cmax(i__3,i__2) * ka1;
1141             nr = (*n - j2 + *ka) / ka1;
1142             j1 = j2 + (nr - 1) * ka1;
1143             if (nr > 0) {
1144
1145 /*              generate rotations in 2nd set to annihilate elements */
1146 /*              which have been created outside the band */
1147
1148                 dlargv_(&nr, &ab[j2 * ab_dim1 + 1], &inca, &work[j2], &ka1, &
1149                         work[*n + j2], &ka1);
1150
1151 /*              apply rotations in 2nd set from the right */
1152
1153                 i__3 = *ka - 1;
1154                 for (l = 1; l <= i__3; ++l) {
1155                     dlartv_(&nr, &ab[ka1 - l + j2 * ab_dim1], &inca, &ab[*ka 
1156                             - l + (j2 + 1) * ab_dim1], &inca, &work[*n + j2], 
1157                             &work[j2], &ka1);
1158 /* L180: */
1159                 }
1160
1161 /*              apply rotations in 2nd set from both sides to diagonal */
1162 /*              blocks */
1163
1164                 dlar2v_(&nr, &ab[ka1 + j2 * ab_dim1], &ab[ka1 + (j2 + 1) * 
1165                         ab_dim1], &ab[*ka + (j2 + 1) * ab_dim1], &inca, &work[
1166                         *n + j2], &work[j2], &ka1);
1167
1168             }
1169
1170 /*           start applying rotations in 2nd set from the left */
1171
1172             i__3 = *kb - k + 1;
1173             for (l = *ka - 1; l >= i__3; --l) {
1174                 nrt = (*n - j2 + l) / ka1;
1175                 if (nrt > 0) {
1176                     dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, &
1177                             ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, &
1178                             work[*n + j2], &work[j2], &ka1);
1179                 }
1180 /* L190: */
1181             }
1182
1183             if (wantx) {
1184
1185 /*              post-multiply X by product of rotations in 2nd set */
1186
1187                 i__3 = j1;
1188                 i__2 = ka1;
1189                 for (j = j2; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) {
1190                     i__4 = *n - m;
1191                     drot_(&i__4, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j 
1192                             + 1) * x_dim1], &c__1, &work[*n + j], &work[j]);
1193 /* L200: */
1194                 }
1195             }
1196 /* L210: */
1197         }
1198
1199         i__2 = *kb - 1;
1200         for (k = 1; k <= i__2; ++k) {
1201 /* Computing MAX */
1202             i__3 = 1, i__4 = k - i0 + 2;
1203             j2 = i__ - k - 1 + f2cmax(i__3,i__4) * ka1;
1204
1205 /*           finish applying rotations in 1st set from the left */
1206
1207             for (l = *kb - k; l >= 1; --l) {
1208                 nrt = (*n - j2 + l) / ka1;
1209                 if (nrt > 0) {
1210                     dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, &
1211                             ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, &
1212                             work[*n + j2 - m], &work[j2 - m], &ka1);
1213                 }
1214 /* L220: */
1215             }
1216 /* L230: */
1217         }
1218
1219         if (*kb > 1) {
1220             i__2 = i__ - *kb + (*ka << 1) + 1;
1221             for (j = *n - 1; j >= i__2; --j) {
1222                 work[*n + j - m] = work[*n + j - *ka - m];
1223                 work[j - m] = work[j - *ka - m];
1224 /* L240: */
1225             }
1226         }
1227
1228     } else {
1229
1230 /*        Transform A, working with the lower triangle */
1231
1232         if (update) {
1233
1234 /*           Form  inv(S(i))**T * A * inv(S(i)) */
1235
1236             bii = bb[i__ * bb_dim1 + 1];
1237             i__2 = i1;
1238             for (j = i__; j <= i__2; ++j) {
1239                 ab[j - i__ + 1 + i__ * ab_dim1] /= bii;
1240 /* L250: */
1241             }
1242 /* Computing MAX */
1243             i__2 = 1, i__3 = i__ - *ka;
1244             i__4 = i__;
1245             for (j = f2cmax(i__2,i__3); j <= i__4; ++j) {
1246                 ab[i__ - j + 1 + j * ab_dim1] /= bii;
1247 /* L260: */
1248             }
1249             i__4 = i__ - 1;
1250             for (k = i__ - kbt; k <= i__4; ++k) {
1251                 i__2 = k;
1252                 for (j = i__ - kbt; j <= i__2; ++j) {
1253                     ab[k - j + 1 + j * ab_dim1] = ab[k - j + 1 + j * ab_dim1] 
1254                             - bb[i__ - j + 1 + j * bb_dim1] * ab[i__ - k + 1 
1255                             + k * ab_dim1] - bb[i__ - k + 1 + k * bb_dim1] * 
1256                             ab[i__ - j + 1 + j * ab_dim1] + ab[i__ * ab_dim1 
1257                             + 1] * bb[i__ - j + 1 + j * bb_dim1] * bb[i__ - k 
1258                             + 1 + k * bb_dim1];
1259 /* L270: */
1260                 }
1261 /* Computing MAX */
1262                 i__2 = 1, i__3 = i__ - *ka;
1263                 i__1 = i__ - kbt - 1;
1264                 for (j = f2cmax(i__2,i__3); j <= i__1; ++j) {
1265                     ab[k - j + 1 + j * ab_dim1] -= bb[i__ - k + 1 + k * 
1266                             bb_dim1] * ab[i__ - j + 1 + j * ab_dim1];
1267 /* L280: */
1268                 }
1269 /* L290: */
1270             }
1271             i__4 = i1;
1272             for (j = i__; j <= i__4; ++j) {
1273 /* Computing MAX */
1274                 i__1 = j - *ka, i__2 = i__ - kbt;
1275                 i__3 = i__ - 1;
1276                 for (k = f2cmax(i__1,i__2); k <= i__3; ++k) {
1277                     ab[j - k + 1 + k * ab_dim1] -= bb[i__ - k + 1 + k * 
1278                             bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1];
1279 /* L300: */
1280                 }
1281 /* L310: */
1282             }
1283
1284             if (wantx) {
1285
1286 /*              post-multiply X by inv(S(i)) */
1287
1288                 i__4 = *n - m;
1289                 d__1 = 1. / bii;
1290                 dscal_(&i__4, &d__1, &x[m + 1 + i__ * x_dim1], &c__1);
1291                 if (kbt > 0) {
1292                     i__4 = *n - m;
1293                     i__3 = *ldbb - 1;
1294                     dger_(&i__4, &kbt, &c_b20, &x[m + 1 + i__ * x_dim1], &
1295                             c__1, &bb[kbt + 1 + (i__ - kbt) * bb_dim1], &i__3,
1296                              &x[m + 1 + (i__ - kbt) * x_dim1], ldx);
1297                 }
1298             }
1299
1300 /*           store a(i1,i) in RA1 for use in next loop over K */
1301
1302             ra1 = ab[i1 - i__ + 1 + i__ * ab_dim1];
1303         }
1304
1305 /*        Generate and apply vectors of rotations to chase all the */
1306 /*        existing bulges KA positions down toward the bottom of the */
1307 /*        band */
1308
1309         i__4 = *kb - 1;
1310         for (k = 1; k <= i__4; ++k) {
1311             if (update) {
1312
1313 /*              Determine the rotations which would annihilate the bulge */
1314 /*              which has in theory just been created */
1315
1316                 if (i__ - k + *ka < *n && i__ - k > 1) {
1317
1318 /*                 generate rotation to annihilate a(i-k+ka+1,i) */
1319
1320                     dlartg_(&ab[ka1 - k + i__ * ab_dim1], &ra1, &work[*n + 
1321                             i__ - k + *ka - m], &work[i__ - k + *ka - m], &ra)
1322                             ;
1323
1324 /*                 create nonzero element a(i-k+ka+1,i-k) outside the */
1325 /*                 band and store it in WORK(i-k) */
1326
1327                     t = -bb[k + 1 + (i__ - k) * bb_dim1] * ra1;
1328                     work[i__ - k] = work[*n + i__ - k + *ka - m] * t - work[
1329                             i__ - k + *ka - m] * ab[ka1 + (i__ - k) * ab_dim1]
1330                             ;
1331                     ab[ka1 + (i__ - k) * ab_dim1] = work[i__ - k + *ka - m] * 
1332                             t + work[*n + i__ - k + *ka - m] * ab[ka1 + (i__ 
1333                             - k) * ab_dim1];
1334                     ra1 = ra;
1335                 }
1336             }
1337 /* Computing MAX */
1338             i__3 = 1, i__1 = k - i0 + 2;
1339             j2 = i__ - k - 1 + f2cmax(i__3,i__1) * ka1;
1340             nr = (*n - j2 + *ka) / ka1;
1341             j1 = j2 + (nr - 1) * ka1;
1342             if (update) {
1343 /* Computing MAX */
1344                 i__3 = j2, i__1 = i__ + (*ka << 1) - k + 1;
1345                 j2t = f2cmax(i__3,i__1);
1346             } else {
1347                 j2t = j2;
1348             }
1349             nrt = (*n - j2t + *ka) / ka1;
1350             i__3 = j1;
1351             i__1 = ka1;
1352             for (j = j2t; i__1 < 0 ? j >= i__3 : j <= i__3; j += i__1) {
1353
1354 /*              create nonzero element a(j+1,j-ka) outside the band */
1355 /*              and store it in WORK(j-m) */
1356
1357                 work[j - m] *= ab[ka1 + (j - *ka + 1) * ab_dim1];
1358                 ab[ka1 + (j - *ka + 1) * ab_dim1] = work[*n + j - m] * ab[ka1 
1359                         + (j - *ka + 1) * ab_dim1];
1360 /* L320: */
1361             }
1362
1363 /*           generate rotations in 1st set to annihilate elements which */
1364 /*           have been created outside the band */
1365
1366             if (nrt > 0) {
1367                 dlargv_(&nrt, &ab[ka1 + (j2t - *ka) * ab_dim1], &inca, &work[
1368                         j2t - m], &ka1, &work[*n + j2t - m], &ka1);
1369             }
1370             if (nr > 0) {
1371
1372 /*              apply rotations in 1st set from the left */
1373
1374                 i__1 = *ka - 1;
1375                 for (l = 1; l <= i__1; ++l) {
1376                     dlartv_(&nr, &ab[l + 1 + (j2 - l) * ab_dim1], &inca, &ab[
1377                             l + 2 + (j2 - l) * ab_dim1], &inca, &work[*n + j2 
1378                             - m], &work[j2 - m], &ka1);
1379 /* L330: */
1380                 }
1381
1382 /*              apply rotations in 1st set from both sides to diagonal */
1383 /*              blocks */
1384
1385                 dlar2v_(&nr, &ab[j2 * ab_dim1 + 1], &ab[(j2 + 1) * ab_dim1 + 
1386                         1], &ab[j2 * ab_dim1 + 2], &inca, &work[*n + j2 - m], 
1387                         &work[j2 - m], &ka1);
1388
1389             }
1390
1391 /*           start applying rotations in 1st set from the right */
1392
1393             i__1 = *kb - k + 1;
1394             for (l = *ka - 1; l >= i__1; --l) {
1395                 nrt = (*n - j2 + l) / ka1;
1396                 if (nrt > 0) {
1397                     dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[
1398                             ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n + 
1399                             j2 - m], &work[j2 - m], &ka1);
1400                 }
1401 /* L340: */
1402             }
1403
1404             if (wantx) {
1405
1406 /*              post-multiply X by product of rotations in 1st set */
1407
1408                 i__1 = j1;
1409                 i__3 = ka1;
1410                 for (j = j2; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) {
1411                     i__2 = *n - m;
1412                     drot_(&i__2, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j 
1413                             + 1) * x_dim1], &c__1, &work[*n + j - m], &work[j 
1414                             - m]);
1415 /* L350: */
1416                 }
1417             }
1418 /* L360: */
1419         }
1420
1421         if (update) {
1422             if (i2 <= *n && kbt > 0) {
1423
1424 /*              create nonzero element a(i-kbt+ka+1,i-kbt) outside the */
1425 /*              band and store it in WORK(i-kbt) */
1426
1427                 work[i__ - kbt] = -bb[kbt + 1 + (i__ - kbt) * bb_dim1] * ra1;
1428             }
1429         }
1430
1431         for (k = *kb; k >= 1; --k) {
1432             if (update) {
1433 /* Computing MAX */
1434                 i__4 = 2, i__3 = k - i0 + 1;
1435                 j2 = i__ - k - 1 + f2cmax(i__4,i__3) * ka1;
1436             } else {
1437 /* Computing MAX */
1438                 i__4 = 1, i__3 = k - i0 + 1;
1439                 j2 = i__ - k - 1 + f2cmax(i__4,i__3) * ka1;
1440             }
1441
1442 /*           finish applying rotations in 2nd set from the right */
1443
1444             for (l = *kb - k; l >= 1; --l) {
1445                 nrt = (*n - j2 + *ka + l) / ka1;
1446                 if (nrt > 0) {
1447                     dlartv_(&nrt, &ab[ka1 - l + 1 + (j2 - *ka) * ab_dim1], &
1448                             inca, &ab[ka1 - l + (j2 - *ka + 1) * ab_dim1], &
1449                             inca, &work[*n + j2 - *ka], &work[j2 - *ka], &ka1)
1450                             ;
1451                 }
1452 /* L370: */
1453             }
1454             nr = (*n - j2 + *ka) / ka1;
1455             j1 = j2 + (nr - 1) * ka1;
1456             i__4 = j2;
1457             i__3 = -ka1;
1458             for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
1459                 work[j] = work[j - *ka];
1460                 work[*n + j] = work[*n + j - *ka];
1461 /* L380: */
1462             }
1463             i__3 = j1;
1464             i__4 = ka1;
1465             for (j = j2; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
1466
1467 /*              create nonzero element a(j+1,j-ka) outside the band */
1468 /*              and store it in WORK(j) */
1469
1470                 work[j] *= ab[ka1 + (j - *ka + 1) * ab_dim1];
1471                 ab[ka1 + (j - *ka + 1) * ab_dim1] = work[*n + j] * ab[ka1 + (
1472                         j - *ka + 1) * ab_dim1];
1473 /* L390: */
1474             }
1475             if (update) {
1476                 if (i__ - k < *n - *ka && k <= kbt) {
1477                     work[i__ - k + *ka] = work[i__ - k];
1478                 }
1479             }
1480 /* L400: */
1481         }
1482
1483         for (k = *kb; k >= 1; --k) {
1484 /* Computing MAX */
1485             i__4 = 1, i__3 = k - i0 + 1;
1486             j2 = i__ - k - 1 + f2cmax(i__4,i__3) * ka1;
1487             nr = (*n - j2 + *ka) / ka1;
1488             j1 = j2 + (nr - 1) * ka1;
1489             if (nr > 0) {
1490
1491 /*              generate rotations in 2nd set to annihilate elements */
1492 /*              which have been created outside the band */
1493
1494                 dlargv_(&nr, &ab[ka1 + (j2 - *ka) * ab_dim1], &inca, &work[j2]
1495                         , &ka1, &work[*n + j2], &ka1);
1496
1497 /*              apply rotations in 2nd set from the left */
1498
1499                 i__4 = *ka - 1;
1500                 for (l = 1; l <= i__4; ++l) {
1501                     dlartv_(&nr, &ab[l + 1 + (j2 - l) * ab_dim1], &inca, &ab[
1502                             l + 2 + (j2 - l) * ab_dim1], &inca, &work[*n + j2]
1503                             , &work[j2], &ka1);
1504 /* L410: */
1505                 }
1506
1507 /*              apply rotations in 2nd set from both sides to diagonal */
1508 /*              blocks */
1509
1510                 dlar2v_(&nr, &ab[j2 * ab_dim1 + 1], &ab[(j2 + 1) * ab_dim1 + 
1511                         1], &ab[j2 * ab_dim1 + 2], &inca, &work[*n + j2], &
1512                         work[j2], &ka1);
1513
1514             }
1515
1516 /*           start applying rotations in 2nd set from the right */
1517
1518             i__4 = *kb - k + 1;
1519             for (l = *ka - 1; l >= i__4; --l) {
1520                 nrt = (*n - j2 + l) / ka1;
1521                 if (nrt > 0) {
1522                     dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[
1523                             ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n + 
1524                             j2], &work[j2], &ka1);
1525                 }
1526 /* L420: */
1527             }
1528
1529             if (wantx) {
1530
1531 /*              post-multiply X by product of rotations in 2nd set */
1532
1533                 i__4 = j1;
1534                 i__3 = ka1;
1535                 for (j = j2; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
1536                     i__1 = *n - m;
1537                     drot_(&i__1, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j 
1538                             + 1) * x_dim1], &c__1, &work[*n + j], &work[j]);
1539 /* L430: */
1540                 }
1541             }
1542 /* L440: */
1543         }
1544
1545         i__3 = *kb - 1;
1546         for (k = 1; k <= i__3; ++k) {
1547 /* Computing MAX */
1548             i__4 = 1, i__1 = k - i0 + 2;
1549             j2 = i__ - k - 1 + f2cmax(i__4,i__1) * ka1;
1550
1551 /*           finish applying rotations in 1st set from the right */
1552
1553             for (l = *kb - k; l >= 1; --l) {
1554                 nrt = (*n - j2 + l) / ka1;
1555                 if (nrt > 0) {
1556                     dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[
1557                             ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n + 
1558                             j2 - m], &work[j2 - m], &ka1);
1559                 }
1560 /* L450: */
1561             }
1562 /* L460: */
1563         }
1564
1565         if (*kb > 1) {
1566             i__3 = i__ - *kb + (*ka << 1) + 1;
1567             for (j = *n - 1; j >= i__3; --j) {
1568                 work[*n + j - m] = work[*n + j - *ka - m];
1569                 work[j - m] = work[j - *ka - m];
1570 /* L470: */
1571             }
1572         }
1573
1574     }
1575
1576     goto L10;
1577
1578 L480:
1579
1580 /*     **************************** Phase 2 ***************************** */
1581
1582 /*     The logical structure of this phase is: */
1583
1584 /*     UPDATE = .TRUE. */
1585 /*     DO I = 1, M */
1586 /*        use S(i) to update A and create a new bulge */
1587 /*        apply rotations to push all bulges KA positions upward */
1588 /*     END DO */
1589 /*     UPDATE = .FALSE. */
1590 /*     DO I = M - KA - 1, 2, -1 */
1591 /*        apply rotations to push all bulges KA positions upward */
1592 /*     END DO */
1593
1594 /*     To avoid duplicating code, the two loops are merged. */
1595
1596     update = TRUE_;
1597     i__ = 0;
1598 L490:
1599     if (update) {
1600         ++i__;
1601 /* Computing MIN */
1602         i__3 = *kb, i__4 = m - i__;
1603         kbt = f2cmin(i__3,i__4);
1604         i0 = i__ + 1;
1605 /* Computing MAX */
1606         i__3 = 1, i__4 = i__ - *ka;
1607         i1 = f2cmax(i__3,i__4);
1608         i2 = i__ + kbt - ka1;
1609         if (i__ > m) {
1610             update = FALSE_;
1611             --i__;
1612             i0 = m + 1;
1613             if (*ka == 0) {
1614                 return 0;
1615             }
1616             goto L490;
1617         }
1618     } else {
1619         i__ -= *ka;
1620         if (i__ < 2) {
1621             return 0;
1622         }
1623     }
1624
1625     if (i__ < m - kbt) {
1626         nx = m;
1627     } else {
1628         nx = *n;
1629     }
1630
1631     if (upper) {
1632
1633 /*        Transform A, working with the upper triangle */
1634
1635         if (update) {
1636
1637 /*           Form  inv(S(i))**T * A * inv(S(i)) */
1638
1639             bii = bb[kb1 + i__ * bb_dim1];
1640             i__3 = i__;
1641             for (j = i1; j <= i__3; ++j) {
1642                 ab[j - i__ + ka1 + i__ * ab_dim1] /= bii;
1643 /* L500: */
1644             }
1645 /* Computing MIN */
1646             i__4 = *n, i__1 = i__ + *ka;
1647             i__3 = f2cmin(i__4,i__1);
1648             for (j = i__; j <= i__3; ++j) {
1649                 ab[i__ - j + ka1 + j * ab_dim1] /= bii;
1650 /* L510: */
1651             }
1652             i__3 = i__ + kbt;
1653             for (k = i__ + 1; k <= i__3; ++k) {
1654                 i__4 = i__ + kbt;
1655                 for (j = k; j <= i__4; ++j) {
1656                     ab[k - j + ka1 + j * ab_dim1] = ab[k - j + ka1 + j * 
1657                             ab_dim1] - bb[i__ - j + kb1 + j * bb_dim1] * ab[
1658                             i__ - k + ka1 + k * ab_dim1] - bb[i__ - k + kb1 + 
1659                             k * bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1] + 
1660                             ab[ka1 + i__ * ab_dim1] * bb[i__ - j + kb1 + j * 
1661                             bb_dim1] * bb[i__ - k + kb1 + k * bb_dim1];
1662 /* L520: */
1663                 }
1664 /* Computing MIN */
1665                 i__1 = *n, i__2 = i__ + *ka;
1666                 i__4 = f2cmin(i__1,i__2);
1667                 for (j = i__ + kbt + 1; j <= i__4; ++j) {
1668                     ab[k - j + ka1 + j * ab_dim1] -= bb[i__ - k + kb1 + k * 
1669                             bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1];
1670 /* L530: */
1671                 }
1672 /* L540: */
1673             }
1674             i__3 = i__;
1675             for (j = i1; j <= i__3; ++j) {
1676 /* Computing MIN */
1677                 i__1 = j + *ka, i__2 = i__ + kbt;
1678                 i__4 = f2cmin(i__1,i__2);
1679                 for (k = i__ + 1; k <= i__4; ++k) {
1680                     ab[j - k + ka1 + k * ab_dim1] -= bb[i__ - k + kb1 + k * 
1681                             bb_dim1] * ab[j - i__ + ka1 + i__ * ab_dim1];
1682 /* L550: */
1683                 }
1684 /* L560: */
1685             }
1686
1687             if (wantx) {
1688
1689 /*              post-multiply X by inv(S(i)) */
1690
1691                 d__1 = 1. / bii;
1692                 dscal_(&nx, &d__1, &x[i__ * x_dim1 + 1], &c__1);
1693                 if (kbt > 0) {
1694                     i__3 = *ldbb - 1;
1695                     dger_(&nx, &kbt, &c_b20, &x[i__ * x_dim1 + 1], &c__1, &bb[
1696                             *kb + (i__ + 1) * bb_dim1], &i__3, &x[(i__ + 1) * 
1697                             x_dim1 + 1], ldx);
1698                 }
1699             }
1700
1701 /*           store a(i1,i) in RA1 for use in next loop over K */
1702
1703             ra1 = ab[i1 - i__ + ka1 + i__ * ab_dim1];
1704         }
1705
1706 /*        Generate and apply vectors of rotations to chase all the */
1707 /*        existing bulges KA positions up toward the top of the band */
1708
1709         i__3 = *kb - 1;
1710         for (k = 1; k <= i__3; ++k) {
1711             if (update) {
1712
1713 /*              Determine the rotations which would annihilate the bulge */
1714 /*              which has in theory just been created */
1715
1716                 if (i__ + k - ka1 > 0 && i__ + k < m) {
1717
1718 /*                 generate rotation to annihilate a(i+k-ka-1,i) */
1719
1720                     dlartg_(&ab[k + 1 + i__ * ab_dim1], &ra1, &work[*n + i__ 
1721                             + k - *ka], &work[i__ + k - *ka], &ra);
1722
1723 /*                 create nonzero element a(i+k-ka-1,i+k) outside the */
1724 /*                 band and store it in WORK(m-kb+i+k) */
1725
1726                     t = -bb[kb1 - k + (i__ + k) * bb_dim1] * ra1;
1727                     work[m - *kb + i__ + k] = work[*n + i__ + k - *ka] * t - 
1728                             work[i__ + k - *ka] * ab[(i__ + k) * ab_dim1 + 1];
1729                     ab[(i__ + k) * ab_dim1 + 1] = work[i__ + k - *ka] * t + 
1730                             work[*n + i__ + k - *ka] * ab[(i__ + k) * ab_dim1 
1731                             + 1];
1732                     ra1 = ra;
1733                 }
1734             }
1735 /* Computing MAX */
1736             i__4 = 1, i__1 = k + i0 - m + 1;
1737             j2 = i__ + k + 1 - f2cmax(i__4,i__1) * ka1;
1738             nr = (j2 + *ka - 1) / ka1;
1739             j1 = j2 - (nr - 1) * ka1;
1740             if (update) {
1741 /* Computing MIN */
1742                 i__4 = j2, i__1 = i__ - (*ka << 1) + k - 1;
1743                 j2t = f2cmin(i__4,i__1);
1744             } else {
1745                 j2t = j2;
1746             }
1747             nrt = (j2t + *ka - 1) / ka1;
1748             i__4 = j2t;
1749             i__1 = ka1;
1750             for (j = j1; i__1 < 0 ? j >= i__4 : j <= i__4; j += i__1) {
1751
1752 /*              create nonzero element a(j-1,j+ka) outside the band */
1753 /*              and store it in WORK(j) */
1754
1755                 work[j] *= ab[(j + *ka - 1) * ab_dim1 + 1];
1756                 ab[(j + *ka - 1) * ab_dim1 + 1] = work[*n + j] * ab[(j + *ka 
1757                         - 1) * ab_dim1 + 1];
1758 /* L570: */
1759             }
1760
1761 /*           generate rotations in 1st set to annihilate elements which */
1762 /*           have been created outside the band */
1763
1764             if (nrt > 0) {
1765                 dlargv_(&nrt, &ab[(j1 + *ka) * ab_dim1 + 1], &inca, &work[j1],
1766                          &ka1, &work[*n + j1], &ka1);
1767             }
1768             if (nr > 0) {
1769
1770 /*              apply rotations in 1st set from the left */
1771
1772                 i__1 = *ka - 1;
1773                 for (l = 1; l <= i__1; ++l) {
1774                     dlartv_(&nr, &ab[ka1 - l + (j1 + l) * ab_dim1], &inca, &
1775                             ab[*ka - l + (j1 + l) * ab_dim1], &inca, &work[*n 
1776                             + j1], &work[j1], &ka1);
1777 /* L580: */
1778                 }
1779
1780 /*              apply rotations in 1st set from both sides to diagonal */
1781 /*              blocks */
1782
1783                 dlar2v_(&nr, &ab[ka1 + j1 * ab_dim1], &ab[ka1 + (j1 - 1) * 
1784                         ab_dim1], &ab[*ka + j1 * ab_dim1], &inca, &work[*n + 
1785                         j1], &work[j1], &ka1);
1786
1787             }
1788
1789 /*           start applying rotations in 1st set from the right */
1790
1791             i__1 = *kb - k + 1;
1792             for (l = *ka - 1; l >= i__1; --l) {
1793                 nrt = (j2 + l - 1) / ka1;
1794                 j1t = j2 - (nrt - 1) * ka1;
1795                 if (nrt > 0) {
1796                     dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + (
1797                             j1t - 1) * ab_dim1], &inca, &work[*n + j1t], &
1798                             work[j1t], &ka1);
1799                 }
1800 /* L590: */
1801             }
1802
1803             if (wantx) {
1804
1805 /*              post-multiply X by product of rotations in 1st set */
1806
1807                 i__1 = j2;
1808                 i__4 = ka1;
1809                 for (j = j1; i__4 < 0 ? j >= i__1 : j <= i__1; j += i__4) {
1810                     drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 
1811                             + 1], &c__1, &work[*n + j], &work[j]);
1812 /* L600: */
1813                 }
1814             }
1815 /* L610: */
1816         }
1817
1818         if (update) {
1819             if (i2 > 0 && kbt > 0) {
1820
1821 /*              create nonzero element a(i+kbt-ka-1,i+kbt) outside the */
1822 /*              band and store it in WORK(m-kb+i+kbt) */
1823
1824                 work[m - *kb + i__ + kbt] = -bb[kb1 - kbt + (i__ + kbt) * 
1825                         bb_dim1] * ra1;
1826             }
1827         }
1828
1829         for (k = *kb; k >= 1; --k) {
1830             if (update) {
1831 /* Computing MAX */
1832                 i__3 = 2, i__4 = k + i0 - m;
1833                 j2 = i__ + k + 1 - f2cmax(i__3,i__4) * ka1;
1834             } else {
1835 /* Computing MAX */
1836                 i__3 = 1, i__4 = k + i0 - m;
1837                 j2 = i__ + k + 1 - f2cmax(i__3,i__4) * ka1;
1838             }
1839
1840 /*           finish applying rotations in 2nd set from the right */
1841
1842             for (l = *kb - k; l >= 1; --l) {
1843                 nrt = (j2 + *ka + l - 1) / ka1;
1844                 j1t = j2 - (nrt - 1) * ka1;
1845                 if (nrt > 0) {
1846                     dlartv_(&nrt, &ab[l + (j1t + *ka) * ab_dim1], &inca, &ab[
1847                             l + 1 + (j1t + *ka - 1) * ab_dim1], &inca, &work[*
1848                             n + m - *kb + j1t + *ka], &work[m - *kb + j1t + *
1849                             ka], &ka1);
1850                 }
1851 /* L620: */
1852             }
1853             nr = (j2 + *ka - 1) / ka1;
1854             j1 = j2 - (nr - 1) * ka1;
1855             i__3 = j2;
1856             i__4 = ka1;
1857             for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
1858                 work[m - *kb + j] = work[m - *kb + j + *ka];
1859                 work[*n + m - *kb + j] = work[*n + m - *kb + j + *ka];
1860 /* L630: */
1861             }
1862             i__4 = j2;
1863             i__3 = ka1;
1864             for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
1865
1866 /*              create nonzero element a(j-1,j+ka) outside the band */
1867 /*              and store it in WORK(m-kb+j) */
1868
1869                 work[m - *kb + j] *= ab[(j + *ka - 1) * ab_dim1 + 1];
1870                 ab[(j + *ka - 1) * ab_dim1 + 1] = work[*n + m - *kb + j] * ab[
1871                         (j + *ka - 1) * ab_dim1 + 1];
1872 /* L640: */
1873             }
1874             if (update) {
1875                 if (i__ + k > ka1 && k <= kbt) {
1876                     work[m - *kb + i__ + k - *ka] = work[m - *kb + i__ + k];
1877                 }
1878             }
1879 /* L650: */
1880         }
1881
1882         for (k = *kb; k >= 1; --k) {
1883 /* Computing MAX */
1884             i__3 = 1, i__4 = k + i0 - m;
1885             j2 = i__ + k + 1 - f2cmax(i__3,i__4) * ka1;
1886             nr = (j2 + *ka - 1) / ka1;
1887             j1 = j2 - (nr - 1) * ka1;
1888             if (nr > 0) {
1889
1890 /*              generate rotations in 2nd set to annihilate elements */
1891 /*              which have been created outside the band */
1892
1893                 dlargv_(&nr, &ab[(j1 + *ka) * ab_dim1 + 1], &inca, &work[m - *
1894                         kb + j1], &ka1, &work[*n + m - *kb + j1], &ka1);
1895
1896 /*              apply rotations in 2nd set from the left */
1897
1898                 i__3 = *ka - 1;
1899                 for (l = 1; l <= i__3; ++l) {
1900                     dlartv_(&nr, &ab[ka1 - l + (j1 + l) * ab_dim1], &inca, &
1901                             ab[*ka - l + (j1 + l) * ab_dim1], &inca, &work[*n 
1902                             + m - *kb + j1], &work[m - *kb + j1], &ka1);
1903 /* L660: */
1904                 }
1905
1906 /*              apply rotations in 2nd set from both sides to diagonal */
1907 /*              blocks */
1908
1909                 dlar2v_(&nr, &ab[ka1 + j1 * ab_dim1], &ab[ka1 + (j1 - 1) * 
1910                         ab_dim1], &ab[*ka + j1 * ab_dim1], &inca, &work[*n + 
1911                         m - *kb + j1], &work[m - *kb + j1], &ka1);
1912
1913             }
1914
1915 /*           start applying rotations in 2nd set from the right */
1916
1917             i__3 = *kb - k + 1;
1918             for (l = *ka - 1; l >= i__3; --l) {
1919                 nrt = (j2 + l - 1) / ka1;
1920                 j1t = j2 - (nrt - 1) * ka1;
1921                 if (nrt > 0) {
1922                     dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + (
1923                             j1t - 1) * ab_dim1], &inca, &work[*n + m - *kb + 
1924                             j1t], &work[m - *kb + j1t], &ka1);
1925                 }
1926 /* L670: */
1927             }
1928
1929             if (wantx) {
1930
1931 /*              post-multiply X by product of rotations in 2nd set */
1932
1933                 i__3 = j2;
1934                 i__4 = ka1;
1935                 for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
1936                     drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 
1937                             + 1], &c__1, &work[*n + m - *kb + j], &work[m - *
1938                             kb + j]);
1939 /* L680: */
1940                 }
1941             }
1942 /* L690: */
1943         }
1944
1945         i__4 = *kb - 1;
1946         for (k = 1; k <= i__4; ++k) {
1947 /* Computing MAX */
1948             i__3 = 1, i__1 = k + i0 - m + 1;
1949             j2 = i__ + k + 1 - f2cmax(i__3,i__1) * ka1;
1950
1951 /*           finish applying rotations in 1st set from the right */
1952
1953             for (l = *kb - k; l >= 1; --l) {
1954                 nrt = (j2 + l - 1) / ka1;
1955                 j1t = j2 - (nrt - 1) * ka1;
1956                 if (nrt > 0) {
1957                     dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + (
1958                             j1t - 1) * ab_dim1], &inca, &work[*n + j1t], &
1959                             work[j1t], &ka1);
1960                 }
1961 /* L700: */
1962             }
1963 /* L710: */
1964         }
1965
1966         if (*kb > 1) {
1967 /* Computing MIN */
1968             i__3 = i__ + *kb;
1969             i__4 = f2cmin(i__3,m) - (*ka << 1) - 1;
1970             for (j = 2; j <= i__4; ++j) {
1971                 work[*n + j] = work[*n + j + *ka];
1972                 work[j] = work[j + *ka];
1973 /* L720: */
1974             }
1975         }
1976
1977     } else {
1978
1979 /*        Transform A, working with the lower triangle */
1980
1981         if (update) {
1982
1983 /*           Form  inv(S(i))**T * A * inv(S(i)) */
1984
1985             bii = bb[i__ * bb_dim1 + 1];
1986             i__4 = i__;
1987             for (j = i1; j <= i__4; ++j) {
1988                 ab[i__ - j + 1 + j * ab_dim1] /= bii;
1989 /* L730: */
1990             }
1991 /* Computing MIN */
1992             i__3 = *n, i__1 = i__ + *ka;
1993             i__4 = f2cmin(i__3,i__1);
1994             for (j = i__; j <= i__4; ++j) {
1995                 ab[j - i__ + 1 + i__ * ab_dim1] /= bii;
1996 /* L740: */
1997             }
1998             i__4 = i__ + kbt;
1999             for (k = i__ + 1; k <= i__4; ++k) {
2000                 i__3 = i__ + kbt;
2001                 for (j = k; j <= i__3; ++j) {
2002                     ab[j - k + 1 + k * ab_dim1] = ab[j - k + 1 + k * ab_dim1] 
2003                             - bb[j - i__ + 1 + i__ * bb_dim1] * ab[k - i__ + 
2004                             1 + i__ * ab_dim1] - bb[k - i__ + 1 + i__ * 
2005                             bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1] + ab[
2006                             i__ * ab_dim1 + 1] * bb[j - i__ + 1 + i__ * 
2007                             bb_dim1] * bb[k - i__ + 1 + i__ * bb_dim1];
2008 /* L750: */
2009                 }
2010 /* Computing MIN */
2011                 i__1 = *n, i__2 = i__ + *ka;
2012                 i__3 = f2cmin(i__1,i__2);
2013                 for (j = i__ + kbt + 1; j <= i__3; ++j) {
2014                     ab[j - k + 1 + k * ab_dim1] -= bb[k - i__ + 1 + i__ * 
2015                             bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1];
2016 /* L760: */
2017                 }
2018 /* L770: */
2019             }
2020             i__4 = i__;
2021             for (j = i1; j <= i__4; ++j) {
2022 /* Computing MIN */
2023                 i__1 = j + *ka, i__2 = i__ + kbt;
2024                 i__3 = f2cmin(i__1,i__2);
2025                 for (k = i__ + 1; k <= i__3; ++k) {
2026                     ab[k - j + 1 + j * ab_dim1] -= bb[k - i__ + 1 + i__ * 
2027                             bb_dim1] * ab[i__ - j + 1 + j * ab_dim1];
2028 /* L780: */
2029                 }
2030 /* L790: */
2031             }
2032
2033             if (wantx) {
2034
2035 /*              post-multiply X by inv(S(i)) */
2036
2037                 d__1 = 1. / bii;
2038                 dscal_(&nx, &d__1, &x[i__ * x_dim1 + 1], &c__1);
2039                 if (kbt > 0) {
2040                     dger_(&nx, &kbt, &c_b20, &x[i__ * x_dim1 + 1], &c__1, &bb[
2041                             i__ * bb_dim1 + 2], &c__1, &x[(i__ + 1) * x_dim1 
2042                             + 1], ldx);
2043                 }
2044             }
2045
2046 /*           store a(i,i1) in RA1 for use in next loop over K */
2047
2048             ra1 = ab[i__ - i1 + 1 + i1 * ab_dim1];
2049         }
2050
2051 /*        Generate and apply vectors of rotations to chase all the */
2052 /*        existing bulges KA positions up toward the top of the band */
2053
2054         i__4 = *kb - 1;
2055         for (k = 1; k <= i__4; ++k) {
2056             if (update) {
2057
2058 /*              Determine the rotations which would annihilate the bulge */
2059 /*              which has in theory just been created */
2060
2061                 if (i__ + k - ka1 > 0 && i__ + k < m) {
2062
2063 /*                 generate rotation to annihilate a(i,i+k-ka-1) */
2064
2065                     dlartg_(&ab[ka1 - k + (i__ + k - *ka) * ab_dim1], &ra1, &
2066                             work[*n + i__ + k - *ka], &work[i__ + k - *ka], &
2067                             ra);
2068
2069 /*                 create nonzero element a(i+k,i+k-ka-1) outside the */
2070 /*                 band and store it in WORK(m-kb+i+k) */
2071
2072                     t = -bb[k + 1 + i__ * bb_dim1] * ra1;
2073                     work[m - *kb + i__ + k] = work[*n + i__ + k - *ka] * t - 
2074                             work[i__ + k - *ka] * ab[ka1 + (i__ + k - *ka) * 
2075                             ab_dim1];
2076                     ab[ka1 + (i__ + k - *ka) * ab_dim1] = work[i__ + k - *ka] 
2077                             * t + work[*n + i__ + k - *ka] * ab[ka1 + (i__ + 
2078                             k - *ka) * ab_dim1];
2079                     ra1 = ra;
2080                 }
2081             }
2082 /* Computing MAX */
2083             i__3 = 1, i__1 = k + i0 - m + 1;
2084             j2 = i__ + k + 1 - f2cmax(i__3,i__1) * ka1;
2085             nr = (j2 + *ka - 1) / ka1;
2086             j1 = j2 - (nr - 1) * ka1;
2087             if (update) {
2088 /* Computing MIN */
2089                 i__3 = j2, i__1 = i__ - (*ka << 1) + k - 1;
2090                 j2t = f2cmin(i__3,i__1);
2091             } else {
2092                 j2t = j2;
2093             }
2094             nrt = (j2t + *ka - 1) / ka1;
2095             i__3 = j2t;
2096             i__1 = ka1;
2097             for (j = j1; i__1 < 0 ? j >= i__3 : j <= i__3; j += i__1) {
2098
2099 /*              create nonzero element a(j+ka,j-1) outside the band */
2100 /*              and store it in WORK(j) */
2101
2102                 work[j] *= ab[ka1 + (j - 1) * ab_dim1];
2103                 ab[ka1 + (j - 1) * ab_dim1] = work[*n + j] * ab[ka1 + (j - 1) 
2104                         * ab_dim1];
2105 /* L800: */
2106             }
2107
2108 /*           generate rotations in 1st set to annihilate elements which */
2109 /*           have been created outside the band */
2110
2111             if (nrt > 0) {
2112                 dlargv_(&nrt, &ab[ka1 + j1 * ab_dim1], &inca, &work[j1], &ka1,
2113                          &work[*n + j1], &ka1);
2114             }
2115             if (nr > 0) {
2116
2117 /*              apply rotations in 1st set from the right */
2118
2119                 i__1 = *ka - 1;
2120                 for (l = 1; l <= i__1; ++l) {
2121                     dlartv_(&nr, &ab[l + 1 + j1 * ab_dim1], &inca, &ab[l + 2 
2122                             + (j1 - 1) * ab_dim1], &inca, &work[*n + j1], &
2123                             work[j1], &ka1);
2124 /* L810: */
2125                 }
2126
2127 /*              apply rotations in 1st set from both sides to diagonal */
2128 /*              blocks */
2129
2130                 dlar2v_(&nr, &ab[j1 * ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 + 
2131                         1], &ab[(j1 - 1) * ab_dim1 + 2], &inca, &work[*n + j1]
2132                         , &work[j1], &ka1);
2133
2134             }
2135
2136 /*           start applying rotations in 1st set from the left */
2137
2138             i__1 = *kb - k + 1;
2139             for (l = *ka - 1; l >= i__1; --l) {
2140                 nrt = (j2 + l - 1) / ka1;
2141                 j1t = j2 - (nrt - 1) * ka1;
2142                 if (nrt > 0) {
2143                     dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1]
2144                             , &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1],
2145                              &inca, &work[*n + j1t], &work[j1t], &ka1);
2146                 }
2147 /* L820: */
2148             }
2149
2150             if (wantx) {
2151
2152 /*              post-multiply X by product of rotations in 1st set */
2153
2154                 i__1 = j2;
2155                 i__3 = ka1;
2156                 for (j = j1; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) {
2157                     drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 
2158                             + 1], &c__1, &work[*n + j], &work[j]);
2159 /* L830: */
2160                 }
2161             }
2162 /* L840: */
2163         }
2164
2165         if (update) {
2166             if (i2 > 0 && kbt > 0) {
2167
2168 /*              create nonzero element a(i+kbt,i+kbt-ka-1) outside the */
2169 /*              band and store it in WORK(m-kb+i+kbt) */
2170
2171                 work[m - *kb + i__ + kbt] = -bb[kbt + 1 + i__ * bb_dim1] * 
2172                         ra1;
2173             }
2174         }
2175
2176         for (k = *kb; k >= 1; --k) {
2177             if (update) {
2178 /* Computing MAX */
2179                 i__4 = 2, i__3 = k + i0 - m;
2180                 j2 = i__ + k + 1 - f2cmax(i__4,i__3) * ka1;
2181             } else {
2182 /* Computing MAX */
2183                 i__4 = 1, i__3 = k + i0 - m;
2184                 j2 = i__ + k + 1 - f2cmax(i__4,i__3) * ka1;
2185             }
2186
2187 /*           finish applying rotations in 2nd set from the left */
2188
2189             for (l = *kb - k; l >= 1; --l) {
2190                 nrt = (j2 + *ka + l - 1) / ka1;
2191                 j1t = j2 - (nrt - 1) * ka1;
2192                 if (nrt > 0) {
2193                     dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t + l - 1) * ab_dim1], 
2194                             &inca, &ab[ka1 - l + (j1t + l - 1) * ab_dim1], &
2195                             inca, &work[*n + m - *kb + j1t + *ka], &work[m - *
2196                             kb + j1t + *ka], &ka1);
2197                 }
2198 /* L850: */
2199             }
2200             nr = (j2 + *ka - 1) / ka1;
2201             j1 = j2 - (nr - 1) * ka1;
2202             i__4 = j2;
2203             i__3 = ka1;
2204             for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
2205                 work[m - *kb + j] = work[m - *kb + j + *ka];
2206                 work[*n + m - *kb + j] = work[*n + m - *kb + j + *ka];
2207 /* L860: */
2208             }
2209             i__3 = j2;
2210             i__4 = ka1;
2211             for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
2212
2213 /*              create nonzero element a(j+ka,j-1) outside the band */
2214 /*              and store it in WORK(m-kb+j) */
2215
2216                 work[m - *kb + j] *= ab[ka1 + (j - 1) * ab_dim1];
2217                 ab[ka1 + (j - 1) * ab_dim1] = work[*n + m - *kb + j] * ab[ka1 
2218                         + (j - 1) * ab_dim1];
2219 /* L870: */
2220             }
2221             if (update) {
2222                 if (i__ + k > ka1 && k <= kbt) {
2223                     work[m - *kb + i__ + k - *ka] = work[m - *kb + i__ + k];
2224                 }
2225             }
2226 /* L880: */
2227         }
2228
2229         for (k = *kb; k >= 1; --k) {
2230 /* Computing MAX */
2231             i__4 = 1, i__3 = k + i0 - m;
2232             j2 = i__ + k + 1 - f2cmax(i__4,i__3) * ka1;
2233             nr = (j2 + *ka - 1) / ka1;
2234             j1 = j2 - (nr - 1) * ka1;
2235             if (nr > 0) {
2236
2237 /*              generate rotations in 2nd set to annihilate elements */
2238 /*              which have been created outside the band */
2239
2240                 dlargv_(&nr, &ab[ka1 + j1 * ab_dim1], &inca, &work[m - *kb + 
2241                         j1], &ka1, &work[*n + m - *kb + j1], &ka1);
2242
2243 /*              apply rotations in 2nd set from the right */
2244
2245                 i__4 = *ka - 1;
2246                 for (l = 1; l <= i__4; ++l) {
2247                     dlartv_(&nr, &ab[l + 1 + j1 * ab_dim1], &inca, &ab[l + 2 
2248                             + (j1 - 1) * ab_dim1], &inca, &work[*n + m - *kb 
2249                             + j1], &work[m - *kb + j1], &ka1);
2250 /* L890: */
2251                 }
2252
2253 /*              apply rotations in 2nd set from both sides to diagonal */
2254 /*              blocks */
2255
2256                 dlar2v_(&nr, &ab[j1 * ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 + 
2257                         1], &ab[(j1 - 1) * ab_dim1 + 2], &inca, &work[*n + m 
2258                         - *kb + j1], &work[m - *kb + j1], &ka1);
2259
2260             }
2261
2262 /*           start applying rotations in 2nd set from the left */
2263
2264             i__4 = *kb - k + 1;
2265             for (l = *ka - 1; l >= i__4; --l) {
2266                 nrt = (j2 + l - 1) / ka1;
2267                 j1t = j2 - (nrt - 1) * ka1;
2268                 if (nrt > 0) {
2269                     dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1]
2270                             , &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1],
2271                              &inca, &work[*n + m - *kb + j1t], &work[m - *kb 
2272                             + j1t], &ka1);
2273                 }
2274 /* L900: */
2275             }
2276
2277             if (wantx) {
2278
2279 /*              post-multiply X by product of rotations in 2nd set */
2280
2281                 i__4 = j2;
2282                 i__3 = ka1;
2283                 for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
2284                     drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 
2285                             + 1], &c__1, &work[*n + m - *kb + j], &work[m - *
2286                             kb + j]);
2287 /* L910: */
2288                 }
2289             }
2290 /* L920: */
2291         }
2292
2293         i__3 = *kb - 1;
2294         for (k = 1; k <= i__3; ++k) {
2295 /* Computing MAX */
2296             i__4 = 1, i__1 = k + i0 - m + 1;
2297             j2 = i__ + k + 1 - f2cmax(i__4,i__1) * ka1;
2298
2299 /*           finish applying rotations in 1st set from the left */
2300
2301             for (l = *kb - k; l >= 1; --l) {
2302                 nrt = (j2 + l - 1) / ka1;
2303                 j1t = j2 - (nrt - 1) * ka1;
2304                 if (nrt > 0) {
2305                     dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1]
2306                             , &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1],
2307                              &inca, &work[*n + j1t], &work[j1t], &ka1);
2308                 }
2309 /* L930: */
2310             }
2311 /* L940: */
2312         }
2313
2314         if (*kb > 1) {
2315 /* Computing MIN */
2316             i__4 = i__ + *kb;
2317             i__3 = f2cmin(i__4,m) - (*ka << 1) - 1;
2318             for (j = 2; j <= i__3; ++j) {
2319                 work[*n + j] = work[*n + j + *ka];
2320                 work[j] = work[j + *ka];
2321 /* L950: */
2322             }
2323         }
2324
2325     }
2326
2327     goto L490;
2328
2329 /*     End of DSBGST */
2330
2331 } /* dsbgst_ */
2332