C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / TESTING / MATGEN / slatms.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__1 = 1;
516 static real c_b22 = 0.f;
517 static logical c_true = TRUE_;
518 static logical c_false = FALSE_;
519
520 /* > \brief \b SLATMS */
521
522 /*  =========== DOCUMENTATION =========== */
523
524 /* Online html documentation available at */
525 /*            http://www.netlib.org/lapack/explore-html/ */
526
527 /*  Definition: */
528 /*  =========== */
529
530 /*       SUBROUTINE SLATMS( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
531 /*                          KL, KU, PACK, A, LDA, WORK, INFO ) */
532
533 /*       CHARACTER          DIST, PACK, SYM */
534 /*       INTEGER            INFO, KL, KU, LDA, M, MODE, N */
535 /*       REAL               COND, DMAX */
536 /*       INTEGER            ISEED( 4 ) */
537 /*       REAL               A( LDA, * ), D( * ), WORK( * ) */
538
539
540 /* > \par Purpose: */
541 /*  ============= */
542 /* > */
543 /* > \verbatim */
544 /* > */
545 /* >    SLATMS generates random matrices with specified singular values */
546 /* >    (or symmetric/hermitian with specified eigenvalues) */
547 /* >    for testing LAPACK programs. */
548 /* > */
549 /* >    SLATMS operates by applying the following sequence of */
550 /* >    operations: */
551 /* > */
552 /* >      Set the diagonal to D, where D may be input or */
553 /* >         computed according to MODE, COND, DMAX, and SYM */
554 /* >         as described below. */
555 /* > */
556 /* >      Generate a matrix with the appropriate band structure, by one */
557 /* >         of two methods: */
558 /* > */
559 /* >      Method A: */
560 /* >          Generate a dense M x N matrix by multiplying D on the left */
561 /* >              and the right by random unitary matrices, then: */
562 /* > */
563 /* >          Reduce the bandwidth according to KL and KU, using */
564 /* >          Householder transformations. */
565 /* > */
566 /* >      Method B: */
567 /* >          Convert the bandwidth-0 (i.e., diagonal) matrix to a */
568 /* >              bandwidth-1 matrix using Givens rotations, "chasing" */
569 /* >              out-of-band elements back, much as in QR; then */
570 /* >              convert the bandwidth-1 to a bandwidth-2 matrix, etc. */
571 /* >              Note that for reasonably small bandwidths (relative to */
572 /* >              M and N) this requires less storage, as a dense matrix */
573 /* >              is not generated.  Also, for symmetric matrices, only */
574 /* >              one triangle is generated. */
575 /* > */
576 /* >      Method A is chosen if the bandwidth is a large fraction of the */
577 /* >          order of the matrix, and LDA is at least M (so a dense */
578 /* >          matrix can be stored.)  Method B is chosen if the bandwidth */
579 /* >          is small (< 1/2 N for symmetric, < .3 N+M for */
580 /* >          non-symmetric), or LDA is less than M and not less than the */
581 /* >          bandwidth. */
582 /* > */
583 /* >      Pack the matrix if desired. Options specified by PACK are: */
584 /* >         no packing */
585 /* >         zero out upper half (if symmetric) */
586 /* >         zero out lower half (if symmetric) */
587 /* >         store the upper half columnwise (if symmetric or upper */
588 /* >               triangular) */
589 /* >         store the lower half columnwise (if symmetric or lower */
590 /* >               triangular) */
591 /* >         store the lower triangle in banded format (if symmetric */
592 /* >               or lower triangular) */
593 /* >         store the upper triangle in banded format (if symmetric */
594 /* >               or upper triangular) */
595 /* >         store the entire matrix in banded format */
596 /* >      If Method B is chosen, and band format is specified, then the */
597 /* >         matrix will be generated in the band format, so no repacking */
598 /* >         will be necessary. */
599 /* > \endverbatim */
600
601 /*  Arguments: */
602 /*  ========== */
603
604 /* > \param[in] M */
605 /* > \verbatim */
606 /* >          M is INTEGER */
607 /* >           The number of rows of A. Not modified. */
608 /* > \endverbatim */
609 /* > */
610 /* > \param[in] N */
611 /* > \verbatim */
612 /* >          N is INTEGER */
613 /* >           The number of columns of A. Not modified. */
614 /* > \endverbatim */
615 /* > */
616 /* > \param[in] DIST */
617 /* > \verbatim */
618 /* >          DIST is CHARACTER*1 */
619 /* >           On entry, DIST specifies the type of distribution to be used */
620 /* >           to generate the random eigen-/singular values. */
621 /* >           'U' => UNIFORM( 0, 1 )  ( 'U' for uniform ) */
622 /* >           'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
623 /* >           'N' => NORMAL( 0, 1 )   ( 'N' for normal ) */
624 /* >           Not modified. */
625 /* > \endverbatim */
626 /* > */
627 /* > \param[in,out] ISEED */
628 /* > \verbatim */
629 /* >          ISEED is INTEGER array, dimension ( 4 ) */
630 /* >           On entry ISEED specifies the seed of the random number */
631 /* >           generator. They should lie between 0 and 4095 inclusive, */
632 /* >           and ISEED(4) should be odd. The random number generator */
633 /* >           uses a linear congruential sequence limited to small */
634 /* >           integers, and so should produce machine independent */
635 /* >           random numbers. The values of ISEED are changed on */
636 /* >           exit, and can be used in the next call to SLATMS */
637 /* >           to continue the same random number sequence. */
638 /* >           Changed on exit. */
639 /* > \endverbatim */
640 /* > */
641 /* > \param[in] SYM */
642 /* > \verbatim */
643 /* >          SYM is CHARACTER*1 */
644 /* >           If SYM='S' or 'H', the generated matrix is symmetric, with */
645 /* >             eigenvalues specified by D, COND, MODE, and DMAX; they */
646 /* >             may be positive, negative, or zero. */
647 /* >           If SYM='P', the generated matrix is symmetric, with */
648 /* >             eigenvalues (= singular values) specified by D, COND, */
649 /* >             MODE, and DMAX; they will not be negative. */
650 /* >           If SYM='N', the generated matrix is nonsymmetric, with */
651 /* >             singular values specified by D, COND, MODE, and DMAX; */
652 /* >             they will not be negative. */
653 /* >           Not modified. */
654 /* > \endverbatim */
655 /* > */
656 /* > \param[in,out] D */
657 /* > \verbatim */
658 /* >          D is REAL array, dimension ( MIN( M , N ) ) */
659 /* >           This array is used to specify the singular values or */
660 /* >           eigenvalues of A (see SYM, above.)  If MODE=0, then D is */
661 /* >           assumed to contain the singular/eigenvalues, otherwise */
662 /* >           they will be computed according to MODE, COND, and DMAX, */
663 /* >           and placed in D. */
664 /* >           Modified if MODE is nonzero. */
665 /* > \endverbatim */
666 /* > */
667 /* > \param[in] MODE */
668 /* > \verbatim */
669 /* >          MODE is INTEGER */
670 /* >           On entry this describes how the singular/eigenvalues are to */
671 /* >           be specified: */
672 /* >           MODE = 0 means use D as input */
673 /* >           MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
674 /* >           MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
675 /* >           MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
676 /* >           MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
677 /* >           MODE = 5 sets D to random numbers in the range */
678 /* >                    ( 1/COND , 1 ) such that their logarithms */
679 /* >                    are uniformly distributed. */
680 /* >           MODE = 6 set D to random numbers from same distribution */
681 /* >                    as the rest of the matrix. */
682 /* >           MODE < 0 has the same meaning as ABS(MODE), except that */
683 /* >              the order of the elements of D is reversed. */
684 /* >           Thus if MODE is positive, D has entries ranging from */
685 /* >              1 to 1/COND, if negative, from 1/COND to 1, */
686 /* >           If SYM='S' or 'H', and MODE is neither 0, 6, nor -6, then */
687 /* >              the elements of D will also be multiplied by a random */
688 /* >              sign (i.e., +1 or -1.) */
689 /* >           Not modified. */
690 /* > \endverbatim */
691 /* > */
692 /* > \param[in] COND */
693 /* > \verbatim */
694 /* >          COND is REAL */
695 /* >           On entry, this is used as described under MODE above. */
696 /* >           If used, it must be >= 1. Not modified. */
697 /* > \endverbatim */
698 /* > */
699 /* > \param[in] DMAX */
700 /* > \verbatim */
701 /* >          DMAX is REAL */
702 /* >           If MODE is neither -6, 0 nor 6, the contents of D, as */
703 /* >           computed according to MODE and COND, will be scaled by */
704 /* >           DMAX / f2cmax(abs(D(i))); thus, the maximum absolute eigen- or */
705 /* >           singular value (which is to say the norm) will be abs(DMAX). */
706 /* >           Note that DMAX need not be positive: if DMAX is negative */
707 /* >           (or zero), D will be scaled by a negative number (or zero). */
708 /* >           Not modified. */
709 /* > \endverbatim */
710 /* > */
711 /* > \param[in] KL */
712 /* > \verbatim */
713 /* >          KL is INTEGER */
714 /* >           This specifies the lower bandwidth of the  matrix. For */
715 /* >           example, KL=0 implies upper triangular, KL=1 implies upper */
716 /* >           Hessenberg, and KL being at least M-1 means that the matrix */
717 /* >           has full lower bandwidth.  KL must equal KU if the matrix */
718 /* >           is symmetric. */
719 /* >           Not modified. */
720 /* > \endverbatim */
721 /* > */
722 /* > \param[in] KU */
723 /* > \verbatim */
724 /* >          KU is INTEGER */
725 /* >           This specifies the upper bandwidth of the  matrix. For */
726 /* >           example, KU=0 implies lower triangular, KU=1 implies lower */
727 /* >           Hessenberg, and KU being at least N-1 means that the matrix */
728 /* >           has full upper bandwidth.  KL must equal KU if the matrix */
729 /* >           is symmetric. */
730 /* >           Not modified. */
731 /* > \endverbatim */
732 /* > */
733 /* > \param[in] PACK */
734 /* > \verbatim */
735 /* >          PACK is CHARACTER*1 */
736 /* >           This specifies packing of matrix as follows: */
737 /* >           'N' => no packing */
738 /* >           'U' => zero out all subdiagonal entries (if symmetric) */
739 /* >           'L' => zero out all superdiagonal entries (if symmetric) */
740 /* >           'C' => store the upper triangle columnwise */
741 /* >                  (only if the matrix is symmetric or upper triangular) */
742 /* >           'R' => store the lower triangle columnwise */
743 /* >                  (only if the matrix is symmetric or lower triangular) */
744 /* >           'B' => store the lower triangle in band storage scheme */
745 /* >                  (only if matrix symmetric or lower triangular) */
746 /* >           'Q' => store the upper triangle in band storage scheme */
747 /* >                  (only if matrix symmetric or upper triangular) */
748 /* >           'Z' => store the entire matrix in band storage scheme */
749 /* >                      (pivoting can be provided for by using this */
750 /* >                      option to store A in the trailing rows of */
751 /* >                      the allocated storage) */
752 /* > */
753 /* >           Using these options, the various LAPACK packed and banded */
754 /* >           storage schemes can be obtained: */
755 /* >           GB               - use 'Z' */
756 /* >           PB, SB or TB     - use 'B' or 'Q' */
757 /* >           PP, SP or TP     - use 'C' or 'R' */
758 /* > */
759 /* >           If two calls to SLATMS differ only in the PACK parameter, */
760 /* >           they will generate mathematically equivalent matrices. */
761 /* >           Not modified. */
762 /* > \endverbatim */
763 /* > */
764 /* > \param[in,out] A */
765 /* > \verbatim */
766 /* >          A is REAL array, dimension ( LDA, N ) */
767 /* >           On exit A is the desired test matrix.  A is first generated */
768 /* >           in full (unpacked) form, and then packed, if so specified */
769 /* >           by PACK.  Thus, the first M elements of the first N */
770 /* >           columns will always be modified.  If PACK specifies a */
771 /* >           packed or banded storage scheme, all LDA elements of the */
772 /* >           first N columns will be modified; the elements of the */
773 /* >           array which do not correspond to elements of the generated */
774 /* >           matrix are set to zero. */
775 /* >           Modified. */
776 /* > \endverbatim */
777 /* > */
778 /* > \param[in] LDA */
779 /* > \verbatim */
780 /* >          LDA is INTEGER */
781 /* >           LDA specifies the first dimension of A as declared in the */
782 /* >           calling program.  If PACK='N', 'U', 'L', 'C', or 'R', then */
783 /* >           LDA must be at least M.  If PACK='B' or 'Q', then LDA must */
784 /* >           be at least MIN( KL, M-1) (which is equal to MIN(KU,N-1)). */
785 /* >           If PACK='Z', LDA must be large enough to hold the packed */
786 /* >           array: MIN( KU, N-1) + MIN( KL, M-1) + 1. */
787 /* >           Not modified. */
788 /* > \endverbatim */
789 /* > */
790 /* > \param[out] WORK */
791 /* > \verbatim */
792 /* >          WORK is REAL array, dimension ( 3*MAX( N , M ) ) */
793 /* >           Workspace. */
794 /* >           Modified. */
795 /* > \endverbatim */
796 /* > */
797 /* > \param[out] INFO */
798 /* > \verbatim */
799 /* >          INFO is INTEGER */
800 /* >           Error code.  On exit, INFO will be set to one of the */
801 /* >           following values: */
802 /* >             0 => normal return */
803 /* >            -1 => M negative or unequal to N and SYM='S', 'H', or 'P' */
804 /* >            -2 => N negative */
805 /* >            -3 => DIST illegal string */
806 /* >            -5 => SYM illegal string */
807 /* >            -7 => MODE not in range -6 to 6 */
808 /* >            -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
809 /* >           -10 => KL negative */
810 /* >           -11 => KU negative, or SYM='S' or 'H' and KU not equal to KL */
811 /* >           -12 => PACK illegal string, or PACK='U' or 'L', and SYM='N'; */
812 /* >                  or PACK='C' or 'Q' and SYM='N' and KL is not zero; */
813 /* >                  or PACK='R' or 'B' and SYM='N' and KU is not zero; */
814 /* >                  or PACK='U', 'L', 'C', 'R', 'B', or 'Q', and M is not */
815 /* >                  N. */
816 /* >           -14 => LDA is less than M, or PACK='Z' and LDA is less than */
817 /* >                  MIN(KU,N-1) + MIN(KL,M-1) + 1. */
818 /* >            1  => Error return from SLATM1 */
819 /* >            2  => Cannot scale to DMAX (f2cmax. sing. value is 0) */
820 /* >            3  => Error return from SLAGGE or SLAGSY */
821 /* > \endverbatim */
822
823 /*  Authors: */
824 /*  ======== */
825
826 /* > \author Univ. of Tennessee */
827 /* > \author Univ. of California Berkeley */
828 /* > \author Univ. of Colorado Denver */
829 /* > \author NAG Ltd. */
830
831 /* > \date December 2016 */
832
833 /* > \ingroup real_matgen */
834
835 /*  ===================================================================== */
836 /* Subroutine */ int slatms_(integer *m, integer *n, char *dist, integer *
837         iseed, char *sym, real *d__, integer *mode, real *cond, real *dmax__, 
838         integer *kl, integer *ku, char *pack, real *a, integer *lda, real *
839         work, integer *info)
840 {
841     /* System generated locals */
842     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
843     real r__1, r__2, r__3;
844     logical L__1;
845
846     /* Local variables */
847     integer ilda, icol;
848     real temp;
849     integer irow, isym;
850     real c__;
851     integer i__, j, k;
852     real s, alpha, angle;
853     integer ipack, ioffg;
854     extern logical lsame_(char *, char *);
855     integer iinfo;
856     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
857     integer idist, mnmin, iskew;
858     real extra, dummy;
859     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
860             integer *), slatm1_(integer *, real *, integer *, integer *, 
861             integer *, real *, integer *, integer *);
862     integer ic, jc, nc, il, iendch, ir, jr, ipackg, mr;
863     extern /* Subroutine */ int slagge_(integer *, integer *, integer *, 
864             integer *, real *, real *, integer *, integer *, real *, integer *
865             );
866     integer minlda;
867     extern /* Subroutine */ int xerbla_(char *, integer *);
868     extern real slarnd_(integer *, integer *);
869     logical iltemp, givens;
870     integer ioffst, irsign;
871     extern /* Subroutine */ int slartg_(real *, real *, real *, real *, real *
872             ), slaset_(char *, integer *, integer *, real *, real *, real *, 
873             integer *), slagsy_(integer *, integer *, real *, real *, 
874             integer *, integer *, real *, integer *), slarot_(logical *, 
875             logical *, logical *, integer *, real *, real *, real *, integer *
876             , real *, real *);
877     logical ilextr, topdwn;
878     integer ir1, ir2, isympk, jch, llb, jkl, jku, uub;
879
880
881 /*  -- LAPACK computational routine (version 3.7.0) -- */
882 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
883 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
884 /*     December 2016 */
885
886
887 /*  ===================================================================== */
888
889
890 /*     1)      Decode and Test the input parameters. */
891 /*             Initialize flags & seed. */
892
893     /* Parameter adjustments */
894     --iseed;
895     --d__;
896     a_dim1 = *lda;
897     a_offset = 1 + a_dim1 * 1;
898     a -= a_offset;
899     --work;
900
901     /* Function Body */
902     *info = 0;
903
904 /*     Quick return if possible */
905
906     if (*m == 0 || *n == 0) {
907         return 0;
908     }
909
910 /*     Decode DIST */
911
912     if (lsame_(dist, "U")) {
913         idist = 1;
914     } else if (lsame_(dist, "S")) {
915         idist = 2;
916     } else if (lsame_(dist, "N")) {
917         idist = 3;
918     } else {
919         idist = -1;
920     }
921
922 /*     Decode SYM */
923
924     if (lsame_(sym, "N")) {
925         isym = 1;
926         irsign = 0;
927     } else if (lsame_(sym, "P")) {
928         isym = 2;
929         irsign = 0;
930     } else if (lsame_(sym, "S")) {
931         isym = 2;
932         irsign = 1;
933     } else if (lsame_(sym, "H")) {
934         isym = 2;
935         irsign = 1;
936     } else {
937         isym = -1;
938     }
939
940 /*     Decode PACK */
941
942     isympk = 0;
943     if (lsame_(pack, "N")) {
944         ipack = 0;
945     } else if (lsame_(pack, "U")) {
946         ipack = 1;
947         isympk = 1;
948     } else if (lsame_(pack, "L")) {
949         ipack = 2;
950         isympk = 1;
951     } else if (lsame_(pack, "C")) {
952         ipack = 3;
953         isympk = 2;
954     } else if (lsame_(pack, "R")) {
955         ipack = 4;
956         isympk = 3;
957     } else if (lsame_(pack, "B")) {
958         ipack = 5;
959         isympk = 3;
960     } else if (lsame_(pack, "Q")) {
961         ipack = 6;
962         isympk = 2;
963     } else if (lsame_(pack, "Z")) {
964         ipack = 7;
965     } else {
966         ipack = -1;
967     }
968
969 /*     Set certain internal parameters */
970
971     mnmin = f2cmin(*m,*n);
972 /* Computing MIN */
973     i__1 = *kl, i__2 = *m - 1;
974     llb = f2cmin(i__1,i__2);
975 /* Computing MIN */
976     i__1 = *ku, i__2 = *n - 1;
977     uub = f2cmin(i__1,i__2);
978 /* Computing MIN */
979     i__1 = *m, i__2 = *n + llb;
980     mr = f2cmin(i__1,i__2);
981 /* Computing MIN */
982     i__1 = *n, i__2 = *m + uub;
983     nc = f2cmin(i__1,i__2);
984
985     if (ipack == 5 || ipack == 6) {
986         minlda = uub + 1;
987     } else if (ipack == 7) {
988         minlda = llb + uub + 1;
989     } else {
990         minlda = *m;
991     }
992
993 /*     Use Givens rotation method if bandwidth small enough, */
994 /*     or if LDA is too small to store the matrix unpacked. */
995
996     givens = FALSE_;
997     if (isym == 1) {
998 /* Computing MAX */
999         i__1 = 1, i__2 = mr + nc;
1000         if ((real) (llb + uub) < (real) f2cmax(i__1,i__2) * .3f) {
1001             givens = TRUE_;
1002         }
1003     } else {
1004         if (llb << 1 < *m) {
1005             givens = TRUE_;
1006         }
1007     }
1008     if (*lda < *m && *lda >= minlda) {
1009         givens = TRUE_;
1010     }
1011
1012 /*     Set INFO if an error */
1013
1014     if (*m < 0) {
1015         *info = -1;
1016     } else if (*m != *n && isym != 1) {
1017         *info = -1;
1018     } else if (*n < 0) {
1019         *info = -2;
1020     } else if (idist == -1) {
1021         *info = -3;
1022     } else if (isym == -1) {
1023         *info = -5;
1024     } else if (abs(*mode) > 6) {
1025         *info = -7;
1026     } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) {
1027         *info = -8;
1028     } else if (*kl < 0) {
1029         *info = -10;
1030     } else if (*ku < 0 || isym != 1 && *kl != *ku) {
1031         *info = -11;
1032     } else if (ipack == -1 || isympk == 1 && isym == 1 || isympk == 2 && isym 
1033             == 1 && *kl > 0 || isympk == 3 && isym == 1 && *ku > 0 || isympk 
1034             != 0 && *m != *n) {
1035         *info = -12;
1036     } else if (*lda < f2cmax(1,minlda)) {
1037         *info = -14;
1038     }
1039
1040     if (*info != 0) {
1041         i__1 = -(*info);
1042         xerbla_("SLATMS", &i__1);
1043         return 0;
1044     }
1045
1046 /*     Initialize random number generator */
1047
1048     for (i__ = 1; i__ <= 4; ++i__) {
1049         iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
1050 /* L10: */
1051     }
1052
1053     if (iseed[4] % 2 != 1) {
1054         ++iseed[4];
1055     }
1056
1057 /*     2)      Set up D  if indicated. */
1058
1059 /*             Compute D according to COND and MODE */
1060
1061     slatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, &iinfo);
1062     if (iinfo != 0) {
1063         *info = 1;
1064         return 0;
1065     }
1066
1067 /*     Choose Top-Down if D is (apparently) increasing, */
1068 /*     Bottom-Up if D is (apparently) decreasing. */
1069
1070     if (abs(d__[1]) <= (r__1 = d__[mnmin], abs(r__1))) {
1071         topdwn = TRUE_;
1072     } else {
1073         topdwn = FALSE_;
1074     }
1075
1076     if (*mode != 0 && abs(*mode) != 6) {
1077
1078 /*        Scale by DMAX */
1079
1080         temp = abs(d__[1]);
1081         i__1 = mnmin;
1082         for (i__ = 2; i__ <= i__1; ++i__) {
1083 /* Computing MAX */
1084             r__2 = temp, r__3 = (r__1 = d__[i__], abs(r__1));
1085             temp = f2cmax(r__2,r__3);
1086 /* L20: */
1087         }
1088
1089         if (temp > 0.f) {
1090             alpha = *dmax__ / temp;
1091         } else {
1092             *info = 2;
1093             return 0;
1094         }
1095
1096         sscal_(&mnmin, &alpha, &d__[1], &c__1);
1097
1098     }
1099
1100 /*     3)      Generate Banded Matrix using Givens rotations. */
1101 /*             Also the special case of UUB=LLB=0 */
1102
1103 /*               Compute Addressing constants to cover all */
1104 /*               storage formats.  Whether GE, SY, GB, or SB, */
1105 /*               upper or lower triangle or both, */
1106 /*               the (i,j)-th element is in */
1107 /*               A( i - ISKEW*j + IOFFST, j ) */
1108
1109     if (ipack > 4) {
1110         ilda = *lda - 1;
1111         iskew = 1;
1112         if (ipack > 5) {
1113             ioffst = uub + 1;
1114         } else {
1115             ioffst = 1;
1116         }
1117     } else {
1118         ilda = *lda;
1119         iskew = 0;
1120         ioffst = 0;
1121     }
1122
1123 /*     IPACKG is the format that the matrix is generated in. If this is */
1124 /*     different from IPACK, then the matrix must be repacked at the */
1125 /*     end.  It also signals how to compute the norm, for scaling. */
1126
1127     ipackg = 0;
1128     slaset_("Full", lda, n, &c_b22, &c_b22, &a[a_offset], lda);
1129
1130 /*     Diagonal Matrix -- We are done, unless it */
1131 /*     is to be stored SP/PP/TP (PACK='R' or 'C') */
1132
1133     if (llb == 0 && uub == 0) {
1134         i__1 = ilda + 1;
1135         scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &i__1)
1136                 ;
1137         if (ipack <= 2 || ipack >= 5) {
1138             ipackg = ipack;
1139         }
1140
1141     } else if (givens) {
1142
1143 /*        Check whether to use Givens rotations, */
1144 /*        Householder transformations, or nothing. */
1145
1146         if (isym == 1) {
1147
1148 /*           Non-symmetric -- A = U D V */
1149
1150             if (ipack > 4) {
1151                 ipackg = ipack;
1152             } else {
1153                 ipackg = 0;
1154             }
1155
1156             i__1 = ilda + 1;
1157             scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &
1158                     i__1);
1159
1160             if (topdwn) {
1161                 jkl = 0;
1162                 i__1 = uub;
1163                 for (jku = 1; jku <= i__1; ++jku) {
1164
1165 /*                 Transform from bandwidth JKL, JKU-1 to JKL, JKU */
1166
1167 /*                 Last row actually rotated is M */
1168 /*                 Last column actually rotated is MIN( M+JKU, N ) */
1169
1170 /* Computing MIN */
1171                     i__3 = *m + jku;
1172                     i__2 = f2cmin(i__3,*n) + jkl - 1;
1173                     for (jr = 1; jr <= i__2; ++jr) {
1174                         extra = 0.f;
1175                         angle = slarnd_(&c__1, &iseed[1]) * 
1176                                 6.2831853071795864769252867663f;
1177                         c__ = cos(angle);
1178                         s = sin(angle);
1179 /* Computing MAX */
1180                         i__3 = 1, i__4 = jr - jkl;
1181                         icol = f2cmax(i__3,i__4);
1182                         if (jr < *m) {
1183 /* Computing MIN */
1184                             i__3 = *n, i__4 = jr + jku;
1185                             il = f2cmin(i__3,i__4) + 1 - icol;
1186                             L__1 = jr > jkl;
1187                             slarot_(&c_true, &L__1, &c_false, &il, &c__, &s, &
1188                                     a[jr - iskew * icol + ioffst + icol * 
1189                                     a_dim1], &ilda, &extra, &dummy);
1190                         }
1191
1192 /*                    Chase "EXTRA" back up */
1193
1194                         ir = jr;
1195                         ic = icol;
1196                         i__3 = -jkl - jku;
1197                         for (jch = jr - jkl; i__3 < 0 ? jch >= 1 : jch <= 1; 
1198                                 jch += i__3) {
1199                             if (ir < *m) {
1200                                 slartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst 
1201                                         + (ic + 1) * a_dim1], &extra, &c__, &
1202                                         s, &dummy);
1203                             }
1204 /* Computing MAX */
1205                             i__4 = 1, i__5 = jch - jku;
1206                             irow = f2cmax(i__4,i__5);
1207                             il = ir + 2 - irow;
1208                             temp = 0.f;
1209                             iltemp = jch > jku;
1210                             r__1 = -s;
1211                             slarot_(&c_false, &iltemp, &c_true, &il, &c__, &
1212                                     r__1, &a[irow - iskew * ic + ioffst + ic *
1213                                      a_dim1], &ilda, &temp, &extra);
1214                             if (iltemp) {
1215                                 slartg_(&a[irow + 1 - iskew * (ic + 1) + 
1216                                         ioffst + (ic + 1) * a_dim1], &temp, &
1217                                         c__, &s, &dummy);
1218 /* Computing MAX */
1219                                 i__4 = 1, i__5 = jch - jku - jkl;
1220                                 icol = f2cmax(i__4,i__5);
1221                                 il = ic + 2 - icol;
1222                                 extra = 0.f;
1223                                 L__1 = jch > jku + jkl;
1224                                 r__1 = -s;
1225                                 slarot_(&c_true, &L__1, &c_true, &il, &c__, &
1226                                         r__1, &a[irow - iskew * icol + ioffst 
1227                                         + icol * a_dim1], &ilda, &extra, &
1228                                         temp);
1229                                 ic = icol;
1230                                 ir = irow;
1231                             }
1232 /* L30: */
1233                         }
1234 /* L40: */
1235                     }
1236 /* L50: */
1237                 }
1238
1239                 jku = uub;
1240                 i__1 = llb;
1241                 for (jkl = 1; jkl <= i__1; ++jkl) {
1242
1243 /*                 Transform from bandwidth JKL-1, JKU to JKL, JKU */
1244
1245 /* Computing MIN */
1246                     i__3 = *n + jkl;
1247                     i__2 = f2cmin(i__3,*m) + jku - 1;
1248                     for (jc = 1; jc <= i__2; ++jc) {
1249                         extra = 0.f;
1250                         angle = slarnd_(&c__1, &iseed[1]) * 
1251                                 6.2831853071795864769252867663f;
1252                         c__ = cos(angle);
1253                         s = sin(angle);
1254 /* Computing MAX */
1255                         i__3 = 1, i__4 = jc - jku;
1256                         irow = f2cmax(i__3,i__4);
1257                         if (jc < *n) {
1258 /* Computing MIN */
1259                             i__3 = *m, i__4 = jc + jkl;
1260                             il = f2cmin(i__3,i__4) + 1 - irow;
1261                             L__1 = jc > jku;
1262                             slarot_(&c_false, &L__1, &c_false, &il, &c__, &s, 
1263                                     &a[irow - iskew * jc + ioffst + jc * 
1264                                     a_dim1], &ilda, &extra, &dummy);
1265                         }
1266
1267 /*                    Chase "EXTRA" back up */
1268
1269                         ic = jc;
1270                         ir = irow;
1271                         i__3 = -jkl - jku;
1272                         for (jch = jc - jku; i__3 < 0 ? jch >= 1 : jch <= 1; 
1273                                 jch += i__3) {
1274                             if (ic < *n) {
1275                                 slartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst 
1276                                         + (ic + 1) * a_dim1], &extra, &c__, &
1277                                         s, &dummy);
1278                             }
1279 /* Computing MAX */
1280                             i__4 = 1, i__5 = jch - jkl;
1281                             icol = f2cmax(i__4,i__5);
1282                             il = ic + 2 - icol;
1283                             temp = 0.f;
1284                             iltemp = jch > jkl;
1285                             r__1 = -s;
1286                             slarot_(&c_true, &iltemp, &c_true, &il, &c__, &
1287                                     r__1, &a[ir - iskew * icol + ioffst + 
1288                                     icol * a_dim1], &ilda, &temp, &extra);
1289                             if (iltemp) {
1290                                 slartg_(&a[ir + 1 - iskew * (icol + 1) + 
1291                                         ioffst + (icol + 1) * a_dim1], &temp, 
1292                                         &c__, &s, &dummy);
1293 /* Computing MAX */
1294                                 i__4 = 1, i__5 = jch - jkl - jku;
1295                                 irow = f2cmax(i__4,i__5);
1296                                 il = ir + 2 - irow;
1297                                 extra = 0.f;
1298                                 L__1 = jch > jkl + jku;
1299                                 r__1 = -s;
1300                                 slarot_(&c_false, &L__1, &c_true, &il, &c__, &
1301                                         r__1, &a[irow - iskew * icol + ioffst 
1302                                         + icol * a_dim1], &ilda, &extra, &
1303                                         temp);
1304                                 ic = icol;
1305                                 ir = irow;
1306                             }
1307 /* L60: */
1308                         }
1309 /* L70: */
1310                     }
1311 /* L80: */
1312                 }
1313
1314             } else {
1315
1316 /*              Bottom-Up -- Start at the bottom right. */
1317
1318                 jkl = 0;
1319                 i__1 = uub;
1320                 for (jku = 1; jku <= i__1; ++jku) {
1321
1322 /*                 Transform from bandwidth JKL, JKU-1 to JKL, JKU */
1323
1324 /*                 First row actually rotated is M */
1325 /*                 First column actually rotated is MIN( M+JKU, N ) */
1326
1327 /* Computing MIN */
1328                     i__2 = *m, i__3 = *n + jkl;
1329                     iendch = f2cmin(i__2,i__3) - 1;
1330 /* Computing MIN */
1331                     i__2 = *m + jku;
1332                     i__3 = 1 - jkl;
1333                     for (jc = f2cmin(i__2,*n) - 1; jc >= i__3; --jc) {
1334                         extra = 0.f;
1335                         angle = slarnd_(&c__1, &iseed[1]) * 
1336                                 6.2831853071795864769252867663f;
1337                         c__ = cos(angle);
1338                         s = sin(angle);
1339 /* Computing MAX */
1340                         i__2 = 1, i__4 = jc - jku + 1;
1341                         irow = f2cmax(i__2,i__4);
1342                         if (jc > 0) {
1343 /* Computing MIN */
1344                             i__2 = *m, i__4 = jc + jkl + 1;
1345                             il = f2cmin(i__2,i__4) + 1 - irow;
1346                             L__1 = jc + jkl < *m;
1347                             slarot_(&c_false, &c_false, &L__1, &il, &c__, &s, 
1348                                     &a[irow - iskew * jc + ioffst + jc * 
1349                                     a_dim1], &ilda, &dummy, &extra);
1350                         }
1351
1352 /*                    Chase "EXTRA" back down */
1353
1354                         ic = jc;
1355                         i__2 = iendch;
1356                         i__4 = jkl + jku;
1357                         for (jch = jc + jkl; i__4 < 0 ? jch >= i__2 : jch <= 
1358                                 i__2; jch += i__4) {
1359                             ilextr = ic > 0;
1360                             if (ilextr) {
1361                                 slartg_(&a[jch - iskew * ic + ioffst + ic * 
1362                                         a_dim1], &extra, &c__, &s, &dummy);
1363                             }
1364                             ic = f2cmax(1,ic);
1365 /* Computing MIN */
1366                             i__5 = *n - 1, i__6 = jch + jku;
1367                             icol = f2cmin(i__5,i__6);
1368                             iltemp = jch + jku < *n;
1369                             temp = 0.f;
1370                             i__5 = icol + 2 - ic;
1371                             slarot_(&c_true, &ilextr, &iltemp, &i__5, &c__, &
1372                                     s, &a[jch - iskew * ic + ioffst + ic * 
1373                                     a_dim1], &ilda, &extra, &temp);
1374                             if (iltemp) {
1375                                 slartg_(&a[jch - iskew * icol + ioffst + icol 
1376                                         * a_dim1], &temp, &c__, &s, &dummy);
1377 /* Computing MIN */
1378                                 i__5 = iendch, i__6 = jch + jkl + jku;
1379                                 il = f2cmin(i__5,i__6) + 2 - jch;
1380                                 extra = 0.f;
1381                                 L__1 = jch + jkl + jku <= iendch;
1382                                 slarot_(&c_false, &c_true, &L__1, &il, &c__, &
1383                                         s, &a[jch - iskew * icol + ioffst + 
1384                                         icol * a_dim1], &ilda, &temp, &extra);
1385                                 ic = icol;
1386                             }
1387 /* L90: */
1388                         }
1389 /* L100: */
1390                     }
1391 /* L110: */
1392                 }
1393
1394                 jku = uub;
1395                 i__1 = llb;
1396                 for (jkl = 1; jkl <= i__1; ++jkl) {
1397
1398 /*                 Transform from bandwidth JKL-1, JKU to JKL, JKU */
1399
1400 /*                 First row actually rotated is MIN( N+JKL, M ) */
1401 /*                 First column actually rotated is N */
1402
1403 /* Computing MIN */
1404                     i__3 = *n, i__4 = *m + jku;
1405                     iendch = f2cmin(i__3,i__4) - 1;
1406 /* Computing MIN */
1407                     i__3 = *n + jkl;
1408                     i__4 = 1 - jku;
1409                     for (jr = f2cmin(i__3,*m) - 1; jr >= i__4; --jr) {
1410                         extra = 0.f;
1411                         angle = slarnd_(&c__1, &iseed[1]) * 
1412                                 6.2831853071795864769252867663f;
1413                         c__ = cos(angle);
1414                         s = sin(angle);
1415 /* Computing MAX */
1416                         i__3 = 1, i__2 = jr - jkl + 1;
1417                         icol = f2cmax(i__3,i__2);
1418                         if (jr > 0) {
1419 /* Computing MIN */
1420                             i__3 = *n, i__2 = jr + jku + 1;
1421                             il = f2cmin(i__3,i__2) + 1 - icol;
1422                             L__1 = jr + jku < *n;
1423                             slarot_(&c_true, &c_false, &L__1, &il, &c__, &s, &
1424                                     a[jr - iskew * icol + ioffst + icol * 
1425                                     a_dim1], &ilda, &dummy, &extra);
1426                         }
1427
1428 /*                    Chase "EXTRA" back down */
1429
1430                         ir = jr;
1431                         i__3 = iendch;
1432                         i__2 = jkl + jku;
1433                         for (jch = jr + jku; i__2 < 0 ? jch >= i__3 : jch <= 
1434                                 i__3; jch += i__2) {
1435                             ilextr = ir > 0;
1436                             if (ilextr) {
1437                                 slartg_(&a[ir - iskew * jch + ioffst + jch * 
1438                                         a_dim1], &extra, &c__, &s, &dummy);
1439                             }
1440                             ir = f2cmax(1,ir);
1441 /* Computing MIN */
1442                             i__5 = *m - 1, i__6 = jch + jkl;
1443                             irow = f2cmin(i__5,i__6);
1444                             iltemp = jch + jkl < *m;
1445                             temp = 0.f;
1446                             i__5 = irow + 2 - ir;
1447                             slarot_(&c_false, &ilextr, &iltemp, &i__5, &c__, &
1448                                     s, &a[ir - iskew * jch + ioffst + jch * 
1449                                     a_dim1], &ilda, &extra, &temp);
1450                             if (iltemp) {
1451                                 slartg_(&a[irow - iskew * jch + ioffst + jch *
1452                                          a_dim1], &temp, &c__, &s, &dummy);
1453 /* Computing MIN */
1454                                 i__5 = iendch, i__6 = jch + jkl + jku;
1455                                 il = f2cmin(i__5,i__6) + 2 - jch;
1456                                 extra = 0.f;
1457                                 L__1 = jch + jkl + jku <= iendch;
1458                                 slarot_(&c_true, &c_true, &L__1, &il, &c__, &
1459                                         s, &a[irow - iskew * jch + ioffst + 
1460                                         jch * a_dim1], &ilda, &temp, &extra);
1461                                 ir = irow;
1462                             }
1463 /* L120: */
1464                         }
1465 /* L130: */
1466                     }
1467 /* L140: */
1468                 }
1469             }
1470
1471         } else {
1472
1473 /*           Symmetric -- A = U D U' */
1474
1475             ipackg = ipack;
1476             ioffg = ioffst;
1477
1478             if (topdwn) {
1479
1480 /*              Top-Down -- Generate Upper triangle only */
1481
1482                 if (ipack >= 5) {
1483                     ipackg = 6;
1484                     ioffg = uub + 1;
1485                 } else {
1486                     ipackg = 1;
1487                 }
1488                 i__1 = ilda + 1;
1489                 scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
1490                          &i__1);
1491
1492                 i__1 = uub;
1493                 for (k = 1; k <= i__1; ++k) {
1494                     i__4 = *n - 1;
1495                     for (jc = 1; jc <= i__4; ++jc) {
1496 /* Computing MAX */
1497                         i__2 = 1, i__3 = jc - k;
1498                         irow = f2cmax(i__2,i__3);
1499 /* Computing MIN */
1500                         i__2 = jc + 1, i__3 = k + 2;
1501                         il = f2cmin(i__2,i__3);
1502                         extra = 0.f;
1503                         temp = a[jc - iskew * (jc + 1) + ioffg + (jc + 1) * 
1504                                 a_dim1];
1505                         angle = slarnd_(&c__1, &iseed[1]) * 
1506                                 6.2831853071795864769252867663f;
1507                         c__ = cos(angle);
1508                         s = sin(angle);
1509                         L__1 = jc > k;
1510                         slarot_(&c_false, &L__1, &c_true, &il, &c__, &s, &a[
1511                                 irow - iskew * jc + ioffg + jc * a_dim1], &
1512                                 ilda, &extra, &temp);
1513 /* Computing MIN */
1514                         i__3 = k, i__5 = *n - jc;
1515                         i__2 = f2cmin(i__3,i__5) + 1;
1516                         slarot_(&c_true, &c_true, &c_false, &i__2, &c__, &s, &
1517                                 a[(1 - iskew) * jc + ioffg + jc * a_dim1], &
1518                                 ilda, &temp, &dummy);
1519
1520 /*                    Chase EXTRA back up the matrix */
1521
1522                         icol = jc;
1523                         i__2 = -k;
1524                         for (jch = jc - k; i__2 < 0 ? jch >= 1 : jch <= 1; 
1525                                 jch += i__2) {
1526                             slartg_(&a[jch + 1 - iskew * (icol + 1) + ioffg + 
1527                                     (icol + 1) * a_dim1], &extra, &c__, &s, &
1528                                     dummy);
1529                             temp = a[jch - iskew * (jch + 1) + ioffg + (jch + 
1530                                     1) * a_dim1];
1531                             i__3 = k + 2;
1532                             r__1 = -s;
1533                             slarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
1534                                     r__1, &a[(1 - iskew) * jch + ioffg + jch *
1535                                      a_dim1], &ilda, &temp, &extra);
1536 /* Computing MAX */
1537                             i__3 = 1, i__5 = jch - k;
1538                             irow = f2cmax(i__3,i__5);
1539 /* Computing MIN */
1540                             i__3 = jch + 1, i__5 = k + 2;
1541                             il = f2cmin(i__3,i__5);
1542                             extra = 0.f;
1543                             L__1 = jch > k;
1544                             r__1 = -s;
1545                             slarot_(&c_false, &L__1, &c_true, &il, &c__, &
1546                                     r__1, &a[irow - iskew * jch + ioffg + jch 
1547                                     * a_dim1], &ilda, &extra, &temp);
1548                             icol = jch;
1549 /* L150: */
1550                         }
1551 /* L160: */
1552                     }
1553 /* L170: */
1554                 }
1555
1556 /*              If we need lower triangle, copy from upper. Note that */
1557 /*              the order of copying is chosen to work for 'q' -> 'b' */
1558
1559                 if (ipack != ipackg && ipack != 3) {
1560                     i__1 = *n;
1561                     for (jc = 1; jc <= i__1; ++jc) {
1562                         irow = ioffst - iskew * jc;
1563 /* Computing MIN */
1564                         i__2 = *n, i__3 = jc + uub;
1565                         i__4 = f2cmin(i__2,i__3);
1566                         for (jr = jc; jr <= i__4; ++jr) {
1567                             a[jr + irow + jc * a_dim1] = a[jc - iskew * jr + 
1568                                     ioffg + jr * a_dim1];
1569 /* L180: */
1570                         }
1571 /* L190: */
1572                     }
1573                     if (ipack == 5) {
1574                         i__1 = *n;
1575                         for (jc = *n - uub + 1; jc <= i__1; ++jc) {
1576                             i__4 = uub + 1;
1577                             for (jr = *n + 2 - jc; jr <= i__4; ++jr) {
1578                                 a[jr + jc * a_dim1] = 0.f;
1579 /* L200: */
1580                             }
1581 /* L210: */
1582                         }
1583                     }
1584                     if (ipackg == 6) {
1585                         ipackg = ipack;
1586                     } else {
1587                         ipackg = 0;
1588                     }
1589                 }
1590             } else {
1591
1592 /*              Bottom-Up -- Generate Lower triangle only */
1593
1594                 if (ipack >= 5) {
1595                     ipackg = 5;
1596                     if (ipack == 6) {
1597                         ioffg = 1;
1598                     }
1599                 } else {
1600                     ipackg = 2;
1601                 }
1602                 i__1 = ilda + 1;
1603                 scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
1604                          &i__1);
1605
1606                 i__1 = uub;
1607                 for (k = 1; k <= i__1; ++k) {
1608                     for (jc = *n - 1; jc >= 1; --jc) {
1609 /* Computing MIN */
1610                         i__4 = *n + 1 - jc, i__2 = k + 2;
1611                         il = f2cmin(i__4,i__2);
1612                         extra = 0.f;
1613                         temp = a[(1 - iskew) * jc + 1 + ioffg + jc * a_dim1];
1614                         angle = slarnd_(&c__1, &iseed[1]) * 
1615                                 6.2831853071795864769252867663f;
1616                         c__ = cos(angle);
1617                         s = -sin(angle);
1618                         L__1 = *n - jc > k;
1619                         slarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &a[(
1620                                 1 - iskew) * jc + ioffg + jc * a_dim1], &ilda,
1621                                  &temp, &extra);
1622 /* Computing MAX */
1623                         i__4 = 1, i__2 = jc - k + 1;
1624                         icol = f2cmax(i__4,i__2);
1625                         i__4 = jc + 2 - icol;
1626                         slarot_(&c_true, &c_false, &c_true, &i__4, &c__, &s, &
1627                                 a[jc - iskew * icol + ioffg + icol * a_dim1], 
1628                                 &ilda, &dummy, &temp);
1629
1630 /*                    Chase EXTRA back down the matrix */
1631
1632                         icol = jc;
1633                         i__4 = *n - 1;
1634                         i__2 = k;
1635                         for (jch = jc + k; i__2 < 0 ? jch >= i__4 : jch <= 
1636                                 i__4; jch += i__2) {
1637                             slartg_(&a[jch - iskew * icol + ioffg + icol * 
1638                                     a_dim1], &extra, &c__, &s, &dummy);
1639                             temp = a[(1 - iskew) * jch + 1 + ioffg + jch * 
1640                                     a_dim1];
1641                             i__3 = k + 2;
1642                             slarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
1643                                     s, &a[jch - iskew * icol + ioffg + icol * 
1644                                     a_dim1], &ilda, &extra, &temp);
1645 /* Computing MIN */
1646                             i__3 = *n + 1 - jch, i__5 = k + 2;
1647                             il = f2cmin(i__3,i__5);
1648                             extra = 0.f;
1649                             L__1 = *n - jch > k;
1650                             slarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &
1651                                     a[(1 - iskew) * jch + ioffg + jch * 
1652                                     a_dim1], &ilda, &temp, &extra);
1653                             icol = jch;
1654 /* L220: */
1655                         }
1656 /* L230: */
1657                     }
1658 /* L240: */
1659                 }
1660
1661 /*              If we need upper triangle, copy from lower. Note that */
1662 /*              the order of copying is chosen to work for 'b' -> 'q' */
1663
1664                 if (ipack != ipackg && ipack != 4) {
1665                     for (jc = *n; jc >= 1; --jc) {
1666                         irow = ioffst - iskew * jc;
1667 /* Computing MAX */
1668                         i__2 = 1, i__4 = jc - uub;
1669                         i__1 = f2cmax(i__2,i__4);
1670                         for (jr = jc; jr >= i__1; --jr) {
1671                             a[jr + irow + jc * a_dim1] = a[jc - iskew * jr + 
1672                                     ioffg + jr * a_dim1];
1673 /* L250: */
1674                         }
1675 /* L260: */
1676                     }
1677                     if (ipack == 6) {
1678                         i__1 = uub;
1679                         for (jc = 1; jc <= i__1; ++jc) {
1680                             i__2 = uub + 1 - jc;
1681                             for (jr = 1; jr <= i__2; ++jr) {
1682                                 a[jr + jc * a_dim1] = 0.f;
1683 /* L270: */
1684                             }
1685 /* L280: */
1686                         }
1687                     }
1688                     if (ipackg == 5) {
1689                         ipackg = ipack;
1690                     } else {
1691                         ipackg = 0;
1692                     }
1693                 }
1694             }
1695         }
1696
1697     } else {
1698
1699 /*        4)      Generate Banded Matrix by first */
1700 /*                Rotating by random Unitary matrices, */
1701 /*                then reducing the bandwidth using Householder */
1702 /*                transformations. */
1703
1704 /*                Note: we should get here only if LDA .ge. N */
1705
1706         if (isym == 1) {
1707
1708 /*           Non-symmetric -- A = U D V */
1709
1710             slagge_(&mr, &nc, &llb, &uub, &d__[1], &a[a_offset], lda, &iseed[
1711                     1], &work[1], &iinfo);
1712         } else {
1713
1714 /*           Symmetric -- A = U D U' */
1715
1716             slagsy_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[1], 
1717                     &iinfo);
1718
1719         }
1720         if (iinfo != 0) {
1721             *info = 3;
1722             return 0;
1723         }
1724     }
1725
1726 /*     5)      Pack the matrix */
1727
1728     if (ipack != ipackg) {
1729         if (ipack == 1) {
1730
1731 /*           'U' -- Upper triangular, not packed */
1732
1733             i__1 = *m;
1734             for (j = 1; j <= i__1; ++j) {
1735                 i__2 = *m;
1736                 for (i__ = j + 1; i__ <= i__2; ++i__) {
1737                     a[i__ + j * a_dim1] = 0.f;
1738 /* L290: */
1739                 }
1740 /* L300: */
1741             }
1742
1743         } else if (ipack == 2) {
1744
1745 /*           'L' -- Lower triangular, not packed */
1746
1747             i__1 = *m;
1748             for (j = 2; j <= i__1; ++j) {
1749                 i__2 = j - 1;
1750                 for (i__ = 1; i__ <= i__2; ++i__) {
1751                     a[i__ + j * a_dim1] = 0.f;
1752 /* L310: */
1753                 }
1754 /* L320: */
1755             }
1756
1757         } else if (ipack == 3) {
1758
1759 /*           'C' -- Upper triangle packed Columnwise. */
1760
1761             icol = 1;
1762             irow = 0;
1763             i__1 = *m;
1764             for (j = 1; j <= i__1; ++j) {
1765                 i__2 = j;
1766                 for (i__ = 1; i__ <= i__2; ++i__) {
1767                     ++irow;
1768                     if (irow > *lda) {
1769                         irow = 1;
1770                         ++icol;
1771                     }
1772                     a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
1773 /* L330: */
1774                 }
1775 /* L340: */
1776             }
1777
1778         } else if (ipack == 4) {
1779
1780 /*           'R' -- Lower triangle packed Columnwise. */
1781
1782             icol = 1;
1783             irow = 0;
1784             i__1 = *m;
1785             for (j = 1; j <= i__1; ++j) {
1786                 i__2 = *m;
1787                 for (i__ = j; i__ <= i__2; ++i__) {
1788                     ++irow;
1789                     if (irow > *lda) {
1790                         irow = 1;
1791                         ++icol;
1792                     }
1793                     a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
1794 /* L350: */
1795                 }
1796 /* L360: */
1797             }
1798
1799         } else if (ipack >= 5) {
1800
1801 /*           'B' -- The lower triangle is packed as a band matrix. */
1802 /*           'Q' -- The upper triangle is packed as a band matrix. */
1803 /*           'Z' -- The whole matrix is packed as a band matrix. */
1804
1805             if (ipack == 5) {
1806                 uub = 0;
1807             }
1808             if (ipack == 6) {
1809                 llb = 0;
1810             }
1811
1812             i__1 = uub;
1813             for (j = 1; j <= i__1; ++j) {
1814 /* Computing MIN */
1815                 i__2 = j + llb;
1816                 for (i__ = f2cmin(i__2,*m); i__ >= 1; --i__) {
1817                     a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
1818 /* L370: */
1819                 }
1820 /* L380: */
1821             }
1822
1823             i__1 = *n;
1824             for (j = uub + 2; j <= i__1; ++j) {
1825 /* Computing MIN */
1826                 i__4 = j + llb;
1827                 i__2 = f2cmin(i__4,*m);
1828                 for (i__ = j - uub; i__ <= i__2; ++i__) {
1829                     a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
1830 /* L390: */
1831                 }
1832 /* L400: */
1833             }
1834         }
1835
1836 /*        If packed, zero out extraneous elements. */
1837
1838 /*        Symmetric/Triangular Packed -- */
1839 /*        zero out everything after A(IROW,ICOL) */
1840
1841         if (ipack == 3 || ipack == 4) {
1842             i__1 = *m;
1843             for (jc = icol; jc <= i__1; ++jc) {
1844                 i__2 = *lda;
1845                 for (jr = irow + 1; jr <= i__2; ++jr) {
1846                     a[jr + jc * a_dim1] = 0.f;
1847 /* L410: */
1848                 }
1849                 irow = 0;
1850 /* L420: */
1851             }
1852
1853         } else if (ipack >= 5) {
1854
1855 /*           Packed Band -- */
1856 /*              1st row is now in A( UUB+2-j, j), zero above it */
1857 /*              m-th row is now in A( M+UUB-j,j), zero below it */
1858 /*              last non-zero diagonal is now in A( UUB+LLB+1,j ), */
1859 /*                 zero below it, too. */
1860
1861             ir1 = uub + llb + 2;
1862             ir2 = uub + *m + 2;
1863             i__1 = *n;
1864             for (jc = 1; jc <= i__1; ++jc) {
1865                 i__2 = uub + 1 - jc;
1866                 for (jr = 1; jr <= i__2; ++jr) {
1867                     a[jr + jc * a_dim1] = 0.f;
1868 /* L430: */
1869                 }
1870 /* Computing MAX */
1871 /* Computing MIN */
1872                 i__3 = ir1, i__5 = ir2 - jc;
1873                 i__2 = 1, i__4 = f2cmin(i__3,i__5);
1874                 i__6 = *lda;
1875                 for (jr = f2cmax(i__2,i__4); jr <= i__6; ++jr) {
1876                     a[jr + jc * a_dim1] = 0.f;
1877 /* L440: */
1878                 }
1879 /* L450: */
1880             }
1881         }
1882     }
1883
1884     return 0;
1885
1886 /*     End of SLATMS */
1887
1888 } /* slatms_ */
1889