C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / TESTING / MATGEN / zlatmr.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 integer c__0 = 0;
517 static integer c__1 = 1;
518
519 /* > \brief \b ZLATMR */
520
521 /*  =========== DOCUMENTATION =========== */
522
523 /* Online html documentation available at */
524 /*            http://www.netlib.org/lapack/explore-html/ */
525
526 /*  Definition: */
527 /*  =========== */
528
529 /*       SUBROUTINE ZLATMR( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
530 /*                          RSIGN, GRADE, DL, MODEL, CONDL, DR, MODER, */
531 /*                          CONDR, PIVTNG, IPIVOT, KL, KU, SPARSE, ANORM, */
532 /*                          PACK, A, LDA, IWORK, INFO ) */
533
534 /*       CHARACTER          DIST, GRADE, PACK, PIVTNG, RSIGN, SYM */
535 /*       INTEGER            INFO, KL, KU, LDA, M, MODE, MODEL, MODER, N */
536 /*       DOUBLE PRECISION   ANORM, COND, CONDL, CONDR, SPARSE */
537 /*       COMPLEX*16         DMAX */
538 /*       INTEGER            IPIVOT( * ), ISEED( 4 ), IWORK( * ) */
539 /*       COMPLEX*16         A( LDA, * ), D( * ), DL( * ), DR( * ) */
540
541
542 /* > \par Purpose: */
543 /*  ============= */
544 /* > */
545 /* > \verbatim */
546 /* > */
547 /* >    ZLATMR generates random matrices of various types for testing */
548 /* >    LAPACK programs. */
549 /* > */
550 /* >    ZLATMR operates by applying the following sequence of */
551 /* >    operations: */
552 /* > */
553 /* >      Generate a matrix A with random entries of distribution DIST */
554 /* >         which is symmetric if SYM='S', Hermitian if SYM='H', and */
555 /* >         nonsymmetric if SYM='N'. */
556 /* > */
557 /* >      Set the diagonal to D, where D may be input or */
558 /* >         computed according to MODE, COND, DMAX and RSIGN */
559 /* >         as described below. */
560 /* > */
561 /* >      Grade the matrix, if desired, from the left and/or right */
562 /* >         as specified by GRADE. The inputs DL, MODEL, CONDL, DR, */
563 /* >         MODER and CONDR also determine the grading as described */
564 /* >         below. */
565 /* > */
566 /* >      Permute, if desired, the rows and/or columns as specified by */
567 /* >         PIVTNG and IPIVOT. */
568 /* > */
569 /* >      Set random entries to zero, if desired, to get a random sparse */
570 /* >         matrix as specified by SPARSE. */
571 /* > */
572 /* >      Make A a band matrix, if desired, by zeroing out the matrix */
573 /* >         outside a band of lower bandwidth KL and upper bandwidth KU. */
574 /* > */
575 /* >      Scale A, if desired, to have maximum entry ANORM. */
576 /* > */
577 /* >      Pack the matrix if desired. Options specified by PACK are: */
578 /* >         no packing */
579 /* >         zero out upper half (if symmetric or Hermitian) */
580 /* >         zero out lower half (if symmetric or Hermitian) */
581 /* >         store the upper half columnwise (if symmetric or Hermitian */
582 /* >             or square upper triangular) */
583 /* >         store the lower half columnwise (if symmetric or Hermitian */
584 /* >             or square lower triangular) */
585 /* >             same as upper half rowwise if symmetric */
586 /* >             same as conjugate upper half rowwise if Hermitian */
587 /* >         store the lower triangle in banded format */
588 /* >             (if symmetric or Hermitian) */
589 /* >         store the upper triangle in banded format */
590 /* >             (if symmetric or Hermitian) */
591 /* >         store the entire matrix in banded format */
592 /* > */
593 /* >    Note: If two calls to ZLATMR differ only in the PACK parameter, */
594 /* >          they will generate mathematically equivalent matrices. */
595 /* > */
596 /* >          If two calls to ZLATMR both have full bandwidth (KL = M-1 */
597 /* >          and KU = N-1), and differ only in the PIVTNG and PACK */
598 /* >          parameters, then the matrices generated will differ only */
599 /* >          in the order of the rows and/or columns, and otherwise */
600 /* >          contain the same data. This consistency cannot be and */
601 /* >          is not maintained with less than full bandwidth. */
602 /* > \endverbatim */
603
604 /*  Arguments: */
605 /*  ========== */
606
607 /* > \param[in] M */
608 /* > \verbatim */
609 /* >          M is INTEGER */
610 /* >           Number of rows of A. Not modified. */
611 /* > \endverbatim */
612 /* > */
613 /* > \param[in] N */
614 /* > \verbatim */
615 /* >          N is INTEGER */
616 /* >           Number of columns of A. Not modified. */
617 /* > \endverbatim */
618 /* > */
619 /* > \param[in] DIST */
620 /* > \verbatim */
621 /* >          DIST is CHARACTER*1 */
622 /* >           On entry, DIST specifies the type of distribution to be used */
623 /* >           to generate a random matrix . */
624 /* >           'U' => real and imaginary parts are independent */
625 /* >                  UNIFORM( 0, 1 )  ( 'U' for uniform ) */
626 /* >           'S' => real and imaginary parts are independent */
627 /* >                  UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
628 /* >           'N' => real and imaginary parts are independent */
629 /* >                  NORMAL( 0, 1 )   ( 'N' for normal ) */
630 /* >           'D' => uniform on interior of unit disk ( 'D' for disk ) */
631 /* >           Not modified. */
632 /* > \endverbatim */
633 /* > */
634 /* > \param[in,out] ISEED */
635 /* > \verbatim */
636 /* >          ISEED is INTEGER array, dimension (4) */
637 /* >           On entry ISEED specifies the seed of the random number */
638 /* >           generator. They should lie between 0 and 4095 inclusive, */
639 /* >           and ISEED(4) should be odd. The random number generator */
640 /* >           uses a linear congruential sequence limited to small */
641 /* >           integers, and so should produce machine independent */
642 /* >           random numbers. The values of ISEED are changed on */
643 /* >           exit, and can be used in the next call to ZLATMR */
644 /* >           to continue the same random number sequence. */
645 /* >           Changed on exit. */
646 /* > \endverbatim */
647 /* > */
648 /* > \param[in] SYM */
649 /* > \verbatim */
650 /* >          SYM is CHARACTER*1 */
651 /* >           If SYM='S', generated matrix is symmetric. */
652 /* >           If SYM='H', generated matrix is Hermitian. */
653 /* >           If SYM='N', generated matrix is nonsymmetric. */
654 /* >           Not modified. */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in,out] D */
658 /* > \verbatim */
659 /* >          D is COMPLEX*16 array, dimension (f2cmin(M,N)) */
660 /* >           On entry this array specifies the diagonal entries */
661 /* >           of the diagonal of A.  D may either be specified */
662 /* >           on entry, or set according to MODE and COND as described */
663 /* >           below. If the matrix is Hermitian, the real part of D */
664 /* >           will be taken. May be changed on exit if MODE is nonzero. */
665 /* > \endverbatim */
666 /* > */
667 /* > \param[in] MODE */
668 /* > \verbatim */
669 /* >          MODE is INTEGER */
670 /* >           On entry describes how D is to be used: */
671 /* >           MODE = 0 means use D as input */
672 /* >           MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
673 /* >           MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
674 /* >           MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
675 /* >           MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
676 /* >           MODE = 5 sets D to random numbers in the range */
677 /* >                    ( 1/COND , 1 ) such that their logarithms */
678 /* >                    are uniformly distributed. */
679 /* >           MODE = 6 set D to random numbers from same distribution */
680 /* >                    as the rest of the matrix. */
681 /* >           MODE < 0 has the same meaning as ABS(MODE), except that */
682 /* >              the order of the elements of D is reversed. */
683 /* >           Thus if MODE is positive, D has entries ranging from */
684 /* >              1 to 1/COND, if negative, from 1/COND to 1, */
685 /* >           Not modified. */
686 /* > \endverbatim */
687 /* > */
688 /* > \param[in] COND */
689 /* > \verbatim */
690 /* >          COND is DOUBLE PRECISION */
691 /* >           On entry, used as described under MODE above. */
692 /* >           If used, it must be >= 1. Not modified. */
693 /* > \endverbatim */
694 /* > */
695 /* > \param[in] DMAX */
696 /* > \verbatim */
697 /* >          DMAX is COMPLEX*16 */
698 /* >           If MODE neither -6, 0 nor 6, the diagonal is scaled by */
699 /* >           DMAX / f2cmax(abs(D(i))), so that maximum absolute entry */
700 /* >           of diagonal is abs(DMAX). If DMAX is complex (or zero), */
701 /* >           diagonal will be scaled by a complex number (or zero). */
702 /* > \endverbatim */
703 /* > */
704 /* > \param[in] RSIGN */
705 /* > \verbatim */
706 /* >          RSIGN is CHARACTER*1 */
707 /* >           If MODE neither -6, 0 nor 6, specifies sign of diagonal */
708 /* >           as follows: */
709 /* >           'T' => diagonal entries are multiplied by a random complex */
710 /* >                  number uniformly distributed with absolute value 1 */
711 /* >           'F' => diagonal unchanged */
712 /* >           Not modified. */
713 /* > \endverbatim */
714 /* > */
715 /* > \param[in] GRADE */
716 /* > \verbatim */
717 /* >          GRADE is CHARACTER*1 */
718 /* >           Specifies grading of matrix as follows: */
719 /* >           'N'  => no grading */
720 /* >           'L'  => matrix premultiplied by diag( DL ) */
721 /* >                   (only if matrix nonsymmetric) */
722 /* >           'R'  => matrix postmultiplied by diag( DR ) */
723 /* >                   (only if matrix nonsymmetric) */
724 /* >           'B'  => matrix premultiplied by diag( DL ) and */
725 /* >                         postmultiplied by diag( DR ) */
726 /* >                   (only if matrix nonsymmetric) */
727 /* >           'H'  => matrix premultiplied by diag( DL ) and */
728 /* >                         postmultiplied by diag( CONJG(DL) ) */
729 /* >                   (only if matrix Hermitian or nonsymmetric) */
730 /* >           'S'  => matrix premultiplied by diag( DL ) and */
731 /* >                         postmultiplied by diag( DL ) */
732 /* >                   (only if matrix symmetric or nonsymmetric) */
733 /* >           'E'  => matrix premultiplied by diag( DL ) and */
734 /* >                         postmultiplied by inv( diag( DL ) ) */
735 /* >                         ( 'S' for similarity ) */
736 /* >                   (only if matrix nonsymmetric) */
737 /* >                   Note: if GRADE='S', then M must equal N. */
738 /* >           Not modified. */
739 /* > \endverbatim */
740 /* > */
741 /* > \param[in,out] DL */
742 /* > \verbatim */
743 /* >          DL is COMPLEX*16 array, dimension (M) */
744 /* >           If MODEL=0, then on entry this array specifies the diagonal */
745 /* >           entries of a diagonal matrix used as described under GRADE */
746 /* >           above. If MODEL is not zero, then DL will be set according */
747 /* >           to MODEL and CONDL, analogous to the way D is set according */
748 /* >           to MODE and COND (except there is no DMAX parameter for DL). */
749 /* >           If GRADE='E', then DL cannot have zero entries. */
750 /* >           Not referenced if GRADE = 'N' or 'R'. Changed on exit. */
751 /* > \endverbatim */
752 /* > */
753 /* > \param[in] MODEL */
754 /* > \verbatim */
755 /* >          MODEL is INTEGER */
756 /* >           This specifies how the diagonal array DL is to be computed, */
757 /* >           just as MODE specifies how D is to be computed. */
758 /* >           Not modified. */
759 /* > \endverbatim */
760 /* > */
761 /* > \param[in] CONDL */
762 /* > \verbatim */
763 /* >          CONDL is DOUBLE PRECISION */
764 /* >           When MODEL is not zero, this specifies the condition number */
765 /* >           of the computed DL.  Not modified. */
766 /* > \endverbatim */
767 /* > */
768 /* > \param[in,out] DR */
769 /* > \verbatim */
770 /* >          DR is COMPLEX*16 array, dimension (N) */
771 /* >           If MODER=0, then on entry this array specifies the diagonal */
772 /* >           entries of a diagonal matrix used as described under GRADE */
773 /* >           above. If MODER is not zero, then DR will be set according */
774 /* >           to MODER and CONDR, analogous to the way D is set according */
775 /* >           to MODE and COND (except there is no DMAX parameter for DR). */
776 /* >           Not referenced if GRADE = 'N', 'L', 'H' or 'S'. */
777 /* >           Changed on exit. */
778 /* > \endverbatim */
779 /* > */
780 /* > \param[in] MODER */
781 /* > \verbatim */
782 /* >          MODER is INTEGER */
783 /* >           This specifies how the diagonal array DR is to be computed, */
784 /* >           just as MODE specifies how D is to be computed. */
785 /* >           Not modified. */
786 /* > \endverbatim */
787 /* > */
788 /* > \param[in] CONDR */
789 /* > \verbatim */
790 /* >          CONDR is DOUBLE PRECISION */
791 /* >           When MODER is not zero, this specifies the condition number */
792 /* >           of the computed DR.  Not modified. */
793 /* > \endverbatim */
794 /* > */
795 /* > \param[in] PIVTNG */
796 /* > \verbatim */
797 /* >          PIVTNG is CHARACTER*1 */
798 /* >           On entry specifies pivoting permutations as follows: */
799 /* >           'N' or ' ' => none. */
800 /* >           'L' => left or row pivoting (matrix must be nonsymmetric). */
801 /* >           'R' => right or column pivoting (matrix must be */
802 /* >                  nonsymmetric). */
803 /* >           'B' or 'F' => both or full pivoting, i.e., on both sides. */
804 /* >                         In this case, M must equal N */
805 /* > */
806 /* >           If two calls to ZLATMR both have full bandwidth (KL = M-1 */
807 /* >           and KU = N-1), and differ only in the PIVTNG and PACK */
808 /* >           parameters, then the matrices generated will differ only */
809 /* >           in the order of the rows and/or columns, and otherwise */
810 /* >           contain the same data. This consistency cannot be */
811 /* >           maintained with less than full bandwidth. */
812 /* > \endverbatim */
813 /* > */
814 /* > \param[in] IPIVOT */
815 /* > \verbatim */
816 /* >          IPIVOT is INTEGER array, dimension (N or M) */
817 /* >           This array specifies the permutation used.  After the */
818 /* >           basic matrix is generated, the rows, columns, or both */
819 /* >           are permuted.   If, say, row pivoting is selected, ZLATMR */
820 /* >           starts with the *last* row and interchanges the M-th and */
821 /* >           IPIVOT(M)-th rows, then moves to the next-to-last row, */
822 /* >           interchanging the (M-1)-th and the IPIVOT(M-1)-th rows, */
823 /* >           and so on.  In terms of "2-cycles", the permutation is */
824 /* >           (1 IPIVOT(1)) (2 IPIVOT(2)) ... (M IPIVOT(M)) */
825 /* >           where the rightmost cycle is applied first.  This is the */
826 /* >           *inverse* of the effect of pivoting in LINPACK.  The idea */
827 /* >           is that factoring (with pivoting) an identity matrix */
828 /* >           which has been inverse-pivoted in this way should */
829 /* >           result in a pivot vector identical to IPIVOT. */
830 /* >           Not referenced if PIVTNG = 'N'. Not modified. */
831 /* > \endverbatim */
832 /* > */
833 /* > \param[in] KL */
834 /* > \verbatim */
835 /* >          KL is INTEGER */
836 /* >           On entry specifies the lower bandwidth of the  matrix. For */
837 /* >           example, KL=0 implies upper triangular, KL=1 implies upper */
838 /* >           Hessenberg, and KL at least M-1 implies the matrix is not */
839 /* >           banded. Must equal KU if matrix is symmetric or Hermitian. */
840 /* >           Not modified. */
841 /* > \endverbatim */
842 /* > */
843 /* > \param[in] KU */
844 /* > \verbatim */
845 /* >          KU is INTEGER */
846 /* >           On entry specifies the upper bandwidth of the  matrix. For */
847 /* >           example, KU=0 implies lower triangular, KU=1 implies lower */
848 /* >           Hessenberg, and KU at least N-1 implies the matrix is not */
849 /* >           banded. Must equal KL if matrix is symmetric or Hermitian. */
850 /* >           Not modified. */
851 /* > \endverbatim */
852 /* > */
853 /* > \param[in] SPARSE */
854 /* > \verbatim */
855 /* >          SPARSE is DOUBLE PRECISION */
856 /* >           On entry specifies the sparsity of the matrix if a sparse */
857 /* >           matrix is to be generated. SPARSE should lie between */
858 /* >           0 and 1. To generate a sparse matrix, for each matrix entry */
859 /* >           a uniform ( 0, 1 ) random number x is generated and */
860 /* >           compared to SPARSE; if x is larger the matrix entry */
861 /* >           is unchanged and if x is smaller the entry is set */
862 /* >           to zero. Thus on the average a fraction SPARSE of the */
863 /* >           entries will be set to zero. */
864 /* >           Not modified. */
865 /* > \endverbatim */
866 /* > */
867 /* > \param[in] ANORM */
868 /* > \verbatim */
869 /* >          ANORM is DOUBLE PRECISION */
870 /* >           On entry specifies maximum entry of output matrix */
871 /* >           (output matrix will by multiplied by a constant so that */
872 /* >           its largest absolute entry equal ANORM) */
873 /* >           if ANORM is nonnegative. If ANORM is negative no scaling */
874 /* >           is done. Not modified. */
875 /* > \endverbatim */
876 /* > */
877 /* > \param[in] PACK */
878 /* > \verbatim */
879 /* >          PACK is CHARACTER*1 */
880 /* >           On entry specifies packing of matrix as follows: */
881 /* >           'N' => no packing */
882 /* >           'U' => zero out all subdiagonal entries */
883 /* >                  (if symmetric or Hermitian) */
884 /* >           'L' => zero out all superdiagonal entries */
885 /* >                  (if symmetric or Hermitian) */
886 /* >           'C' => store the upper triangle columnwise */
887 /* >                  (only if matrix symmetric or Hermitian or */
888 /* >                   square upper triangular) */
889 /* >           'R' => store the lower triangle columnwise */
890 /* >                  (only if matrix symmetric or Hermitian or */
891 /* >                   square lower triangular) */
892 /* >                  (same as upper half rowwise if symmetric) */
893 /* >                  (same as conjugate upper half rowwise if Hermitian) */
894 /* >           'B' => store the lower triangle in band storage scheme */
895 /* >                  (only if matrix symmetric or Hermitian) */
896 /* >           'Q' => store the upper triangle in band storage scheme */
897 /* >                  (only if matrix symmetric or Hermitian) */
898 /* >           'Z' => store the entire matrix in band storage scheme */
899 /* >                      (pivoting can be provided for by using this */
900 /* >                      option to store A in the trailing rows of */
901 /* >                      the allocated storage) */
902 /* > */
903 /* >           Using these options, the various LAPACK packed and banded */
904 /* >           storage schemes can be obtained: */
905 /* >           GB               - use 'Z' */
906 /* >           PB, HB or TB     - use 'B' or 'Q' */
907 /* >           PP, HP or TP     - use 'C' or 'R' */
908 /* > */
909 /* >           If two calls to ZLATMR differ only in the PACK parameter, */
910 /* >           they will generate mathematically equivalent matrices. */
911 /* >           Not modified. */
912 /* > \endverbatim */
913 /* > */
914 /* > \param[in,out] A */
915 /* > \verbatim */
916 /* >          A is COMPLEX*16 array, dimension (LDA,N) */
917 /* >           On exit A is the desired test matrix. Only those */
918 /* >           entries of A which are significant on output */
919 /* >           will be referenced (even if A is in packed or band */
920 /* >           storage format). The 'unoccupied corners' of A in */
921 /* >           band format will be zeroed out. */
922 /* > \endverbatim */
923 /* > */
924 /* > \param[in] LDA */
925 /* > \verbatim */
926 /* >          LDA is INTEGER */
927 /* >           on entry LDA specifies the first dimension of A as */
928 /* >           declared in the calling program. */
929 /* >           If PACK='N', 'U' or 'L', LDA must be at least f2cmax ( 1, M ). */
930 /* >           If PACK='C' or 'R', LDA must be at least 1. */
931 /* >           If PACK='B', or 'Q', LDA must be MIN ( KU+1, N ) */
932 /* >           If PACK='Z', LDA must be at least KUU+KLL+1, where */
933 /* >           KUU = MIN ( KU, N-1 ) and KLL = MIN ( KL, M-1 ) */
934 /* >           Not modified. */
935 /* > \endverbatim */
936 /* > */
937 /* > \param[out] IWORK */
938 /* > \verbatim */
939 /* >          IWORK is INTEGER array, dimension (N or M) */
940 /* >           Workspace. Not referenced if PIVTNG = 'N'. Changed on exit. */
941 /* > \endverbatim */
942 /* > */
943 /* > \param[out] INFO */
944 /* > \verbatim */
945 /* >          INFO is INTEGER */
946 /* >           Error parameter on exit: */
947 /* >             0 => normal return */
948 /* >            -1 => M negative or unequal to N and SYM='S' or 'H' */
949 /* >            -2 => N negative */
950 /* >            -3 => DIST illegal string */
951 /* >            -5 => SYM illegal string */
952 /* >            -7 => MODE not in range -6 to 6 */
953 /* >            -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
954 /* >           -10 => MODE neither -6, 0 nor 6 and RSIGN illegal string */
955 /* >           -11 => GRADE illegal string, or GRADE='E' and */
956 /* >                  M not equal to N, or GRADE='L', 'R', 'B', 'S' or 'E' */
957 /* >                  and SYM = 'H', or GRADE='L', 'R', 'B', 'H' or 'E' */
958 /* >                  and SYM = 'S' */
959 /* >           -12 => GRADE = 'E' and DL contains zero */
960 /* >           -13 => MODEL not in range -6 to 6 and GRADE= 'L', 'B', 'H', */
961 /* >                  'S' or 'E' */
962 /* >           -14 => CONDL less than 1.0, GRADE='L', 'B', 'H', 'S' or 'E', */
963 /* >                  and MODEL neither -6, 0 nor 6 */
964 /* >           -16 => MODER not in range -6 to 6 and GRADE= 'R' or 'B' */
965 /* >           -17 => CONDR less than 1.0, GRADE='R' or 'B', and */
966 /* >                  MODER neither -6, 0 nor 6 */
967 /* >           -18 => PIVTNG illegal string, or PIVTNG='B' or 'F' and */
968 /* >                  M not equal to N, or PIVTNG='L' or 'R' and SYM='S' */
969 /* >                  or 'H' */
970 /* >           -19 => IPIVOT contains out of range number and */
971 /* >                  PIVTNG not equal to 'N' */
972 /* >           -20 => KL negative */
973 /* >           -21 => KU negative, or SYM='S' or 'H' and KU not equal to KL */
974 /* >           -22 => SPARSE not in range 0. to 1. */
975 /* >           -24 => PACK illegal string, or PACK='U', 'L', 'B' or 'Q' */
976 /* >                  and SYM='N', or PACK='C' and SYM='N' and either KL */
977 /* >                  not equal to 0 or N not equal to M, or PACK='R' and */
978 /* >                  SYM='N', and either KU not equal to 0 or N not equal */
979 /* >                  to M */
980 /* >           -26 => LDA too small */
981 /* >             1 => Error return from ZLATM1 (computing D) */
982 /* >             2 => Cannot scale diagonal to DMAX (f2cmax. entry is 0) */
983 /* >             3 => Error return from ZLATM1 (computing DL) */
984 /* >             4 => Error return from ZLATM1 (computing DR) */
985 /* >             5 => ANORM is positive, but matrix constructed prior to */
986 /* >                  attempting to scale it to have norm ANORM, is zero */
987 /* > \endverbatim */
988
989 /*  Authors: */
990 /*  ======== */
991
992 /* > \author Univ. of Tennessee */
993 /* > \author Univ. of California Berkeley */
994 /* > \author Univ. of Colorado Denver */
995 /* > \author NAG Ltd. */
996
997 /* > \date December 2016 */
998
999 /* > \ingroup complex16_matgen */
1000
1001 /*  ===================================================================== */
1002 /* Subroutine */ int zlatmr_(integer *m, integer *n, char *dist, integer *
1003         iseed, char *sym, doublecomplex *d__, integer *mode, doublereal *cond,
1004          doublecomplex *dmax__, char *rsign, char *grade, doublecomplex *dl, 
1005         integer *model, doublereal *condl, doublecomplex *dr, integer *moder, 
1006         doublereal *condr, char *pivtng, integer *ipivot, integer *kl, 
1007         integer *ku, doublereal *sparse, doublereal *anorm, char *pack, 
1008         doublecomplex *a, integer *lda, integer *iwork, integer *info)
1009 {
1010     /* System generated locals */
1011     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
1012     doublereal d__1, d__2;
1013     doublecomplex z__1, z__2;
1014
1015     /* Local variables */
1016     integer isub, jsub;
1017     doublereal temp;
1018     integer isym, i__, j, k, ipack;
1019     extern logical lsame_(char *, char *);
1020     doublereal tempa[1];
1021     doublecomplex ctemp;
1022     integer iisub, idist, jjsub, mnmin;
1023     logical dzero;
1024     integer mnsub;
1025     doublereal onorm;
1026     integer mxsub, npvts;
1027     extern /* Subroutine */ int zlatm1_(integer *, doublereal *, integer *, 
1028             integer *, integer *, doublecomplex *, integer *, integer *);
1029     extern /* Double Complex */ VOID zlatm2_(doublecomplex *, integer *, 
1030             integer *, integer *, integer *, integer *, integer *, integer *, 
1031             integer *, doublecomplex *, integer *, doublecomplex *, 
1032             doublecomplex *, integer *, integer *, doublereal *), zlatm3_(
1033             doublecomplex *, integer *, integer *, integer *, integer *, 
1034             integer *, integer *, integer *, integer *, integer *, integer *, 
1035             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
1036             integer *, integer *, doublereal *);
1037     doublecomplex calpha;
1038     integer igrade;
1039     logical fulbnd;
1040     extern doublereal zlangb_(char *, integer *, integer *, integer *, 
1041             doublecomplex *, integer *, doublereal *);
1042     extern /* Subroutine */ int xerbla_(char *, integer *);
1043     logical badpvt;
1044     extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, 
1045             integer *, doublereal *);
1046     extern /* Subroutine */ int zdscal_(integer *, doublereal *, 
1047             doublecomplex *, integer *);
1048     extern doublereal zlansb_(char *, char *, integer *, integer *, 
1049             doublecomplex *, integer *, doublereal *);
1050     integer irsign, ipvtng;
1051     extern doublereal zlansp_(char *, char *, integer *, doublecomplex *, 
1052             doublereal *), zlansy_(char *, char *, integer *, 
1053             doublecomplex *, integer *, doublereal *);
1054     integer kll, kuu;
1055
1056
1057 /*  -- LAPACK computational routine (version 3.7.0) -- */
1058 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
1059 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
1060 /*     December 2016 */
1061
1062
1063 /*  ===================================================================== */
1064
1065
1066 /*     1)      Decode and Test the input parameters. */
1067 /*             Initialize flags & seed. */
1068
1069     /* Parameter adjustments */
1070     --iseed;
1071     --d__;
1072     --dl;
1073     --dr;
1074     --ipivot;
1075     a_dim1 = *lda;
1076     a_offset = 1 + a_dim1 * 1;
1077     a -= a_offset;
1078     --iwork;
1079
1080     /* Function Body */
1081     *info = 0;
1082
1083 /*     Quick return if possible */
1084
1085     if (*m == 0 || *n == 0) {
1086         return 0;
1087     }
1088
1089 /*     Decode DIST */
1090
1091     if (lsame_(dist, "U")) {
1092         idist = 1;
1093     } else if (lsame_(dist, "S")) {
1094         idist = 2;
1095     } else if (lsame_(dist, "N")) {
1096         idist = 3;
1097     } else if (lsame_(dist, "D")) {
1098         idist = 4;
1099     } else {
1100         idist = -1;
1101     }
1102
1103 /*     Decode SYM */
1104
1105     if (lsame_(sym, "H")) {
1106         isym = 0;
1107     } else if (lsame_(sym, "N")) {
1108         isym = 1;
1109     } else if (lsame_(sym, "S")) {
1110         isym = 2;
1111     } else {
1112         isym = -1;
1113     }
1114
1115 /*     Decode RSIGN */
1116
1117     if (lsame_(rsign, "F")) {
1118         irsign = 0;
1119     } else if (lsame_(rsign, "T")) {
1120         irsign = 1;
1121     } else {
1122         irsign = -1;
1123     }
1124
1125 /*     Decode PIVTNG */
1126
1127     if (lsame_(pivtng, "N")) {
1128         ipvtng = 0;
1129     } else if (lsame_(pivtng, " ")) {
1130         ipvtng = 0;
1131     } else if (lsame_(pivtng, "L")) {
1132         ipvtng = 1;
1133         npvts = *m;
1134     } else if (lsame_(pivtng, "R")) {
1135         ipvtng = 2;
1136         npvts = *n;
1137     } else if (lsame_(pivtng, "B")) {
1138         ipvtng = 3;
1139         npvts = f2cmin(*n,*m);
1140     } else if (lsame_(pivtng, "F")) {
1141         ipvtng = 3;
1142         npvts = f2cmin(*n,*m);
1143     } else {
1144         ipvtng = -1;
1145     }
1146
1147 /*     Decode GRADE */
1148
1149     if (lsame_(grade, "N")) {
1150         igrade = 0;
1151     } else if (lsame_(grade, "L")) {
1152         igrade = 1;
1153     } else if (lsame_(grade, "R")) {
1154         igrade = 2;
1155     } else if (lsame_(grade, "B")) {
1156         igrade = 3;
1157     } else if (lsame_(grade, "E")) {
1158         igrade = 4;
1159     } else if (lsame_(grade, "H")) {
1160         igrade = 5;
1161     } else if (lsame_(grade, "S")) {
1162         igrade = 6;
1163     } else {
1164         igrade = -1;
1165     }
1166
1167 /*     Decode PACK */
1168
1169     if (lsame_(pack, "N")) {
1170         ipack = 0;
1171     } else if (lsame_(pack, "U")) {
1172         ipack = 1;
1173     } else if (lsame_(pack, "L")) {
1174         ipack = 2;
1175     } else if (lsame_(pack, "C")) {
1176         ipack = 3;
1177     } else if (lsame_(pack, "R")) {
1178         ipack = 4;
1179     } else if (lsame_(pack, "B")) {
1180         ipack = 5;
1181     } else if (lsame_(pack, "Q")) {
1182         ipack = 6;
1183     } else if (lsame_(pack, "Z")) {
1184         ipack = 7;
1185     } else {
1186         ipack = -1;
1187     }
1188
1189 /*     Set certain internal parameters */
1190
1191     mnmin = f2cmin(*m,*n);
1192 /* Computing MIN */
1193     i__1 = *kl, i__2 = *m - 1;
1194     kll = f2cmin(i__1,i__2);
1195 /* Computing MIN */
1196     i__1 = *ku, i__2 = *n - 1;
1197     kuu = f2cmin(i__1,i__2);
1198
1199 /*     If inv(DL) is used, check to see if DL has a zero entry. */
1200
1201     dzero = FALSE_;
1202     if (igrade == 4 && *model == 0) {
1203         i__1 = *m;
1204         for (i__ = 1; i__ <= i__1; ++i__) {
1205             i__2 = i__;
1206             if (dl[i__2].r == 0. && dl[i__2].i == 0.) {
1207                 dzero = TRUE_;
1208             }
1209 /* L10: */
1210         }
1211     }
1212
1213 /*     Check values in IPIVOT */
1214
1215     badpvt = FALSE_;
1216     if (ipvtng > 0) {
1217         i__1 = npvts;
1218         for (j = 1; j <= i__1; ++j) {
1219             if (ipivot[j] <= 0 || ipivot[j] > npvts) {
1220                 badpvt = TRUE_;
1221             }
1222 /* L20: */
1223         }
1224     }
1225
1226 /*     Set INFO if an error */
1227
1228     if (*m < 0) {
1229         *info = -1;
1230     } else if (*m != *n && (isym == 0 || isym == 2)) {
1231         *info = -1;
1232     } else if (*n < 0) {
1233         *info = -2;
1234     } else if (idist == -1) {
1235         *info = -3;
1236     } else if (isym == -1) {
1237         *info = -5;
1238     } else if (*mode < -6 || *mode > 6) {
1239         *info = -7;
1240     } else if (*mode != -6 && *mode != 0 && *mode != 6 && *cond < 1.) {
1241         *info = -8;
1242     } else if (*mode != -6 && *mode != 0 && *mode != 6 && irsign == -1) {
1243         *info = -10;
1244     } else if (igrade == -1 || igrade == 4 && *m != *n || (igrade == 1 || 
1245             igrade == 2 || igrade == 3 || igrade == 4 || igrade == 6) && isym 
1246             == 0 || (igrade == 1 || igrade == 2 || igrade == 3 || igrade == 4 
1247             || igrade == 5) && isym == 2) {
1248         *info = -11;
1249     } else if (igrade == 4 && dzero) {
1250         *info = -12;
1251     } else if ((igrade == 1 || igrade == 3 || igrade == 4 || igrade == 5 || 
1252             igrade == 6) && (*model < -6 || *model > 6)) {
1253         *info = -13;
1254     } else if ((igrade == 1 || igrade == 3 || igrade == 4 || igrade == 5 || 
1255             igrade == 6) && (*model != -6 && *model != 0 && *model != 6) && *
1256             condl < 1.) {
1257         *info = -14;
1258     } else if ((igrade == 2 || igrade == 3) && (*moder < -6 || *moder > 6)) {
1259         *info = -16;
1260     } else if ((igrade == 2 || igrade == 3) && (*moder != -6 && *moder != 0 &&
1261              *moder != 6) && *condr < 1.) {
1262         *info = -17;
1263     } else if (ipvtng == -1 || ipvtng == 3 && *m != *n || (ipvtng == 1 || 
1264             ipvtng == 2) && (isym == 0 || isym == 2)) {
1265         *info = -18;
1266     } else if (ipvtng != 0 && badpvt) {
1267         *info = -19;
1268     } else if (*kl < 0) {
1269         *info = -20;
1270     } else if (*ku < 0 || (isym == 0 || isym == 2) && *kl != *ku) {
1271         *info = -21;
1272     } else if (*sparse < 0. || *sparse > 1.) {
1273         *info = -22;
1274     } else if (ipack == -1 || (ipack == 1 || ipack == 2 || ipack == 5 || 
1275             ipack == 6) && isym == 1 || ipack == 3 && isym == 1 && (*kl != 0 
1276             || *m != *n) || ipack == 4 && isym == 1 && (*ku != 0 || *m != *n))
1277              {
1278         *info = -24;
1279     } else if ((ipack == 0 || ipack == 1 || ipack == 2) && *lda < f2cmax(1,*m) ||
1280              (ipack == 3 || ipack == 4) && *lda < 1 || (ipack == 5 || ipack ==
1281              6) && *lda < kuu + 1 || ipack == 7 && *lda < kll + kuu + 1) {
1282         *info = -26;
1283     }
1284
1285     if (*info != 0) {
1286         i__1 = -(*info);
1287         xerbla_("ZLATMR", &i__1);
1288         return 0;
1289     }
1290
1291 /*     Decide if we can pivot consistently */
1292
1293     fulbnd = FALSE_;
1294     if (kuu == *n - 1 && kll == *m - 1) {
1295         fulbnd = TRUE_;
1296     }
1297
1298 /*     Initialize random number generator */
1299
1300     for (i__ = 1; i__ <= 4; ++i__) {
1301         iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
1302 /* L30: */
1303     }
1304
1305     iseed[4] = (iseed[4] / 2 << 1) + 1;
1306
1307 /*     2)      Set up D, DL, and DR, if indicated. */
1308
1309 /*             Compute D according to COND and MODE */
1310
1311     zlatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, info);
1312     if (*info != 0) {
1313         *info = 1;
1314         return 0;
1315     }
1316     if (*mode != 0 && *mode != -6 && *mode != 6) {
1317
1318 /*        Scale by DMAX */
1319
1320         temp = z_abs(&d__[1]);
1321         i__1 = mnmin;
1322         for (i__ = 2; i__ <= i__1; ++i__) {
1323 /* Computing MAX */
1324             d__1 = temp, d__2 = z_abs(&d__[i__]);
1325             temp = f2cmax(d__1,d__2);
1326 /* L40: */
1327         }
1328         if (temp == 0. && (dmax__->r != 0. || dmax__->i != 0.)) {
1329             *info = 2;
1330             return 0;
1331         }
1332         if (temp != 0.) {
1333             z__1.r = dmax__->r / temp, z__1.i = dmax__->i / temp;
1334             calpha.r = z__1.r, calpha.i = z__1.i;
1335         } else {
1336             calpha.r = 1., calpha.i = 0.;
1337         }
1338         i__1 = mnmin;
1339         for (i__ = 1; i__ <= i__1; ++i__) {
1340             i__2 = i__;
1341             i__3 = i__;
1342             z__1.r = calpha.r * d__[i__3].r - calpha.i * d__[i__3].i, z__1.i =
1343                      calpha.r * d__[i__3].i + calpha.i * d__[i__3].r;
1344             d__[i__2].r = z__1.r, d__[i__2].i = z__1.i;
1345 /* L50: */
1346         }
1347
1348     }
1349
1350 /*     If matrix Hermitian, make D real */
1351
1352     if (isym == 0) {
1353         i__1 = mnmin;
1354         for (i__ = 1; i__ <= i__1; ++i__) {
1355             i__2 = i__;
1356             i__3 = i__;
1357             d__1 = d__[i__3].r;
1358             d__[i__2].r = d__1, d__[i__2].i = 0.;
1359 /* L60: */
1360         }
1361     }
1362
1363 /*     Compute DL if grading set */
1364
1365     if (igrade == 1 || igrade == 3 || igrade == 4 || igrade == 5 || igrade == 
1366             6) {
1367         zlatm1_(model, condl, &c__0, &idist, &iseed[1], &dl[1], m, info);
1368         if (*info != 0) {
1369             *info = 3;
1370             return 0;
1371         }
1372     }
1373
1374 /*     Compute DR if grading set */
1375
1376     if (igrade == 2 || igrade == 3) {
1377         zlatm1_(moder, condr, &c__0, &idist, &iseed[1], &dr[1], n, info);
1378         if (*info != 0) {
1379             *info = 4;
1380             return 0;
1381         }
1382     }
1383
1384 /*     3)     Generate IWORK if pivoting */
1385
1386     if (ipvtng > 0) {
1387         i__1 = npvts;
1388         for (i__ = 1; i__ <= i__1; ++i__) {
1389             iwork[i__] = i__;
1390 /* L70: */
1391         }
1392         if (fulbnd) {
1393             i__1 = npvts;
1394             for (i__ = 1; i__ <= i__1; ++i__) {
1395                 k = ipivot[i__];
1396                 j = iwork[i__];
1397                 iwork[i__] = iwork[k];
1398                 iwork[k] = j;
1399 /* L80: */
1400             }
1401         } else {
1402             for (i__ = npvts; i__ >= 1; --i__) {
1403                 k = ipivot[i__];
1404                 j = iwork[i__];
1405                 iwork[i__] = iwork[k];
1406                 iwork[k] = j;
1407 /* L90: */
1408             }
1409         }
1410     }
1411
1412 /*     4)      Generate matrices for each kind of PACKing */
1413 /*             Always sweep matrix columnwise (if symmetric, upper */
1414 /*             half only) so that matrix generated does not depend */
1415 /*             on PACK */
1416
1417     if (fulbnd) {
1418
1419 /*        Use ZLATM3 so matrices generated with differing PIVOTing only */
1420 /*        differ only in the order of their rows and/or columns. */
1421
1422         if (ipack == 0) {
1423             if (isym == 0) {
1424                 i__1 = *n;
1425                 for (j = 1; j <= i__1; ++j) {
1426                     i__2 = j;
1427                     for (i__ = 1; i__ <= i__2; ++i__) {
1428                         zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1429                                 idist, &iseed[1], &d__[1], &igrade, &dl[1], &
1430                                 dr[1], &ipvtng, &iwork[1], sparse);
1431                         ctemp.r = z__1.r, ctemp.i = z__1.i;
1432                         i__3 = isub + jsub * a_dim1;
1433                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1434                         i__3 = jsub + isub * a_dim1;
1435                         d_cnjg(&z__1, &ctemp);
1436                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1437 /* L100: */
1438                     }
1439 /* L110: */
1440                 }
1441             } else if (isym == 1) {
1442                 i__1 = *n;
1443                 for (j = 1; j <= i__1; ++j) {
1444                     i__2 = *m;
1445                     for (i__ = 1; i__ <= i__2; ++i__) {
1446                         zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1447                                 idist, &iseed[1], &d__[1], &igrade, &dl[1], &
1448                                 dr[1], &ipvtng, &iwork[1], sparse);
1449                         ctemp.r = z__1.r, ctemp.i = z__1.i;
1450                         i__3 = isub + jsub * a_dim1;
1451                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1452 /* L120: */
1453                     }
1454 /* L130: */
1455                 }
1456             } else if (isym == 2) {
1457                 i__1 = *n;
1458                 for (j = 1; j <= i__1; ++j) {
1459                     i__2 = j;
1460                     for (i__ = 1; i__ <= i__2; ++i__) {
1461                         zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1462                                 idist, &iseed[1], &d__[1], &igrade, &dl[1], &
1463                                 dr[1], &ipvtng, &iwork[1], sparse);
1464                         ctemp.r = z__1.r, ctemp.i = z__1.i;
1465                         i__3 = isub + jsub * a_dim1;
1466                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1467                         i__3 = jsub + isub * a_dim1;
1468                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1469 /* L140: */
1470                     }
1471 /* L150: */
1472                 }
1473             }
1474
1475         } else if (ipack == 1) {
1476
1477             i__1 = *n;
1478             for (j = 1; j <= i__1; ++j) {
1479                 i__2 = j;
1480                 for (i__ = 1; i__ <= i__2; ++i__) {
1481                     zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1482                             idist, &iseed[1], &d__[1], &igrade, &dl[1], &dr[1]
1483                             , &ipvtng, &iwork[1], sparse);
1484                     ctemp.r = z__1.r, ctemp.i = z__1.i;
1485                     mnsub = f2cmin(isub,jsub);
1486                     mxsub = f2cmax(isub,jsub);
1487                     if (mxsub == isub && isym == 0) {
1488                         i__3 = mnsub + mxsub * a_dim1;
1489                         d_cnjg(&z__1, &ctemp);
1490                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1491                     } else {
1492                         i__3 = mnsub + mxsub * a_dim1;
1493                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1494                     }
1495                     if (mnsub != mxsub) {
1496                         i__3 = mxsub + mnsub * a_dim1;
1497                         a[i__3].r = 0., a[i__3].i = 0.;
1498                     }
1499 /* L160: */
1500                 }
1501 /* L170: */
1502             }
1503
1504         } else if (ipack == 2) {
1505
1506             i__1 = *n;
1507             for (j = 1; j <= i__1; ++j) {
1508                 i__2 = j;
1509                 for (i__ = 1; i__ <= i__2; ++i__) {
1510                     zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1511                             idist, &iseed[1], &d__[1], &igrade, &dl[1], &dr[1]
1512                             , &ipvtng, &iwork[1], sparse);
1513                     ctemp.r = z__1.r, ctemp.i = z__1.i;
1514                     mnsub = f2cmin(isub,jsub);
1515                     mxsub = f2cmax(isub,jsub);
1516                     if (mxsub == jsub && isym == 0) {
1517                         i__3 = mxsub + mnsub * a_dim1;
1518                         d_cnjg(&z__1, &ctemp);
1519                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1520                     } else {
1521                         i__3 = mxsub + mnsub * a_dim1;
1522                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1523                     }
1524                     if (mnsub != mxsub) {
1525                         i__3 = mnsub + mxsub * a_dim1;
1526                         a[i__3].r = 0., a[i__3].i = 0.;
1527                     }
1528 /* L180: */
1529                 }
1530 /* L190: */
1531             }
1532
1533         } else if (ipack == 3) {
1534
1535             i__1 = *n;
1536             for (j = 1; j <= i__1; ++j) {
1537                 i__2 = j;
1538                 for (i__ = 1; i__ <= i__2; ++i__) {
1539                     zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1540                             idist, &iseed[1], &d__[1], &igrade, &dl[1], &dr[1]
1541                             , &ipvtng, &iwork[1], sparse);
1542                     ctemp.r = z__1.r, ctemp.i = z__1.i;
1543
1544 /*                 Compute K = location of (ISUB,JSUB) entry in packed */
1545 /*                 array */
1546
1547                     mnsub = f2cmin(isub,jsub);
1548                     mxsub = f2cmax(isub,jsub);
1549                     k = mxsub * (mxsub - 1) / 2 + mnsub;
1550
1551 /*                 Convert K to (IISUB,JJSUB) location */
1552
1553                     jjsub = (k - 1) / *lda + 1;
1554                     iisub = k - *lda * (jjsub - 1);
1555
1556                     if (mxsub == isub && isym == 0) {
1557                         i__3 = iisub + jjsub * a_dim1;
1558                         d_cnjg(&z__1, &ctemp);
1559                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1560                     } else {
1561                         i__3 = iisub + jjsub * a_dim1;
1562                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1563                     }
1564 /* L200: */
1565                 }
1566 /* L210: */
1567             }
1568
1569         } else if (ipack == 4) {
1570
1571             i__1 = *n;
1572             for (j = 1; j <= i__1; ++j) {
1573                 i__2 = j;
1574                 for (i__ = 1; i__ <= i__2; ++i__) {
1575                     zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1576                             idist, &iseed[1], &d__[1], &igrade, &dl[1], &dr[1]
1577                             , &ipvtng, &iwork[1], sparse);
1578                     ctemp.r = z__1.r, ctemp.i = z__1.i;
1579
1580 /*                 Compute K = location of (I,J) entry in packed array */
1581
1582                     mnsub = f2cmin(isub,jsub);
1583                     mxsub = f2cmax(isub,jsub);
1584                     if (mnsub == 1) {
1585                         k = mxsub;
1586                     } else {
1587                         k = *n * (*n + 1) / 2 - (*n - mnsub + 1) * (*n - 
1588                                 mnsub + 2) / 2 + mxsub - mnsub + 1;
1589                     }
1590
1591 /*                 Convert K to (IISUB,JJSUB) location */
1592
1593                     jjsub = (k - 1) / *lda + 1;
1594                     iisub = k - *lda * (jjsub - 1);
1595
1596                     if (mxsub == jsub && isym == 0) {
1597                         i__3 = iisub + jjsub * a_dim1;
1598                         d_cnjg(&z__1, &ctemp);
1599                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1600                     } else {
1601                         i__3 = iisub + jjsub * a_dim1;
1602                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1603                     }
1604 /* L220: */
1605                 }
1606 /* L230: */
1607             }
1608
1609         } else if (ipack == 5) {
1610
1611             i__1 = *n;
1612             for (j = 1; j <= i__1; ++j) {
1613                 i__2 = j;
1614                 for (i__ = j - kuu; i__ <= i__2; ++i__) {
1615                     if (i__ < 1) {
1616                         i__3 = j - i__ + 1 + (i__ + *n) * a_dim1;
1617                         a[i__3].r = 0., a[i__3].i = 0.;
1618                     } else {
1619                         zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1620                                 idist, &iseed[1], &d__[1], &igrade, &dl[1], &
1621                                 dr[1], &ipvtng, &iwork[1], sparse);
1622                         ctemp.r = z__1.r, ctemp.i = z__1.i;
1623                         mnsub = f2cmin(isub,jsub);
1624                         mxsub = f2cmax(isub,jsub);
1625                         if (mxsub == jsub && isym == 0) {
1626                             i__3 = mxsub - mnsub + 1 + mnsub * a_dim1;
1627                             d_cnjg(&z__1, &ctemp);
1628                             a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1629                         } else {
1630                             i__3 = mxsub - mnsub + 1 + mnsub * a_dim1;
1631                             a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1632                         }
1633                     }
1634 /* L240: */
1635                 }
1636 /* L250: */
1637             }
1638
1639         } else if (ipack == 6) {
1640
1641             i__1 = *n;
1642             for (j = 1; j <= i__1; ++j) {
1643                 i__2 = j;
1644                 for (i__ = j - kuu; i__ <= i__2; ++i__) {
1645                     zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1646                             idist, &iseed[1], &d__[1], &igrade, &dl[1], &dr[1]
1647                             , &ipvtng, &iwork[1], sparse);
1648                     ctemp.r = z__1.r, ctemp.i = z__1.i;
1649                     mnsub = f2cmin(isub,jsub);
1650                     mxsub = f2cmax(isub,jsub);
1651                     if (mxsub == isub && isym == 0) {
1652                         i__3 = mnsub - mxsub + kuu + 1 + mxsub * a_dim1;
1653                         d_cnjg(&z__1, &ctemp);
1654                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1655                     } else {
1656                         i__3 = mnsub - mxsub + kuu + 1 + mxsub * a_dim1;
1657                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1658                     }
1659 /* L260: */
1660                 }
1661 /* L270: */
1662             }
1663
1664         } else if (ipack == 7) {
1665
1666             if (isym != 1) {
1667                 i__1 = *n;
1668                 for (j = 1; j <= i__1; ++j) {
1669                     i__2 = j;
1670                     for (i__ = j - kuu; i__ <= i__2; ++i__) {
1671                         zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1672                                 idist, &iseed[1], &d__[1], &igrade, &dl[1], &
1673                                 dr[1], &ipvtng, &iwork[1], sparse);
1674                         ctemp.r = z__1.r, ctemp.i = z__1.i;
1675                         mnsub = f2cmin(isub,jsub);
1676                         mxsub = f2cmax(isub,jsub);
1677                         if (i__ < 1) {
1678                             i__3 = j - i__ + 1 + kuu + (i__ + *n) * a_dim1;
1679                             a[i__3].r = 0., a[i__3].i = 0.;
1680                         }
1681                         if (mxsub == isub && isym == 0) {
1682                             i__3 = mnsub - mxsub + kuu + 1 + mxsub * a_dim1;
1683                             d_cnjg(&z__1, &ctemp);
1684                             a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1685                         } else {
1686                             i__3 = mnsub - mxsub + kuu + 1 + mxsub * a_dim1;
1687                             a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1688                         }
1689                         if (i__ >= 1 && mnsub != mxsub) {
1690                             if (mnsub == isub && isym == 0) {
1691                                 i__3 = mxsub - mnsub + 1 + kuu + mnsub * 
1692                                         a_dim1;
1693                                 d_cnjg(&z__1, &ctemp);
1694                                 a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1695                             } else {
1696                                 i__3 = mxsub - mnsub + 1 + kuu + mnsub * 
1697                                         a_dim1;
1698                                 a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1699                             }
1700                         }
1701 /* L280: */
1702                     }
1703 /* L290: */
1704                 }
1705             } else if (isym == 1) {
1706                 i__1 = *n;
1707                 for (j = 1; j <= i__1; ++j) {
1708                     i__2 = j + kll;
1709                     for (i__ = j - kuu; i__ <= i__2; ++i__) {
1710                         zlatm3_(&z__1, m, n, &i__, &j, &isub, &jsub, kl, ku, &
1711                                 idist, &iseed[1], &d__[1], &igrade, &dl[1], &
1712                                 dr[1], &ipvtng, &iwork[1], sparse);
1713                         ctemp.r = z__1.r, ctemp.i = z__1.i;
1714                         i__3 = isub - jsub + kuu + 1 + jsub * a_dim1;
1715                         a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
1716 /* L300: */
1717                     }
1718 /* L310: */
1719                 }
1720             }
1721
1722         }
1723
1724     } else {
1725
1726 /*        Use ZLATM2 */
1727
1728         if (ipack == 0) {
1729             if (isym == 0) {
1730                 i__1 = *n;
1731                 for (j = 1; j <= i__1; ++j) {
1732                     i__2 = j;
1733                     for (i__ = 1; i__ <= i__2; ++i__) {
1734                         i__3 = i__ + j * a_dim1;
1735                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1736                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1737                                  &iwork[1], sparse);
1738                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1739                         i__3 = j + i__ * a_dim1;
1740                         d_cnjg(&z__1, &a[i__ + j * a_dim1]);
1741                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1742 /* L320: */
1743                     }
1744 /* L330: */
1745                 }
1746             } else if (isym == 1) {
1747                 i__1 = *n;
1748                 for (j = 1; j <= i__1; ++j) {
1749                     i__2 = *m;
1750                     for (i__ = 1; i__ <= i__2; ++i__) {
1751                         i__3 = i__ + j * a_dim1;
1752                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1753                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1754                                  &iwork[1], sparse);
1755                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1756 /* L340: */
1757                     }
1758 /* L350: */
1759                 }
1760             } else if (isym == 2) {
1761                 i__1 = *n;
1762                 for (j = 1; j <= i__1; ++j) {
1763                     i__2 = j;
1764                     for (i__ = 1; i__ <= i__2; ++i__) {
1765                         i__3 = i__ + j * a_dim1;
1766                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1767                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1768                                  &iwork[1], sparse);
1769                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1770                         i__3 = j + i__ * a_dim1;
1771                         i__4 = i__ + j * a_dim1;
1772                         a[i__3].r = a[i__4].r, a[i__3].i = a[i__4].i;
1773 /* L360: */
1774                     }
1775 /* L370: */
1776                 }
1777             }
1778
1779         } else if (ipack == 1) {
1780
1781             i__1 = *n;
1782             for (j = 1; j <= i__1; ++j) {
1783                 i__2 = j;
1784                 for (i__ = 1; i__ <= i__2; ++i__) {
1785                     i__3 = i__ + j * a_dim1;
1786                     zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[1], 
1787                             &d__[1], &igrade, &dl[1], &dr[1], &ipvtng, &iwork[
1788                             1], sparse);
1789                     a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1790                     if (i__ != j) {
1791                         i__3 = j + i__ * a_dim1;
1792                         a[i__3].r = 0., a[i__3].i = 0.;
1793                     }
1794 /* L380: */
1795                 }
1796 /* L390: */
1797             }
1798
1799         } else if (ipack == 2) {
1800
1801             i__1 = *n;
1802             for (j = 1; j <= i__1; ++j) {
1803                 i__2 = j;
1804                 for (i__ = 1; i__ <= i__2; ++i__) {
1805                     if (isym == 0) {
1806                         i__3 = j + i__ * a_dim1;
1807                         zlatm2_(&z__2, m, n, &i__, &j, kl, ku, &idist, &iseed[
1808                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1809                                  &iwork[1], sparse);
1810                         d_cnjg(&z__1, &z__2);
1811                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1812                     } else {
1813                         i__3 = j + i__ * a_dim1;
1814                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1815                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1816                                  &iwork[1], sparse);
1817                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1818                     }
1819                     if (i__ != j) {
1820                         i__3 = i__ + j * a_dim1;
1821                         a[i__3].r = 0., a[i__3].i = 0.;
1822                     }
1823 /* L400: */
1824                 }
1825 /* L410: */
1826             }
1827
1828         } else if (ipack == 3) {
1829
1830             isub = 0;
1831             jsub = 1;
1832             i__1 = *n;
1833             for (j = 1; j <= i__1; ++j) {
1834                 i__2 = j;
1835                 for (i__ = 1; i__ <= i__2; ++i__) {
1836                     ++isub;
1837                     if (isub > *lda) {
1838                         isub = 1;
1839                         ++jsub;
1840                     }
1841                     i__3 = isub + jsub * a_dim1;
1842                     zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[1], 
1843                             &d__[1], &igrade, &dl[1], &dr[1], &ipvtng, &iwork[
1844                             1], sparse);
1845                     a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1846 /* L420: */
1847                 }
1848 /* L430: */
1849             }
1850
1851         } else if (ipack == 4) {
1852
1853             if (isym == 0 || isym == 2) {
1854                 i__1 = *n;
1855                 for (j = 1; j <= i__1; ++j) {
1856                     i__2 = j;
1857                     for (i__ = 1; i__ <= i__2; ++i__) {
1858
1859 /*                    Compute K = location of (I,J) entry in packed array */
1860
1861                         if (i__ == 1) {
1862                             k = j;
1863                         } else {
1864                             k = *n * (*n + 1) / 2 - (*n - i__ + 1) * (*n - 
1865                                     i__ + 2) / 2 + j - i__ + 1;
1866                         }
1867
1868 /*                    Convert K to (ISUB,JSUB) location */
1869
1870                         jsub = (k - 1) / *lda + 1;
1871                         isub = k - *lda * (jsub - 1);
1872
1873                         i__3 = isub + jsub * a_dim1;
1874                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1875                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1876                                  &iwork[1], sparse);
1877                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1878                         if (isym == 0) {
1879                             i__3 = isub + jsub * a_dim1;
1880                             d_cnjg(&z__1, &a[isub + jsub * a_dim1]);
1881                             a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1882                         }
1883 /* L440: */
1884                     }
1885 /* L450: */
1886                 }
1887             } else {
1888                 isub = 0;
1889                 jsub = 1;
1890                 i__1 = *n;
1891                 for (j = 1; j <= i__1; ++j) {
1892                     i__2 = *m;
1893                     for (i__ = j; i__ <= i__2; ++i__) {
1894                         ++isub;
1895                         if (isub > *lda) {
1896                             isub = 1;
1897                             ++jsub;
1898                         }
1899                         i__3 = isub + jsub * a_dim1;
1900                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1901                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1902                                  &iwork[1], sparse);
1903                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1904 /* L460: */
1905                     }
1906 /* L470: */
1907                 }
1908             }
1909
1910         } else if (ipack == 5) {
1911
1912             i__1 = *n;
1913             for (j = 1; j <= i__1; ++j) {
1914                 i__2 = j;
1915                 for (i__ = j - kuu; i__ <= i__2; ++i__) {
1916                     if (i__ < 1) {
1917                         i__3 = j - i__ + 1 + (i__ + *n) * a_dim1;
1918                         a[i__3].r = 0., a[i__3].i = 0.;
1919                     } else {
1920                         if (isym == 0) {
1921                             i__3 = j - i__ + 1 + i__ * a_dim1;
1922                             zlatm2_(&z__2, m, n, &i__, &j, kl, ku, &idist, &
1923                                     iseed[1], &d__[1], &igrade, &dl[1], &dr[1]
1924                                     , &ipvtng, &iwork[1], sparse);
1925                             d_cnjg(&z__1, &z__2);
1926                             a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1927                         } else {
1928                             i__3 = j - i__ + 1 + i__ * a_dim1;
1929                             zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &
1930                                     iseed[1], &d__[1], &igrade, &dl[1], &dr[1]
1931                                     , &ipvtng, &iwork[1], sparse);
1932                             a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1933                         }
1934                     }
1935 /* L480: */
1936                 }
1937 /* L490: */
1938             }
1939
1940         } else if (ipack == 6) {
1941
1942             i__1 = *n;
1943             for (j = 1; j <= i__1; ++j) {
1944                 i__2 = j;
1945                 for (i__ = j - kuu; i__ <= i__2; ++i__) {
1946                     i__3 = i__ - j + kuu + 1 + j * a_dim1;
1947                     zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[1], 
1948                             &d__[1], &igrade, &dl[1], &dr[1], &ipvtng, &iwork[
1949                             1], sparse);
1950                     a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1951 /* L500: */
1952                 }
1953 /* L510: */
1954             }
1955
1956         } else if (ipack == 7) {
1957
1958             if (isym != 1) {
1959                 i__1 = *n;
1960                 for (j = 1; j <= i__1; ++j) {
1961                     i__2 = j;
1962                     for (i__ = j - kuu; i__ <= i__2; ++i__) {
1963                         i__3 = i__ - j + kuu + 1 + j * a_dim1;
1964                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1965                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1966                                  &iwork[1], sparse);
1967                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1968                         if (i__ < 1) {
1969                             i__3 = j - i__ + 1 + kuu + (i__ + *n) * a_dim1;
1970                             a[i__3].r = 0., a[i__3].i = 0.;
1971                         }
1972                         if (i__ >= 1 && i__ != j) {
1973                             if (isym == 0) {
1974                                 i__3 = j - i__ + 1 + kuu + i__ * a_dim1;
1975                                 d_cnjg(&z__1, &a[i__ - j + kuu + 1 + j * 
1976                                         a_dim1]);
1977                                 a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1978                             } else {
1979                                 i__3 = j - i__ + 1 + kuu + i__ * a_dim1;
1980                                 i__4 = i__ - j + kuu + 1 + j * a_dim1;
1981                                 a[i__3].r = a[i__4].r, a[i__3].i = a[i__4].i;
1982                             }
1983                         }
1984 /* L520: */
1985                     }
1986 /* L530: */
1987                 }
1988             } else if (isym == 1) {
1989                 i__1 = *n;
1990                 for (j = 1; j <= i__1; ++j) {
1991                     i__2 = j + kll;
1992                     for (i__ = j - kuu; i__ <= i__2; ++i__) {
1993                         i__3 = i__ - j + kuu + 1 + j * a_dim1;
1994                         zlatm2_(&z__1, m, n, &i__, &j, kl, ku, &idist, &iseed[
1995                                 1], &d__[1], &igrade, &dl[1], &dr[1], &ipvtng,
1996                                  &iwork[1], sparse);
1997                         a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1998 /* L540: */
1999                     }
2000 /* L550: */
2001                 }
2002             }
2003
2004         }
2005
2006     }
2007
2008 /*     5)      Scaling the norm */
2009
2010     if (ipack == 0) {
2011         onorm = zlange_("M", m, n, &a[a_offset], lda, tempa);
2012     } else if (ipack == 1) {
2013         onorm = zlansy_("M", "U", n, &a[a_offset], lda, tempa);
2014     } else if (ipack == 2) {
2015         onorm = zlansy_("M", "L", n, &a[a_offset], lda, tempa);
2016     } else if (ipack == 3) {
2017         onorm = zlansp_("M", "U", n, &a[a_offset], tempa);
2018     } else if (ipack == 4) {
2019         onorm = zlansp_("M", "L", n, &a[a_offset], tempa);
2020     } else if (ipack == 5) {
2021         onorm = zlansb_("M", "L", n, &kll, &a[a_offset], lda, tempa);
2022     } else if (ipack == 6) {
2023         onorm = zlansb_("M", "U", n, &kuu, &a[a_offset], lda, tempa);
2024     } else if (ipack == 7) {
2025         onorm = zlangb_("M", n, &kll, &kuu, &a[a_offset], lda, tempa);
2026     }
2027
2028     if (*anorm >= 0.) {
2029
2030         if (*anorm > 0. && onorm == 0.) {
2031
2032 /*           Desired scaling impossible */
2033
2034             *info = 5;
2035             return 0;
2036
2037         } else if (*anorm > 1. && onorm < 1. || *anorm < 1. && onorm > 1.) {
2038
2039 /*           Scale carefully to avoid over / underflow */
2040
2041             if (ipack <= 2) {
2042                 i__1 = *n;
2043                 for (j = 1; j <= i__1; ++j) {
2044                     d__1 = 1. / onorm;
2045                     zdscal_(m, &d__1, &a[j * a_dim1 + 1], &c__1);
2046                     zdscal_(m, anorm, &a[j * a_dim1 + 1], &c__1);
2047 /* L560: */
2048                 }
2049
2050             } else if (ipack == 3 || ipack == 4) {
2051
2052                 i__1 = *n * (*n + 1) / 2;
2053                 d__1 = 1. / onorm;
2054                 zdscal_(&i__1, &d__1, &a[a_offset], &c__1);
2055                 i__1 = *n * (*n + 1) / 2;
2056                 zdscal_(&i__1, anorm, &a[a_offset], &c__1);
2057
2058             } else if (ipack >= 5) {
2059
2060                 i__1 = *n;
2061                 for (j = 1; j <= i__1; ++j) {
2062                     i__2 = kll + kuu + 1;
2063                     d__1 = 1. / onorm;
2064                     zdscal_(&i__2, &d__1, &a[j * a_dim1 + 1], &c__1);
2065                     i__2 = kll + kuu + 1;
2066                     zdscal_(&i__2, anorm, &a[j * a_dim1 + 1], &c__1);
2067 /* L570: */
2068                 }
2069
2070             }
2071
2072         } else {
2073
2074 /*           Scale straightforwardly */
2075
2076             if (ipack <= 2) {
2077                 i__1 = *n;
2078                 for (j = 1; j <= i__1; ++j) {
2079                     d__1 = *anorm / onorm;
2080                     zdscal_(m, &d__1, &a[j * a_dim1 + 1], &c__1);
2081 /* L580: */
2082                 }
2083
2084             } else if (ipack == 3 || ipack == 4) {
2085
2086                 i__1 = *n * (*n + 1) / 2;
2087                 d__1 = *anorm / onorm;
2088                 zdscal_(&i__1, &d__1, &a[a_offset], &c__1);
2089
2090             } else if (ipack >= 5) {
2091
2092                 i__1 = *n;
2093                 for (j = 1; j <= i__1; ++j) {
2094                     i__2 = kll + kuu + 1;
2095                     d__1 = *anorm / onorm;
2096                     zdscal_(&i__2, &d__1, &a[j * a_dim1 + 1], &c__1);
2097 /* L590: */
2098                 }
2099             }
2100
2101         }
2102
2103     }
2104
2105 /*     End of ZLATMR */
2106
2107     return 0;
2108 } /* zlatmr_ */
2109