C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / TESTING / MATGEN / clatms.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 complex c_b1 = {0.f,0.f};
516 static integer c__1 = 1;
517 static integer c__5 = 5;
518 static logical c_true = TRUE_;
519 static logical c_false = FALSE_;
520
521 /* > \brief \b CLATMS */
522
523 /*  =========== DOCUMENTATION =========== */
524
525 /* Online html documentation available at */
526 /*            http://www.netlib.org/lapack/explore-html/ */
527
528 /*  Definition: */
529 /*  =========== */
530
531 /*       SUBROUTINE CLATMS( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
532 /*                          KL, KU, PACK, A, LDA, WORK, INFO ) */
533
534 /*       CHARACTER          DIST, PACK, SYM */
535 /*       INTEGER            INFO, KL, KU, LDA, M, MODE, N */
536 /*       REAL               COND, DMAX */
537 /*       INTEGER            ISEED( 4 ) */
538 /*       REAL               D( * ) */
539 /*       COMPLEX            A( LDA, * ), WORK( * ) */
540
541
542 /* > \par Purpose: */
543 /*  ============= */
544 /* > */
545 /* > \verbatim */
546 /* > */
547 /* >    CLATMS generates random matrices with specified singular values */
548 /* >    (or hermitian with specified eigenvalues) */
549 /* >    for testing LAPACK programs. */
550 /* > */
551 /* >    CLATMS operates by applying the following sequence of */
552 /* >    operations: */
553 /* > */
554 /* >      Set the diagonal to D, where D may be input or */
555 /* >         computed according to MODE, COND, DMAX, and SYM */
556 /* >         as described below. */
557 /* > */
558 /* >      Generate a matrix with the appropriate band structure, by one */
559 /* >         of two methods: */
560 /* > */
561 /* >      Method A: */
562 /* >          Generate a dense M x N matrix by multiplying D on the left */
563 /* >              and the right by random unitary matrices, then: */
564 /* > */
565 /* >          Reduce the bandwidth according to KL and KU, using */
566 /* >              Householder transformations. */
567 /* > */
568 /* >      Method B: */
569 /* >          Convert the bandwidth-0 (i.e., diagonal) matrix to a */
570 /* >              bandwidth-1 matrix using Givens rotations, "chasing" */
571 /* >              out-of-band elements back, much as in QR; then convert */
572 /* >              the bandwidth-1 to a bandwidth-2 matrix, etc.  Note */
573 /* >              that for reasonably small bandwidths (relative to M and */
574 /* >              N) this requires less storage, as a dense matrix is not */
575 /* >              generated.  Also, for hermitian or symmetric matrices, */
576 /* >              only one triangle is generated. */
577 /* > */
578 /* >      Method A is chosen if the bandwidth is a large fraction of the */
579 /* >          order of the matrix, and LDA is at least M (so a dense */
580 /* >          matrix can be stored.)  Method B is chosen if the bandwidth */
581 /* >          is small (< 1/2 N for hermitian or symmetric, < .3 N+M for */
582 /* >          non-symmetric), or LDA is less than M and not less than the */
583 /* >          bandwidth. */
584 /* > */
585 /* >      Pack the matrix if desired. Options specified by PACK are: */
586 /* >         no packing */
587 /* >         zero out upper half (if hermitian) */
588 /* >         zero out lower half (if hermitian) */
589 /* >         store the upper half columnwise (if hermitian or upper */
590 /* >               triangular) */
591 /* >         store the lower half columnwise (if hermitian or lower */
592 /* >               triangular) */
593 /* >         store the lower triangle in banded format (if hermitian or */
594 /* >               lower triangular) */
595 /* >         store the upper triangle in banded format (if hermitian or */
596 /* >               upper triangular) */
597 /* >         store the entire matrix in banded format */
598 /* >      If Method B is chosen, and band format is specified, then the */
599 /* >         matrix will be generated in the band format, so no repacking */
600 /* >         will be necessary. */
601 /* > \endverbatim */
602
603 /*  Arguments: */
604 /*  ========== */
605
606 /* > \param[in] M */
607 /* > \verbatim */
608 /* >          M is INTEGER */
609 /* >           The number of rows of A. Not modified. */
610 /* > \endverbatim */
611 /* > */
612 /* > \param[in] N */
613 /* > \verbatim */
614 /* >          N is INTEGER */
615 /* >           The number of columns of A. N must equal M if the matrix */
616 /* >           is symmetric or hermitian (i.e., if SYM is not 'N') */
617 /* >           Not modified. */
618 /* > \endverbatim */
619 /* > */
620 /* > \param[in] DIST */
621 /* > \verbatim */
622 /* >          DIST is CHARACTER*1 */
623 /* >           On entry, DIST specifies the type of distribution to be used */
624 /* >           to generate the random eigen-/singular values. */
625 /* >           'U' => UNIFORM( 0, 1 )  ( 'U' for uniform ) */
626 /* >           'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
627 /* >           'N' => NORMAL( 0, 1 )   ( 'N' for normal ) */
628 /* >           Not modified. */
629 /* > \endverbatim */
630 /* > */
631 /* > \param[in,out] ISEED */
632 /* > \verbatim */
633 /* >          ISEED is INTEGER array, dimension ( 4 ) */
634 /* >           On entry ISEED specifies the seed of the random number */
635 /* >           generator. They should lie between 0 and 4095 inclusive, */
636 /* >           and ISEED(4) should be odd. The random number generator */
637 /* >           uses a linear congruential sequence limited to small */
638 /* >           integers, and so should produce machine independent */
639 /* >           random numbers. The values of ISEED are changed on */
640 /* >           exit, and can be used in the next call to CLATMS */
641 /* >           to continue the same random number sequence. */
642 /* >           Changed on exit. */
643 /* > \endverbatim */
644 /* > */
645 /* > \param[in] SYM */
646 /* > \verbatim */
647 /* >          SYM is CHARACTER*1 */
648 /* >           If SYM='H', the generated matrix is hermitian, with */
649 /* >             eigenvalues specified by D, COND, MODE, and DMAX; they */
650 /* >             may be positive, negative, or zero. */
651 /* >           If SYM='P', the generated matrix is hermitian, with */
652 /* >             eigenvalues (= singular values) specified by D, COND, */
653 /* >             MODE, and DMAX; they will not be negative. */
654 /* >           If SYM='N', the generated matrix is nonsymmetric, with */
655 /* >             singular values specified by D, COND, MODE, and DMAX; */
656 /* >             they will not be negative. */
657 /* >           If SYM='S', the generated matrix is (complex) symmetric, */
658 /* >             with singular values specified by D, COND, MODE, and */
659 /* >             DMAX; they will not be negative. */
660 /* >           Not modified. */
661 /* > \endverbatim */
662 /* > */
663 /* > \param[in,out] D */
664 /* > \verbatim */
665 /* >          D is REAL array, dimension ( MIN( M, N ) ) */
666 /* >           This array is used to specify the singular values or */
667 /* >           eigenvalues of A (see SYM, above.)  If MODE=0, then D is */
668 /* >           assumed to contain the singular/eigenvalues, otherwise */
669 /* >           they will be computed according to MODE, COND, and DMAX, */
670 /* >           and placed in D. */
671 /* >           Modified if MODE is nonzero. */
672 /* > \endverbatim */
673 /* > */
674 /* > \param[in] MODE */
675 /* > \verbatim */
676 /* >          MODE is INTEGER */
677 /* >           On entry this describes how the singular/eigenvalues are to */
678 /* >           be specified: */
679 /* >           MODE = 0 means use D as input */
680 /* >           MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
681 /* >           MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
682 /* >           MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
683 /* >           MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
684 /* >           MODE = 5 sets D to random numbers in the range */
685 /* >                    ( 1/COND , 1 ) such that their logarithms */
686 /* >                    are uniformly distributed. */
687 /* >           MODE = 6 set D to random numbers from same distribution */
688 /* >                    as the rest of the matrix. */
689 /* >           MODE < 0 has the same meaning as ABS(MODE), except that */
690 /* >              the order of the elements of D is reversed. */
691 /* >           Thus if MODE is positive, D has entries ranging from */
692 /* >              1 to 1/COND, if negative, from 1/COND to 1, */
693 /* >           If SYM='H', and MODE is neither 0, 6, nor -6, then */
694 /* >              the elements of D will also be multiplied by a random */
695 /* >              sign (i.e., +1 or -1.) */
696 /* >           Not modified. */
697 /* > \endverbatim */
698 /* > */
699 /* > \param[in] COND */
700 /* > \verbatim */
701 /* >          COND is REAL */
702 /* >           On entry, this is used as described under MODE above. */
703 /* >           If used, it must be >= 1. Not modified. */
704 /* > \endverbatim */
705 /* > */
706 /* > \param[in] DMAX */
707 /* > \verbatim */
708 /* >          DMAX is REAL */
709 /* >           If MODE is neither -6, 0 nor 6, the contents of D, as */
710 /* >           computed according to MODE and COND, will be scaled by */
711 /* >           DMAX / f2cmax(abs(D(i))); thus, the maximum absolute eigen- or */
712 /* >           singular value (which is to say the norm) will be abs(DMAX). */
713 /* >           Note that DMAX need not be positive: if DMAX is negative */
714 /* >           (or zero), D will be scaled by a negative number (or zero). */
715 /* >           Not modified. */
716 /* > \endverbatim */
717 /* > */
718 /* > \param[in] KL */
719 /* > \verbatim */
720 /* >          KL is INTEGER */
721 /* >           This specifies the lower bandwidth of the  matrix. For */
722 /* >           example, KL=0 implies upper triangular, KL=1 implies upper */
723 /* >           Hessenberg, and KL being at least M-1 means that the matrix */
724 /* >           has full lower bandwidth.  KL must equal KU if the matrix */
725 /* >           is symmetric or hermitian. */
726 /* >           Not modified. */
727 /* > \endverbatim */
728 /* > */
729 /* > \param[in] KU */
730 /* > \verbatim */
731 /* >          KU is INTEGER */
732 /* >           This specifies the upper bandwidth of the  matrix. For */
733 /* >           example, KU=0 implies lower triangular, KU=1 implies lower */
734 /* >           Hessenberg, and KU being at least N-1 means that the matrix */
735 /* >           has full upper bandwidth.  KL must equal KU if the matrix */
736 /* >           is symmetric or hermitian. */
737 /* >           Not modified. */
738 /* > \endverbatim */
739 /* > */
740 /* > \param[in] PACK */
741 /* > \verbatim */
742 /* >          PACK is CHARACTER*1 */
743 /* >           This specifies packing of matrix as follows: */
744 /* >           'N' => no packing */
745 /* >           'U' => zero out all subdiagonal entries (if symmetric */
746 /* >                  or hermitian) */
747 /* >           'L' => zero out all superdiagonal entries (if symmetric */
748 /* >                  or hermitian) */
749 /* >           'C' => store the upper triangle columnwise (only if the */
750 /* >                  matrix is symmetric, hermitian, or upper triangular) */
751 /* >           'R' => store the lower triangle columnwise (only if the */
752 /* >                  matrix is symmetric, hermitian, or lower triangular) */
753 /* >           'B' => store the lower triangle in band storage scheme */
754 /* >                  (only if the matrix is symmetric, hermitian, or */
755 /* >                  lower triangular) */
756 /* >           'Q' => store the upper triangle in band storage scheme */
757 /* >                  (only if the matrix is symmetric, hermitian, or */
758 /* >                  upper triangular) */
759 /* >           'Z' => store the entire matrix in band storage scheme */
760 /* >                      (pivoting can be provided for by using this */
761 /* >                      option to store A in the trailing rows of */
762 /* >                      the allocated storage) */
763 /* > */
764 /* >           Using these options, the various LAPACK packed and banded */
765 /* >           storage schemes can be obtained: */
766 /* >           GB                    - use 'Z' */
767 /* >           PB, SB, HB, or TB     - use 'B' or 'Q' */
768 /* >           PP, SP, HB, or TP     - use 'C' or 'R' */
769 /* > */
770 /* >           If two calls to CLATMS differ only in the PACK parameter, */
771 /* >           they will generate mathematically equivalent matrices. */
772 /* >           Not modified. */
773 /* > \endverbatim */
774 /* > */
775 /* > \param[in,out] A */
776 /* > \verbatim */
777 /* >          A is COMPLEX array, dimension ( LDA, N ) */
778 /* >           On exit A is the desired test matrix.  A is first generated */
779 /* >           in full (unpacked) form, and then packed, if so specified */
780 /* >           by PACK.  Thus, the first M elements of the first N */
781 /* >           columns will always be modified.  If PACK specifies a */
782 /* >           packed or banded storage scheme, all LDA elements of the */
783 /* >           first N columns will be modified; the elements of the */
784 /* >           array which do not correspond to elements of the generated */
785 /* >           matrix are set to zero. */
786 /* >           Modified. */
787 /* > \endverbatim */
788 /* > */
789 /* > \param[in] LDA */
790 /* > \verbatim */
791 /* >          LDA is INTEGER */
792 /* >           LDA specifies the first dimension of A as declared in the */
793 /* >           calling program.  If PACK='N', 'U', 'L', 'C', or 'R', then */
794 /* >           LDA must be at least M.  If PACK='B' or 'Q', then LDA must */
795 /* >           be at least MIN( KL, M-1) (which is equal to MIN(KU,N-1)). */
796 /* >           If PACK='Z', LDA must be large enough to hold the packed */
797 /* >           array: MIN( KU, N-1) + MIN( KL, M-1) + 1. */
798 /* >           Not modified. */
799 /* > \endverbatim */
800 /* > */
801 /* > \param[out] WORK */
802 /* > \verbatim */
803 /* >          WORK is COMPLEX array, dimension ( 3*MAX( N, M ) ) */
804 /* >           Workspace. */
805 /* >           Modified. */
806 /* > \endverbatim */
807 /* > */
808 /* > \param[out] INFO */
809 /* > \verbatim */
810 /* >          INFO is INTEGER */
811 /* >           Error code.  On exit, INFO will be set to one of the */
812 /* >           following values: */
813 /* >             0 => normal return */
814 /* >            -1 => M negative or unequal to N and SYM='S', 'H', or 'P' */
815 /* >            -2 => N negative */
816 /* >            -3 => DIST illegal string */
817 /* >            -5 => SYM illegal string */
818 /* >            -7 => MODE not in range -6 to 6 */
819 /* >            -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
820 /* >           -10 => KL negative */
821 /* >           -11 => KU negative, or SYM is not 'N' and KU is not equal to */
822 /* >                  KL */
823 /* >           -12 => PACK illegal string, or PACK='U' or 'L', and SYM='N'; */
824 /* >                  or PACK='C' or 'Q' and SYM='N' and KL is not zero; */
825 /* >                  or PACK='R' or 'B' and SYM='N' and KU is not zero; */
826 /* >                  or PACK='U', 'L', 'C', 'R', 'B', or 'Q', and M is not */
827 /* >                  N. */
828 /* >           -14 => LDA is less than M, or PACK='Z' and LDA is less than */
829 /* >                  MIN(KU,N-1) + MIN(KL,M-1) + 1. */
830 /* >            1  => Error return from SLATM1 */
831 /* >            2  => Cannot scale to DMAX (f2cmax. sing. value is 0) */
832 /* >            3  => Error return from CLAGGE, CLAGHE or CLAGSY */
833 /* > \endverbatim */
834
835 /*  Authors: */
836 /*  ======== */
837
838 /* > \author Univ. of Tennessee */
839 /* > \author Univ. of California Berkeley */
840 /* > \author Univ. of Colorado Denver */
841 /* > \author NAG Ltd. */
842
843 /* > \date December 2016 */
844
845 /* > \ingroup complex_matgen */
846
847 /*  ===================================================================== */
848 /* Subroutine */ int clatms_(integer *m, integer *n, char *dist, integer *
849         iseed, char *sym, real *d__, integer *mode, real *cond, real *dmax__, 
850         integer *kl, integer *ku, char *pack, complex *a, integer *lda, 
851         complex *work, integer *info)
852 {
853     /* System generated locals */
854     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
855     real r__1, r__2, r__3;
856     complex q__1, q__2, q__3;
857     logical L__1;
858
859     /* Local variables */
860     integer ilda, icol;
861     real temp;
862     logical csym;
863     integer irow, isym;
864     complex c__;
865     integer i__, j, k;
866     complex s;
867     real alpha, angle;
868     integer ipack;
869     real realc;
870     integer ioffg;
871     extern logical lsame_(char *, char *);
872     integer iinfo;
873     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
874     complex ctemp;
875     integer idist, mnmin, iskew;
876     complex extra, dummy;
877     extern /* Subroutine */ int slatm1_(integer *, real *, integer *, integer 
878             *, integer *, real *, integer *, integer *);
879     integer ic, jc, nc;
880     extern /* Subroutine */ int clagge_(integer *, integer *, integer *, 
881             integer *, real *, complex *, integer *, integer *, complex *, 
882             integer *), claghe_(integer *, integer *, real *, complex *, 
883             integer *, integer *, complex *, integer *);
884     integer il;
885     complex ct;
886     integer iendch, ir, jr, ipackg, mr;
887     //extern /* Complex */ VOID clarnd_(complex *, integer *, integer *);
888     extern complex clarnd_(integer *, integer *);
889     integer minlda;
890     complex st;
891     extern /* Subroutine */ int claset_(char *, integer *, integer *, complex 
892             *, complex *, complex *, integer *), clartg_(complex *, 
893             complex *, real *, complex *, complex *), xerbla_(char *, integer 
894             *), clagsy_(integer *, integer *, real *, complex *, 
895             integer *, integer *, complex *, integer *);
896     extern real slarnd_(integer *, integer *);
897     extern /* Subroutine */ int clarot_(logical *, logical *, logical *, 
898             integer *, complex *, complex *, complex *, integer *, complex *, 
899             complex *);
900     logical iltemp, givens;
901     integer ioffst, irsign;
902     logical ilextr, topdwn;
903     integer ir1, ir2, isympk, jch, llb, jkl, jku, uub;
904
905
906 /*  -- LAPACK computational routine (version 3.7.0) -- */
907 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
908 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
909 /*     December 2016 */
910
911
912 /*  ===================================================================== */
913
914
915 /*     1)      Decode and Test the input parameters. */
916 /*             Initialize flags & seed. */
917
918     /* Parameter adjustments */
919     --iseed;
920     --d__;
921     a_dim1 = *lda;
922     a_offset = 1 + a_dim1 * 1;
923     a -= a_offset;
924     --work;
925
926     /* Function Body */
927     *info = 0;
928
929 /*     Quick return if possible */
930
931     if (*m == 0 || *n == 0) {
932         return 0;
933     }
934
935 /*     Decode DIST */
936
937     if (lsame_(dist, "U")) {
938         idist = 1;
939     } else if (lsame_(dist, "S")) {
940         idist = 2;
941     } else if (lsame_(dist, "N")) {
942         idist = 3;
943     } else {
944         idist = -1;
945     }
946
947 /*     Decode SYM */
948
949     if (lsame_(sym, "N")) {
950         isym = 1;
951         irsign = 0;
952         csym = FALSE_;
953     } else if (lsame_(sym, "P")) {
954         isym = 2;
955         irsign = 0;
956         csym = FALSE_;
957     } else if (lsame_(sym, "S")) {
958         isym = 2;
959         irsign = 0;
960         csym = TRUE_;
961     } else if (lsame_(sym, "H")) {
962         isym = 2;
963         irsign = 1;
964         csym = FALSE_;
965     } else {
966         isym = -1;
967     }
968
969 /*     Decode PACK */
970
971     isympk = 0;
972     if (lsame_(pack, "N")) {
973         ipack = 0;
974     } else if (lsame_(pack, "U")) {
975         ipack = 1;
976         isympk = 1;
977     } else if (lsame_(pack, "L")) {
978         ipack = 2;
979         isympk = 1;
980     } else if (lsame_(pack, "C")) {
981         ipack = 3;
982         isympk = 2;
983     } else if (lsame_(pack, "R")) {
984         ipack = 4;
985         isympk = 3;
986     } else if (lsame_(pack, "B")) {
987         ipack = 5;
988         isympk = 3;
989     } else if (lsame_(pack, "Q")) {
990         ipack = 6;
991         isympk = 2;
992     } else if (lsame_(pack, "Z")) {
993         ipack = 7;
994     } else {
995         ipack = -1;
996     }
997
998 /*     Set certain internal parameters */
999
1000     mnmin = f2cmin(*m,*n);
1001 /* Computing MIN */
1002     i__1 = *kl, i__2 = *m - 1;
1003     llb = f2cmin(i__1,i__2);
1004 /* Computing MIN */
1005     i__1 = *ku, i__2 = *n - 1;
1006     uub = f2cmin(i__1,i__2);
1007 /* Computing MIN */
1008     i__1 = *m, i__2 = *n + llb;
1009     mr = f2cmin(i__1,i__2);
1010 /* Computing MIN */
1011     i__1 = *n, i__2 = *m + uub;
1012     nc = f2cmin(i__1,i__2);
1013
1014     if (ipack == 5 || ipack == 6) {
1015         minlda = uub + 1;
1016     } else if (ipack == 7) {
1017         minlda = llb + uub + 1;
1018     } else {
1019         minlda = *m;
1020     }
1021
1022 /*     Use Givens rotation method if bandwidth small enough, */
1023 /*     or if LDA is too small to store the matrix unpacked. */
1024
1025     givens = FALSE_;
1026     if (isym == 1) {
1027 /* Computing MAX */
1028         i__1 = 1, i__2 = mr + nc;
1029         if ((real) (llb + uub) < (real) f2cmax(i__1,i__2) * .3f) {
1030             givens = TRUE_;
1031         }
1032     } else {
1033         if (llb << 1 < *m) {
1034             givens = TRUE_;
1035         }
1036     }
1037     if (*lda < *m && *lda >= minlda) {
1038         givens = TRUE_;
1039     }
1040
1041 /*     Set INFO if an error */
1042
1043     if (*m < 0) {
1044         *info = -1;
1045     } else if (*m != *n && isym != 1) {
1046         *info = -1;
1047     } else if (*n < 0) {
1048         *info = -2;
1049     } else if (idist == -1) {
1050         *info = -3;
1051     } else if (isym == -1) {
1052         *info = -5;
1053     } else if (abs(*mode) > 6) {
1054         *info = -7;
1055     } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) {
1056         *info = -8;
1057     } else if (*kl < 0) {
1058         *info = -10;
1059     } else if (*ku < 0 || isym != 1 && *kl != *ku) {
1060         *info = -11;
1061     } else if (ipack == -1 || isympk == 1 && isym == 1 || isympk == 2 && isym 
1062             == 1 && *kl > 0 || isympk == 3 && isym == 1 && *ku > 0 || isympk 
1063             != 0 && *m != *n) {
1064         *info = -12;
1065     } else if (*lda < f2cmax(1,minlda)) {
1066         *info = -14;
1067     }
1068
1069     if (*info != 0) {
1070         i__1 = -(*info);
1071         xerbla_("CLATMS", &i__1);
1072         return 0;
1073     }
1074
1075 /*     Initialize random number generator */
1076
1077     for (i__ = 1; i__ <= 4; ++i__) {
1078         iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
1079 /* L10: */
1080     }
1081
1082     if (iseed[4] % 2 != 1) {
1083         ++iseed[4];
1084     }
1085
1086 /*     2)      Set up D  if indicated. */
1087
1088 /*             Compute D according to COND and MODE */
1089
1090     slatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, &iinfo);
1091     if (iinfo != 0) {
1092         *info = 1;
1093         return 0;
1094     }
1095
1096 /*     Choose Top-Down if D is (apparently) increasing, */
1097 /*     Bottom-Up if D is (apparently) decreasing. */
1098
1099     if (abs(d__[1]) <= (r__1 = d__[mnmin], abs(r__1))) {
1100         topdwn = TRUE_;
1101     } else {
1102         topdwn = FALSE_;
1103     }
1104
1105     if (*mode != 0 && abs(*mode) != 6) {
1106
1107 /*        Scale by DMAX */
1108
1109         temp = abs(d__[1]);
1110         i__1 = mnmin;
1111         for (i__ = 2; i__ <= i__1; ++i__) {
1112 /* Computing MAX */
1113             r__2 = temp, r__3 = (r__1 = d__[i__], abs(r__1));
1114             temp = f2cmax(r__2,r__3);
1115 /* L20: */
1116         }
1117
1118         if (temp > 0.f) {
1119             alpha = *dmax__ / temp;
1120         } else {
1121             *info = 2;
1122             return 0;
1123         }
1124
1125         sscal_(&mnmin, &alpha, &d__[1], &c__1);
1126
1127     }
1128
1129     claset_("Full", lda, n, &c_b1, &c_b1, &a[a_offset], lda);
1130
1131 /*     3)      Generate Banded Matrix using Givens rotations. */
1132 /*             Also the special case of UUB=LLB=0 */
1133
1134 /*               Compute Addressing constants to cover all */
1135 /*               storage formats.  Whether GE, HE, SY, GB, HB, or SB, */
1136 /*               upper or lower triangle or both, */
1137 /*               the (i,j)-th element is in */
1138 /*               A( i - ISKEW*j + IOFFST, j ) */
1139
1140     if (ipack > 4) {
1141         ilda = *lda - 1;
1142         iskew = 1;
1143         if (ipack > 5) {
1144             ioffst = uub + 1;
1145         } else {
1146             ioffst = 1;
1147         }
1148     } else {
1149         ilda = *lda;
1150         iskew = 0;
1151         ioffst = 0;
1152     }
1153
1154 /*     IPACKG is the format that the matrix is generated in. If this is */
1155 /*     different from IPACK, then the matrix must be repacked at the */
1156 /*     end.  It also signals how to compute the norm, for scaling. */
1157
1158     ipackg = 0;
1159
1160 /*     Diagonal Matrix -- We are done, unless it */
1161 /*     is to be stored HP/SP/PP/TP (PACK='R' or 'C') */
1162
1163     if (llb == 0 && uub == 0) {
1164         i__1 = mnmin;
1165         for (j = 1; j <= i__1; ++j) {
1166             i__2 = (1 - iskew) * j + ioffst + j * a_dim1;
1167             i__3 = j;
1168             q__1.r = d__[i__3], q__1.i = 0.f;
1169             a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1170 /* L30: */
1171         }
1172
1173         if (ipack <= 2 || ipack >= 5) {
1174             ipackg = ipack;
1175         }
1176
1177     } else if (givens) {
1178
1179 /*        Check whether to use Givens rotations, */
1180 /*        Householder transformations, or nothing. */
1181
1182         if (isym == 1) {
1183
1184 /*           Non-symmetric -- A = U D V */
1185
1186             if (ipack > 4) {
1187                 ipackg = ipack;
1188             } else {
1189                 ipackg = 0;
1190             }
1191
1192             i__1 = mnmin;
1193             for (j = 1; j <= i__1; ++j) {
1194                 i__2 = (1 - iskew) * j + ioffst + j * a_dim1;
1195                 i__3 = j;
1196                 q__1.r = d__[i__3], q__1.i = 0.f;
1197                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1198 /* L40: */
1199             }
1200
1201             if (topdwn) {
1202                 jkl = 0;
1203                 i__1 = uub;
1204                 for (jku = 1; jku <= i__1; ++jku) {
1205
1206 /*                 Transform from bandwidth JKL, JKU-1 to JKL, JKU */
1207
1208 /*                 Last row actually rotated is M */
1209 /*                 Last column actually rotated is MIN( M+JKU, N ) */
1210
1211 /* Computing MIN */
1212                     i__3 = *m + jku;
1213                     i__2 = f2cmin(i__3,*n) + jkl - 1;
1214                     for (jr = 1; jr <= i__2; ++jr) {
1215                         extra.r = 0.f, extra.i = 0.f;
1216                         angle = slarnd_(&c__1, &iseed[1]) * 
1217                                 6.2831853071795864769252867663f;
1218                         r__1 = cos(angle);
1219                         //clarnd_(&q__2, &c__5, &iseed[1]);
1220                         q__2=clarnd_(&c__5, &iseed[1]);
1221                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1222                         c__.r = q__1.r, c__.i = q__1.i;
1223                         r__1 = sin(angle);
1224                         //clarnd_(&q__2, &c__5, &iseed[1]);
1225                         q__2=clarnd_(&c__5, &iseed[1]);
1226                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1227                         s.r = q__1.r, s.i = q__1.i;
1228 /* Computing MAX */
1229                         i__3 = 1, i__4 = jr - jkl;
1230                         icol = f2cmax(i__3,i__4);
1231                         if (jr < *m) {
1232 /* Computing MIN */
1233                             i__3 = *n, i__4 = jr + jku;
1234                             il = f2cmin(i__3,i__4) + 1 - icol;
1235                             L__1 = jr > jkl;
1236                             clarot_(&c_true, &L__1, &c_false, &il, &c__, &s, &
1237                                     a[jr - iskew * icol + ioffst + icol * 
1238                                     a_dim1], &ilda, &extra, &dummy);
1239                         }
1240
1241 /*                    Chase "EXTRA" back up */
1242
1243                         ir = jr;
1244                         ic = icol;
1245                         i__3 = -jkl - jku;
1246                         for (jch = jr - jkl; i__3 < 0 ? jch >= 1 : jch <= 1; 
1247                                 jch += i__3) {
1248                             if (ir < *m) {
1249                                 clartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst 
1250                                         + (ic + 1) * a_dim1], &extra, &realc, 
1251                                         &s, &dummy);
1252                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1253                                 q__1=clarnd_(&c__5, &iseed[1]);
1254                                 dummy.r = q__1.r, dummy.i = q__1.i;
1255                                 q__2.r = realc * dummy.r, q__2.i = realc * 
1256                                         dummy.i;
1257                                 r_cnjg(&q__1, &q__2);
1258                                 c__.r = q__1.r, c__.i = q__1.i;
1259                                 q__3.r = -s.r, q__3.i = -s.i;
1260                                 q__2.r = q__3.r * dummy.r - q__3.i * dummy.i, 
1261                                         q__2.i = q__3.r * dummy.i + q__3.i * 
1262                                         dummy.r;
1263                                 r_cnjg(&q__1, &q__2);
1264                                 s.r = q__1.r, s.i = q__1.i;
1265                             }
1266 /* Computing MAX */
1267                             i__4 = 1, i__5 = jch - jku;
1268                             irow = f2cmax(i__4,i__5);
1269                             il = ir + 2 - irow;
1270                             ctemp.r = 0.f, ctemp.i = 0.f;
1271                             iltemp = jch > jku;
1272                             clarot_(&c_false, &iltemp, &c_true, &il, &c__, &s,
1273                                      &a[irow - iskew * ic + ioffst + ic * 
1274                                     a_dim1], &ilda, &ctemp, &extra);
1275                             if (iltemp) {
1276                                 clartg_(&a[irow + 1 - iskew * (ic + 1) + 
1277                                         ioffst + (ic + 1) * a_dim1], &ctemp, &
1278                                         realc, &s, &dummy);
1279                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1280                                 q__1=clarnd_(&c__5, &iseed[1]);
1281                                 dummy.r = q__1.r, dummy.i = q__1.i;
1282                                 q__2.r = realc * dummy.r, q__2.i = realc * 
1283                                         dummy.i;
1284                                 r_cnjg(&q__1, &q__2);
1285                                 c__.r = q__1.r, c__.i = q__1.i;
1286                                 q__3.r = -s.r, q__3.i = -s.i;
1287                                 q__2.r = q__3.r * dummy.r - q__3.i * dummy.i, 
1288                                         q__2.i = q__3.r * dummy.i + q__3.i * 
1289                                         dummy.r;
1290                                 r_cnjg(&q__1, &q__2);
1291                                 s.r = q__1.r, s.i = q__1.i;
1292
1293 /* Computing MAX */
1294                                 i__4 = 1, i__5 = jch - jku - jkl;
1295                                 icol = f2cmax(i__4,i__5);
1296                                 il = ic + 2 - icol;
1297                                 extra.r = 0.f, extra.i = 0.f;
1298                                 L__1 = jch > jku + jkl;
1299                                 clarot_(&c_true, &L__1, &c_true, &il, &c__, &
1300                                         s, &a[irow - iskew * icol + ioffst + 
1301                                         icol * a_dim1], &ilda, &extra, &ctemp)
1302                                         ;
1303                                 ic = icol;
1304                                 ir = irow;
1305                             }
1306 /* L50: */
1307                         }
1308 /* L60: */
1309                     }
1310 /* L70: */
1311                 }
1312
1313                 jku = uub;
1314                 i__1 = llb;
1315                 for (jkl = 1; jkl <= i__1; ++jkl) {
1316
1317 /*                 Transform from bandwidth JKL-1, JKU to JKL, JKU */
1318
1319 /* Computing MIN */
1320                     i__3 = *n + jkl;
1321                     i__2 = f2cmin(i__3,*m) + jku - 1;
1322                     for (jc = 1; jc <= i__2; ++jc) {
1323                         extra.r = 0.f, extra.i = 0.f;
1324                         angle = slarnd_(&c__1, &iseed[1]) * 
1325                                 6.2831853071795864769252867663f;
1326                         r__1 = cos(angle);
1327                         //clarnd_(&q__2, &c__5, &iseed[1]);
1328                         q__2=clarnd_(&c__5, &iseed[1]);
1329                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1330                         c__.r = q__1.r, c__.i = q__1.i;
1331                         r__1 = sin(angle);
1332                         //clarnd_(&q__2, &c__5, &iseed[1]);
1333                         q__2=clarnd_(&c__5, &iseed[1]);
1334                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1335                         s.r = q__1.r, s.i = q__1.i;
1336 /* Computing MAX */
1337                         i__3 = 1, i__4 = jc - jku;
1338                         irow = f2cmax(i__3,i__4);
1339                         if (jc < *n) {
1340 /* Computing MIN */
1341                             i__3 = *m, i__4 = jc + jkl;
1342                             il = f2cmin(i__3,i__4) + 1 - irow;
1343                             L__1 = jc > jku;
1344                             clarot_(&c_false, &L__1, &c_false, &il, &c__, &s, 
1345                                     &a[irow - iskew * jc + ioffst + jc * 
1346                                     a_dim1], &ilda, &extra, &dummy);
1347                         }
1348
1349 /*                    Chase "EXTRA" back up */
1350
1351                         ic = jc;
1352                         ir = irow;
1353                         i__3 = -jkl - jku;
1354                         for (jch = jc - jku; i__3 < 0 ? jch >= 1 : jch <= 1; 
1355                                 jch += i__3) {
1356                             if (ic < *n) {
1357                                 clartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst 
1358                                         + (ic + 1) * a_dim1], &extra, &realc, 
1359                                         &s, &dummy);
1360                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1361                                 q__1=clarnd_(&c__5, &iseed[1]);
1362                                 dummy.r = q__1.r, dummy.i = q__1.i;
1363                                 q__2.r = realc * dummy.r, q__2.i = realc * 
1364                                         dummy.i;
1365                                 r_cnjg(&q__1, &q__2);
1366                                 c__.r = q__1.r, c__.i = q__1.i;
1367                                 q__3.r = -s.r, q__3.i = -s.i;
1368                                 q__2.r = q__3.r * dummy.r - q__3.i * dummy.i, 
1369                                         q__2.i = q__3.r * dummy.i + q__3.i * 
1370                                         dummy.r;
1371                                 r_cnjg(&q__1, &q__2);
1372                                 s.r = q__1.r, s.i = q__1.i;
1373                             }
1374 /* Computing MAX */
1375                             i__4 = 1, i__5 = jch - jkl;
1376                             icol = f2cmax(i__4,i__5);
1377                             il = ic + 2 - icol;
1378                             ctemp.r = 0.f, ctemp.i = 0.f;
1379                             iltemp = jch > jkl;
1380                             clarot_(&c_true, &iltemp, &c_true, &il, &c__, &s, 
1381                                     &a[ir - iskew * icol + ioffst + icol * 
1382                                     a_dim1], &ilda, &ctemp, &extra);
1383                             if (iltemp) {
1384                                 clartg_(&a[ir + 1 - iskew * (icol + 1) + 
1385                                         ioffst + (icol + 1) * a_dim1], &ctemp,
1386                                          &realc, &s, &dummy);
1387                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1388                                 q__1=clarnd_(&c__5, &iseed[1]);
1389                                 dummy.r = q__1.r, dummy.i = q__1.i;
1390                                 q__2.r = realc * dummy.r, q__2.i = realc * 
1391                                         dummy.i;
1392                                 r_cnjg(&q__1, &q__2);
1393                                 c__.r = q__1.r, c__.i = q__1.i;
1394                                 q__3.r = -s.r, q__3.i = -s.i;
1395                                 q__2.r = q__3.r * dummy.r - q__3.i * dummy.i, 
1396                                         q__2.i = q__3.r * dummy.i + q__3.i * 
1397                                         dummy.r;
1398                                 r_cnjg(&q__1, &q__2);
1399                                 s.r = q__1.r, s.i = q__1.i;
1400 /* Computing MAX */
1401                                 i__4 = 1, i__5 = jch - jkl - jku;
1402                                 irow = f2cmax(i__4,i__5);
1403                                 il = ir + 2 - irow;
1404                                 extra.r = 0.f, extra.i = 0.f;
1405                                 L__1 = jch > jkl + jku;
1406                                 clarot_(&c_false, &L__1, &c_true, &il, &c__, &
1407                                         s, &a[irow - iskew * icol + ioffst + 
1408                                         icol * a_dim1], &ilda, &extra, &ctemp)
1409                                         ;
1410                                 ic = icol;
1411                                 ir = irow;
1412                             }
1413 /* L80: */
1414                         }
1415 /* L90: */
1416                     }
1417 /* L100: */
1418                 }
1419
1420             } else {
1421
1422 /*              Bottom-Up -- Start at the bottom right. */
1423
1424                 jkl = 0;
1425                 i__1 = uub;
1426                 for (jku = 1; jku <= i__1; ++jku) {
1427
1428 /*                 Transform from bandwidth JKL, JKU-1 to JKL, JKU */
1429
1430 /*                 First row actually rotated is M */
1431 /*                 First column actually rotated is MIN( M+JKU, N ) */
1432
1433 /* Computing MIN */
1434                     i__2 = *m, i__3 = *n + jkl;
1435                     iendch = f2cmin(i__2,i__3) - 1;
1436 /* Computing MIN */
1437                     i__2 = *m + jku;
1438                     i__3 = 1 - jkl;
1439                     for (jc = f2cmin(i__2,*n) - 1; jc >= i__3; --jc) {
1440                         extra.r = 0.f, extra.i = 0.f;
1441                         angle = slarnd_(&c__1, &iseed[1]) * 
1442                                 6.2831853071795864769252867663f;
1443                         r__1 = cos(angle);
1444                         //clarnd_(&q__2, &c__5, &iseed[1]);
1445                         q__2=clarnd_(&c__5, &iseed[1]);
1446                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1447                         c__.r = q__1.r, c__.i = q__1.i;
1448                         r__1 = sin(angle);
1449                         //clarnd_(&q__2, &c__5, &iseed[1]);
1450                         q__2=clarnd_(&c__5, &iseed[1]);
1451                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1452                         s.r = q__1.r, s.i = q__1.i;
1453 /* Computing MAX */
1454                         i__2 = 1, i__4 = jc - jku + 1;
1455                         irow = f2cmax(i__2,i__4);
1456                         if (jc > 0) {
1457 /* Computing MIN */
1458                             i__2 = *m, i__4 = jc + jkl + 1;
1459                             il = f2cmin(i__2,i__4) + 1 - irow;
1460                             L__1 = jc + jkl < *m;
1461                             clarot_(&c_false, &c_false, &L__1, &il, &c__, &s, 
1462                                     &a[irow - iskew * jc + ioffst + jc * 
1463                                     a_dim1], &ilda, &dummy, &extra);
1464                         }
1465
1466 /*                    Chase "EXTRA" back down */
1467
1468                         ic = jc;
1469                         i__2 = iendch;
1470                         i__4 = jkl + jku;
1471                         for (jch = jc + jkl; i__4 < 0 ? jch >= i__2 : jch <= 
1472                                 i__2; jch += i__4) {
1473                             ilextr = ic > 0;
1474                             if (ilextr) {
1475                                 clartg_(&a[jch - iskew * ic + ioffst + ic * 
1476                                         a_dim1], &extra, &realc, &s, &dummy);
1477                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1478                                 q__1=clarnd_(&c__5, &iseed[1]);
1479                                 dummy.r = q__1.r, dummy.i = q__1.i;
1480                                 q__1.r = realc * dummy.r, q__1.i = realc * 
1481                                         dummy.i;
1482                                 c__.r = q__1.r, c__.i = q__1.i;
1483                                 q__1.r = s.r * dummy.r - s.i * dummy.i, 
1484                                         q__1.i = s.r * dummy.i + s.i * 
1485                                         dummy.r;
1486                                 s.r = q__1.r, s.i = q__1.i;
1487                             }
1488                             ic = f2cmax(1,ic);
1489 /* Computing MIN */
1490                             i__5 = *n - 1, i__6 = jch + jku;
1491                             icol = f2cmin(i__5,i__6);
1492                             iltemp = jch + jku < *n;
1493                             ctemp.r = 0.f, ctemp.i = 0.f;
1494                             i__5 = icol + 2 - ic;
1495                             clarot_(&c_true, &ilextr, &iltemp, &i__5, &c__, &
1496                                     s, &a[jch - iskew * ic + ioffst + ic * 
1497                                     a_dim1], &ilda, &extra, &ctemp);
1498                             if (iltemp) {
1499                                 clartg_(&a[jch - iskew * icol + ioffst + icol 
1500                                         * a_dim1], &ctemp, &realc, &s, &dummy)
1501                                         ;
1502                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1503                                 q__1=clarnd_(&c__5, &iseed[1]);
1504                                 dummy.r = q__1.r, dummy.i = q__1.i;
1505                                 q__1.r = realc * dummy.r, q__1.i = realc * 
1506                                         dummy.i;
1507                                 c__.r = q__1.r, c__.i = q__1.i;
1508                                 q__1.r = s.r * dummy.r - s.i * dummy.i, 
1509                                         q__1.i = s.r * dummy.i + s.i * 
1510                                         dummy.r;
1511                                 s.r = q__1.r, s.i = q__1.i;
1512 /* Computing MIN */
1513                                 i__5 = iendch, i__6 = jch + jkl + jku;
1514                                 il = f2cmin(i__5,i__6) + 2 - jch;
1515                                 extra.r = 0.f, extra.i = 0.f;
1516                                 L__1 = jch + jkl + jku <= iendch;
1517                                 clarot_(&c_false, &c_true, &L__1, &il, &c__, &
1518                                         s, &a[jch - iskew * icol + ioffst + 
1519                                         icol * a_dim1], &ilda, &ctemp, &extra)
1520                                         ;
1521                                 ic = icol;
1522                             }
1523 /* L110: */
1524                         }
1525 /* L120: */
1526                     }
1527 /* L130: */
1528                 }
1529
1530                 jku = uub;
1531                 i__1 = llb;
1532                 for (jkl = 1; jkl <= i__1; ++jkl) {
1533
1534 /*                 Transform from bandwidth JKL-1, JKU to JKL, JKU */
1535
1536 /*                 First row actually rotated is MIN( N+JKL, M ) */
1537 /*                 First column actually rotated is N */
1538
1539 /* Computing MIN */
1540                     i__3 = *n, i__4 = *m + jku;
1541                     iendch = f2cmin(i__3,i__4) - 1;
1542 /* Computing MIN */
1543                     i__3 = *n + jkl;
1544                     i__4 = 1 - jku;
1545                     for (jr = f2cmin(i__3,*m) - 1; jr >= i__4; --jr) {
1546                         extra.r = 0.f, extra.i = 0.f;
1547                         angle = slarnd_(&c__1, &iseed[1]) * 
1548                                 6.2831853071795864769252867663f;
1549                         r__1 = cos(angle);
1550                         //clarnd_(&q__2, &c__5, &iseed[1]);
1551                         q__2=clarnd_(&c__5, &iseed[1]);
1552                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1553                         c__.r = q__1.r, c__.i = q__1.i;
1554                         r__1 = sin(angle);
1555                         //clarnd_(&q__2, &c__5, &iseed[1]);
1556                         q__2=clarnd_(&c__5, &iseed[1]);
1557                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1558                         s.r = q__1.r, s.i = q__1.i;
1559 /* Computing MAX */
1560                         i__3 = 1, i__2 = jr - jkl + 1;
1561                         icol = f2cmax(i__3,i__2);
1562                         if (jr > 0) {
1563 /* Computing MIN */
1564                             i__3 = *n, i__2 = jr + jku + 1;
1565                             il = f2cmin(i__3,i__2) + 1 - icol;
1566                             L__1 = jr + jku < *n;
1567                             clarot_(&c_true, &c_false, &L__1, &il, &c__, &s, &
1568                                     a[jr - iskew * icol + ioffst + icol * 
1569                                     a_dim1], &ilda, &dummy, &extra);
1570                         }
1571
1572 /*                    Chase "EXTRA" back down */
1573
1574                         ir = jr;
1575                         i__3 = iendch;
1576                         i__2 = jkl + jku;
1577                         for (jch = jr + jku; i__2 < 0 ? jch >= i__3 : jch <= 
1578                                 i__3; jch += i__2) {
1579                             ilextr = ir > 0;
1580                             if (ilextr) {
1581                                 clartg_(&a[ir - iskew * jch + ioffst + jch * 
1582                                         a_dim1], &extra, &realc, &s, &dummy);
1583                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1584                                 q__1=clarnd_(&c__5, &iseed[1]);
1585                                 dummy.r = q__1.r, dummy.i = q__1.i;
1586                                 q__1.r = realc * dummy.r, q__1.i = realc * 
1587                                         dummy.i;
1588                                 c__.r = q__1.r, c__.i = q__1.i;
1589                                 q__1.r = s.r * dummy.r - s.i * dummy.i, 
1590                                         q__1.i = s.r * dummy.i + s.i * 
1591                                         dummy.r;
1592                                 s.r = q__1.r, s.i = q__1.i;
1593                             }
1594                             ir = f2cmax(1,ir);
1595 /* Computing MIN */
1596                             i__5 = *m - 1, i__6 = jch + jkl;
1597                             irow = f2cmin(i__5,i__6);
1598                             iltemp = jch + jkl < *m;
1599                             ctemp.r = 0.f, ctemp.i = 0.f;
1600                             i__5 = irow + 2 - ir;
1601                             clarot_(&c_false, &ilextr, &iltemp, &i__5, &c__, &
1602                                     s, &a[ir - iskew * jch + ioffst + jch * 
1603                                     a_dim1], &ilda, &extra, &ctemp);
1604                             if (iltemp) {
1605                                 clartg_(&a[irow - iskew * jch + ioffst + jch *
1606                                          a_dim1], &ctemp, &realc, &s, &dummy);
1607                                 //clarnd_(&q__1, &c__5, &iseed[1]);
1608                                 q__1=clarnd_(&c__5, &iseed[1]);
1609                                 dummy.r = q__1.r, dummy.i = q__1.i;
1610                                 q__1.r = realc * dummy.r, q__1.i = realc * 
1611                                         dummy.i;
1612                                 c__.r = q__1.r, c__.i = q__1.i;
1613                                 q__1.r = s.r * dummy.r - s.i * dummy.i, 
1614                                         q__1.i = s.r * dummy.i + s.i * 
1615                                         dummy.r;
1616                                 s.r = q__1.r, s.i = q__1.i;
1617 /* Computing MIN */
1618                                 i__5 = iendch, i__6 = jch + jkl + jku;
1619                                 il = f2cmin(i__5,i__6) + 2 - jch;
1620                                 extra.r = 0.f, extra.i = 0.f;
1621                                 L__1 = jch + jkl + jku <= iendch;
1622                                 clarot_(&c_true, &c_true, &L__1, &il, &c__, &
1623                                         s, &a[irow - iskew * jch + ioffst + 
1624                                         jch * a_dim1], &ilda, &ctemp, &extra);
1625                                 ir = irow;
1626                             }
1627 /* L140: */
1628                         }
1629 /* L150: */
1630                     }
1631 /* L160: */
1632                 }
1633
1634             }
1635
1636         } else {
1637
1638 /*           Symmetric -- A = U D U' */
1639 /*           Hermitian -- A = U D U* */
1640
1641             ipackg = ipack;
1642             ioffg = ioffst;
1643
1644             if (topdwn) {
1645
1646 /*              Top-Down -- Generate Upper triangle only */
1647
1648                 if (ipack >= 5) {
1649                     ipackg = 6;
1650                     ioffg = uub + 1;
1651                 } else {
1652                     ipackg = 1;
1653                 }
1654
1655                 i__1 = mnmin;
1656                 for (j = 1; j <= i__1; ++j) {
1657                     i__4 = (1 - iskew) * j + ioffg + j * a_dim1;
1658                     i__2 = j;
1659                     q__1.r = d__[i__2], q__1.i = 0.f;
1660                     a[i__4].r = q__1.r, a[i__4].i = q__1.i;
1661 /* L170: */
1662                 }
1663
1664                 i__1 = uub;
1665                 for (k = 1; k <= i__1; ++k) {
1666                     i__4 = *n - 1;
1667                     for (jc = 1; jc <= i__4; ++jc) {
1668 /* Computing MAX */
1669                         i__2 = 1, i__3 = jc - k;
1670                         irow = f2cmax(i__2,i__3);
1671 /* Computing MIN */
1672                         i__2 = jc + 1, i__3 = k + 2;
1673                         il = f2cmin(i__2,i__3);
1674                         extra.r = 0.f, extra.i = 0.f;
1675                         i__2 = jc - iskew * (jc + 1) + ioffg + (jc + 1) * 
1676                                 a_dim1;
1677                         ctemp.r = a[i__2].r, ctemp.i = a[i__2].i;
1678                         angle = slarnd_(&c__1, &iseed[1]) * 
1679                                 6.2831853071795864769252867663f;
1680                         r__1 = cos(angle);
1681                         //clarnd_(&q__2, &c__5, &iseed[1]);
1682                         q__2=clarnd_(&c__5, &iseed[1]);
1683                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1684                         c__.r = q__1.r, c__.i = q__1.i;
1685                         r__1 = sin(angle);
1686                         //clarnd_(&q__2, &c__5, &iseed[1]);
1687                         q__2=clarnd_(&c__5, &iseed[1]);
1688                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1689                         s.r = q__1.r, s.i = q__1.i;
1690                         if (csym) {
1691                             ct.r = c__.r, ct.i = c__.i;
1692                             st.r = s.r, st.i = s.i;
1693                         } else {
1694                             r_cnjg(&q__1, &ctemp);
1695                             ctemp.r = q__1.r, ctemp.i = q__1.i;
1696                             r_cnjg(&q__1, &c__);
1697                             ct.r = q__1.r, ct.i = q__1.i;
1698                             r_cnjg(&q__1, &s);
1699                             st.r = q__1.r, st.i = q__1.i;
1700                         }
1701                         L__1 = jc > k;
1702                         clarot_(&c_false, &L__1, &c_true, &il, &c__, &s, &a[
1703                                 irow - iskew * jc + ioffg + jc * a_dim1], &
1704                                 ilda, &extra, &ctemp);
1705 /* Computing MIN */
1706                         i__3 = k, i__5 = *n - jc;
1707                         i__2 = f2cmin(i__3,i__5) + 1;
1708                         clarot_(&c_true, &c_true, &c_false, &i__2, &ct, &st, &
1709                                 a[(1 - iskew) * jc + ioffg + jc * a_dim1], &
1710                                 ilda, &ctemp, &dummy);
1711
1712 /*                    Chase EXTRA back up the matrix */
1713
1714                         icol = jc;
1715                         i__2 = -k;
1716                         for (jch = jc - k; i__2 < 0 ? jch >= 1 : jch <= 1; 
1717                                 jch += i__2) {
1718                             clartg_(&a[jch + 1 - iskew * (icol + 1) + ioffg + 
1719                                     (icol + 1) * a_dim1], &extra, &realc, &s, 
1720                                     &dummy);
1721                             //clarnd_(&q__1, &c__5, &iseed[1]);
1722                             q__1=clarnd_(&c__5, &iseed[1]);
1723                             dummy.r = q__1.r, dummy.i = q__1.i;
1724                             q__2.r = realc * dummy.r, q__2.i = realc * 
1725                                     dummy.i;
1726                             r_cnjg(&q__1, &q__2);
1727                             c__.r = q__1.r, c__.i = q__1.i;
1728                             q__3.r = -s.r, q__3.i = -s.i;
1729                             q__2.r = q__3.r * dummy.r - q__3.i * dummy.i, 
1730                                     q__2.i = q__3.r * dummy.i + q__3.i * 
1731                                     dummy.r;
1732                             r_cnjg(&q__1, &q__2);
1733                             s.r = q__1.r, s.i = q__1.i;
1734                             i__3 = jch - iskew * (jch + 1) + ioffg + (jch + 1)
1735                                      * a_dim1;
1736                             ctemp.r = a[i__3].r, ctemp.i = a[i__3].i;
1737                             if (csym) {
1738                                 ct.r = c__.r, ct.i = c__.i;
1739                                 st.r = s.r, st.i = s.i;
1740                             } else {
1741                                 r_cnjg(&q__1, &ctemp);
1742                                 ctemp.r = q__1.r, ctemp.i = q__1.i;
1743                                 r_cnjg(&q__1, &c__);
1744                                 ct.r = q__1.r, ct.i = q__1.i;
1745                                 r_cnjg(&q__1, &s);
1746                                 st.r = q__1.r, st.i = q__1.i;
1747                             }
1748                             i__3 = k + 2;
1749                             clarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
1750                                     s, &a[(1 - iskew) * jch + ioffg + jch * 
1751                                     a_dim1], &ilda, &ctemp, &extra);
1752 /* Computing MAX */
1753                             i__3 = 1, i__5 = jch - k;
1754                             irow = f2cmax(i__3,i__5);
1755 /* Computing MIN */
1756                             i__3 = jch + 1, i__5 = k + 2;
1757                             il = f2cmin(i__3,i__5);
1758                             extra.r = 0.f, extra.i = 0.f;
1759                             L__1 = jch > k;
1760                             clarot_(&c_false, &L__1, &c_true, &il, &ct, &st, &
1761                                     a[irow - iskew * jch + ioffg + jch * 
1762                                     a_dim1], &ilda, &extra, &ctemp);
1763                             icol = jch;
1764 /* L180: */
1765                         }
1766 /* L190: */
1767                     }
1768 /* L200: */
1769                 }
1770
1771 /*              If we need lower triangle, copy from upper. Note that */
1772 /*              the order of copying is chosen to work for 'q' -> 'b' */
1773
1774                 if (ipack != ipackg && ipack != 3) {
1775                     i__1 = *n;
1776                     for (jc = 1; jc <= i__1; ++jc) {
1777                         irow = ioffst - iskew * jc;
1778                         if (csym) {
1779 /* Computing MIN */
1780                             i__2 = *n, i__3 = jc + uub;
1781                             i__4 = f2cmin(i__2,i__3);
1782                             for (jr = jc; jr <= i__4; ++jr) {
1783                                 i__2 = jr + irow + jc * a_dim1;
1784                                 i__3 = jc - iskew * jr + ioffg + jr * a_dim1;
1785                                 a[i__2].r = a[i__3].r, a[i__2].i = a[i__3].i;
1786 /* L210: */
1787                             }
1788                         } else {
1789 /* Computing MIN */
1790                             i__2 = *n, i__3 = jc + uub;
1791                             i__4 = f2cmin(i__2,i__3);
1792                             for (jr = jc; jr <= i__4; ++jr) {
1793                                 i__2 = jr + irow + jc * a_dim1;
1794                                 r_cnjg(&q__1, &a[jc - iskew * jr + ioffg + jr 
1795                                         * a_dim1]);
1796                                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1797 /* L220: */
1798                             }
1799                         }
1800 /* L230: */
1801                     }
1802                     if (ipack == 5) {
1803                         i__1 = *n;
1804                         for (jc = *n - uub + 1; jc <= i__1; ++jc) {
1805                             i__4 = uub + 1;
1806                             for (jr = *n + 2 - jc; jr <= i__4; ++jr) {
1807                                 i__2 = jr + jc * a_dim1;
1808                                 a[i__2].r = 0.f, a[i__2].i = 0.f;
1809 /* L240: */
1810                             }
1811 /* L250: */
1812                         }
1813                     }
1814                     if (ipackg == 6) {
1815                         ipackg = ipack;
1816                     } else {
1817                         ipackg = 0;
1818                     }
1819                 }
1820             } else {
1821
1822 /*              Bottom-Up -- Generate Lower triangle only */
1823
1824                 if (ipack >= 5) {
1825                     ipackg = 5;
1826                     if (ipack == 6) {
1827                         ioffg = 1;
1828                     }
1829                 } else {
1830                     ipackg = 2;
1831                 }
1832
1833                 i__1 = mnmin;
1834                 for (j = 1; j <= i__1; ++j) {
1835                     i__4 = (1 - iskew) * j + ioffg + j * a_dim1;
1836                     i__2 = j;
1837                     q__1.r = d__[i__2], q__1.i = 0.f;
1838                     a[i__4].r = q__1.r, a[i__4].i = q__1.i;
1839 /* L260: */
1840                 }
1841
1842                 i__1 = uub;
1843                 for (k = 1; k <= i__1; ++k) {
1844                     for (jc = *n - 1; jc >= 1; --jc) {
1845 /* Computing MIN */
1846                         i__4 = *n + 1 - jc, i__2 = k + 2;
1847                         il = f2cmin(i__4,i__2);
1848                         extra.r = 0.f, extra.i = 0.f;
1849                         i__4 = (1 - iskew) * jc + 1 + ioffg + jc * a_dim1;
1850                         ctemp.r = a[i__4].r, ctemp.i = a[i__4].i;
1851                         angle = slarnd_(&c__1, &iseed[1]) * 
1852                                 6.2831853071795864769252867663f;
1853                         r__1 = cos(angle);
1854                         //clarnd_(&q__2, &c__5, &iseed[1]);
1855                         q__2=clarnd_(&c__5, &iseed[1]);
1856                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1857                         c__.r = q__1.r, c__.i = q__1.i;
1858                         r__1 = sin(angle);
1859                         //clarnd_(&q__2, &c__5, &iseed[1]);
1860                         q__2=clarnd_(&c__5, &iseed[1]);
1861                         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
1862                         s.r = q__1.r, s.i = q__1.i;
1863                         if (csym) {
1864                             ct.r = c__.r, ct.i = c__.i;
1865                             st.r = s.r, st.i = s.i;
1866                         } else {
1867                             r_cnjg(&q__1, &ctemp);
1868                             ctemp.r = q__1.r, ctemp.i = q__1.i;
1869                             r_cnjg(&q__1, &c__);
1870                             ct.r = q__1.r, ct.i = q__1.i;
1871                             r_cnjg(&q__1, &s);
1872                             st.r = q__1.r, st.i = q__1.i;
1873                         }
1874                         L__1 = *n - jc > k;
1875                         clarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &a[(
1876                                 1 - iskew) * jc + ioffg + jc * a_dim1], &ilda,
1877                                  &ctemp, &extra);
1878 /* Computing MAX */
1879                         i__4 = 1, i__2 = jc - k + 1;
1880                         icol = f2cmax(i__4,i__2);
1881                         i__4 = jc + 2 - icol;
1882                         clarot_(&c_true, &c_false, &c_true, &i__4, &ct, &st, &
1883                                 a[jc - iskew * icol + ioffg + icol * a_dim1], 
1884                                 &ilda, &dummy, &ctemp);
1885
1886 /*                    Chase EXTRA back down the matrix */
1887
1888                         icol = jc;
1889                         i__4 = *n - 1;
1890                         i__2 = k;
1891                         for (jch = jc + k; i__2 < 0 ? jch >= i__4 : jch <= 
1892                                 i__4; jch += i__2) {
1893                             clartg_(&a[jch - iskew * icol + ioffg + icol * 
1894                                     a_dim1], &extra, &realc, &s, &dummy);
1895                             //clarnd_(&q__1, &c__5, &iseed[1]);
1896                             q__1=clarnd_(&c__5, &iseed[1]);
1897                             dummy.r = q__1.r, dummy.i = q__1.i;
1898                             q__1.r = realc * dummy.r, q__1.i = realc * 
1899                                     dummy.i;
1900                             c__.r = q__1.r, c__.i = q__1.i;
1901                             q__1.r = s.r * dummy.r - s.i * dummy.i, q__1.i = 
1902                                     s.r * dummy.i + s.i * dummy.r;
1903                             s.r = q__1.r, s.i = q__1.i;
1904                             i__3 = (1 - iskew) * jch + 1 + ioffg + jch * 
1905                                     a_dim1;
1906                             ctemp.r = a[i__3].r, ctemp.i = a[i__3].i;
1907                             if (csym) {
1908                                 ct.r = c__.r, ct.i = c__.i;
1909                                 st.r = s.r, st.i = s.i;
1910                             } else {
1911                                 r_cnjg(&q__1, &ctemp);
1912                                 ctemp.r = q__1.r, ctemp.i = q__1.i;
1913                                 r_cnjg(&q__1, &c__);
1914                                 ct.r = q__1.r, ct.i = q__1.i;
1915                                 r_cnjg(&q__1, &s);
1916                                 st.r = q__1.r, st.i = q__1.i;
1917                             }
1918                             i__3 = k + 2;
1919                             clarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
1920                                     s, &a[jch - iskew * icol + ioffg + icol * 
1921                                     a_dim1], &ilda, &extra, &ctemp);
1922 /* Computing MIN */
1923                             i__3 = *n + 1 - jch, i__5 = k + 2;
1924                             il = f2cmin(i__3,i__5);
1925                             extra.r = 0.f, extra.i = 0.f;
1926                             L__1 = *n - jch > k;
1927                             clarot_(&c_false, &c_true, &L__1, &il, &ct, &st, &
1928                                     a[(1 - iskew) * jch + ioffg + jch * 
1929                                     a_dim1], &ilda, &ctemp, &extra);
1930                             icol = jch;
1931 /* L270: */
1932                         }
1933 /* L280: */
1934                     }
1935 /* L290: */
1936                 }
1937
1938 /*              If we need upper triangle, copy from lower. Note that */
1939 /*              the order of copying is chosen to work for 'b' -> 'q' */
1940
1941                 if (ipack != ipackg && ipack != 4) {
1942                     for (jc = *n; jc >= 1; --jc) {
1943                         irow = ioffst - iskew * jc;
1944                         if (csym) {
1945 /* Computing MAX */
1946                             i__2 = 1, i__4 = jc - uub;
1947                             i__1 = f2cmax(i__2,i__4);
1948                             for (jr = jc; jr >= i__1; --jr) {
1949                                 i__2 = jr + irow + jc * a_dim1;
1950                                 i__4 = jc - iskew * jr + ioffg + jr * a_dim1;
1951                                 a[i__2].r = a[i__4].r, a[i__2].i = a[i__4].i;
1952 /* L300: */
1953                             }
1954                         } else {
1955 /* Computing MAX */
1956                             i__2 = 1, i__4 = jc - uub;
1957                             i__1 = f2cmax(i__2,i__4);
1958                             for (jr = jc; jr >= i__1; --jr) {
1959                                 i__2 = jr + irow + jc * a_dim1;
1960                                 r_cnjg(&q__1, &a[jc - iskew * jr + ioffg + jr 
1961                                         * a_dim1]);
1962                                 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1963 /* L310: */
1964                             }
1965                         }
1966 /* L320: */
1967                     }
1968                     if (ipack == 6) {
1969                         i__1 = uub;
1970                         for (jc = 1; jc <= i__1; ++jc) {
1971                             i__2 = uub + 1 - jc;
1972                             for (jr = 1; jr <= i__2; ++jr) {
1973                                 i__4 = jr + jc * a_dim1;
1974                                 a[i__4].r = 0.f, a[i__4].i = 0.f;
1975 /* L330: */
1976                             }
1977 /* L340: */
1978                         }
1979                     }
1980                     if (ipackg == 5) {
1981                         ipackg = ipack;
1982                     } else {
1983                         ipackg = 0;
1984                     }
1985                 }
1986             }
1987
1988 /*           Ensure that the diagonal is real if Hermitian */
1989
1990             if (! csym) {
1991                 i__1 = *n;
1992                 for (jc = 1; jc <= i__1; ++jc) {
1993                     irow = ioffst + (1 - iskew) * jc;
1994                     i__2 = irow + jc * a_dim1;
1995                     i__4 = irow + jc * a_dim1;
1996                     r__1 = a[i__4].r;
1997                     q__1.r = r__1, q__1.i = 0.f;
1998                     a[i__2].r = q__1.r, a[i__2].i = q__1.i;
1999 /* L350: */
2000                 }
2001             }
2002
2003         }
2004
2005     } else {
2006
2007 /*        4)      Generate Banded Matrix by first */
2008 /*                Rotating by random Unitary matrices, */
2009 /*                then reducing the bandwidth using Householder */
2010 /*                transformations. */
2011
2012 /*                Note: we should get here only if LDA .ge. N */
2013
2014         if (isym == 1) {
2015
2016 /*           Non-symmetric -- A = U D V */
2017
2018             clagge_(&mr, &nc, &llb, &uub, &d__[1], &a[a_offset], lda, &iseed[
2019                     1], &work[1], &iinfo);
2020         } else {
2021
2022 /*           Symmetric -- A = U D U' or */
2023 /*           Hermitian -- A = U D U* */
2024
2025             if (csym) {
2026                 clagsy_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[
2027                         1], &iinfo);
2028             } else {
2029                 claghe_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[
2030                         1], &iinfo);
2031             }
2032         }
2033
2034         if (iinfo != 0) {
2035             *info = 3;
2036             return 0;
2037         }
2038     }
2039
2040 /*     5)      Pack the matrix */
2041
2042     if (ipack != ipackg) {
2043         if (ipack == 1) {
2044
2045 /*           'U' -- Upper triangular, not packed */
2046
2047             i__1 = *m;
2048             for (j = 1; j <= i__1; ++j) {
2049                 i__2 = *m;
2050                 for (i__ = j + 1; i__ <= i__2; ++i__) {
2051                     i__4 = i__ + j * a_dim1;
2052                     a[i__4].r = 0.f, a[i__4].i = 0.f;
2053 /* L360: */
2054                 }
2055 /* L370: */
2056             }
2057
2058         } else if (ipack == 2) {
2059
2060 /*           'L' -- Lower triangular, not packed */
2061
2062             i__1 = *m;
2063             for (j = 2; j <= i__1; ++j) {
2064                 i__2 = j - 1;
2065                 for (i__ = 1; i__ <= i__2; ++i__) {
2066                     i__4 = i__ + j * a_dim1;
2067                     a[i__4].r = 0.f, a[i__4].i = 0.f;
2068 /* L380: */
2069                 }
2070 /* L390: */
2071             }
2072
2073         } else if (ipack == 3) {
2074
2075 /*           'C' -- Upper triangle packed Columnwise. */
2076
2077             icol = 1;
2078             irow = 0;
2079             i__1 = *m;
2080             for (j = 1; j <= i__1; ++j) {
2081                 i__2 = j;
2082                 for (i__ = 1; i__ <= i__2; ++i__) {
2083                     ++irow;
2084                     if (irow > *lda) {
2085                         irow = 1;
2086                         ++icol;
2087                     }
2088                     i__4 = irow + icol * a_dim1;
2089                     i__3 = i__ + j * a_dim1;
2090                     a[i__4].r = a[i__3].r, a[i__4].i = a[i__3].i;
2091 /* L400: */
2092                 }
2093 /* L410: */
2094             }
2095
2096         } else if (ipack == 4) {
2097
2098 /*           'R' -- Lower triangle packed Columnwise. */
2099
2100             icol = 1;
2101             irow = 0;
2102             i__1 = *m;
2103             for (j = 1; j <= i__1; ++j) {
2104                 i__2 = *m;
2105                 for (i__ = j; i__ <= i__2; ++i__) {
2106                     ++irow;
2107                     if (irow > *lda) {
2108                         irow = 1;
2109                         ++icol;
2110                     }
2111                     i__4 = irow + icol * a_dim1;
2112                     i__3 = i__ + j * a_dim1;
2113                     a[i__4].r = a[i__3].r, a[i__4].i = a[i__3].i;
2114 /* L420: */
2115                 }
2116 /* L430: */
2117             }
2118
2119         } else if (ipack >= 5) {
2120
2121 /*           'B' -- The lower triangle is packed as a band matrix. */
2122 /*           'Q' -- The upper triangle is packed as a band matrix. */
2123 /*           'Z' -- The whole matrix is packed as a band matrix. */
2124
2125             if (ipack == 5) {
2126                 uub = 0;
2127             }
2128             if (ipack == 6) {
2129                 llb = 0;
2130             }
2131
2132             i__1 = uub;
2133             for (j = 1; j <= i__1; ++j) {
2134 /* Computing MIN */
2135                 i__2 = j + llb;
2136                 for (i__ = f2cmin(i__2,*m); i__ >= 1; --i__) {
2137                     i__2 = i__ - j + uub + 1 + j * a_dim1;
2138                     i__4 = i__ + j * a_dim1;
2139                     a[i__2].r = a[i__4].r, a[i__2].i = a[i__4].i;
2140 /* L440: */
2141                 }
2142 /* L450: */
2143             }
2144
2145             i__1 = *n;
2146             for (j = uub + 2; j <= i__1; ++j) {
2147 /* Computing MIN */
2148                 i__4 = j + llb;
2149                 i__2 = f2cmin(i__4,*m);
2150                 for (i__ = j - uub; i__ <= i__2; ++i__) {
2151                     i__4 = i__ - j + uub + 1 + j * a_dim1;
2152                     i__3 = i__ + j * a_dim1;
2153                     a[i__4].r = a[i__3].r, a[i__4].i = a[i__3].i;
2154 /* L460: */
2155                 }
2156 /* L470: */
2157             }
2158         }
2159
2160 /*        If packed, zero out extraneous elements. */
2161
2162 /*        Symmetric/Triangular Packed -- */
2163 /*        zero out everything after A(IROW,ICOL) */
2164
2165         if (ipack == 3 || ipack == 4) {
2166             i__1 = *m;
2167             for (jc = icol; jc <= i__1; ++jc) {
2168                 i__2 = *lda;
2169                 for (jr = irow + 1; jr <= i__2; ++jr) {
2170                     i__4 = jr + jc * a_dim1;
2171                     a[i__4].r = 0.f, a[i__4].i = 0.f;
2172 /* L480: */
2173                 }
2174                 irow = 0;
2175 /* L490: */
2176             }
2177
2178         } else if (ipack >= 5) {
2179
2180 /*           Packed Band -- */
2181 /*              1st row is now in A( UUB+2-j, j), zero above it */
2182 /*              m-th row is now in A( M+UUB-j,j), zero below it */
2183 /*              last non-zero diagonal is now in A( UUB+LLB+1,j ), */
2184 /*                 zero below it, too. */
2185
2186             ir1 = uub + llb + 2;
2187             ir2 = uub + *m + 2;
2188             i__1 = *n;
2189             for (jc = 1; jc <= i__1; ++jc) {
2190                 i__2 = uub + 1 - jc;
2191                 for (jr = 1; jr <= i__2; ++jr) {
2192                     i__4 = jr + jc * a_dim1;
2193                     a[i__4].r = 0.f, a[i__4].i = 0.f;
2194 /* L500: */
2195                 }
2196 /* Computing MAX */
2197 /* Computing MIN */
2198                 i__3 = ir1, i__5 = ir2 - jc;
2199                 i__2 = 1, i__4 = f2cmin(i__3,i__5);
2200                 i__6 = *lda;
2201                 for (jr = f2cmax(i__2,i__4); jr <= i__6; ++jr) {
2202                     i__2 = jr + jc * a_dim1;
2203                     a[i__2].r = 0.f, a[i__2].i = 0.f;
2204 /* L510: */
2205                 }
2206 /* L520: */
2207             }
2208         }
2209     }
2210
2211     return 0;
2212
2213 /*     End of CLATMS */
2214
2215 } /* clatms_ */
2216