C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / TESTING / MATGEN / dlatmt.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 doublereal c_b22 = 0.;
517 static logical c_true = TRUE_;
518 static logical c_false = FALSE_;
519
520 /* > \brief \b DLATMT */
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 DLATMT( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
531 /*                          RANK, KL, KU, PACK, A, LDA, WORK, INFO ) */
532
533 /*       DOUBLE PRECISION   COND, DMAX */
534 /*       INTEGER            INFO, KL, KU, LDA, M, MODE, N, RANK */
535 /*       CHARACTER          DIST, PACK, SYM */
536 /*       DOUBLE PRECISION   A( LDA, * ), D( * ), WORK( * ) */
537 /*       INTEGER            ISEED( 4 ) */
538
539
540 /* > \par Purpose: */
541 /*  ============= */
542 /* > */
543 /* > \verbatim */
544 /* > */
545 /* >    DLATMT generates random matrices with specified singular values */
546 /* >    (or symmetric/hermitian with specified eigenvalues) */
547 /* >    for testing LAPACK programs. */
548 /* > */
549 /* >    DLATMT 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 DLATMT */
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 DOUBLE PRECISION 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 /* > */
674 /* >           MODE = 1 sets D(1)=1 and D(2:RANK)=1.0/COND */
675 /* >           MODE = 2 sets D(1:RANK-1)=1 and D(RANK)=1.0/COND */
676 /* >           MODE = 3 sets D(I)=COND**(-(I-1)/(RANK-1)) */
677 /* > */
678 /* >           MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
679 /* >           MODE = 5 sets D to random numbers in the range */
680 /* >                    ( 1/COND , 1 ) such that their logarithms */
681 /* >                    are uniformly distributed. */
682 /* >           MODE = 6 set D to random numbers from same distribution */
683 /* >                    as the rest of the matrix. */
684 /* >           MODE < 0 has the same meaning as ABS(MODE), except that */
685 /* >              the order of the elements of D is reversed. */
686 /* >           Thus if MODE is positive, D has entries ranging from */
687 /* >              1 to 1/COND, if negative, from 1/COND to 1, */
688 /* >           If SYM='S' or 'H', and MODE is neither 0, 6, nor -6, then */
689 /* >              the elements of D will also be multiplied by a random */
690 /* >              sign (i.e., +1 or -1.) */
691 /* >           Not modified. */
692 /* > \endverbatim */
693 /* > */
694 /* > \param[in] COND */
695 /* > \verbatim */
696 /* >          COND is DOUBLE PRECISION */
697 /* >           On entry, this is used as described under MODE above. */
698 /* >           If used, it must be >= 1. Not modified. */
699 /* > \endverbatim */
700 /* > */
701 /* > \param[in] DMAX */
702 /* > \verbatim */
703 /* >          DMAX is DOUBLE PRECISION */
704 /* >           If MODE is neither -6, 0 nor 6, the contents of D, as */
705 /* >           computed according to MODE and COND, will be scaled by */
706 /* >           DMAX / f2cmax(abs(D(i))); thus, the maximum absolute eigen- or */
707 /* >           singular value (which is to say the norm) will be abs(DMAX). */
708 /* >           Note that DMAX need not be positive: if DMAX is negative */
709 /* >           (or zero), D will be scaled by a negative number (or zero). */
710 /* >           Not modified. */
711 /* > \endverbatim */
712 /* > */
713 /* > \param[in] RANK */
714 /* > \verbatim */
715 /* >          RANK is INTEGER */
716 /* >           The rank of matrix to be generated for modes 1,2,3 only. */
717 /* >           D( RANK+1:N ) = 0. */
718 /* >           Not modified. */
719 /* > \endverbatim */
720 /* > */
721 /* > \param[in] KL */
722 /* > \verbatim */
723 /* >          KL is INTEGER */
724 /* >           This specifies the lower bandwidth of the  matrix. For */
725 /* >           example, KL=0 implies upper triangular, KL=1 implies upper */
726 /* >           Hessenberg, and KL being at least M-1 means that the matrix */
727 /* >           has full lower bandwidth.  KL must equal KU if the matrix */
728 /* >           is symmetric. */
729 /* >           Not modified. */
730 /* > \endverbatim */
731 /* > */
732 /* > \param[in] KU */
733 /* > \verbatim */
734 /* >          KU is INTEGER */
735 /* >           This specifies the upper bandwidth of the  matrix. For */
736 /* >           example, KU=0 implies lower triangular, KU=1 implies lower */
737 /* >           Hessenberg, and KU being at least N-1 means that the matrix */
738 /* >           has full upper bandwidth.  KL must equal KU if the matrix */
739 /* >           is symmetric. */
740 /* >           Not modified. */
741 /* > \endverbatim */
742 /* > */
743 /* > \param[in] PACK */
744 /* > \verbatim */
745 /* >          PACK is CHARACTER*1 */
746 /* >           This specifies packing of matrix as follows: */
747 /* >           'N' => no packing */
748 /* >           'U' => zero out all subdiagonal entries (if symmetric) */
749 /* >           'L' => zero out all superdiagonal entries (if symmetric) */
750 /* >           'C' => store the upper triangle columnwise */
751 /* >                  (only if the matrix is symmetric or upper triangular) */
752 /* >           'R' => store the lower triangle columnwise */
753 /* >                  (only if the matrix is symmetric or lower triangular) */
754 /* >           'B' => store the lower triangle in band storage scheme */
755 /* >                  (only if matrix symmetric or lower triangular) */
756 /* >           'Q' => store the upper triangle in band storage scheme */
757 /* >                  (only if matrix symmetric or upper triangular) */
758 /* >           'Z' => store the entire matrix in band storage scheme */
759 /* >                      (pivoting can be provided for by using this */
760 /* >                      option to store A in the trailing rows of */
761 /* >                      the allocated storage) */
762 /* > */
763 /* >           Using these options, the various LAPACK packed and banded */
764 /* >           storage schemes can be obtained: */
765 /* >           GB               - use 'Z' */
766 /* >           PB, SB or TB     - use 'B' or 'Q' */
767 /* >           PP, SP or TP     - use 'C' or 'R' */
768 /* > */
769 /* >           If two calls to DLATMT differ only in the PACK parameter, */
770 /* >           they will generate mathematically equivalent matrices. */
771 /* >           Not modified. */
772 /* > \endverbatim */
773 /* > */
774 /* > \param[in,out] A */
775 /* > \verbatim */
776 /* >          A is DOUBLE PRECISION array, dimension ( LDA, N ) */
777 /* >           On exit A is the desired test matrix.  A is first generated */
778 /* >           in full (unpacked) form, and then packed, if so specified */
779 /* >           by PACK.  Thus, the first M elements of the first N */
780 /* >           columns will always be modified.  If PACK specifies a */
781 /* >           packed or banded storage scheme, all LDA elements of the */
782 /* >           first N columns will be modified; the elements of the */
783 /* >           array which do not correspond to elements of the generated */
784 /* >           matrix are set to zero. */
785 /* >           Modified. */
786 /* > \endverbatim */
787 /* > */
788 /* > \param[in] LDA */
789 /* > \verbatim */
790 /* >          LDA is INTEGER */
791 /* >           LDA specifies the first dimension of A as declared in the */
792 /* >           calling program.  If PACK='N', 'U', 'L', 'C', or 'R', then */
793 /* >           LDA must be at least M.  If PACK='B' or 'Q', then LDA must */
794 /* >           be at least MIN( KL, M-1) (which is equal to MIN(KU,N-1)). */
795 /* >           If PACK='Z', LDA must be large enough to hold the packed */
796 /* >           array: MIN( KU, N-1) + MIN( KL, M-1) + 1. */
797 /* >           Not modified. */
798 /* > \endverbatim */
799 /* > */
800 /* > \param[out] WORK */
801 /* > \verbatim */
802 /* >          WORK is DOUBLE PRECISION array, dimension ( 3*MAX( N , M ) ) */
803 /* >           Workspace. */
804 /* >           Modified. */
805 /* > \endverbatim */
806 /* > */
807 /* > \param[out] INFO */
808 /* > \verbatim */
809 /* >          INFO is INTEGER */
810 /* >           Error code.  On exit, INFO will be set to one of the */
811 /* >           following values: */
812 /* >             0 => normal return */
813 /* >            -1 => M negative or unequal to N and SYM='S', 'H', or 'P' */
814 /* >            -2 => N negative */
815 /* >            -3 => DIST illegal string */
816 /* >            -5 => SYM illegal string */
817 /* >            -7 => MODE not in range -6 to 6 */
818 /* >            -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
819 /* >           -10 => KL negative */
820 /* >           -11 => KU negative, or SYM='S' or 'H' and KU not equal to KL */
821 /* >           -12 => PACK illegal string, or PACK='U' or 'L', and SYM='N'; */
822 /* >                  or PACK='C' or 'Q' and SYM='N' and KL is not zero; */
823 /* >                  or PACK='R' or 'B' and SYM='N' and KU is not zero; */
824 /* >                  or PACK='U', 'L', 'C', 'R', 'B', or 'Q', and M is not */
825 /* >                  N. */
826 /* >           -14 => LDA is less than M, or PACK='Z' and LDA is less than */
827 /* >                  MIN(KU,N-1) + MIN(KL,M-1) + 1. */
828 /* >            1  => Error return from DLATM7 */
829 /* >            2  => Cannot scale to DMAX (f2cmax. sing. value is 0) */
830 /* >            3  => Error return from DLAGGE or DLAGSY */
831 /* > \endverbatim */
832
833 /*  Authors: */
834 /*  ======== */
835
836 /* > \author Univ. of Tennessee */
837 /* > \author Univ. of California Berkeley */
838 /* > \author Univ. of Colorado Denver */
839 /* > \author NAG Ltd. */
840
841 /* > \date December 2016 */
842
843 /* > \ingroup double_matgen */
844
845 /*  ===================================================================== */
846 /* Subroutine */ int dlatmt_(integer *m, integer *n, char *dist, integer *
847         iseed, char *sym, doublereal *d__, integer *mode, doublereal *cond, 
848         doublereal *dmax__, integer *rank, integer *kl, integer *ku, char *
849         pack, doublereal *a, integer *lda, doublereal *work, integer *info)
850 {
851     /* System generated locals */
852     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
853     doublereal d__1, d__2, d__3;
854     logical L__1;
855
856     /* Local variables */
857     integer ilda, icol;
858     doublereal temp;
859     integer irow, isym;
860     doublereal c__;
861     integer i__, j, k;
862     doublereal s, alpha, angle;
863     integer ipack;
864     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
865             integer *);
866     integer ioffg;
867     extern logical lsame_(char *, char *);
868     integer iinfo, idist, mnmin;
869     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
870             doublereal *, integer *);
871     integer iskew;
872     doublereal extra, dummy;
873     extern /* Subroutine */ int dlatm7_(integer *, doublereal *, integer *, 
874             integer *, integer *, doublereal *, integer *, integer *, integer 
875             *);
876     integer ic, jc, nc;
877     extern /* Subroutine */ int dlagge_(integer *, integer *, integer *, 
878             integer *, doublereal *, doublereal *, integer *, integer *, 
879             doublereal *, integer *);
880     integer il, iendch, ir, jr, ipackg, mr, minlda;
881     extern doublereal dlarnd_(integer *, integer *);
882     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
883             doublereal *, doublereal *, doublereal *, integer *), 
884             dlartg_(doublereal *, doublereal *, doublereal *, doublereal *, 
885             doublereal *), xerbla_(char *, integer *), dlagsy_(
886             integer *, integer *, doublereal *, doublereal *, integer *, 
887             integer *, doublereal *, integer *), dlarot_(logical *, logical *,
888              logical *, integer *, doublereal *, doublereal *, doublereal *, 
889             integer *, doublereal *, doublereal *);
890     integer ioffst, irsign;
891     logical givens, iltemp, ilextr, topdwn;
892     integer ir1, ir2, isympk, jch, llb, jkl, jku, uub;
893
894
895 /*  -- LAPACK computational routine (version 3.7.0) -- */
896 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
897 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
898 /*     December 2016 */
899
900
901 /*  ===================================================================== */
902
903
904 /*     1)      Decode and Test the input parameters. */
905 /*             Initialize flags & seed. */
906
907     /* Parameter adjustments */
908     --iseed;
909     --d__;
910     a_dim1 = *lda;
911     a_offset = 1 + a_dim1 * 1;
912     a -= a_offset;
913     --work;
914
915     /* Function Body */
916     *info = 0;
917
918 /*     Quick return if possible */
919
920     if (*m == 0 || *n == 0) {
921         return 0;
922     }
923
924 /*     Decode DIST */
925
926     if (lsame_(dist, "U")) {
927         idist = 1;
928     } else if (lsame_(dist, "S")) {
929         idist = 2;
930     } else if (lsame_(dist, "N")) {
931         idist = 3;
932     } else {
933         idist = -1;
934     }
935
936 /*     Decode SYM */
937
938     if (lsame_(sym, "N")) {
939         isym = 1;
940         irsign = 0;
941     } else if (lsame_(sym, "P")) {
942         isym = 2;
943         irsign = 0;
944     } else if (lsame_(sym, "S")) {
945         isym = 2;
946         irsign = 1;
947     } else if (lsame_(sym, "H")) {
948         isym = 2;
949         irsign = 1;
950     } else {
951         isym = -1;
952     }
953
954 /*     Decode PACK */
955
956     isympk = 0;
957     if (lsame_(pack, "N")) {
958         ipack = 0;
959     } else if (lsame_(pack, "U")) {
960         ipack = 1;
961         isympk = 1;
962     } else if (lsame_(pack, "L")) {
963         ipack = 2;
964         isympk = 1;
965     } else if (lsame_(pack, "C")) {
966         ipack = 3;
967         isympk = 2;
968     } else if (lsame_(pack, "R")) {
969         ipack = 4;
970         isympk = 3;
971     } else if (lsame_(pack, "B")) {
972         ipack = 5;
973         isympk = 3;
974     } else if (lsame_(pack, "Q")) {
975         ipack = 6;
976         isympk = 2;
977     } else if (lsame_(pack, "Z")) {
978         ipack = 7;
979     } else {
980         ipack = -1;
981     }
982
983 /*     Set certain internal parameters */
984
985     mnmin = f2cmin(*m,*n);
986 /* Computing MIN */
987     i__1 = *kl, i__2 = *m - 1;
988     llb = f2cmin(i__1,i__2);
989 /* Computing MIN */
990     i__1 = *ku, i__2 = *n - 1;
991     uub = f2cmin(i__1,i__2);
992 /* Computing MIN */
993     i__1 = *m, i__2 = *n + llb;
994     mr = f2cmin(i__1,i__2);
995 /* Computing MIN */
996     i__1 = *n, i__2 = *m + uub;
997     nc = f2cmin(i__1,i__2);
998
999     if (ipack == 5 || ipack == 6) {
1000         minlda = uub + 1;
1001     } else if (ipack == 7) {
1002         minlda = llb + uub + 1;
1003     } else {
1004         minlda = *m;
1005     }
1006
1007 /*     Use Givens rotation method if bandwidth small enough, */
1008 /*     or if LDA is too small to store the matrix unpacked. */
1009
1010     givens = FALSE_;
1011     if (isym == 1) {
1012 /* Computing MAX */
1013         i__1 = 1, i__2 = mr + nc;
1014         if ((doublereal) (llb + uub) < (doublereal) f2cmax(i__1,i__2) * .3) {
1015             givens = TRUE_;
1016         }
1017     } else {
1018         if (llb << 1 < *m) {
1019             givens = TRUE_;
1020         }
1021     }
1022     if (*lda < *m && *lda >= minlda) {
1023         givens = TRUE_;
1024     }
1025
1026 /*     Set INFO if an error */
1027
1028     if (*m < 0) {
1029         *info = -1;
1030     } else if (*m != *n && isym != 1) {
1031         *info = -1;
1032     } else if (*n < 0) {
1033         *info = -2;
1034     } else if (idist == -1) {
1035         *info = -3;
1036     } else if (isym == -1) {
1037         *info = -5;
1038     } else if (abs(*mode) > 6) {
1039         *info = -7;
1040     } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.) {
1041         *info = -8;
1042     } else if (*kl < 0) {
1043         *info = -10;
1044     } else if (*ku < 0 || isym != 1 && *kl != *ku) {
1045         *info = -11;
1046     } else if (ipack == -1 || isympk == 1 && isym == 1 || isympk == 2 && isym 
1047             == 1 && *kl > 0 || isympk == 3 && isym == 1 && *ku > 0 || isympk 
1048             != 0 && *m != *n) {
1049         *info = -12;
1050     } else if (*lda < f2cmax(1,minlda)) {
1051         *info = -14;
1052     }
1053
1054     if (*info != 0) {
1055         i__1 = -(*info);
1056         xerbla_("DLATMT", &i__1);
1057         return 0;
1058     }
1059
1060 /*     Initialize random number generator */
1061
1062     for (i__ = 1; i__ <= 4; ++i__) {
1063         iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
1064 /* L100: */
1065     }
1066
1067     if (iseed[4] % 2 != 1) {
1068         ++iseed[4];
1069     }
1070
1071 /*     2)      Set up D  if indicated. */
1072
1073 /*             Compute D according to COND and MODE */
1074
1075     dlatm7_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, rank, &
1076             iinfo);
1077     if (iinfo != 0) {
1078         *info = 1;
1079         return 0;
1080     }
1081
1082 /*     Choose Top-Down if D is (apparently) increasing, */
1083 /*     Bottom-Up if D is (apparently) decreasing. */
1084
1085     if (abs(d__[1]) <= (d__1 = d__[*rank], abs(d__1))) {
1086         topdwn = TRUE_;
1087     } else {
1088         topdwn = FALSE_;
1089     }
1090
1091     if (*mode != 0 && abs(*mode) != 6) {
1092
1093 /*        Scale by DMAX */
1094
1095         temp = abs(d__[1]);
1096         i__1 = *rank;
1097         for (i__ = 2; i__ <= i__1; ++i__) {
1098 /* Computing MAX */
1099             d__2 = temp, d__3 = (d__1 = d__[i__], abs(d__1));
1100             temp = f2cmax(d__2,d__3);
1101 /* L110: */
1102         }
1103
1104         if (temp > 0.) {
1105             alpha = *dmax__ / temp;
1106         } else {
1107             *info = 2;
1108             return 0;
1109         }
1110
1111         dscal_(rank, &alpha, &d__[1], &c__1);
1112
1113     }
1114
1115 /*     3)      Generate Banded Matrix using Givens rotations. */
1116 /*             Also the special case of UUB=LLB=0 */
1117
1118 /*               Compute Addressing constants to cover all */
1119 /*               storage formats.  Whether GE, SY, GB, or SB, */
1120 /*               upper or lower triangle or both, */
1121 /*               the (i,j)-th element is in */
1122 /*               A( i - ISKEW*j + IOFFST, j ) */
1123
1124     if (ipack > 4) {
1125         ilda = *lda - 1;
1126         iskew = 1;
1127         if (ipack > 5) {
1128             ioffst = uub + 1;
1129         } else {
1130             ioffst = 1;
1131         }
1132     } else {
1133         ilda = *lda;
1134         iskew = 0;
1135         ioffst = 0;
1136     }
1137
1138 /*     IPACKG is the format that the matrix is generated in. If this is */
1139 /*     different from IPACK, then the matrix must be repacked at the */
1140 /*     end.  It also signals how to compute the norm, for scaling. */
1141
1142     ipackg = 0;
1143     dlaset_("Full", lda, n, &c_b22, &c_b22, &a[a_offset], lda);
1144
1145 /*     Diagonal Matrix -- We are done, unless it */
1146 /*     is to be stored SP/PP/TP (PACK='R' or 'C') */
1147
1148     if (llb == 0 && uub == 0) {
1149         i__1 = ilda + 1;
1150         dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &i__1)
1151                 ;
1152         if (ipack <= 2 || ipack >= 5) {
1153             ipackg = ipack;
1154         }
1155
1156     } else if (givens) {
1157
1158 /*        Check whether to use Givens rotations, */
1159 /*        Householder transformations, or nothing. */
1160
1161         if (isym == 1) {
1162
1163 /*           Non-symmetric -- A = U D V */
1164
1165             if (ipack > 4) {
1166                 ipackg = ipack;
1167             } else {
1168                 ipackg = 0;
1169             }
1170
1171             i__1 = ilda + 1;
1172             dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &
1173                     i__1);
1174
1175             if (topdwn) {
1176                 jkl = 0;
1177                 i__1 = uub;
1178                 for (jku = 1; jku <= i__1; ++jku) {
1179
1180 /*                 Transform from bandwidth JKL, JKU-1 to JKL, JKU */
1181
1182 /*                 Last row actually rotated is M */
1183 /*                 Last column actually rotated is MIN( M+JKU, N ) */
1184
1185 /* Computing MIN */
1186                     i__3 = *m + jku;
1187                     i__2 = f2cmin(i__3,*n) + jkl - 1;
1188                     for (jr = 1; jr <= i__2; ++jr) {
1189                         extra = 0.;
1190                         angle = dlarnd_(&c__1, &iseed[1]) * 
1191                                 6.2831853071795864769252867663;
1192                         c__ = cos(angle);
1193                         s = sin(angle);
1194 /* Computing MAX */
1195                         i__3 = 1, i__4 = jr - jkl;
1196                         icol = f2cmax(i__3,i__4);
1197                         if (jr < *m) {
1198 /* Computing MIN */
1199                             i__3 = *n, i__4 = jr + jku;
1200                             il = f2cmin(i__3,i__4) + 1 - icol;
1201                             L__1 = jr > jkl;
1202                             dlarot_(&c_true, &L__1, &c_false, &il, &c__, &s, &
1203                                     a[jr - iskew * icol + ioffst + icol * 
1204                                     a_dim1], &ilda, &extra, &dummy);
1205                         }
1206
1207 /*                    Chase "EXTRA" back up */
1208
1209                         ir = jr;
1210                         ic = icol;
1211                         i__3 = -jkl - jku;
1212                         for (jch = jr - jkl; i__3 < 0 ? jch >= 1 : jch <= 1; 
1213                                 jch += i__3) {
1214                             if (ir < *m) {
1215                                 dlartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst 
1216                                         + (ic + 1) * a_dim1], &extra, &c__, &
1217                                         s, &dummy);
1218                             }
1219 /* Computing MAX */
1220                             i__4 = 1, i__5 = jch - jku;
1221                             irow = f2cmax(i__4,i__5);
1222                             il = ir + 2 - irow;
1223                             temp = 0.;
1224                             iltemp = jch > jku;
1225                             d__1 = -s;
1226                             dlarot_(&c_false, &iltemp, &c_true, &il, &c__, &
1227                                     d__1, &a[irow - iskew * ic + ioffst + ic *
1228                                      a_dim1], &ilda, &temp, &extra);
1229                             if (iltemp) {
1230                                 dlartg_(&a[irow + 1 - iskew * (ic + 1) + 
1231                                         ioffst + (ic + 1) * a_dim1], &temp, &
1232                                         c__, &s, &dummy);
1233 /* Computing MAX */
1234                                 i__4 = 1, i__5 = jch - jku - jkl;
1235                                 icol = f2cmax(i__4,i__5);
1236                                 il = ic + 2 - icol;
1237                                 extra = 0.;
1238                                 L__1 = jch > jku + jkl;
1239                                 d__1 = -s;
1240                                 dlarot_(&c_true, &L__1, &c_true, &il, &c__, &
1241                                         d__1, &a[irow - iskew * icol + ioffst 
1242                                         + icol * a_dim1], &ilda, &extra, &
1243                                         temp);
1244                                 ic = icol;
1245                                 ir = irow;
1246                             }
1247 /* L120: */
1248                         }
1249 /* L130: */
1250                     }
1251 /* L140: */
1252                 }
1253
1254                 jku = uub;
1255                 i__1 = llb;
1256                 for (jkl = 1; jkl <= i__1; ++jkl) {
1257
1258 /*                 Transform from bandwidth JKL-1, JKU to JKL, JKU */
1259
1260 /* Computing MIN */
1261                     i__3 = *n + jkl;
1262                     i__2 = f2cmin(i__3,*m) + jku - 1;
1263                     for (jc = 1; jc <= i__2; ++jc) {
1264                         extra = 0.;
1265                         angle = dlarnd_(&c__1, &iseed[1]) * 
1266                                 6.2831853071795864769252867663;
1267                         c__ = cos(angle);
1268                         s = sin(angle);
1269 /* Computing MAX */
1270                         i__3 = 1, i__4 = jc - jku;
1271                         irow = f2cmax(i__3,i__4);
1272                         if (jc < *n) {
1273 /* Computing MIN */
1274                             i__3 = *m, i__4 = jc + jkl;
1275                             il = f2cmin(i__3,i__4) + 1 - irow;
1276                             L__1 = jc > jku;
1277                             dlarot_(&c_false, &L__1, &c_false, &il, &c__, &s, 
1278                                     &a[irow - iskew * jc + ioffst + jc * 
1279                                     a_dim1], &ilda, &extra, &dummy);
1280                         }
1281
1282 /*                    Chase "EXTRA" back up */
1283
1284                         ic = jc;
1285                         ir = irow;
1286                         i__3 = -jkl - jku;
1287                         for (jch = jc - jku; i__3 < 0 ? jch >= 1 : jch <= 1; 
1288                                 jch += i__3) {
1289                             if (ic < *n) {
1290                                 dlartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst 
1291                                         + (ic + 1) * a_dim1], &extra, &c__, &
1292                                         s, &dummy);
1293                             }
1294 /* Computing MAX */
1295                             i__4 = 1, i__5 = jch - jkl;
1296                             icol = f2cmax(i__4,i__5);
1297                             il = ic + 2 - icol;
1298                             temp = 0.;
1299                             iltemp = jch > jkl;
1300                             d__1 = -s;
1301                             dlarot_(&c_true, &iltemp, &c_true, &il, &c__, &
1302                                     d__1, &a[ir - iskew * icol + ioffst + 
1303                                     icol * a_dim1], &ilda, &temp, &extra);
1304                             if (iltemp) {
1305                                 dlartg_(&a[ir + 1 - iskew * (icol + 1) + 
1306                                         ioffst + (icol + 1) * a_dim1], &temp, 
1307                                         &c__, &s, &dummy);
1308 /* Computing MAX */
1309                                 i__4 = 1, i__5 = jch - jkl - jku;
1310                                 irow = f2cmax(i__4,i__5);
1311                                 il = ir + 2 - irow;
1312                                 extra = 0.;
1313                                 L__1 = jch > jkl + jku;
1314                                 d__1 = -s;
1315                                 dlarot_(&c_false, &L__1, &c_true, &il, &c__, &
1316                                         d__1, &a[irow - iskew * icol + ioffst 
1317                                         + icol * a_dim1], &ilda, &extra, &
1318                                         temp);
1319                                 ic = icol;
1320                                 ir = irow;
1321                             }
1322 /* L150: */
1323                         }
1324 /* L160: */
1325                     }
1326 /* L170: */
1327                 }
1328
1329             } else {
1330
1331 /*              Bottom-Up -- Start at the bottom right. */
1332
1333                 jkl = 0;
1334                 i__1 = uub;
1335                 for (jku = 1; jku <= i__1; ++jku) {
1336
1337 /*                 Transform from bandwidth JKL, JKU-1 to JKL, JKU */
1338
1339 /*                 First row actually rotated is M */
1340 /*                 First column actually rotated is MIN( M+JKU, N ) */
1341
1342 /* Computing MIN */
1343                     i__2 = *m, i__3 = *n + jkl;
1344                     iendch = f2cmin(i__2,i__3) - 1;
1345 /* Computing MIN */
1346                     i__2 = *m + jku;
1347                     i__3 = 1 - jkl;
1348                     for (jc = f2cmin(i__2,*n) - 1; jc >= i__3; --jc) {
1349                         extra = 0.;
1350                         angle = dlarnd_(&c__1, &iseed[1]) * 
1351                                 6.2831853071795864769252867663;
1352                         c__ = cos(angle);
1353                         s = sin(angle);
1354 /* Computing MAX */
1355                         i__2 = 1, i__4 = jc - jku + 1;
1356                         irow = f2cmax(i__2,i__4);
1357                         if (jc > 0) {
1358 /* Computing MIN */
1359                             i__2 = *m, i__4 = jc + jkl + 1;
1360                             il = f2cmin(i__2,i__4) + 1 - irow;
1361                             L__1 = jc + jkl < *m;
1362                             dlarot_(&c_false, &c_false, &L__1, &il, &c__, &s, 
1363                                     &a[irow - iskew * jc + ioffst + jc * 
1364                                     a_dim1], &ilda, &dummy, &extra);
1365                         }
1366
1367 /*                    Chase "EXTRA" back down */
1368
1369                         ic = jc;
1370                         i__2 = iendch;
1371                         i__4 = jkl + jku;
1372                         for (jch = jc + jkl; i__4 < 0 ? jch >= i__2 : jch <= 
1373                                 i__2; jch += i__4) {
1374                             ilextr = ic > 0;
1375                             if (ilextr) {
1376                                 dlartg_(&a[jch - iskew * ic + ioffst + ic * 
1377                                         a_dim1], &extra, &c__, &s, &dummy);
1378                             }
1379                             ic = f2cmax(1,ic);
1380 /* Computing MIN */
1381                             i__5 = *n - 1, i__6 = jch + jku;
1382                             icol = f2cmin(i__5,i__6);
1383                             iltemp = jch + jku < *n;
1384                             temp = 0.;
1385                             i__5 = icol + 2 - ic;
1386                             dlarot_(&c_true, &ilextr, &iltemp, &i__5, &c__, &
1387                                     s, &a[jch - iskew * ic + ioffst + ic * 
1388                                     a_dim1], &ilda, &extra, &temp);
1389                             if (iltemp) {
1390                                 dlartg_(&a[jch - iskew * icol + ioffst + icol 
1391                                         * a_dim1], &temp, &c__, &s, &dummy);
1392 /* Computing MIN */
1393                                 i__5 = iendch, i__6 = jch + jkl + jku;
1394                                 il = f2cmin(i__5,i__6) + 2 - jch;
1395                                 extra = 0.;
1396                                 L__1 = jch + jkl + jku <= iendch;
1397                                 dlarot_(&c_false, &c_true, &L__1, &il, &c__, &
1398                                         s, &a[jch - iskew * icol + ioffst + 
1399                                         icol * a_dim1], &ilda, &temp, &extra);
1400                                 ic = icol;
1401                             }
1402 /* L180: */
1403                         }
1404 /* L190: */
1405                     }
1406 /* L200: */
1407                 }
1408
1409                 jku = uub;
1410                 i__1 = llb;
1411                 for (jkl = 1; jkl <= i__1; ++jkl) {
1412
1413 /*                 Transform from bandwidth JKL-1, JKU to JKL, JKU */
1414
1415 /*                 First row actually rotated is MIN( N+JKL, M ) */
1416 /*                 First column actually rotated is N */
1417
1418 /* Computing MIN */
1419                     i__3 = *n, i__4 = *m + jku;
1420                     iendch = f2cmin(i__3,i__4) - 1;
1421 /* Computing MIN */
1422                     i__3 = *n + jkl;
1423                     i__4 = 1 - jku;
1424                     for (jr = f2cmin(i__3,*m) - 1; jr >= i__4; --jr) {
1425                         extra = 0.;
1426                         angle = dlarnd_(&c__1, &iseed[1]) * 
1427                                 6.2831853071795864769252867663;
1428                         c__ = cos(angle);
1429                         s = sin(angle);
1430 /* Computing MAX */
1431                         i__3 = 1, i__2 = jr - jkl + 1;
1432                         icol = f2cmax(i__3,i__2);
1433                         if (jr > 0) {
1434 /* Computing MIN */
1435                             i__3 = *n, i__2 = jr + jku + 1;
1436                             il = f2cmin(i__3,i__2) + 1 - icol;
1437                             L__1 = jr + jku < *n;
1438                             dlarot_(&c_true, &c_false, &L__1, &il, &c__, &s, &
1439                                     a[jr - iskew * icol + ioffst + icol * 
1440                                     a_dim1], &ilda, &dummy, &extra);
1441                         }
1442
1443 /*                    Chase "EXTRA" back down */
1444
1445                         ir = jr;
1446                         i__3 = iendch;
1447                         i__2 = jkl + jku;
1448                         for (jch = jr + jku; i__2 < 0 ? jch >= i__3 : jch <= 
1449                                 i__3; jch += i__2) {
1450                             ilextr = ir > 0;
1451                             if (ilextr) {
1452                                 dlartg_(&a[ir - iskew * jch + ioffst + jch * 
1453                                         a_dim1], &extra, &c__, &s, &dummy);
1454                             }
1455                             ir = f2cmax(1,ir);
1456 /* Computing MIN */
1457                             i__5 = *m - 1, i__6 = jch + jkl;
1458                             irow = f2cmin(i__5,i__6);
1459                             iltemp = jch + jkl < *m;
1460                             temp = 0.;
1461                             i__5 = irow + 2 - ir;
1462                             dlarot_(&c_false, &ilextr, &iltemp, &i__5, &c__, &
1463                                     s, &a[ir - iskew * jch + ioffst + jch * 
1464                                     a_dim1], &ilda, &extra, &temp);
1465                             if (iltemp) {
1466                                 dlartg_(&a[irow - iskew * jch + ioffst + jch *
1467                                          a_dim1], &temp, &c__, &s, &dummy);
1468 /* Computing MIN */
1469                                 i__5 = iendch, i__6 = jch + jkl + jku;
1470                                 il = f2cmin(i__5,i__6) + 2 - jch;
1471                                 extra = 0.;
1472                                 L__1 = jch + jkl + jku <= iendch;
1473                                 dlarot_(&c_true, &c_true, &L__1, &il, &c__, &
1474                                         s, &a[irow - iskew * jch + ioffst + 
1475                                         jch * a_dim1], &ilda, &temp, &extra);
1476                                 ir = irow;
1477                             }
1478 /* L210: */
1479                         }
1480 /* L220: */
1481                     }
1482 /* L230: */
1483                 }
1484             }
1485
1486         } else {
1487
1488 /*           Symmetric -- A = U D U' */
1489
1490             ipackg = ipack;
1491             ioffg = ioffst;
1492
1493             if (topdwn) {
1494
1495 /*              Top-Down -- Generate Upper triangle only */
1496
1497                 if (ipack >= 5) {
1498                     ipackg = 6;
1499                     ioffg = uub + 1;
1500                 } else {
1501                     ipackg = 1;
1502                 }
1503                 i__1 = ilda + 1;
1504                 dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
1505                          &i__1);
1506
1507                 i__1 = uub;
1508                 for (k = 1; k <= i__1; ++k) {
1509                     i__4 = *n - 1;
1510                     for (jc = 1; jc <= i__4; ++jc) {
1511 /* Computing MAX */
1512                         i__2 = 1, i__3 = jc - k;
1513                         irow = f2cmax(i__2,i__3);
1514 /* Computing MIN */
1515                         i__2 = jc + 1, i__3 = k + 2;
1516                         il = f2cmin(i__2,i__3);
1517                         extra = 0.;
1518                         temp = a[jc - iskew * (jc + 1) + ioffg + (jc + 1) * 
1519                                 a_dim1];
1520                         angle = dlarnd_(&c__1, &iseed[1]) * 
1521                                 6.2831853071795864769252867663;
1522                         c__ = cos(angle);
1523                         s = sin(angle);
1524                         L__1 = jc > k;
1525                         dlarot_(&c_false, &L__1, &c_true, &il, &c__, &s, &a[
1526                                 irow - iskew * jc + ioffg + jc * a_dim1], &
1527                                 ilda, &extra, &temp);
1528 /* Computing MIN */
1529                         i__3 = k, i__5 = *n - jc;
1530                         i__2 = f2cmin(i__3,i__5) + 1;
1531                         dlarot_(&c_true, &c_true, &c_false, &i__2, &c__, &s, &
1532                                 a[(1 - iskew) * jc + ioffg + jc * a_dim1], &
1533                                 ilda, &temp, &dummy);
1534
1535 /*                    Chase EXTRA back up the matrix */
1536
1537                         icol = jc;
1538                         i__2 = -k;
1539                         for (jch = jc - k; i__2 < 0 ? jch >= 1 : jch <= 1; 
1540                                 jch += i__2) {
1541                             dlartg_(&a[jch + 1 - iskew * (icol + 1) + ioffg + 
1542                                     (icol + 1) * a_dim1], &extra, &c__, &s, &
1543                                     dummy);
1544                             temp = a[jch - iskew * (jch + 1) + ioffg + (jch + 
1545                                     1) * a_dim1];
1546                             i__3 = k + 2;
1547                             d__1 = -s;
1548                             dlarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
1549                                     d__1, &a[(1 - iskew) * jch + ioffg + jch *
1550                                      a_dim1], &ilda, &temp, &extra);
1551 /* Computing MAX */
1552                             i__3 = 1, i__5 = jch - k;
1553                             irow = f2cmax(i__3,i__5);
1554 /* Computing MIN */
1555                             i__3 = jch + 1, i__5 = k + 2;
1556                             il = f2cmin(i__3,i__5);
1557                             extra = 0.;
1558                             L__1 = jch > k;
1559                             d__1 = -s;
1560                             dlarot_(&c_false, &L__1, &c_true, &il, &c__, &
1561                                     d__1, &a[irow - iskew * jch + ioffg + jch 
1562                                     * a_dim1], &ilda, &extra, &temp);
1563                             icol = jch;
1564 /* L240: */
1565                         }
1566 /* L250: */
1567                     }
1568 /* L260: */
1569                 }
1570
1571 /*              If we need lower triangle, copy from upper. Note that */
1572 /*              the order of copying is chosen to work for 'q' -> 'b' */
1573
1574                 if (ipack != ipackg && ipack != 3) {
1575                     i__1 = *n;
1576                     for (jc = 1; jc <= i__1; ++jc) {
1577                         irow = ioffst - iskew * jc;
1578 /* Computing MIN */
1579                         i__2 = *n, i__3 = jc + uub;
1580                         i__4 = f2cmin(i__2,i__3);
1581                         for (jr = jc; jr <= i__4; ++jr) {
1582                             a[jr + irow + jc * a_dim1] = a[jc - iskew * jr + 
1583                                     ioffg + jr * a_dim1];
1584 /* L270: */
1585                         }
1586 /* L280: */
1587                     }
1588                     if (ipack == 5) {
1589                         i__1 = *n;
1590                         for (jc = *n - uub + 1; jc <= i__1; ++jc) {
1591                             i__4 = uub + 1;
1592                             for (jr = *n + 2 - jc; jr <= i__4; ++jr) {
1593                                 a[jr + jc * a_dim1] = 0.;
1594 /* L290: */
1595                             }
1596 /* L300: */
1597                         }
1598                     }
1599                     if (ipackg == 6) {
1600                         ipackg = ipack;
1601                     } else {
1602                         ipackg = 0;
1603                     }
1604                 }
1605             } else {
1606
1607 /*              Bottom-Up -- Generate Lower triangle only */
1608
1609                 if (ipack >= 5) {
1610                     ipackg = 5;
1611                     if (ipack == 6) {
1612                         ioffg = 1;
1613                     }
1614                 } else {
1615                     ipackg = 2;
1616                 }
1617                 i__1 = ilda + 1;
1618                 dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
1619                          &i__1);
1620
1621                 i__1 = uub;
1622                 for (k = 1; k <= i__1; ++k) {
1623                     for (jc = *n - 1; jc >= 1; --jc) {
1624 /* Computing MIN */
1625                         i__4 = *n + 1 - jc, i__2 = k + 2;
1626                         il = f2cmin(i__4,i__2);
1627                         extra = 0.;
1628                         temp = a[(1 - iskew) * jc + 1 + ioffg + jc * a_dim1];
1629                         angle = dlarnd_(&c__1, &iseed[1]) * 
1630                                 6.2831853071795864769252867663;
1631                         c__ = cos(angle);
1632                         s = -sin(angle);
1633                         L__1 = *n - jc > k;
1634                         dlarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &a[(
1635                                 1 - iskew) * jc + ioffg + jc * a_dim1], &ilda,
1636                                  &temp, &extra);
1637 /* Computing MAX */
1638                         i__4 = 1, i__2 = jc - k + 1;
1639                         icol = f2cmax(i__4,i__2);
1640                         i__4 = jc + 2 - icol;
1641                         dlarot_(&c_true, &c_false, &c_true, &i__4, &c__, &s, &
1642                                 a[jc - iskew * icol + ioffg + icol * a_dim1], 
1643                                 &ilda, &dummy, &temp);
1644
1645 /*                    Chase EXTRA back down the matrix */
1646
1647                         icol = jc;
1648                         i__4 = *n - 1;
1649                         i__2 = k;
1650                         for (jch = jc + k; i__2 < 0 ? jch >= i__4 : jch <= 
1651                                 i__4; jch += i__2) {
1652                             dlartg_(&a[jch - iskew * icol + ioffg + icol * 
1653                                     a_dim1], &extra, &c__, &s, &dummy);
1654                             temp = a[(1 - iskew) * jch + 1 + ioffg + jch * 
1655                                     a_dim1];
1656                             i__3 = k + 2;
1657                             dlarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
1658                                     s, &a[jch - iskew * icol + ioffg + icol * 
1659                                     a_dim1], &ilda, &extra, &temp);
1660 /* Computing MIN */
1661                             i__3 = *n + 1 - jch, i__5 = k + 2;
1662                             il = f2cmin(i__3,i__5);
1663                             extra = 0.;
1664                             L__1 = *n - jch > k;
1665                             dlarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &
1666                                     a[(1 - iskew) * jch + ioffg + jch * 
1667                                     a_dim1], &ilda, &temp, &extra);
1668                             icol = jch;
1669 /* L310: */
1670                         }
1671 /* L320: */
1672                     }
1673 /* L330: */
1674                 }
1675
1676 /*              If we need upper triangle, copy from lower. Note that */
1677 /*              the order of copying is chosen to work for 'b' -> 'q' */
1678
1679                 if (ipack != ipackg && ipack != 4) {
1680                     for (jc = *n; jc >= 1; --jc) {
1681                         irow = ioffst - iskew * jc;
1682 /* Computing MAX */
1683                         i__2 = 1, i__4 = jc - uub;
1684                         i__1 = f2cmax(i__2,i__4);
1685                         for (jr = jc; jr >= i__1; --jr) {
1686                             a[jr + irow + jc * a_dim1] = a[jc - iskew * jr + 
1687                                     ioffg + jr * a_dim1];
1688 /* L340: */
1689                         }
1690 /* L350: */
1691                     }
1692                     if (ipack == 6) {
1693                         i__1 = uub;
1694                         for (jc = 1; jc <= i__1; ++jc) {
1695                             i__2 = uub + 1 - jc;
1696                             for (jr = 1; jr <= i__2; ++jr) {
1697                                 a[jr + jc * a_dim1] = 0.;
1698 /* L360: */
1699                             }
1700 /* L370: */
1701                         }
1702                     }
1703                     if (ipackg == 5) {
1704                         ipackg = ipack;
1705                     } else {
1706                         ipackg = 0;
1707                     }
1708                 }
1709             }
1710         }
1711
1712     } else {
1713
1714 /*        4)      Generate Banded Matrix by first */
1715 /*                Rotating by random Unitary matrices, */
1716 /*                then reducing the bandwidth using Householder */
1717 /*                transformations. */
1718
1719 /*                Note: we should get here only if LDA .ge. N */
1720
1721         if (isym == 1) {
1722
1723 /*           Non-symmetric -- A = U D V */
1724
1725             dlagge_(&mr, &nc, &llb, &uub, &d__[1], &a[a_offset], lda, &iseed[
1726                     1], &work[1], &iinfo);
1727         } else {
1728
1729 /*           Symmetric -- A = U D U' */
1730
1731             dlagsy_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[1], 
1732                     &iinfo);
1733
1734         }
1735         if (iinfo != 0) {
1736             *info = 3;
1737             return 0;
1738         }
1739     }
1740
1741 /*     5)      Pack the matrix */
1742
1743     if (ipack != ipackg) {
1744         if (ipack == 1) {
1745
1746 /*           'U' -- Upper triangular, not packed */
1747
1748             i__1 = *m;
1749             for (j = 1; j <= i__1; ++j) {
1750                 i__2 = *m;
1751                 for (i__ = j + 1; i__ <= i__2; ++i__) {
1752                     a[i__ + j * a_dim1] = 0.;
1753 /* L380: */
1754                 }
1755 /* L390: */
1756             }
1757
1758         } else if (ipack == 2) {
1759
1760 /*           'L' -- Lower triangular, not packed */
1761
1762             i__1 = *m;
1763             for (j = 2; j <= i__1; ++j) {
1764                 i__2 = j - 1;
1765                 for (i__ = 1; i__ <= i__2; ++i__) {
1766                     a[i__ + j * a_dim1] = 0.;
1767 /* L400: */
1768                 }
1769 /* L410: */
1770             }
1771
1772         } else if (ipack == 3) {
1773
1774 /*           'C' -- Upper triangle packed Columnwise. */
1775
1776             icol = 1;
1777             irow = 0;
1778             i__1 = *m;
1779             for (j = 1; j <= i__1; ++j) {
1780                 i__2 = j;
1781                 for (i__ = 1; i__ <= i__2; ++i__) {
1782                     ++irow;
1783                     if (irow > *lda) {
1784                         irow = 1;
1785                         ++icol;
1786                     }
1787                     a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
1788 /* L420: */
1789                 }
1790 /* L430: */
1791             }
1792
1793         } else if (ipack == 4) {
1794
1795 /*           'R' -- Lower triangle packed Columnwise. */
1796
1797             icol = 1;
1798             irow = 0;
1799             i__1 = *m;
1800             for (j = 1; j <= i__1; ++j) {
1801                 i__2 = *m;
1802                 for (i__ = j; i__ <= i__2; ++i__) {
1803                     ++irow;
1804                     if (irow > *lda) {
1805                         irow = 1;
1806                         ++icol;
1807                     }
1808                     a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
1809 /* L440: */
1810                 }
1811 /* L450: */
1812             }
1813
1814         } else if (ipack >= 5) {
1815
1816 /*           'B' -- The lower triangle is packed as a band matrix. */
1817 /*           'Q' -- The upper triangle is packed as a band matrix. */
1818 /*           'Z' -- The whole matrix is packed as a band matrix. */
1819
1820             if (ipack == 5) {
1821                 uub = 0;
1822             }
1823             if (ipack == 6) {
1824                 llb = 0;
1825             }
1826
1827             i__1 = uub;
1828             for (j = 1; j <= i__1; ++j) {
1829 /* Computing MIN */
1830                 i__2 = j + llb;
1831                 for (i__ = f2cmin(i__2,*m); i__ >= 1; --i__) {
1832                     a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
1833 /* L460: */
1834                 }
1835 /* L470: */
1836             }
1837
1838             i__1 = *n;
1839             for (j = uub + 2; j <= i__1; ++j) {
1840 /* Computing MIN */
1841                 i__4 = j + llb;
1842                 i__2 = f2cmin(i__4,*m);
1843                 for (i__ = j - uub; i__ <= i__2; ++i__) {
1844                     a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
1845 /* L480: */
1846                 }
1847 /* L490: */
1848             }
1849         }
1850
1851 /*        If packed, zero out extraneous elements. */
1852
1853 /*        Symmetric/Triangular Packed -- */
1854 /*        zero out everything after A(IROW,ICOL) */
1855
1856         if (ipack == 3 || ipack == 4) {
1857             i__1 = *m;
1858             for (jc = icol; jc <= i__1; ++jc) {
1859                 i__2 = *lda;
1860                 for (jr = irow + 1; jr <= i__2; ++jr) {
1861                     a[jr + jc * a_dim1] = 0.;
1862 /* L500: */
1863                 }
1864                 irow = 0;
1865 /* L510: */
1866             }
1867
1868         } else if (ipack >= 5) {
1869
1870 /*           Packed Band -- */
1871 /*              1st row is now in A( UUB+2-j, j), zero above it */
1872 /*              m-th row is now in A( M+UUB-j,j), zero below it */
1873 /*              last non-zero diagonal is now in A( UUB+LLB+1,j ), */
1874 /*                 zero below it, too. */
1875
1876             ir1 = uub + llb + 2;
1877             ir2 = uub + *m + 2;
1878             i__1 = *n;
1879             for (jc = 1; jc <= i__1; ++jc) {
1880                 i__2 = uub + 1 - jc;
1881                 for (jr = 1; jr <= i__2; ++jr) {
1882                     a[jr + jc * a_dim1] = 0.;
1883 /* L520: */
1884                 }
1885 /* Computing MAX */
1886 /* Computing MIN */
1887                 i__3 = ir1, i__5 = ir2 - jc;
1888                 i__2 = 1, i__4 = f2cmin(i__3,i__5);
1889                 i__6 = *lda;
1890                 for (jr = f2cmax(i__2,i__4); jr <= i__6; ++jr) {
1891                     a[jr + jc * a_dim1] = 0.;
1892 /* L530: */
1893                 }
1894 /* L540: */
1895             }
1896         }
1897     }
1898
1899     return 0;
1900
1901 /*     End of DLATMT */
1902
1903 } /* dlatmt_ */
1904