C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / TESTING / MATGEN / dlatme.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__1 = 1;
516 static doublereal c_b23 = 0.;
517 static integer c__0 = 0;
518 static doublereal c_b39 = 1.;
519
520 /* > \brief \b DLATME */
521
522 /*  =========== DOCUMENTATION =========== */
523
524 /* Online html documentation available at */
525 /*            http://www.netlib.org/lapack/explore-html/ */
526
527 /*  Definition: */
528 /*  =========== */
529
530 /*       SUBROUTINE DLATME( N, DIST, ISEED, D, MODE, COND, DMAX, EI, */
531 /*         RSIGN, */
532 /*                          UPPER, SIM, DS, MODES, CONDS, KL, KU, ANORM, */
533 /*         A, */
534 /*                          LDA, WORK, INFO ) */
535
536 /*       CHARACTER          DIST, RSIGN, SIM, UPPER */
537 /*       INTEGER            INFO, KL, KU, LDA, MODE, MODES, N */
538 /*       DOUBLE PRECISION   ANORM, COND, CONDS, DMAX */
539 /*       CHARACTER          EI( * ) */
540 /*       INTEGER            ISEED( 4 ) */
541 /*       DOUBLE PRECISION   A( LDA, * ), D( * ), DS( * ), WORK( * ) */
542
543
544 /* > \par Purpose: */
545 /*  ============= */
546 /* > */
547 /* > \verbatim */
548 /* > */
549 /* >    DLATME generates random non-symmetric square matrices with */
550 /* >    specified eigenvalues for testing LAPACK programs. */
551 /* > */
552 /* >    DLATME operates by applying the following sequence of */
553 /* >    operations: */
554 /* > */
555 /* >    1. Set the diagonal to D, where D may be input or */
556 /* >         computed according to MODE, COND, DMAX, and RSIGN */
557 /* >         as described below. */
558 /* > */
559 /* >    2. If complex conjugate pairs are desired (MODE=0 and EI(1)='R', */
560 /* >         or MODE=5), certain pairs of adjacent elements of D are */
561 /* >         interpreted as the real and complex parts of a complex */
562 /* >         conjugate pair; A thus becomes block diagonal, with 1x1 */
563 /* >         and 2x2 blocks. */
564 /* > */
565 /* >    3. If UPPER='T', the upper triangle of A is set to random values */
566 /* >         out of distribution DIST. */
567 /* > */
568 /* >    4. If SIM='T', A is multiplied on the left by a random matrix */
569 /* >         X, whose singular values are specified by DS, MODES, and */
570 /* >         CONDS, and on the right by X inverse. */
571 /* > */
572 /* >    5. If KL < N-1, the lower bandwidth is reduced to KL using */
573 /* >         Householder transformations.  If KU < N-1, the upper */
574 /* >         bandwidth is reduced to KU. */
575 /* > */
576 /* >    6. If ANORM is not negative, the matrix is scaled to have */
577 /* >         maximum-element-norm ANORM. */
578 /* > */
579 /* >    (Note: since the matrix cannot be reduced beyond Hessenberg form, */
580 /* >     no packing options are available.) */
581 /* > \endverbatim */
582
583 /*  Arguments: */
584 /*  ========== */
585
586 /* > \param[in] N */
587 /* > \verbatim */
588 /* >          N is INTEGER */
589 /* >           The number of columns (or rows) of A. Not modified. */
590 /* > \endverbatim */
591 /* > */
592 /* > \param[in] DIST */
593 /* > \verbatim */
594 /* >          DIST is CHARACTER*1 */
595 /* >           On entry, DIST specifies the type of distribution to be used */
596 /* >           to generate the random eigen-/singular values, and for the */
597 /* >           upper triangle (see UPPER). */
598 /* >           'U' => UNIFORM( 0, 1 )  ( 'U' for uniform ) */
599 /* >           'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
600 /* >           'N' => NORMAL( 0, 1 )   ( 'N' for normal ) */
601 /* >           Not modified. */
602 /* > \endverbatim */
603 /* > */
604 /* > \param[in,out] ISEED */
605 /* > \verbatim */
606 /* >          ISEED is INTEGER array, dimension ( 4 ) */
607 /* >           On entry ISEED specifies the seed of the random number */
608 /* >           generator. They should lie between 0 and 4095 inclusive, */
609 /* >           and ISEED(4) should be odd. The random number generator */
610 /* >           uses a linear congruential sequence limited to small */
611 /* >           integers, and so should produce machine independent */
612 /* >           random numbers. The values of ISEED are changed on */
613 /* >           exit, and can be used in the next call to DLATME */
614 /* >           to continue the same random number sequence. */
615 /* >           Changed on exit. */
616 /* > \endverbatim */
617 /* > */
618 /* > \param[in,out] D */
619 /* > \verbatim */
620 /* >          D is DOUBLE PRECISION array, dimension ( N ) */
621 /* >           This array is used to specify the eigenvalues of A.  If */
622 /* >           MODE=0, then D is assumed to contain the eigenvalues (but */
623 /* >           see the description of EI), otherwise they will be */
624 /* >           computed according to MODE, COND, DMAX, and RSIGN and */
625 /* >           placed in D. */
626 /* >           Modified if MODE is nonzero. */
627 /* > \endverbatim */
628 /* > */
629 /* > \param[in] MODE */
630 /* > \verbatim */
631 /* >          MODE is INTEGER */
632 /* >           On entry this describes how the eigenvalues are to */
633 /* >           be specified: */
634 /* >           MODE = 0 means use D (with EI) as input */
635 /* >           MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
636 /* >           MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
637 /* >           MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
638 /* >           MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
639 /* >           MODE = 5 sets D to random numbers in the range */
640 /* >                    ( 1/COND , 1 ) such that their logarithms */
641 /* >                    are uniformly distributed.  Each odd-even pair */
642 /* >                    of elements will be either used as two real */
643 /* >                    eigenvalues or as the real and imaginary part */
644 /* >                    of a complex conjugate pair of eigenvalues; */
645 /* >                    the choice of which is done is random, with */
646 /* >                    50-50 probability, for each pair. */
647 /* >           MODE = 6 set D to random numbers from same distribution */
648 /* >                    as the rest of the matrix. */
649 /* >           MODE < 0 has the same meaning as ABS(MODE), except that */
650 /* >              the order of the elements of D is reversed. */
651 /* >           Thus if MODE is between 1 and 4, D has entries ranging */
652 /* >              from 1 to 1/COND, if between -1 and -4, D has entries */
653 /* >              ranging from 1/COND to 1, */
654 /* >           Not modified. */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in] COND */
658 /* > \verbatim */
659 /* >          COND is DOUBLE PRECISION */
660 /* >           On entry, this is used as described under MODE above. */
661 /* >           If used, it must be >= 1. Not modified. */
662 /* > \endverbatim */
663 /* > */
664 /* > \param[in] DMAX */
665 /* > \verbatim */
666 /* >          DMAX is DOUBLE PRECISION */
667 /* >           If MODE is neither -6, 0 nor 6, the contents of D, as */
668 /* >           computed according to MODE and COND, will be scaled by */
669 /* >           DMAX / f2cmax(abs(D(i))).  Note that DMAX need not be */
670 /* >           positive: if DMAX is negative (or zero), D will be */
671 /* >           scaled by a negative number (or zero). */
672 /* >           Not modified. */
673 /* > \endverbatim */
674 /* > */
675 /* > \param[in] EI */
676 /* > \verbatim */
677 /* >          EI is CHARACTER*1 array, dimension ( N ) */
678 /* >           If MODE is 0, and EI(1) is not ' ' (space character), */
679 /* >           this array specifies which elements of D (on input) are */
680 /* >           real eigenvalues and which are the real and imaginary parts */
681 /* >           of a complex conjugate pair of eigenvalues.  The elements */
682 /* >           of EI may then only have the values 'R' and 'I'.  If */
683 /* >           EI(j)='R' and EI(j+1)='I', then the j-th eigenvalue is */
684 /* >           CMPLX( D(j) , D(j+1) ), and the (j+1)-th is the complex */
685 /* >           conjugate thereof.  If EI(j)=EI(j+1)='R', then the j-th */
686 /* >           eigenvalue is D(j) (i.e., real).  EI(1) may not be 'I', */
687 /* >           nor may two adjacent elements of EI both have the value 'I'. */
688 /* >           If MODE is not 0, then EI is ignored.  If MODE is 0 and */
689 /* >           EI(1)=' ', then the eigenvalues will all be real. */
690 /* >           Not modified. */
691 /* > \endverbatim */
692 /* > */
693 /* > \param[in] RSIGN */
694 /* > \verbatim */
695 /* >          RSIGN is CHARACTER*1 */
696 /* >           If MODE is not 0, 6, or -6, and RSIGN='T', then the */
697 /* >           elements of D, as computed according to MODE and COND, will */
698 /* >           be multiplied by a random sign (+1 or -1).  If RSIGN='F', */
699 /* >           they will not be.  RSIGN may only have the values 'T' or */
700 /* >           'F'. */
701 /* >           Not modified. */
702 /* > \endverbatim */
703 /* > */
704 /* > \param[in] UPPER */
705 /* > \verbatim */
706 /* >          UPPER is CHARACTER*1 */
707 /* >           If UPPER='T', then the elements of A above the diagonal */
708 /* >           (and above the 2x2 diagonal blocks, if A has complex */
709 /* >           eigenvalues) will be set to random numbers out of DIST. */
710 /* >           If UPPER='F', they will not.  UPPER may only have the */
711 /* >           values 'T' or 'F'. */
712 /* >           Not modified. */
713 /* > \endverbatim */
714 /* > */
715 /* > \param[in] SIM */
716 /* > \verbatim */
717 /* >          SIM is CHARACTER*1 */
718 /* >           If SIM='T', then A will be operated on by a "similarity */
719 /* >           transform", i.e., multiplied on the left by a matrix X and */
720 /* >           on the right by X inverse.  X = U S V, where U and V are */
721 /* >           random unitary matrices and S is a (diagonal) matrix of */
722 /* >           singular values specified by DS, MODES, and CONDS.  If */
723 /* >           SIM='F', then A will not be transformed. */
724 /* >           Not modified. */
725 /* > \endverbatim */
726 /* > */
727 /* > \param[in,out] DS */
728 /* > \verbatim */
729 /* >          DS is DOUBLE PRECISION array, dimension ( N ) */
730 /* >           This array is used to specify the singular values of X, */
731 /* >           in the same way that D specifies the eigenvalues of A. */
732 /* >           If MODE=0, the DS contains the singular values, which */
733 /* >           may not be zero. */
734 /* >           Modified if MODE is nonzero. */
735 /* > \endverbatim */
736 /* > */
737 /* > \param[in] MODES */
738 /* > \verbatim */
739 /* >          MODES is INTEGER */
740 /* > \endverbatim */
741 /* > */
742 /* > \param[in] CONDS */
743 /* > \verbatim */
744 /* >          CONDS is DOUBLE PRECISION */
745 /* >           Same as MODE and COND, but for specifying the diagonal */
746 /* >           of S.  MODES=-6 and +6 are not allowed (since they would */
747 /* >           result in randomly ill-conditioned eigenvalues.) */
748 /* > \endverbatim */
749 /* > */
750 /* > \param[in] KL */
751 /* > \verbatim */
752 /* >          KL is INTEGER */
753 /* >           This specifies the lower bandwidth of the  matrix.  KL=1 */
754 /* >           specifies upper Hessenberg form.  If KL is at least N-1, */
755 /* >           then A will have full lower bandwidth.  KL must be at */
756 /* >           least 1. */
757 /* >           Not modified. */
758 /* > \endverbatim */
759 /* > */
760 /* > \param[in] KU */
761 /* > \verbatim */
762 /* >          KU is INTEGER */
763 /* >           This specifies the upper bandwidth of the  matrix.  KU=1 */
764 /* >           specifies lower Hessenberg form.  If KU is at least N-1, */
765 /* >           then A will have full upper bandwidth; if KU and KL */
766 /* >           are both at least N-1, then A will be dense.  Only one of */
767 /* >           KU and KL may be less than N-1.  KU must be at least 1. */
768 /* >           Not modified. */
769 /* > \endverbatim */
770 /* > */
771 /* > \param[in] ANORM */
772 /* > \verbatim */
773 /* >          ANORM is DOUBLE PRECISION */
774 /* >           If ANORM is not negative, then A will be scaled by a non- */
775 /* >           negative real number to make the maximum-element-norm of A */
776 /* >           to be ANORM. */
777 /* >           Not modified. */
778 /* > \endverbatim */
779 /* > */
780 /* > \param[out] A */
781 /* > \verbatim */
782 /* >          A is DOUBLE PRECISION array, dimension ( LDA, N ) */
783 /* >           On exit A is the desired test matrix. */
784 /* >           Modified. */
785 /* > \endverbatim */
786 /* > */
787 /* > \param[in] LDA */
788 /* > \verbatim */
789 /* >          LDA is INTEGER */
790 /* >           LDA specifies the first dimension of A as declared in the */
791 /* >           calling program.  LDA must be at least N. */
792 /* >           Not modified. */
793 /* > \endverbatim */
794 /* > */
795 /* > \param[out] WORK */
796 /* > \verbatim */
797 /* >          WORK is DOUBLE PRECISION array, dimension ( 3*N ) */
798 /* >           Workspace. */
799 /* >           Modified. */
800 /* > \endverbatim */
801 /* > */
802 /* > \param[out] INFO */
803 /* > \verbatim */
804 /* >          INFO is INTEGER */
805 /* >           Error code.  On exit, INFO will be set to one of the */
806 /* >           following values: */
807 /* >             0 => normal return */
808 /* >            -1 => N negative */
809 /* >            -2 => DIST illegal string */
810 /* >            -5 => MODE not in range -6 to 6 */
811 /* >            -6 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
812 /* >            -8 => EI(1) is not ' ' or 'R', EI(j) is not 'R' or 'I', or */
813 /* >                  two adjacent elements of EI are 'I'. */
814 /* >            -9 => RSIGN is not 'T' or 'F' */
815 /* >           -10 => UPPER is not 'T' or 'F' */
816 /* >           -11 => SIM   is not 'T' or 'F' */
817 /* >           -12 => MODES=0 and DS has a zero singular value. */
818 /* >           -13 => MODES is not in the range -5 to 5. */
819 /* >           -14 => MODES is nonzero and CONDS is less than 1. */
820 /* >           -15 => KL is less than 1. */
821 /* >           -16 => KU is less than 1, or KL and KU are both less than */
822 /* >                  N-1. */
823 /* >           -19 => LDA is less than N. */
824 /* >            1  => Error return from DLATM1 (computing D) */
825 /* >            2  => Cannot scale to DMAX (f2cmax. eigenvalue is 0) */
826 /* >            3  => Error return from DLATM1 (computing DS) */
827 /* >            4  => Error return from DLARGE */
828 /* >            5  => Zero singular value from DLATM1. */
829 /* > \endverbatim */
830
831 /*  Authors: */
832 /*  ======== */
833
834 /* > \author Univ. of Tennessee */
835 /* > \author Univ. of California Berkeley */
836 /* > \author Univ. of Colorado Denver */
837 /* > \author NAG Ltd. */
838
839 /* > \date December 2016 */
840
841 /* > \ingroup double_matgen */
842
843 /*  ===================================================================== */
844 /* Subroutine */ int dlatme_(integer *n, char *dist, integer *iseed, 
845         doublereal *d__, integer *mode, doublereal *cond, doublereal *dmax__, 
846         char *ei, char *rsign, char *upper, char *sim, doublereal *ds, 
847         integer *modes, doublereal *conds, integer *kl, integer *ku, 
848         doublereal *anorm, doublereal *a, integer *lda, doublereal *work, 
849         integer *info)
850 {
851     /* System generated locals */
852     integer a_dim1, a_offset, i__1, i__2;
853     doublereal d__1, d__2, d__3;
854
855     /* Local variables */
856     logical bads;
857     extern /* Subroutine */ int dger_(integer *, integer *, doublereal *, 
858             doublereal *, integer *, doublereal *, integer *, doublereal *, 
859             integer *);
860     integer isim;
861     doublereal temp;
862     logical badei;
863     integer i__, j;
864     doublereal alpha;
865     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
866             integer *);
867     extern logical lsame_(char *, char *);
868     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
869             doublereal *, doublereal *, integer *, doublereal *, integer *, 
870             doublereal *, doublereal *, integer *);
871     integer iinfo;
872     doublereal tempa[1];
873     integer icols;
874     logical useei;
875     integer idist;
876     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
877             doublereal *, integer *);
878     integer irows;
879     extern /* Subroutine */ int dlatm1_(integer *, doublereal *, integer *, 
880             integer *, integer *, doublereal *, integer *, integer *);
881     integer ic, jc;
882     extern doublereal dlange_(char *, integer *, integer *, doublereal *, 
883             integer *, doublereal *);
884     integer ir, jr;
885     extern /* Subroutine */ int dlarge_(integer *, doublereal *, integer *, 
886             integer *, doublereal *, integer *), dlarfg_(integer *, 
887             doublereal *, doublereal *, integer *, doublereal *);
888     extern doublereal dlaran_(integer *);
889     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
890             doublereal *, doublereal *, doublereal *, integer *), 
891             xerbla_(char *, integer *), dlarnv_(integer *, integer *, 
892             integer *, doublereal *);
893     integer irsign, iupper;
894     doublereal xnorms;
895     integer jcr;
896     doublereal tau;
897
898
899 /*  -- LAPACK computational routine (version 3.7.0) -- */
900 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
901 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
902 /*     December 2016 */
903
904
905 /*  ===================================================================== */
906
907
908 /*     1)      Decode and Test the input parameters. */
909 /*             Initialize flags & seed. */
910
911     /* Parameter adjustments */
912     --iseed;
913     --d__;
914     --ei;
915     --ds;
916     a_dim1 = *lda;
917     a_offset = 1 + a_dim1 * 1;
918     a -= a_offset;
919     --work;
920
921     /* Function Body */
922     *info = 0;
923
924 /*     Quick return if possible */
925
926     if (*n == 0) {
927         return 0;
928     }
929
930 /*     Decode DIST */
931
932     if (lsame_(dist, "U")) {
933         idist = 1;
934     } else if (lsame_(dist, "S")) {
935         idist = 2;
936     } else if (lsame_(dist, "N")) {
937         idist = 3;
938     } else {
939         idist = -1;
940     }
941
942 /*     Check EI */
943
944     useei = TRUE_;
945     badei = FALSE_;
946     if (lsame_(ei + 1, " ") || *mode != 0) {
947         useei = FALSE_;
948     } else {
949         if (lsame_(ei + 1, "R")) {
950             i__1 = *n;
951             for (j = 2; j <= i__1; ++j) {
952                 if (lsame_(ei + j, "I")) {
953                     if (lsame_(ei + (j - 1), "I")) {
954                         badei = TRUE_;
955                     }
956                 } else {
957                     if (! lsame_(ei + j, "R")) {
958                         badei = TRUE_;
959                     }
960                 }
961 /* L10: */
962             }
963         } else {
964             badei = TRUE_;
965         }
966     }
967
968 /*     Decode RSIGN */
969
970     if (lsame_(rsign, "T")) {
971         irsign = 1;
972     } else if (lsame_(rsign, "F")) {
973         irsign = 0;
974     } else {
975         irsign = -1;
976     }
977
978 /*     Decode UPPER */
979
980     if (lsame_(upper, "T")) {
981         iupper = 1;
982     } else if (lsame_(upper, "F")) {
983         iupper = 0;
984     } else {
985         iupper = -1;
986     }
987
988 /*     Decode SIM */
989
990     if (lsame_(sim, "T")) {
991         isim = 1;
992     } else if (lsame_(sim, "F")) {
993         isim = 0;
994     } else {
995         isim = -1;
996     }
997
998 /*     Check DS, if MODES=0 and ISIM=1 */
999
1000     bads = FALSE_;
1001     if (*modes == 0 && isim == 1) {
1002         i__1 = *n;
1003         for (j = 1; j <= i__1; ++j) {
1004             if (ds[j] == 0.) {
1005                 bads = TRUE_;
1006             }
1007 /* L20: */
1008         }
1009     }
1010
1011 /*     Set INFO if an error */
1012
1013     if (*n < 0) {
1014         *info = -1;
1015     } else if (idist == -1) {
1016         *info = -2;
1017     } else if (abs(*mode) > 6) {
1018         *info = -5;
1019     } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.) {
1020         *info = -6;
1021     } else if (badei) {
1022         *info = -8;
1023     } else if (irsign == -1) {
1024         *info = -9;
1025     } else if (iupper == -1) {
1026         *info = -10;
1027     } else if (isim == -1) {
1028         *info = -11;
1029     } else if (bads) {
1030         *info = -12;
1031     } else if (isim == 1 && abs(*modes) > 5) {
1032         *info = -13;
1033     } else if (isim == 1 && *modes != 0 && *conds < 1.) {
1034         *info = -14;
1035     } else if (*kl < 1) {
1036         *info = -15;
1037     } else if (*ku < 1 || *ku < *n - 1 && *kl < *n - 1) {
1038         *info = -16;
1039     } else if (*lda < f2cmax(1,*n)) {
1040         *info = -19;
1041     }
1042
1043     if (*info != 0) {
1044         i__1 = -(*info);
1045         xerbla_("DLATME", &i__1);
1046         return 0;
1047     }
1048
1049 /*     Initialize random number generator */
1050
1051     for (i__ = 1; i__ <= 4; ++i__) {
1052         iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
1053 /* L30: */
1054     }
1055
1056     if (iseed[4] % 2 != 1) {
1057         ++iseed[4];
1058     }
1059
1060 /*     2)      Set up diagonal of A */
1061
1062 /*             Compute D according to COND and MODE */
1063
1064     dlatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], n, &iinfo);
1065     if (iinfo != 0) {
1066         *info = 1;
1067         return 0;
1068     }
1069     if (*mode != 0 && abs(*mode) != 6) {
1070
1071 /*        Scale by DMAX */
1072
1073         temp = abs(d__[1]);
1074         i__1 = *n;
1075         for (i__ = 2; i__ <= i__1; ++i__) {
1076 /* Computing MAX */
1077             d__2 = temp, d__3 = (d__1 = d__[i__], abs(d__1));
1078             temp = f2cmax(d__2,d__3);
1079 /* L40: */
1080         }
1081
1082         if (temp > 0.) {
1083             alpha = *dmax__ / temp;
1084         } else if (*dmax__ != 0.) {
1085             *info = 2;
1086             return 0;
1087         } else {
1088             alpha = 0.;
1089         }
1090
1091         dscal_(n, &alpha, &d__[1], &c__1);
1092
1093     }
1094
1095     dlaset_("Full", n, n, &c_b23, &c_b23, &a[a_offset], lda);
1096     i__1 = *lda + 1;
1097     dcopy_(n, &d__[1], &c__1, &a[a_offset], &i__1);
1098
1099 /*     Set up complex conjugate pairs */
1100
1101     if (*mode == 0) {
1102         if (useei) {
1103             i__1 = *n;
1104             for (j = 2; j <= i__1; ++j) {
1105                 if (lsame_(ei + j, "I")) {
1106                     a[j - 1 + j * a_dim1] = a[j + j * a_dim1];
1107                     a[j + (j - 1) * a_dim1] = -a[j + j * a_dim1];
1108                     a[j + j * a_dim1] = a[j - 1 + (j - 1) * a_dim1];
1109                 }
1110 /* L50: */
1111             }
1112         }
1113
1114     } else if (abs(*mode) == 5) {
1115
1116         i__1 = *n;
1117         for (j = 2; j <= i__1; j += 2) {
1118             if (dlaran_(&iseed[1]) > .5) {
1119                 a[j - 1 + j * a_dim1] = a[j + j * a_dim1];
1120                 a[j + (j - 1) * a_dim1] = -a[j + j * a_dim1];
1121                 a[j + j * a_dim1] = a[j - 1 + (j - 1) * a_dim1];
1122             }
1123 /* L60: */
1124         }
1125     }
1126
1127 /*     3)      If UPPER='T', set upper triangle of A to random numbers. */
1128 /*             (but don't modify the corners of 2x2 blocks.) */
1129
1130     if (iupper != 0) {
1131         i__1 = *n;
1132         for (jc = 2; jc <= i__1; ++jc) {
1133             if (a[jc - 1 + jc * a_dim1] != 0.) {
1134                 jr = jc - 2;
1135             } else {
1136                 jr = jc - 1;
1137             }
1138             dlarnv_(&idist, &iseed[1], &jr, &a[jc * a_dim1 + 1]);
1139 /* L70: */
1140         }
1141     }
1142
1143 /*     4)      If SIM='T', apply similarity transformation. */
1144
1145 /*                                -1 */
1146 /*             Transform is  X A X  , where X = U S V, thus */
1147
1148 /*             it is  U S V A V' (1/S) U' */
1149
1150     if (isim != 0) {
1151
1152 /*        Compute S (singular values of the eigenvector matrix) */
1153 /*        according to CONDS and MODES */
1154
1155         dlatm1_(modes, conds, &c__0, &c__0, &iseed[1], &ds[1], n, &iinfo);
1156         if (iinfo != 0) {
1157             *info = 3;
1158             return 0;
1159         }
1160
1161 /*        Multiply by V and V' */
1162
1163         dlarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
1164         if (iinfo != 0) {
1165             *info = 4;
1166             return 0;
1167         }
1168
1169 /*        Multiply by S and (1/S) */
1170
1171         i__1 = *n;
1172         for (j = 1; j <= i__1; ++j) {
1173             dscal_(n, &ds[j], &a[j + a_dim1], lda);
1174             if (ds[j] != 0.) {
1175                 d__1 = 1. / ds[j];
1176                 dscal_(n, &d__1, &a[j * a_dim1 + 1], &c__1);
1177             } else {
1178                 *info = 5;
1179                 return 0;
1180             }
1181 /* L80: */
1182         }
1183
1184 /*        Multiply by U and U' */
1185
1186         dlarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
1187         if (iinfo != 0) {
1188             *info = 4;
1189             return 0;
1190         }
1191     }
1192
1193 /*     5)      Reduce the bandwidth. */
1194
1195     if (*kl < *n - 1) {
1196
1197 /*        Reduce bandwidth -- kill column */
1198
1199         i__1 = *n - 1;
1200         for (jcr = *kl + 1; jcr <= i__1; ++jcr) {
1201             ic = jcr - *kl;
1202             irows = *n + 1 - jcr;
1203             icols = *n + *kl - jcr;
1204
1205             dcopy_(&irows, &a[jcr + ic * a_dim1], &c__1, &work[1], &c__1);
1206             xnorms = work[1];
1207             dlarfg_(&irows, &xnorms, &work[2], &c__1, &tau);
1208             work[1] = 1.;
1209
1210             dgemv_("T", &irows, &icols, &c_b39, &a[jcr + (ic + 1) * a_dim1], 
1211                     lda, &work[1], &c__1, &c_b23, &work[irows + 1], &c__1);
1212             d__1 = -tau;
1213             dger_(&irows, &icols, &d__1, &work[1], &c__1, &work[irows + 1], &
1214                     c__1, &a[jcr + (ic + 1) * a_dim1], lda);
1215
1216             dgemv_("N", n, &irows, &c_b39, &a[jcr * a_dim1 + 1], lda, &work[1]
1217                     , &c__1, &c_b23, &work[irows + 1], &c__1);
1218             d__1 = -tau;
1219             dger_(n, &irows, &d__1, &work[irows + 1], &c__1, &work[1], &c__1, 
1220                     &a[jcr * a_dim1 + 1], lda);
1221
1222             a[jcr + ic * a_dim1] = xnorms;
1223             i__2 = irows - 1;
1224             dlaset_("Full", &i__2, &c__1, &c_b23, &c_b23, &a[jcr + 1 + ic * 
1225                     a_dim1], lda);
1226 /* L90: */
1227         }
1228     } else if (*ku < *n - 1) {
1229
1230 /*        Reduce upper bandwidth -- kill a row at a time. */
1231
1232         i__1 = *n - 1;
1233         for (jcr = *ku + 1; jcr <= i__1; ++jcr) {
1234             ir = jcr - *ku;
1235             irows = *n + *ku - jcr;
1236             icols = *n + 1 - jcr;
1237
1238             dcopy_(&icols, &a[ir + jcr * a_dim1], lda, &work[1], &c__1);
1239             xnorms = work[1];
1240             dlarfg_(&icols, &xnorms, &work[2], &c__1, &tau);
1241             work[1] = 1.;
1242
1243             dgemv_("N", &irows, &icols, &c_b39, &a[ir + 1 + jcr * a_dim1], 
1244                     lda, &work[1], &c__1, &c_b23, &work[icols + 1], &c__1);
1245             d__1 = -tau;
1246             dger_(&irows, &icols, &d__1, &work[icols + 1], &c__1, &work[1], &
1247                     c__1, &a[ir + 1 + jcr * a_dim1], lda);
1248
1249             dgemv_("C", &icols, n, &c_b39, &a[jcr + a_dim1], lda, &work[1], &
1250                     c__1, &c_b23, &work[icols + 1], &c__1);
1251             d__1 = -tau;
1252             dger_(&icols, n, &d__1, &work[1], &c__1, &work[icols + 1], &c__1, 
1253                     &a[jcr + a_dim1], lda);
1254
1255             a[ir + jcr * a_dim1] = xnorms;
1256             i__2 = icols - 1;
1257             dlaset_("Full", &c__1, &i__2, &c_b23, &c_b23, &a[ir + (jcr + 1) * 
1258                     a_dim1], lda);
1259 /* L100: */
1260         }
1261     }
1262
1263 /*     Scale the matrix to have norm ANORM */
1264
1265     if (*anorm >= 0.) {
1266         temp = dlange_("M", n, n, &a[a_offset], lda, tempa);
1267         if (temp > 0.) {
1268             alpha = *anorm / temp;
1269             i__1 = *n;
1270             for (j = 1; j <= i__1; ++j) {
1271                 dscal_(n, &alpha, &a[j * a_dim1 + 1], &c__1);
1272 /* L110: */
1273             }
1274         }
1275     }
1276
1277     return 0;
1278
1279 /*     End of DLATME */
1280
1281 } /* dlatme_ */
1282