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