C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / ssbtrd.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 real c_b9 = 0.f;
516 static real c_b10 = 1.f;
517 static integer c__1 = 1;
518
519 /* > \brief \b SSBTRD */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /* > \htmlonly */
527 /* > Download SSBTRD + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssbtrd.
529 f"> */
530 /* > [TGZ]</a> */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssbtrd.
532 f"> */
533 /* > [ZIP]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssbtrd.
535 f"> */
536 /* > [TXT]</a> */
537 /* > \endhtmlonly */
538
539 /*  Definition: */
540 /*  =========== */
541
542 /*       SUBROUTINE SSBTRD( VECT, UPLO, N, KD, AB, LDAB, D, E, Q, LDQ, */
543 /*                          WORK, INFO ) */
544
545 /*       CHARACTER          UPLO, VECT */
546 /*       INTEGER            INFO, KD, LDAB, LDQ, N */
547 /*       REAL               AB( LDAB, * ), D( * ), E( * ), Q( LDQ, * ), */
548 /*      $                   WORK( * ) */
549
550
551 /* > \par Purpose: */
552 /*  ============= */
553 /* > */
554 /* > \verbatim */
555 /* > */
556 /* > SSBTRD reduces a real symmetric band matrix A to symmetric */
557 /* > tridiagonal form T by an orthogonal similarity transformation: */
558 /* > Q**T * A * Q = T. */
559 /* > \endverbatim */
560
561 /*  Arguments: */
562 /*  ========== */
563
564 /* > \param[in] VECT */
565 /* > \verbatim */
566 /* >          VECT is CHARACTER*1 */
567 /* >          = 'N':  do not form Q; */
568 /* >          = 'V':  form Q; */
569 /* >          = 'U':  update a matrix X, by forming X*Q. */
570 /* > \endverbatim */
571 /* > */
572 /* > \param[in] UPLO */
573 /* > \verbatim */
574 /* >          UPLO is CHARACTER*1 */
575 /* >          = 'U':  Upper triangle of A is stored; */
576 /* >          = 'L':  Lower triangle of A is stored. */
577 /* > \endverbatim */
578 /* > */
579 /* > \param[in] N */
580 /* > \verbatim */
581 /* >          N is INTEGER */
582 /* >          The order of the matrix A.  N >= 0. */
583 /* > \endverbatim */
584 /* > */
585 /* > \param[in] KD */
586 /* > \verbatim */
587 /* >          KD is INTEGER */
588 /* >          The number of superdiagonals of the matrix A if UPLO = 'U', */
589 /* >          or the number of subdiagonals if UPLO = 'L'.  KD >= 0. */
590 /* > \endverbatim */
591 /* > */
592 /* > \param[in,out] AB */
593 /* > \verbatim */
594 /* >          AB is REAL array, dimension (LDAB,N) */
595 /* >          On entry, the upper or lower triangle of the symmetric band */
596 /* >          matrix A, stored in the first KD+1 rows of the array.  The */
597 /* >          j-th column of A is stored in the j-th column of the array AB */
598 /* >          as follows: */
599 /* >          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for f2cmax(1,j-kd)<=i<=j; */
600 /* >          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=f2cmin(n,j+kd). */
601 /* >          On exit, the diagonal elements of AB are overwritten by the */
602 /* >          diagonal elements of the tridiagonal matrix T; if KD > 0, the */
603 /* >          elements on the first superdiagonal (if UPLO = 'U') or the */
604 /* >          first subdiagonal (if UPLO = 'L') are overwritten by the */
605 /* >          off-diagonal elements of T; the rest of AB is overwritten by */
606 /* >          values generated during the reduction. */
607 /* > \endverbatim */
608 /* > */
609 /* > \param[in] LDAB */
610 /* > \verbatim */
611 /* >          LDAB is INTEGER */
612 /* >          The leading dimension of the array AB.  LDAB >= KD+1. */
613 /* > \endverbatim */
614 /* > */
615 /* > \param[out] D */
616 /* > \verbatim */
617 /* >          D is REAL array, dimension (N) */
618 /* >          The diagonal elements of the tridiagonal matrix T. */
619 /* > \endverbatim */
620 /* > */
621 /* > \param[out] E */
622 /* > \verbatim */
623 /* >          E is REAL array, dimension (N-1) */
624 /* >          The off-diagonal elements of the tridiagonal matrix T: */
625 /* >          E(i) = T(i,i+1) if UPLO = 'U'; E(i) = T(i+1,i) if UPLO = 'L'. */
626 /* > \endverbatim */
627 /* > */
628 /* > \param[in,out] Q */
629 /* > \verbatim */
630 /* >          Q is REAL array, dimension (LDQ,N) */
631 /* >          On entry, if VECT = 'U', then Q must contain an N-by-N */
632 /* >          matrix X; if VECT = 'N' or 'V', then Q need not be set. */
633 /* > */
634 /* >          On exit: */
635 /* >          if VECT = 'V', Q contains the N-by-N orthogonal matrix Q; */
636 /* >          if VECT = 'U', Q contains the product X*Q; */
637 /* >          if VECT = 'N', the array Q is not referenced. */
638 /* > \endverbatim */
639 /* > */
640 /* > \param[in] LDQ */
641 /* > \verbatim */
642 /* >          LDQ is INTEGER */
643 /* >          The leading dimension of the array Q. */
644 /* >          LDQ >= 1, and LDQ >= N if VECT = 'V' or 'U'. */
645 /* > \endverbatim */
646 /* > */
647 /* > \param[out] WORK */
648 /* > \verbatim */
649 /* >          WORK is REAL array, dimension (N) */
650 /* > \endverbatim */
651 /* > */
652 /* > \param[out] INFO */
653 /* > \verbatim */
654 /* >          INFO is INTEGER */
655 /* >          = 0:  successful exit */
656 /* >          < 0:  if INFO = -i, the i-th argument had an illegal value */
657 /* > \endverbatim */
658
659 /*  Authors: */
660 /*  ======== */
661
662 /* > \author Univ. of Tennessee */
663 /* > \author Univ. of California Berkeley */
664 /* > \author Univ. of Colorado Denver */
665 /* > \author NAG Ltd. */
666
667 /* > \date December 2016 */
668
669 /* > \ingroup realOTHERcomputational */
670
671 /* > \par Further Details: */
672 /*  ===================== */
673 /* > */
674 /* > \verbatim */
675 /* > */
676 /* >  Modified by Linda Kaufman, Bell Labs. */
677 /* > \endverbatim */
678 /* > */
679 /*  ===================================================================== */
680 /* Subroutine */ int ssbtrd_(char *vect, char *uplo, integer *n, integer *kd, 
681         real *ab, integer *ldab, real *d__, real *e, real *q, integer *ldq, 
682         real *work, integer *info)
683 {
684     /* System generated locals */
685     integer ab_dim1, ab_offset, q_dim1, q_offset, i__1, i__2, i__3, i__4, 
686             i__5;
687
688     /* Local variables */
689     integer inca, jend, lend, jinc, incx, last;
690     real temp;
691     extern /* Subroutine */ int srot_(integer *, real *, integer *, real *, 
692             integer *, real *, real *);
693     integer j1end, j1inc, i__, j, k, l, iqend;
694     extern logical lsame_(char *, char *);
695     logical initq, wantq, upper;
696     integer i2, j1, j2;
697     extern /* Subroutine */ int slar2v_(integer *, real *, real *, real *, 
698             integer *, real *, real *, integer *);
699     integer nq, nr, iqaend;
700     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), slaset_(
701             char *, integer *, integer *, real *, real *, real *, integer *), slartg_(real *, real *, real *, real *, real *), slargv_(
702             integer *, real *, integer *, real *, integer *, real *, integer *
703             );
704     integer kd1;
705     extern /* Subroutine */ int slartv_(integer *, real *, integer *, real *, 
706             integer *, real *, real *, integer *);
707     integer ibl, iqb, kdn, jin, nrt, kdm1;
708
709
710 /*  -- LAPACK computational routine (version 3.7.0) -- */
711 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
712 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
713 /*     December 2016 */
714
715
716 /*  ===================================================================== */
717
718
719 /*     Test the input parameters */
720
721     /* Parameter adjustments */
722     ab_dim1 = *ldab;
723     ab_offset = 1 + ab_dim1 * 1;
724     ab -= ab_offset;
725     --d__;
726     --e;
727     q_dim1 = *ldq;
728     q_offset = 1 + q_dim1 * 1;
729     q -= q_offset;
730     --work;
731
732     /* Function Body */
733     initq = lsame_(vect, "V");
734     wantq = initq || lsame_(vect, "U");
735     upper = lsame_(uplo, "U");
736     kd1 = *kd + 1;
737     kdm1 = *kd - 1;
738     incx = *ldab - 1;
739     iqend = 1;
740
741     *info = 0;
742     if (! wantq && ! lsame_(vect, "N")) {
743         *info = -1;
744     } else if (! upper && ! lsame_(uplo, "L")) {
745         *info = -2;
746     } else if (*n < 0) {
747         *info = -3;
748     } else if (*kd < 0) {
749         *info = -4;
750     } else if (*ldab < kd1) {
751         *info = -6;
752     } else if (*ldq < f2cmax(1,*n) && wantq) {
753         *info = -10;
754     }
755     if (*info != 0) {
756         i__1 = -(*info);
757         xerbla_("SSBTRD", &i__1, (ftnlen)6);
758         return 0;
759     }
760
761 /*     Quick return if possible */
762
763     if (*n == 0) {
764         return 0;
765     }
766
767 /*     Initialize Q to the unit matrix, if needed */
768
769     if (initq) {
770         slaset_("Full", n, n, &c_b9, &c_b10, &q[q_offset], ldq);
771     }
772
773 /*     Wherever possible, plane rotations are generated and applied in */
774 /*     vector operations of length NR over the index set J1:J2:KD1. */
775
776 /*     The cosines and sines of the plane rotations are stored in the */
777 /*     arrays D and WORK. */
778
779     inca = kd1 * *ldab;
780 /* Computing MIN */
781     i__1 = *n - 1;
782     kdn = f2cmin(i__1,*kd);
783     if (upper) {
784
785         if (*kd > 1) {
786
787 /*           Reduce to tridiagonal form, working with upper triangle */
788
789             nr = 0;
790             j1 = kdn + 2;
791             j2 = 1;
792
793             i__1 = *n - 2;
794             for (i__ = 1; i__ <= i__1; ++i__) {
795
796 /*              Reduce i-th row of matrix to tridiagonal form */
797
798                 for (k = kdn + 1; k >= 2; --k) {
799                     j1 += kdn;
800                     j2 += kdn;
801
802                     if (nr > 0) {
803
804 /*                    generate plane rotations to annihilate nonzero */
805 /*                    elements which have been created outside the band */
806
807                         slargv_(&nr, &ab[(j1 - 1) * ab_dim1 + 1], &inca, &
808                                 work[j1], &kd1, &d__[j1], &kd1);
809
810 /*                    apply rotations from the right */
811
812
813 /*                    Dependent on the the number of diagonals either */
814 /*                    SLARTV or SROT is used */
815
816                         if (nr >= (*kd << 1) - 1) {
817                             i__2 = *kd - 1;
818                             for (l = 1; l <= i__2; ++l) {
819                                 slartv_(&nr, &ab[l + 1 + (j1 - 1) * ab_dim1], 
820                                         &inca, &ab[l + j1 * ab_dim1], &inca, &
821                                         d__[j1], &work[j1], &kd1);
822 /* L10: */
823                             }
824
825                         } else {
826                             jend = j1 + (nr - 1) * kd1;
827                             i__2 = jend;
828                             i__3 = kd1;
829                             for (jinc = j1; i__3 < 0 ? jinc >= i__2 : jinc <= 
830                                     i__2; jinc += i__3) {
831                                 srot_(&kdm1, &ab[(jinc - 1) * ab_dim1 + 2], &
832                                         c__1, &ab[jinc * ab_dim1 + 1], &c__1, 
833                                         &d__[jinc], &work[jinc]);
834 /* L20: */
835                             }
836                         }
837                     }
838
839
840                     if (k > 2) {
841                         if (k <= *n - i__ + 1) {
842
843 /*                       generate plane rotation to annihilate a(i,i+k-1) */
844 /*                       within the band */
845
846                             slartg_(&ab[*kd - k + 3 + (i__ + k - 2) * ab_dim1]
847                                     , &ab[*kd - k + 2 + (i__ + k - 1) * 
848                                     ab_dim1], &d__[i__ + k - 1], &work[i__ + 
849                                     k - 1], &temp);
850                             ab[*kd - k + 3 + (i__ + k - 2) * ab_dim1] = temp;
851
852 /*                       apply rotation from the right */
853
854                             i__3 = k - 3;
855                             srot_(&i__3, &ab[*kd - k + 4 + (i__ + k - 2) * 
856                                     ab_dim1], &c__1, &ab[*kd - k + 3 + (i__ + 
857                                     k - 1) * ab_dim1], &c__1, &d__[i__ + k - 
858                                     1], &work[i__ + k - 1]);
859                         }
860                         ++nr;
861                         j1 = j1 - kdn - 1;
862                     }
863
864 /*                 apply plane rotations from both sides to diagonal */
865 /*                 blocks */
866
867                     if (nr > 0) {
868                         slar2v_(&nr, &ab[kd1 + (j1 - 1) * ab_dim1], &ab[kd1 + 
869                                 j1 * ab_dim1], &ab[*kd + j1 * ab_dim1], &inca,
870                                  &d__[j1], &work[j1], &kd1);
871                     }
872
873 /*                 apply plane rotations from the left */
874
875                     if (nr > 0) {
876                         if ((*kd << 1) - 1 < nr) {
877
878 /*                    Dependent on the the number of diagonals either */
879 /*                    SLARTV or SROT is used */
880
881                             i__3 = *kd - 1;
882                             for (l = 1; l <= i__3; ++l) {
883                                 if (j2 + l > *n) {
884                                     nrt = nr - 1;
885                                 } else {
886                                     nrt = nr;
887                                 }
888                                 if (nrt > 0) {
889                                     slartv_(&nrt, &ab[*kd - l + (j1 + l) * 
890                                             ab_dim1], &inca, &ab[*kd - l + 1 
891                                             + (j1 + l) * ab_dim1], &inca, &
892                                             d__[j1], &work[j1], &kd1);
893                                 }
894 /* L30: */
895                             }
896                         } else {
897                             j1end = j1 + kd1 * (nr - 2);
898                             if (j1end >= j1) {
899                                 i__3 = j1end;
900                                 i__2 = kd1;
901                                 for (jin = j1; i__2 < 0 ? jin >= i__3 : jin <=
902                                          i__3; jin += i__2) {
903                                     i__4 = *kd - 1;
904                                     srot_(&i__4, &ab[*kd - 1 + (jin + 1) * 
905                                             ab_dim1], &incx, &ab[*kd + (jin + 
906                                             1) * ab_dim1], &incx, &d__[jin], &
907                                             work[jin]);
908 /* L40: */
909                                 }
910                             }
911 /* Computing MIN */
912                             i__2 = kdm1, i__3 = *n - j2;
913                             lend = f2cmin(i__2,i__3);
914                             last = j1end + kd1;
915                             if (lend > 0) {
916                                 srot_(&lend, &ab[*kd - 1 + (last + 1) * 
917                                         ab_dim1], &incx, &ab[*kd + (last + 1) 
918                                         * ab_dim1], &incx, &d__[last], &work[
919                                         last]);
920                             }
921                         }
922                     }
923
924                     if (wantq) {
925
926 /*                    accumulate product of plane rotations in Q */
927
928                         if (initq) {
929
930 /*                 take advantage of the fact that Q was */
931 /*                 initially the Identity matrix */
932
933                             iqend = f2cmax(iqend,j2);
934 /* Computing MAX */
935                             i__2 = 0, i__3 = k - 3;
936                             i2 = f2cmax(i__2,i__3);
937                             iqaend = i__ * *kd + 1;
938                             if (k == 2) {
939                                 iqaend += *kd;
940                             }
941                             iqaend = f2cmin(iqaend,iqend);
942                             i__2 = j2;
943                             i__3 = kd1;
944                             for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j 
945                                     += i__3) {
946                                 ibl = i__ - i2 / kdm1;
947                                 ++i2;
948 /* Computing MAX */
949                                 i__4 = 1, i__5 = j - ibl;
950                                 iqb = f2cmax(i__4,i__5);
951                                 nq = iqaend + 1 - iqb;
952 /* Computing MIN */
953                                 i__4 = iqaend + *kd;
954                                 iqaend = f2cmin(i__4,iqend);
955                                 srot_(&nq, &q[iqb + (j - 1) * q_dim1], &c__1, 
956                                         &q[iqb + j * q_dim1], &c__1, &d__[j], 
957                                         &work[j]);
958 /* L50: */
959                             }
960                         } else {
961
962                             i__3 = j2;
963                             i__2 = kd1;
964                             for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j 
965                                     += i__2) {
966                                 srot_(n, &q[(j - 1) * q_dim1 + 1], &c__1, &q[
967                                         j * q_dim1 + 1], &c__1, &d__[j], &
968                                         work[j]);
969 /* L60: */
970                             }
971                         }
972
973                     }
974
975                     if (j2 + kdn > *n) {
976
977 /*                    adjust J2 to keep within the bounds of the matrix */
978
979                         --nr;
980                         j2 = j2 - kdn - 1;
981                     }
982
983                     i__2 = j2;
984                     i__3 = kd1;
985                     for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) 
986                             {
987
988 /*                    create nonzero element a(j-1,j+kd) outside the band */
989 /*                    and store it in WORK */
990
991                         work[j + *kd] = work[j] * ab[(j + *kd) * ab_dim1 + 1];
992                         ab[(j + *kd) * ab_dim1 + 1] = d__[j] * ab[(j + *kd) * 
993                                 ab_dim1 + 1];
994 /* L70: */
995                     }
996 /* L80: */
997                 }
998 /* L90: */
999             }
1000         }
1001
1002         if (*kd > 0) {
1003
1004 /*           copy off-diagonal elements to E */
1005
1006             i__1 = *n - 1;
1007             for (i__ = 1; i__ <= i__1; ++i__) {
1008                 e[i__] = ab[*kd + (i__ + 1) * ab_dim1];
1009 /* L100: */
1010             }
1011         } else {
1012
1013 /*           set E to zero if original matrix was diagonal */
1014
1015             i__1 = *n - 1;
1016             for (i__ = 1; i__ <= i__1; ++i__) {
1017                 e[i__] = 0.f;
1018 /* L110: */
1019             }
1020         }
1021
1022 /*        copy diagonal elements to D */
1023
1024         i__1 = *n;
1025         for (i__ = 1; i__ <= i__1; ++i__) {
1026             d__[i__] = ab[kd1 + i__ * ab_dim1];
1027 /* L120: */
1028         }
1029
1030     } else {
1031
1032         if (*kd > 1) {
1033
1034 /*           Reduce to tridiagonal form, working with lower triangle */
1035
1036             nr = 0;
1037             j1 = kdn + 2;
1038             j2 = 1;
1039
1040             i__1 = *n - 2;
1041             for (i__ = 1; i__ <= i__1; ++i__) {
1042
1043 /*              Reduce i-th column of matrix to tridiagonal form */
1044
1045                 for (k = kdn + 1; k >= 2; --k) {
1046                     j1 += kdn;
1047                     j2 += kdn;
1048
1049                     if (nr > 0) {
1050
1051 /*                    generate plane rotations to annihilate nonzero */
1052 /*                    elements which have been created outside the band */
1053
1054                         slargv_(&nr, &ab[kd1 + (j1 - kd1) * ab_dim1], &inca, &
1055                                 work[j1], &kd1, &d__[j1], &kd1);
1056
1057 /*                    apply plane rotations from one side */
1058
1059
1060 /*                    Dependent on the the number of diagonals either */
1061 /*                    SLARTV or SROT is used */
1062
1063                         if (nr > (*kd << 1) - 1) {
1064                             i__3 = *kd - 1;
1065                             for (l = 1; l <= i__3; ++l) {
1066                                 slartv_(&nr, &ab[kd1 - l + (j1 - kd1 + l) * 
1067                                         ab_dim1], &inca, &ab[kd1 - l + 1 + (
1068                                         j1 - kd1 + l) * ab_dim1], &inca, &d__[
1069                                         j1], &work[j1], &kd1);
1070 /* L130: */
1071                             }
1072                         } else {
1073                             jend = j1 + kd1 * (nr - 1);
1074                             i__3 = jend;
1075                             i__2 = kd1;
1076                             for (jinc = j1; i__2 < 0 ? jinc >= i__3 : jinc <= 
1077                                     i__3; jinc += i__2) {
1078                                 srot_(&kdm1, &ab[*kd + (jinc - *kd) * ab_dim1]
1079                                         , &incx, &ab[kd1 + (jinc - *kd) * 
1080                                         ab_dim1], &incx, &d__[jinc], &work[
1081                                         jinc]);
1082 /* L140: */
1083                             }
1084                         }
1085
1086                     }
1087
1088                     if (k > 2) {
1089                         if (k <= *n - i__ + 1) {
1090
1091 /*                       generate plane rotation to annihilate a(i+k-1,i) */
1092 /*                       within the band */
1093
1094                             slartg_(&ab[k - 1 + i__ * ab_dim1], &ab[k + i__ * 
1095                                     ab_dim1], &d__[i__ + k - 1], &work[i__ + 
1096                                     k - 1], &temp);
1097                             ab[k - 1 + i__ * ab_dim1] = temp;
1098
1099 /*                       apply rotation from the left */
1100
1101                             i__2 = k - 3;
1102                             i__3 = *ldab - 1;
1103                             i__4 = *ldab - 1;
1104                             srot_(&i__2, &ab[k - 2 + (i__ + 1) * ab_dim1], &
1105                                     i__3, &ab[k - 1 + (i__ + 1) * ab_dim1], &
1106                                     i__4, &d__[i__ + k - 1], &work[i__ + k - 
1107                                     1]);
1108                         }
1109                         ++nr;
1110                         j1 = j1 - kdn - 1;
1111                     }
1112
1113 /*                 apply plane rotations from both sides to diagonal */
1114 /*                 blocks */
1115
1116                     if (nr > 0) {
1117                         slar2v_(&nr, &ab[(j1 - 1) * ab_dim1 + 1], &ab[j1 * 
1118                                 ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 + 2], &
1119                                 inca, &d__[j1], &work[j1], &kd1);
1120                     }
1121
1122 /*                 apply plane rotations from the right */
1123
1124
1125 /*                    Dependent on the the number of diagonals either */
1126 /*                    SLARTV or SROT is used */
1127
1128                     if (nr > 0) {
1129                         if (nr > (*kd << 1) - 1) {
1130                             i__2 = *kd - 1;
1131                             for (l = 1; l <= i__2; ++l) {
1132                                 if (j2 + l > *n) {
1133                                     nrt = nr - 1;
1134                                 } else {
1135                                     nrt = nr;
1136                                 }
1137                                 if (nrt > 0) {
1138                                     slartv_(&nrt, &ab[l + 2 + (j1 - 1) * 
1139                                             ab_dim1], &inca, &ab[l + 1 + j1 * 
1140                                             ab_dim1], &inca, &d__[j1], &work[
1141                                             j1], &kd1);
1142                                 }
1143 /* L150: */
1144                             }
1145                         } else {
1146                             j1end = j1 + kd1 * (nr - 2);
1147                             if (j1end >= j1) {
1148                                 i__2 = j1end;
1149                                 i__3 = kd1;
1150                                 for (j1inc = j1; i__3 < 0 ? j1inc >= i__2 : 
1151                                         j1inc <= i__2; j1inc += i__3) {
1152                                     srot_(&kdm1, &ab[(j1inc - 1) * ab_dim1 + 
1153                                             3], &c__1, &ab[j1inc * ab_dim1 + 
1154                                             2], &c__1, &d__[j1inc], &work[
1155                                             j1inc]);
1156 /* L160: */
1157                                 }
1158                             }
1159 /* Computing MIN */
1160                             i__3 = kdm1, i__2 = *n - j2;
1161                             lend = f2cmin(i__3,i__2);
1162                             last = j1end + kd1;
1163                             if (lend > 0) {
1164                                 srot_(&lend, &ab[(last - 1) * ab_dim1 + 3], &
1165                                         c__1, &ab[last * ab_dim1 + 2], &c__1, 
1166                                         &d__[last], &work[last]);
1167                             }
1168                         }
1169                     }
1170
1171
1172
1173                     if (wantq) {
1174
1175 /*                    accumulate product of plane rotations in Q */
1176
1177                         if (initq) {
1178
1179 /*                 take advantage of the fact that Q was */
1180 /*                 initially the Identity matrix */
1181
1182                             iqend = f2cmax(iqend,j2);
1183 /* Computing MAX */
1184                             i__3 = 0, i__2 = k - 3;
1185                             i2 = f2cmax(i__3,i__2);
1186                             iqaend = i__ * *kd + 1;
1187                             if (k == 2) {
1188                                 iqaend += *kd;
1189                             }
1190                             iqaend = f2cmin(iqaend,iqend);
1191                             i__3 = j2;
1192                             i__2 = kd1;
1193                             for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j 
1194                                     += i__2) {
1195                                 ibl = i__ - i2 / kdm1;
1196                                 ++i2;
1197 /* Computing MAX */
1198                                 i__4 = 1, i__5 = j - ibl;
1199                                 iqb = f2cmax(i__4,i__5);
1200                                 nq = iqaend + 1 - iqb;
1201 /* Computing MIN */
1202                                 i__4 = iqaend + *kd;
1203                                 iqaend = f2cmin(i__4,iqend);
1204                                 srot_(&nq, &q[iqb + (j - 1) * q_dim1], &c__1, 
1205                                         &q[iqb + j * q_dim1], &c__1, &d__[j], 
1206                                         &work[j]);
1207 /* L170: */
1208                             }
1209                         } else {
1210
1211                             i__2 = j2;
1212                             i__3 = kd1;
1213                             for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j 
1214                                     += i__3) {
1215                                 srot_(n, &q[(j - 1) * q_dim1 + 1], &c__1, &q[
1216                                         j * q_dim1 + 1], &c__1, &d__[j], &
1217                                         work[j]);
1218 /* L180: */
1219                             }
1220                         }
1221                     }
1222
1223                     if (j2 + kdn > *n) {
1224
1225 /*                    adjust J2 to keep within the bounds of the matrix */
1226
1227                         --nr;
1228                         j2 = j2 - kdn - 1;
1229                     }
1230
1231                     i__3 = j2;
1232                     i__2 = kd1;
1233                     for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) 
1234                             {
1235
1236 /*                    create nonzero element a(j+kd,j-1) outside the */
1237 /*                    band and store it in WORK */
1238
1239                         work[j + *kd] = work[j] * ab[kd1 + j * ab_dim1];
1240                         ab[kd1 + j * ab_dim1] = d__[j] * ab[kd1 + j * ab_dim1]
1241                                 ;
1242 /* L190: */
1243                     }
1244 /* L200: */
1245                 }
1246 /* L210: */
1247             }
1248         }
1249
1250         if (*kd > 0) {
1251
1252 /*           copy off-diagonal elements to E */
1253
1254             i__1 = *n - 1;
1255             for (i__ = 1; i__ <= i__1; ++i__) {
1256                 e[i__] = ab[i__ * ab_dim1 + 2];
1257 /* L220: */
1258             }
1259         } else {
1260
1261 /*           set E to zero if original matrix was diagonal */
1262
1263             i__1 = *n - 1;
1264             for (i__ = 1; i__ <= i__1; ++i__) {
1265                 e[i__] = 0.f;
1266 /* L230: */
1267             }
1268         }
1269
1270 /*        copy diagonal elements to D */
1271
1272         i__1 = *n;
1273         for (i__ = 1; i__ <= i__1; ++i__) {
1274             d__[i__] = ab[i__ * ab_dim1 + 1];
1275 /* L240: */
1276         }
1277     }
1278
1279     return 0;
1280
1281 /*     End of SSBTRD */
1282
1283 } /* ssbtrd_ */
1284