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