C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / TESTING / MATGEN / zlatme.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]/Cd(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
514 /* Table of constant values */
515
516 static doublecomplex c_b1 = {0.,0.};
517 static doublecomplex c_b2 = {1.,0.};
518 static integer c__1 = 1;
519 static integer c__0 = 0;
520 static integer c__5 = 5;
521
522 /* > \brief \b ZLATME */
523
524 /*  =========== DOCUMENTATION =========== */
525
526 /* Online html documentation available at */
527 /*            http://www.netlib.org/lapack/explore-html/ */
528
529 /*  Definition: */
530 /*  =========== */
531
532 /*       SUBROUTINE ZLATME( N, DIST, ISEED, D, MODE, COND, DMAX, */
533 /*         RSIGN, */
534 /*                          UPPER, SIM, DS, MODES, CONDS, KL, KU, ANORM, */
535 /*         A, */
536 /*                          LDA, WORK, INFO ) */
537
538 /*       CHARACTER          DIST, RSIGN, SIM, UPPER */
539 /*       INTEGER            INFO, KL, KU, LDA, MODE, MODES, N */
540 /*       DOUBLE PRECISION   ANORM, COND, CONDS */
541 /*       COMPLEX*16         DMAX */
542 /*       INTEGER            ISEED( 4 ) */
543 /*       DOUBLE PRECISION   DS( * ) */
544 /*       COMPLEX*16         A( LDA, * ), D( * ), WORK( * ) */
545
546
547 /* > \par Purpose: */
548 /*  ============= */
549 /* > */
550 /* > \verbatim */
551 /* > */
552 /* >    ZLATME generates random non-symmetric square matrices with */
553 /* >    specified eigenvalues for testing LAPACK programs. */
554 /* > */
555 /* >    ZLATME operates by applying the following sequence of */
556 /* >    operations: */
557 /* > */
558 /* >    1. Set the diagonal to D, where D may be input or */
559 /* >         computed according to MODE, COND, DMAX, and RSIGN */
560 /* >         as described below. */
561 /* > */
562 /* >    2. If UPPER='T', the upper triangle of A is set to random values */
563 /* >         out of distribution DIST. */
564 /* > */
565 /* >    3. If SIM='T', A is multiplied on the left by a random matrix */
566 /* >         X, whose singular values are specified by DS, MODES, and */
567 /* >         CONDS, and on the right by X inverse. */
568 /* > */
569 /* >    4. If KL < N-1, the lower bandwidth is reduced to KL using */
570 /* >         Householder transformations.  If KU < N-1, the upper */
571 /* >         bandwidth is reduced to KU. */
572 /* > */
573 /* >    5. If ANORM is not negative, the matrix is scaled to have */
574 /* >         maximum-element-norm ANORM. */
575 /* > */
576 /* >    (Note: since the matrix cannot be reduced beyond Hessenberg form, */
577 /* >     no packing options are available.) */
578 /* > \endverbatim */
579
580 /*  Arguments: */
581 /*  ========== */
582
583 /* > \param[in] N */
584 /* > \verbatim */
585 /* >          N is INTEGER */
586 /* >           The number of columns (or rows) of A. Not modified. */
587 /* > \endverbatim */
588 /* > */
589 /* > \param[in] DIST */
590 /* > \verbatim */
591 /* >          DIST is CHARACTER*1 */
592 /* >           On entry, DIST specifies the type of distribution to be used */
593 /* >           to generate the random eigen-/singular values, and on the */
594 /* >           upper triangle (see UPPER). */
595 /* >           'U' => UNIFORM( 0, 1 )  ( 'U' for uniform ) */
596 /* >           'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
597 /* >           'N' => NORMAL( 0, 1 )   ( 'N' for normal ) */
598 /* >           'D' => uniform on the complex disc |z| < 1. */
599 /* >           Not modified. */
600 /* > \endverbatim */
601 /* > */
602 /* > \param[in,out] ISEED */
603 /* > \verbatim */
604 /* >          ISEED is INTEGER array, dimension ( 4 ) */
605 /* >           On entry ISEED specifies the seed of the random number */
606 /* >           generator. They should lie between 0 and 4095 inclusive, */
607 /* >           and ISEED(4) should be odd. The random number generator */
608 /* >           uses a linear congruential sequence limited to small */
609 /* >           integers, and so should produce machine independent */
610 /* >           random numbers. The values of ISEED are changed on */
611 /* >           exit, and can be used in the next call to ZLATME */
612 /* >           to continue the same random number sequence. */
613 /* >           Changed on exit. */
614 /* > \endverbatim */
615 /* > */
616 /* > \param[in,out] D */
617 /* > \verbatim */
618 /* >          D is COMPLEX*16 array, dimension ( N ) */
619 /* >           This array is used to specify the eigenvalues of A.  If */
620 /* >           MODE=0, then D is assumed to contain the eigenvalues */
621 /* >           otherwise they will be computed according to MODE, COND, */
622 /* >           DMAX, and RSIGN and placed in D. */
623 /* >           Modified if MODE is nonzero. */
624 /* > \endverbatim */
625 /* > */
626 /* > \param[in] MODE */
627 /* > \verbatim */
628 /* >          MODE is INTEGER */
629 /* >           On entry this describes how the eigenvalues are to */
630 /* >           be specified: */
631 /* >           MODE = 0 means use D as input */
632 /* >           MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
633 /* >           MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
634 /* >           MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
635 /* >           MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
636 /* >           MODE = 5 sets D to random numbers in the range */
637 /* >                    ( 1/COND , 1 ) such that their logarithms */
638 /* >                    are uniformly distributed. */
639 /* >           MODE = 6 set D to random numbers from same distribution */
640 /* >                    as the rest of the matrix. */
641 /* >           MODE < 0 has the same meaning as ABS(MODE), except that */
642 /* >              the order of the elements of D is reversed. */
643 /* >           Thus if MODE is between 1 and 4, D has entries ranging */
644 /* >              from 1 to 1/COND, if between -1 and -4, D has entries */
645 /* >              ranging from 1/COND to 1, */
646 /* >           Not modified. */
647 /* > \endverbatim */
648 /* > */
649 /* > \param[in] COND */
650 /* > \verbatim */
651 /* >          COND is DOUBLE PRECISION */
652 /* >           On entry, this is used as described under MODE above. */
653 /* >           If used, it must be >= 1. Not modified. */
654 /* > \endverbatim */
655 /* > */
656 /* > \param[in] DMAX */
657 /* > \verbatim */
658 /* >          DMAX is COMPLEX*16 */
659 /* >           If MODE is neither -6, 0 nor 6, the contents of D, as */
660 /* >           computed according to MODE and COND, will be scaled by */
661 /* >           DMAX / f2cmax(abs(D(i))).  Note that DMAX need not be */
662 /* >           positive or real: if DMAX is negative or complex (or zero), */
663 /* >           D will be scaled by a negative or complex number (or zero). */
664 /* >           If RSIGN='F' then the largest (absolute) eigenvalue will be */
665 /* >           equal to DMAX. */
666 /* >           Not modified. */
667 /* > \endverbatim */
668 /* > */
669 /* > \param[in] RSIGN */
670 /* > \verbatim */
671 /* >          RSIGN is CHARACTER*1 */
672 /* >           If MODE is not 0, 6, or -6, and RSIGN='T', then the */
673 /* >           elements of D, as computed according to MODE and COND, will */
674 /* >           be multiplied by a random complex number from the unit */
675 /* >           circle |z| = 1.  If RSIGN='F', they will not be.  RSIGN may */
676 /* >           only have the values 'T' or 'F'. */
677 /* >           Not modified. */
678 /* > \endverbatim */
679 /* > */
680 /* > \param[in] UPPER */
681 /* > \verbatim */
682 /* >          UPPER is CHARACTER*1 */
683 /* >           If UPPER='T', then the elements of A above the diagonal */
684 /* >           will be set to random numbers out of DIST.  If UPPER='F', */
685 /* >           they will not.  UPPER may only have the values 'T' or 'F'. */
686 /* >           Not modified. */
687 /* > \endverbatim */
688 /* > */
689 /* > \param[in] SIM */
690 /* > \verbatim */
691 /* >          SIM is CHARACTER*1 */
692 /* >           If SIM='T', then A will be operated on by a "similarity */
693 /* >           transform", i.e., multiplied on the left by a matrix X and */
694 /* >           on the right by X inverse.  X = U S V, where U and V are */
695 /* >           random unitary matrices and S is a (diagonal) matrix of */
696 /* >           singular values specified by DS, MODES, and CONDS.  If */
697 /* >           SIM='F', then A will not be transformed. */
698 /* >           Not modified. */
699 /* > \endverbatim */
700 /* > */
701 /* > \param[in,out] DS */
702 /* > \verbatim */
703 /* >          DS is DOUBLE PRECISION array, dimension ( N ) */
704 /* >           This array is used to specify the singular values of X, */
705 /* >           in the same way that D specifies the eigenvalues of A. */
706 /* >           If MODE=0, the DS contains the singular values, which */
707 /* >           may not be zero. */
708 /* >           Modified if MODE is nonzero. */
709 /* > \endverbatim */
710 /* > */
711 /* > \param[in] MODES */
712 /* > \verbatim */
713 /* >          MODES is INTEGER */
714 /* > \endverbatim */
715 /* > */
716 /* > \param[in] CONDS */
717 /* > \verbatim */
718 /* >          CONDS is DOUBLE PRECISION */
719 /* >           Similar to MODE and COND, but for specifying the diagonal */
720 /* >           of S.  MODES=-6 and +6 are not allowed (since they would */
721 /* >           result in randomly ill-conditioned eigenvalues.) */
722 /* > \endverbatim */
723 /* > */
724 /* > \param[in] KL */
725 /* > \verbatim */
726 /* >          KL is INTEGER */
727 /* >           This specifies the lower bandwidth of the  matrix.  KL=1 */
728 /* >           specifies upper Hessenberg form.  If KL is at least N-1, */
729 /* >           then A will have full lower bandwidth. */
730 /* >           Not modified. */
731 /* > \endverbatim */
732 /* > */
733 /* > \param[in] KU */
734 /* > \verbatim */
735 /* >          KU is INTEGER */
736 /* >           This specifies the upper bandwidth of the  matrix.  KU=1 */
737 /* >           specifies lower Hessenberg form.  If KU is at least N-1, */
738 /* >           then A will have full upper bandwidth; if KU and KL */
739 /* >           are both at least N-1, then A will be dense.  Only one of */
740 /* >           KU and KL may be less than N-1. */
741 /* >           Not modified. */
742 /* > \endverbatim */
743 /* > */
744 /* > \param[in] ANORM */
745 /* > \verbatim */
746 /* >          ANORM is DOUBLE PRECISION */
747 /* >           If ANORM is not negative, then A will be scaled by a non- */
748 /* >           negative real number to make the maximum-element-norm of A */
749 /* >           to be ANORM. */
750 /* >           Not modified. */
751 /* > \endverbatim */
752 /* > */
753 /* > \param[out] A */
754 /* > \verbatim */
755 /* >          A is COMPLEX*16 array, dimension ( LDA, N ) */
756 /* >           On exit A is the desired test matrix. */
757 /* >           Modified. */
758 /* > \endverbatim */
759 /* > */
760 /* > \param[in] LDA */
761 /* > \verbatim */
762 /* >          LDA is INTEGER */
763 /* >           LDA specifies the first dimension of A as declared in the */
764 /* >           calling program.  LDA must be at least M. */
765 /* >           Not modified. */
766 /* > \endverbatim */
767 /* > */
768 /* > \param[out] WORK */
769 /* > \verbatim */
770 /* >          WORK is COMPLEX*16 array, dimension ( 3*N ) */
771 /* >           Workspace. */
772 /* >           Modified. */
773 /* > \endverbatim */
774 /* > */
775 /* > \param[out] INFO */
776 /* > \verbatim */
777 /* >          INFO is INTEGER */
778 /* >           Error code.  On exit, INFO will be set to one of the */
779 /* >           following values: */
780 /* >             0 => normal return */
781 /* >            -1 => N negative */
782 /* >            -2 => DIST illegal string */
783 /* >            -5 => MODE not in range -6 to 6 */
784 /* >            -6 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
785 /* >            -9 => RSIGN is not 'T' or 'F' */
786 /* >           -10 => UPPER is not 'T' or 'F' */
787 /* >           -11 => SIM   is not 'T' or 'F' */
788 /* >           -12 => MODES=0 and DS has a zero singular value. */
789 /* >           -13 => MODES is not in the range -5 to 5. */
790 /* >           -14 => MODES is nonzero and CONDS is less than 1. */
791 /* >           -15 => KL is less than 1. */
792 /* >           -16 => KU is less than 1, or KL and KU are both less than */
793 /* >                  N-1. */
794 /* >           -19 => LDA is less than M. */
795 /* >            1  => Error return from ZLATM1 (computing D) */
796 /* >            2  => Cannot scale to DMAX (f2cmax. eigenvalue is 0) */
797 /* >            3  => Error return from DLATM1 (computing DS) */
798 /* >            4  => Error return from ZLARGE */
799 /* >            5  => Zero singular value from DLATM1. */
800 /* > \endverbatim */
801
802 /*  Authors: */
803 /*  ======== */
804
805 /* > \author Univ. of Tennessee */
806 /* > \author Univ. of California Berkeley */
807 /* > \author Univ. of Colorado Denver */
808 /* > \author NAG Ltd. */
809
810 /* > \date December 2016 */
811
812 /* > \ingroup complex16_matgen */
813
814 /*  ===================================================================== */
815 /* Subroutine */ int zlatme_(integer *n, char *dist, integer *iseed, 
816         doublecomplex *d__, integer *mode, doublereal *cond, doublecomplex *
817         dmax__, char *rsign, char *upper, char *sim, doublereal *ds, integer *
818         modes, doublereal *conds, integer *kl, integer *ku, doublereal *anorm,
819          doublecomplex *a, integer *lda, doublecomplex *work, integer *info)
820 {
821     /* System generated locals */
822     integer a_dim1, a_offset, i__1, i__2;
823     doublereal d__1, d__2;
824     doublecomplex z__1, z__2;
825
826     /* Local variables */
827     logical bads;
828     integer isim;
829     doublereal temp;
830     integer i__, j;
831     doublecomplex alpha;
832     extern logical lsame_(char *, char *);
833     integer iinfo;
834     doublereal tempa[1];
835     integer icols;
836     extern /* Subroutine */ int zgerc_(integer *, integer *, doublecomplex *, 
837             doublecomplex *, integer *, doublecomplex *, integer *, 
838             doublecomplex *, integer *);
839     integer idist;
840     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
841             doublecomplex *, integer *), zgemv_(char *, integer *, integer *, 
842             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
843             integer *, doublecomplex *, doublecomplex *, integer *);
844     integer irows;
845     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
846             doublecomplex *, integer *), dlatm1_(integer *, doublereal *, 
847             integer *, integer *, integer *, doublereal *, integer *, integer 
848             *), zlatm1_(integer *, doublereal *, integer *, integer *, 
849             integer *, doublecomplex *, integer *, integer *);
850     integer ic, jc, ir;
851     doublereal ralpha;
852     extern /* Subroutine */ int xerbla_(char *, integer *);
853     extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, 
854             integer *, doublereal *);
855     extern /* Subroutine */ int zdscal_(integer *, doublereal *, 
856             doublecomplex *, integer *), zlarge_(integer *, doublecomplex *, 
857             integer *, integer *, doublecomplex *, integer *), zlarfg_(
858             integer *, doublecomplex *, doublecomplex *, integer *, 
859             doublecomplex *), zlacgv_(integer *, doublecomplex *, integer *);
860     //extern /* Double Complex */ VOID zlarnd_(doublecomplex *, integer *, 
861     extern doublecomplex zlarnd_(integer *, 
862             integer *);
863     integer irsign;
864     extern /* Subroutine */ int zlaset_(char *, integer *, integer *, 
865             doublecomplex *, doublecomplex *, doublecomplex *, integer *);
866     integer iupper;
867     extern /* Subroutine */ int zlarnv_(integer *, integer *, integer *, 
868             doublecomplex *);
869     doublecomplex xnorms;
870     integer jcr;
871     doublecomplex tau;
872
873
874 /*  -- LAPACK computational routine (version 3.7.0) -- */
875 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
876 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
877 /*     December 2016 */
878
879
880 /*  ===================================================================== */
881
882
883 /*     1)      Decode and Test the input parameters. */
884 /*             Initialize flags & seed. */
885
886     /* Parameter adjustments */
887     --iseed;
888     --d__;
889     --ds;
890     a_dim1 = *lda;
891     a_offset = 1 + a_dim1 * 1;
892     a -= a_offset;
893     --work;
894
895     /* Function Body */
896     *info = 0;
897
898 /*     Quick return if possible */
899
900     if (*n == 0) {
901         return 0;
902     }
903
904 /*     Decode DIST */
905
906     if (lsame_(dist, "U")) {
907         idist = 1;
908     } else if (lsame_(dist, "S")) {
909         idist = 2;
910     } else if (lsame_(dist, "N")) {
911         idist = 3;
912     } else if (lsame_(dist, "D")) {
913         idist = 4;
914     } else {
915         idist = -1;
916     }
917
918 /*     Decode RSIGN */
919
920     if (lsame_(rsign, "T")) {
921         irsign = 1;
922     } else if (lsame_(rsign, "F")) {
923         irsign = 0;
924     } else {
925         irsign = -1;
926     }
927
928 /*     Decode UPPER */
929
930     if (lsame_(upper, "T")) {
931         iupper = 1;
932     } else if (lsame_(upper, "F")) {
933         iupper = 0;
934     } else {
935         iupper = -1;
936     }
937
938 /*     Decode SIM */
939
940     if (lsame_(sim, "T")) {
941         isim = 1;
942     } else if (lsame_(sim, "F")) {
943         isim = 0;
944     } else {
945         isim = -1;
946     }
947
948 /*     Check DS, if MODES=0 and ISIM=1 */
949
950     bads = FALSE_;
951     if (*modes == 0 && isim == 1) {
952         i__1 = *n;
953         for (j = 1; j <= i__1; ++j) {
954             if (ds[j] == 0.) {
955                 bads = TRUE_;
956             }
957 /* L10: */
958         }
959     }
960
961 /*     Set INFO if an error */
962
963     if (*n < 0) {
964         *info = -1;
965     } else if (idist == -1) {
966         *info = -2;
967     } else if (abs(*mode) > 6) {
968         *info = -5;
969     } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.) {
970         *info = -6;
971     } else if (irsign == -1) {
972         *info = -9;
973     } else if (iupper == -1) {
974         *info = -10;
975     } else if (isim == -1) {
976         *info = -11;
977     } else if (bads) {
978         *info = -12;
979     } else if (isim == 1 && abs(*modes) > 5) {
980         *info = -13;
981     } else if (isim == 1 && *modes != 0 && *conds < 1.) {
982         *info = -14;
983     } else if (*kl < 1) {
984         *info = -15;
985     } else if (*ku < 1 || *ku < *n - 1 && *kl < *n - 1) {
986         *info = -16;
987     } else if (*lda < f2cmax(1,*n)) {
988         *info = -19;
989     }
990
991     if (*info != 0) {
992         i__1 = -(*info);
993         xerbla_("ZLATME", &i__1);
994         return 0;
995     }
996
997 /*     Initialize random number generator */
998
999     for (i__ = 1; i__ <= 4; ++i__) {
1000         iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
1001 /* L20: */
1002     }
1003
1004     if (iseed[4] % 2 != 1) {
1005         ++iseed[4];
1006     }
1007
1008 /*     2)      Set up diagonal of A */
1009
1010 /*             Compute D according to COND and MODE */
1011
1012     zlatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], n, &iinfo);
1013     if (iinfo != 0) {
1014         *info = 1;
1015         return 0;
1016     }
1017     if (*mode != 0 && abs(*mode) != 6) {
1018
1019 /*        Scale by DMAX */
1020
1021         temp = z_abs(&d__[1]);
1022         i__1 = *n;
1023         for (i__ = 2; i__ <= i__1; ++i__) {
1024 /* Computing MAX */
1025             d__1 = temp, d__2 = z_abs(&d__[i__]);
1026             temp = f2cmax(d__1,d__2);
1027 /* L30: */
1028         }
1029
1030         if (temp > 0.) {
1031             z__1.r = dmax__->r / temp, z__1.i = dmax__->i / temp;
1032             alpha.r = z__1.r, alpha.i = z__1.i;
1033         } else {
1034             *info = 2;
1035             return 0;
1036         }
1037
1038         zscal_(n, &alpha, &d__[1], &c__1);
1039
1040     }
1041
1042     zlaset_("Full", n, n, &c_b1, &c_b1, &a[a_offset], lda);
1043     i__1 = *lda + 1;
1044     zcopy_(n, &d__[1], &c__1, &a[a_offset], &i__1);
1045
1046 /*     3)      If UPPER='T', set upper triangle of A to random numbers. */
1047
1048     if (iupper != 0) {
1049         i__1 = *n;
1050         for (jc = 2; jc <= i__1; ++jc) {
1051             i__2 = jc - 1;
1052             zlarnv_(&idist, &iseed[1], &i__2, &a[jc * a_dim1 + 1]);
1053 /* L40: */
1054         }
1055     }
1056
1057 /*     4)      If SIM='T', apply similarity transformation. */
1058
1059 /*                                -1 */
1060 /*             Transform is  X A X  , where X = U S V, thus */
1061
1062 /*             it is  U S V A V' (1/S) U' */
1063
1064     if (isim != 0) {
1065
1066 /*        Compute S (singular values of the eigenvector matrix) */
1067 /*        according to CONDS and MODES */
1068
1069         dlatm1_(modes, conds, &c__0, &c__0, &iseed[1], &ds[1], n, &iinfo);
1070         if (iinfo != 0) {
1071             *info = 3;
1072             return 0;
1073         }
1074
1075 /*        Multiply by V and V' */
1076
1077         zlarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
1078         if (iinfo != 0) {
1079             *info = 4;
1080             return 0;
1081         }
1082
1083 /*        Multiply by S and (1/S) */
1084
1085         i__1 = *n;
1086         for (j = 1; j <= i__1; ++j) {
1087             zdscal_(n, &ds[j], &a[j + a_dim1], lda);
1088             if (ds[j] != 0.) {
1089                 d__1 = 1. / ds[j];
1090                 zdscal_(n, &d__1, &a[j * a_dim1 + 1], &c__1);
1091             } else {
1092                 *info = 5;
1093                 return 0;
1094             }
1095 /* L50: */
1096         }
1097
1098 /*        Multiply by U and U' */
1099
1100         zlarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
1101         if (iinfo != 0) {
1102             *info = 4;
1103             return 0;
1104         }
1105     }
1106
1107 /*     5)      Reduce the bandwidth. */
1108
1109     if (*kl < *n - 1) {
1110
1111 /*        Reduce bandwidth -- kill column */
1112
1113         i__1 = *n - 1;
1114         for (jcr = *kl + 1; jcr <= i__1; ++jcr) {
1115             ic = jcr - *kl;
1116             irows = *n + 1 - jcr;
1117             icols = *n + *kl - jcr;
1118
1119             zcopy_(&irows, &a[jcr + ic * a_dim1], &c__1, &work[1], &c__1);
1120             xnorms.r = work[1].r, xnorms.i = work[1].i;
1121             zlarfg_(&irows, &xnorms, &work[2], &c__1, &tau);
1122             d_cnjg(&z__1, &tau);
1123             tau.r = z__1.r, tau.i = z__1.i;
1124             work[1].r = 1., work[1].i = 0.;
1125             //zlarnd_(&z__1, &c__5, &iseed[1]);
1126             z__1=zlarnd_(&c__5, &iseed[1]);
1127             alpha.r = z__1.r, alpha.i = z__1.i;
1128
1129             zgemv_("C", &irows, &icols, &c_b2, &a[jcr + (ic + 1) * a_dim1], 
1130                     lda, &work[1], &c__1, &c_b1, &work[irows + 1], &c__1);
1131             z__1.r = -tau.r, z__1.i = -tau.i;
1132             zgerc_(&irows, &icols, &z__1, &work[1], &c__1, &work[irows + 1], &
1133                     c__1, &a[jcr + (ic + 1) * a_dim1], lda);
1134
1135             zgemv_("N", n, &irows, &c_b2, &a[jcr * a_dim1 + 1], lda, &work[1],
1136                      &c__1, &c_b1, &work[irows + 1], &c__1);
1137             d_cnjg(&z__2, &tau);
1138             z__1.r = -z__2.r, z__1.i = -z__2.i;
1139             zgerc_(n, &irows, &z__1, &work[irows + 1], &c__1, &work[1], &c__1,
1140                      &a[jcr * a_dim1 + 1], lda);
1141
1142             i__2 = jcr + ic * a_dim1;
1143             a[i__2].r = xnorms.r, a[i__2].i = xnorms.i;
1144             i__2 = irows - 1;
1145             zlaset_("Full", &i__2, &c__1, &c_b1, &c_b1, &a[jcr + 1 + ic * 
1146                     a_dim1], lda);
1147
1148             i__2 = icols + 1;
1149             zscal_(&i__2, &alpha, &a[jcr + ic * a_dim1], lda);
1150             d_cnjg(&z__1, &alpha);
1151             zscal_(n, &z__1, &a[jcr * a_dim1 + 1], &c__1);
1152 /* L60: */
1153         }
1154     } else if (*ku < *n - 1) {
1155
1156 /*        Reduce upper bandwidth -- kill a row at a time. */
1157
1158         i__1 = *n - 1;
1159         for (jcr = *ku + 1; jcr <= i__1; ++jcr) {
1160             ir = jcr - *ku;
1161             irows = *n + *ku - jcr;
1162             icols = *n + 1 - jcr;
1163
1164             zcopy_(&icols, &a[ir + jcr * a_dim1], lda, &work[1], &c__1);
1165             xnorms.r = work[1].r, xnorms.i = work[1].i;
1166             zlarfg_(&icols, &xnorms, &work[2], &c__1, &tau);
1167             d_cnjg(&z__1, &tau);
1168             tau.r = z__1.r, tau.i = z__1.i;
1169             work[1].r = 1., work[1].i = 0.;
1170             i__2 = icols - 1;
1171             zlacgv_(&i__2, &work[2], &c__1);
1172             //zlarnd_(&z__1, &c__5, &iseed[1]);
1173             z__1 = zlarnd_(&c__5, &iseed[1]);
1174             alpha.r = z__1.r, alpha.i = z__1.i;
1175
1176             zgemv_("N", &irows, &icols, &c_b2, &a[ir + 1 + jcr * a_dim1], lda,
1177                      &work[1], &c__1, &c_b1, &work[icols + 1], &c__1);
1178             z__1.r = -tau.r, z__1.i = -tau.i;
1179             zgerc_(&irows, &icols, &z__1, &work[icols + 1], &c__1, &work[1], &
1180                     c__1, &a[ir + 1 + jcr * a_dim1], lda);
1181
1182             zgemv_("C", &icols, n, &c_b2, &a[jcr + a_dim1], lda, &work[1], &
1183                     c__1, &c_b1, &work[icols + 1], &c__1);
1184             d_cnjg(&z__2, &tau);
1185             z__1.r = -z__2.r, z__1.i = -z__2.i;
1186             zgerc_(&icols, n, &z__1, &work[1], &c__1, &work[icols + 1], &c__1,
1187                      &a[jcr + a_dim1], lda);
1188
1189             i__2 = ir + jcr * a_dim1;
1190             a[i__2].r = xnorms.r, a[i__2].i = xnorms.i;
1191             i__2 = icols - 1;
1192             zlaset_("Full", &c__1, &i__2, &c_b1, &c_b1, &a[ir + (jcr + 1) * 
1193                     a_dim1], lda);
1194
1195             i__2 = irows + 1;
1196             zscal_(&i__2, &alpha, &a[ir + jcr * a_dim1], &c__1);
1197             d_cnjg(&z__1, &alpha);
1198             zscal_(n, &z__1, &a[jcr + a_dim1], lda);
1199 /* L70: */
1200         }
1201     }
1202
1203 /*     Scale the matrix to have norm ANORM */
1204
1205     if (*anorm >= 0.) {
1206         temp = zlange_("M", n, n, &a[a_offset], lda, tempa);
1207         if (temp > 0.) {
1208             ralpha = *anorm / temp;
1209             i__1 = *n;
1210             for (j = 1; j <= i__1; ++j) {
1211                 zdscal_(n, &ralpha, &a[j * a_dim1 + 1], &c__1);
1212 /* L80: */
1213             }
1214         }
1215     }
1216
1217     return 0;
1218
1219 /*     End of ZLATME */
1220
1221 } /* zlatme_ */
1222