You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dlatms.c 48 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  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. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #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]);}
  173. #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]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #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++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #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]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #define F2C_proc_par_types 1
  240. /* Table of constant values */
  241. static integer c__1 = 1;
  242. static doublereal c_b22 = 0.;
  243. static logical c_true = TRUE_;
  244. static logical c_false = FALSE_;
  245. /* > \brief \b DLATMS */
  246. /* =========== DOCUMENTATION =========== */
  247. /* Online html documentation available at */
  248. /* http://www.netlib.org/lapack/explore-html/ */
  249. /* Definition: */
  250. /* =========== */
  251. /* SUBROUTINE DLATMS( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
  252. /* KL, KU, PACK, A, LDA, WORK, INFO ) */
  253. /* CHARACTER DIST, PACK, SYM */
  254. /* INTEGER INFO, KL, KU, LDA, M, MODE, N */
  255. /* DOUBLE PRECISION COND, DMAX */
  256. /* INTEGER ISEED( 4 ) */
  257. /* DOUBLE PRECISION A( LDA, * ), D( * ), WORK( * ) */
  258. /* > \par Purpose: */
  259. /* ============= */
  260. /* > */
  261. /* > \verbatim */
  262. /* > */
  263. /* > DLATMS generates random matrices with specified singular values */
  264. /* > (or symmetric/hermitian with specified eigenvalues) */
  265. /* > for testing LAPACK programs. */
  266. /* > */
  267. /* > DLATMS operates by applying the following sequence of */
  268. /* > operations: */
  269. /* > */
  270. /* > Set the diagonal to D, where D may be input or */
  271. /* > computed according to MODE, COND, DMAX, and SYM */
  272. /* > as described below. */
  273. /* > */
  274. /* > Generate a matrix with the appropriate band structure, by one */
  275. /* > of two methods: */
  276. /* > */
  277. /* > Method A: */
  278. /* > Generate a dense M x N matrix by multiplying D on the left */
  279. /* > and the right by random unitary matrices, then: */
  280. /* > */
  281. /* > Reduce the bandwidth according to KL and KU, using */
  282. /* > Householder transformations. */
  283. /* > */
  284. /* > Method B: */
  285. /* > Convert the bandwidth-0 (i.e., diagonal) matrix to a */
  286. /* > bandwidth-1 matrix using Givens rotations, "chasing" */
  287. /* > out-of-band elements back, much as in QR; then */
  288. /* > convert the bandwidth-1 to a bandwidth-2 matrix, etc. */
  289. /* > Note that for reasonably small bandwidths (relative to */
  290. /* > M and N) this requires less storage, as a dense matrix */
  291. /* > is not generated. Also, for symmetric matrices, only */
  292. /* > one triangle is generated. */
  293. /* > */
  294. /* > Method A is chosen if the bandwidth is a large fraction of the */
  295. /* > order of the matrix, and LDA is at least M (so a dense */
  296. /* > matrix can be stored.) Method B is chosen if the bandwidth */
  297. /* > is small (< 1/2 N for symmetric, < .3 N+M for */
  298. /* > non-symmetric), or LDA is less than M and not less than the */
  299. /* > bandwidth. */
  300. /* > */
  301. /* > Pack the matrix if desired. Options specified by PACK are: */
  302. /* > no packing */
  303. /* > zero out upper half (if symmetric) */
  304. /* > zero out lower half (if symmetric) */
  305. /* > store the upper half columnwise (if symmetric or upper */
  306. /* > triangular) */
  307. /* > store the lower half columnwise (if symmetric or lower */
  308. /* > triangular) */
  309. /* > store the lower triangle in banded format (if symmetric */
  310. /* > or lower triangular) */
  311. /* > store the upper triangle in banded format (if symmetric */
  312. /* > or upper triangular) */
  313. /* > store the entire matrix in banded format */
  314. /* > If Method B is chosen, and band format is specified, then the */
  315. /* > matrix will be generated in the band format, so no repacking */
  316. /* > will be necessary. */
  317. /* > \endverbatim */
  318. /* Arguments: */
  319. /* ========== */
  320. /* > \param[in] M */
  321. /* > \verbatim */
  322. /* > M is INTEGER */
  323. /* > The number of rows of A. Not modified. */
  324. /* > \endverbatim */
  325. /* > */
  326. /* > \param[in] N */
  327. /* > \verbatim */
  328. /* > N is INTEGER */
  329. /* > The number of columns of A. Not modified. */
  330. /* > \endverbatim */
  331. /* > */
  332. /* > \param[in] DIST */
  333. /* > \verbatim */
  334. /* > DIST is CHARACTER*1 */
  335. /* > On entry, DIST specifies the type of distribution to be used */
  336. /* > to generate the random eigen-/singular values. */
  337. /* > 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */
  338. /* > 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
  339. /* > 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */
  340. /* > Not modified. */
  341. /* > \endverbatim */
  342. /* > */
  343. /* > \param[in,out] ISEED */
  344. /* > \verbatim */
  345. /* > ISEED is INTEGER array, dimension ( 4 ) */
  346. /* > On entry ISEED specifies the seed of the random number */
  347. /* > generator. They should lie between 0 and 4095 inclusive, */
  348. /* > and ISEED(4) should be odd. The random number generator */
  349. /* > uses a linear congruential sequence limited to small */
  350. /* > integers, and so should produce machine independent */
  351. /* > random numbers. The values of ISEED are changed on */
  352. /* > exit, and can be used in the next call to DLATMS */
  353. /* > to continue the same random number sequence. */
  354. /* > Changed on exit. */
  355. /* > \endverbatim */
  356. /* > */
  357. /* > \param[in] SYM */
  358. /* > \verbatim */
  359. /* > SYM is CHARACTER*1 */
  360. /* > If SYM='S' or 'H', the generated matrix is symmetric, with */
  361. /* > eigenvalues specified by D, COND, MODE, and DMAX; they */
  362. /* > may be positive, negative, or zero. */
  363. /* > If SYM='P', the generated matrix is symmetric, with */
  364. /* > eigenvalues (= singular values) specified by D, COND, */
  365. /* > MODE, and DMAX; they will not be negative. */
  366. /* > If SYM='N', the generated matrix is nonsymmetric, with */
  367. /* > singular values specified by D, COND, MODE, and DMAX; */
  368. /* > they will not be negative. */
  369. /* > Not modified. */
  370. /* > \endverbatim */
  371. /* > */
  372. /* > \param[in,out] D */
  373. /* > \verbatim */
  374. /* > D is DOUBLE PRECISION array, dimension ( MIN( M , N ) ) */
  375. /* > This array is used to specify the singular values or */
  376. /* > eigenvalues of A (see SYM, above.) If MODE=0, then D is */
  377. /* > assumed to contain the singular/eigenvalues, otherwise */
  378. /* > they will be computed according to MODE, COND, and DMAX, */
  379. /* > and placed in D. */
  380. /* > Modified if MODE is nonzero. */
  381. /* > \endverbatim */
  382. /* > */
  383. /* > \param[in] MODE */
  384. /* > \verbatim */
  385. /* > MODE is INTEGER */
  386. /* > On entry this describes how the singular/eigenvalues are to */
  387. /* > be specified: */
  388. /* > MODE = 0 means use D as input */
  389. /* > MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
  390. /* > MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
  391. /* > MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
  392. /* > MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
  393. /* > MODE = 5 sets D to random numbers in the range */
  394. /* > ( 1/COND , 1 ) such that their logarithms */
  395. /* > are uniformly distributed. */
  396. /* > MODE = 6 set D to random numbers from same distribution */
  397. /* > as the rest of the matrix. */
  398. /* > MODE < 0 has the same meaning as ABS(MODE), except that */
  399. /* > the order of the elements of D is reversed. */
  400. /* > Thus if MODE is positive, D has entries ranging from */
  401. /* > 1 to 1/COND, if negative, from 1/COND to 1, */
  402. /* > If SYM='S' or 'H', and MODE is neither 0, 6, nor -6, then */
  403. /* > the elements of D will also be multiplied by a random */
  404. /* > sign (i.e., +1 or -1.) */
  405. /* > Not modified. */
  406. /* > \endverbatim */
  407. /* > */
  408. /* > \param[in] COND */
  409. /* > \verbatim */
  410. /* > COND is DOUBLE PRECISION */
  411. /* > On entry, this is used as described under MODE above. */
  412. /* > If used, it must be >= 1. Not modified. */
  413. /* > \endverbatim */
  414. /* > */
  415. /* > \param[in] DMAX */
  416. /* > \verbatim */
  417. /* > DMAX is DOUBLE PRECISION */
  418. /* > If MODE is neither -6, 0 nor 6, the contents of D, as */
  419. /* > computed according to MODE and COND, will be scaled by */
  420. /* > DMAX / f2cmax(abs(D(i))); thus, the maximum absolute eigen- or */
  421. /* > singular value (which is to say the norm) will be abs(DMAX). */
  422. /* > Note that DMAX need not be positive: if DMAX is negative */
  423. /* > (or zero), D will be scaled by a negative number (or zero). */
  424. /* > Not modified. */
  425. /* > \endverbatim */
  426. /* > */
  427. /* > \param[in] KL */
  428. /* > \verbatim */
  429. /* > KL is INTEGER */
  430. /* > This specifies the lower bandwidth of the matrix. For */
  431. /* > example, KL=0 implies upper triangular, KL=1 implies upper */
  432. /* > Hessenberg, and KL being at least M-1 means that the matrix */
  433. /* > has full lower bandwidth. KL must equal KU if the matrix */
  434. /* > is symmetric. */
  435. /* > Not modified. */
  436. /* > \endverbatim */
  437. /* > */
  438. /* > \param[in] KU */
  439. /* > \verbatim */
  440. /* > KU is INTEGER */
  441. /* > This specifies the upper bandwidth of the matrix. For */
  442. /* > example, KU=0 implies lower triangular, KU=1 implies lower */
  443. /* > Hessenberg, and KU being at least N-1 means that the matrix */
  444. /* > has full upper bandwidth. KL must equal KU if the matrix */
  445. /* > is symmetric. */
  446. /* > Not modified. */
  447. /* > \endverbatim */
  448. /* > */
  449. /* > \param[in] PACK */
  450. /* > \verbatim */
  451. /* > PACK is CHARACTER*1 */
  452. /* > This specifies packing of matrix as follows: */
  453. /* > 'N' => no packing */
  454. /* > 'U' => zero out all subdiagonal entries (if symmetric) */
  455. /* > 'L' => zero out all superdiagonal entries (if symmetric) */
  456. /* > 'C' => store the upper triangle columnwise */
  457. /* > (only if the matrix is symmetric or upper triangular) */
  458. /* > 'R' => store the lower triangle columnwise */
  459. /* > (only if the matrix is symmetric or lower triangular) */
  460. /* > 'B' => store the lower triangle in band storage scheme */
  461. /* > (only if matrix symmetric or lower triangular) */
  462. /* > 'Q' => store the upper triangle in band storage scheme */
  463. /* > (only if matrix symmetric or upper triangular) */
  464. /* > 'Z' => store the entire matrix in band storage scheme */
  465. /* > (pivoting can be provided for by using this */
  466. /* > option to store A in the trailing rows of */
  467. /* > the allocated storage) */
  468. /* > */
  469. /* > Using these options, the various LAPACK packed and banded */
  470. /* > storage schemes can be obtained: */
  471. /* > GB - use 'Z' */
  472. /* > PB, SB or TB - use 'B' or 'Q' */
  473. /* > PP, SP or TP - use 'C' or 'R' */
  474. /* > */
  475. /* > If two calls to DLATMS differ only in the PACK parameter, */
  476. /* > they will generate mathematically equivalent matrices. */
  477. /* > Not modified. */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[in,out] A */
  481. /* > \verbatim */
  482. /* > A is DOUBLE PRECISION array, dimension ( LDA, N ) */
  483. /* > On exit A is the desired test matrix. A is first generated */
  484. /* > in full (unpacked) form, and then packed, if so specified */
  485. /* > by PACK. Thus, the first M elements of the first N */
  486. /* > columns will always be modified. If PACK specifies a */
  487. /* > packed or banded storage scheme, all LDA elements of the */
  488. /* > first N columns will be modified; the elements of the */
  489. /* > array which do not correspond to elements of the generated */
  490. /* > matrix are set to zero. */
  491. /* > Modified. */
  492. /* > \endverbatim */
  493. /* > */
  494. /* > \param[in] LDA */
  495. /* > \verbatim */
  496. /* > LDA is INTEGER */
  497. /* > LDA specifies the first dimension of A as declared in the */
  498. /* > calling program. If PACK='N', 'U', 'L', 'C', or 'R', then */
  499. /* > LDA must be at least M. If PACK='B' or 'Q', then LDA must */
  500. /* > be at least MIN( KL, M-1) (which is equal to MIN(KU,N-1)). */
  501. /* > If PACK='Z', LDA must be large enough to hold the packed */
  502. /* > array: MIN( KU, N-1) + MIN( KL, M-1) + 1. */
  503. /* > Not modified. */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[out] WORK */
  507. /* > \verbatim */
  508. /* > WORK is DOUBLE PRECISION array, dimension ( 3*MAX( N , M ) ) */
  509. /* > Workspace. */
  510. /* > Modified. */
  511. /* > \endverbatim */
  512. /* > */
  513. /* > \param[out] INFO */
  514. /* > \verbatim */
  515. /* > INFO is INTEGER */
  516. /* > Error code. On exit, INFO will be set to one of the */
  517. /* > following values: */
  518. /* > 0 => normal return */
  519. /* > -1 => M negative or unequal to N and SYM='S', 'H', or 'P' */
  520. /* > -2 => N negative */
  521. /* > -3 => DIST illegal string */
  522. /* > -5 => SYM illegal string */
  523. /* > -7 => MODE not in range -6 to 6 */
  524. /* > -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
  525. /* > -10 => KL negative */
  526. /* > -11 => KU negative, or SYM='S' or 'H' and KU not equal to KL */
  527. /* > -12 => PACK illegal string, or PACK='U' or 'L', and SYM='N'; */
  528. /* > or PACK='C' or 'Q' and SYM='N' and KL is not zero; */
  529. /* > or PACK='R' or 'B' and SYM='N' and KU is not zero; */
  530. /* > or PACK='U', 'L', 'C', 'R', 'B', or 'Q', and M is not */
  531. /* > N. */
  532. /* > -14 => LDA is less than M, or PACK='Z' and LDA is less than */
  533. /* > MIN(KU,N-1) + MIN(KL,M-1) + 1. */
  534. /* > 1 => Error return from DLATM1 */
  535. /* > 2 => Cannot scale to DMAX (f2cmax. sing. value is 0) */
  536. /* > 3 => Error return from DLAGGE or SLAGSY */
  537. /* > \endverbatim */
  538. /* Authors: */
  539. /* ======== */
  540. /* > \author Univ. of Tennessee */
  541. /* > \author Univ. of California Berkeley */
  542. /* > \author Univ. of Colorado Denver */
  543. /* > \author NAG Ltd. */
  544. /* > \date December 2016 */
  545. /* > \ingroup double_matgen */
  546. /* ===================================================================== */
  547. /* Subroutine */ void dlatms_(integer *m, integer *n, char *dist, integer *
  548. iseed, char *sym, doublereal *d__, integer *mode, doublereal *cond,
  549. doublereal *dmax__, integer *kl, integer *ku, char *pack, doublereal *
  550. a, integer *lda, doublereal *work, integer *info)
  551. {
  552. /* System generated locals */
  553. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  554. doublereal d__1, d__2, d__3;
  555. logical L__1;
  556. /* Local variables */
  557. integer ilda, icol;
  558. doublereal temp;
  559. integer irow, isym;
  560. doublereal c__;
  561. integer i__, j, k;
  562. doublereal s, alpha, angle;
  563. integer ipack;
  564. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  565. integer *);
  566. integer ioffg;
  567. extern logical lsame_(char *, char *);
  568. integer iinfo, idist, mnmin;
  569. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  570. doublereal *, integer *);
  571. integer iskew;
  572. doublereal extra, dummy;
  573. extern /* Subroutine */ void dlatm1_(integer *, doublereal *, integer *,
  574. integer *, integer *, doublereal *, integer *, integer *);
  575. integer ic, jc, nc;
  576. extern /* Subroutine */ void dlagge_(integer *, integer *, integer *,
  577. integer *, doublereal *, doublereal *, integer *, integer *,
  578. doublereal *, integer *);
  579. integer il, iendch, ir, jr, ipackg, mr, minlda;
  580. extern doublereal dlarnd_(integer *, integer *);
  581. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  582. doublereal *, doublereal *, doublereal *, integer *),
  583. dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  584. doublereal *);
  585. extern int xerbla_(char *, integer *, ftnlen);
  586. extern void dlagsy_(
  587. integer *, integer *, doublereal *, doublereal *, integer *,
  588. integer *, doublereal *, integer *), dlarot_(logical *, logical *,
  589. logical *, integer *, doublereal *, doublereal *, doublereal *,
  590. integer *, doublereal *, doublereal *);
  591. logical iltemp, givens;
  592. integer ioffst, irsign;
  593. logical ilextr, topdwn;
  594. integer ir1, ir2, isympk, jch, llb, jkl, jku, uub;
  595. /* -- LAPACK computational routine (version 3.7.0) -- */
  596. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  597. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  598. /* December 2016 */
  599. /* ===================================================================== */
  600. /* 1) Decode and Test the input parameters. */
  601. /* Initialize flags & seed. */
  602. /* Parameter adjustments */
  603. --iseed;
  604. --d__;
  605. a_dim1 = *lda;
  606. a_offset = 1 + a_dim1 * 1;
  607. a -= a_offset;
  608. --work;
  609. /* Function Body */
  610. *info = 0;
  611. /* Quick return if possible */
  612. if (*m == 0 || *n == 0) {
  613. return;
  614. }
  615. /* Decode DIST */
  616. if (lsame_(dist, "U")) {
  617. idist = 1;
  618. } else if (lsame_(dist, "S")) {
  619. idist = 2;
  620. } else if (lsame_(dist, "N")) {
  621. idist = 3;
  622. } else {
  623. idist = -1;
  624. }
  625. /* Decode SYM */
  626. if (lsame_(sym, "N")) {
  627. isym = 1;
  628. irsign = 0;
  629. } else if (lsame_(sym, "P")) {
  630. isym = 2;
  631. irsign = 0;
  632. } else if (lsame_(sym, "S")) {
  633. isym = 2;
  634. irsign = 1;
  635. } else if (lsame_(sym, "H")) {
  636. isym = 2;
  637. irsign = 1;
  638. } else {
  639. isym = -1;
  640. }
  641. /* Decode PACK */
  642. isympk = 0;
  643. if (lsame_(pack, "N")) {
  644. ipack = 0;
  645. } else if (lsame_(pack, "U")) {
  646. ipack = 1;
  647. isympk = 1;
  648. } else if (lsame_(pack, "L")) {
  649. ipack = 2;
  650. isympk = 1;
  651. } else if (lsame_(pack, "C")) {
  652. ipack = 3;
  653. isympk = 2;
  654. } else if (lsame_(pack, "R")) {
  655. ipack = 4;
  656. isympk = 3;
  657. } else if (lsame_(pack, "B")) {
  658. ipack = 5;
  659. isympk = 3;
  660. } else if (lsame_(pack, "Q")) {
  661. ipack = 6;
  662. isympk = 2;
  663. } else if (lsame_(pack, "Z")) {
  664. ipack = 7;
  665. } else {
  666. ipack = -1;
  667. }
  668. /* Set certain internal parameters */
  669. mnmin = f2cmin(*m,*n);
  670. /* Computing MIN */
  671. i__1 = *kl, i__2 = *m - 1;
  672. llb = f2cmin(i__1,i__2);
  673. /* Computing MIN */
  674. i__1 = *ku, i__2 = *n - 1;
  675. uub = f2cmin(i__1,i__2);
  676. /* Computing MIN */
  677. i__1 = *m, i__2 = *n + llb;
  678. mr = f2cmin(i__1,i__2);
  679. /* Computing MIN */
  680. i__1 = *n, i__2 = *m + uub;
  681. nc = f2cmin(i__1,i__2);
  682. if (ipack == 5 || ipack == 6) {
  683. minlda = uub + 1;
  684. } else if (ipack == 7) {
  685. minlda = llb + uub + 1;
  686. } else {
  687. minlda = *m;
  688. }
  689. /* Use Givens rotation method if bandwidth small enough, */
  690. /* or if LDA is too small to store the matrix unpacked. */
  691. givens = FALSE_;
  692. if (isym == 1) {
  693. /* Computing MAX */
  694. i__1 = 1, i__2 = mr + nc;
  695. if ((doublereal) (llb + uub) < (doublereal) f2cmax(i__1,i__2) * .3) {
  696. givens = TRUE_;
  697. }
  698. } else {
  699. if (llb << 1 < *m) {
  700. givens = TRUE_;
  701. }
  702. }
  703. if (*lda < *m && *lda >= minlda) {
  704. givens = TRUE_;
  705. }
  706. /* Set INFO if an error */
  707. if (*m < 0) {
  708. *info = -1;
  709. } else if (*m != *n && isym != 1) {
  710. *info = -1;
  711. } else if (*n < 0) {
  712. *info = -2;
  713. } else if (idist == -1) {
  714. *info = -3;
  715. } else if (isym == -1) {
  716. *info = -5;
  717. } else if (abs(*mode) > 6) {
  718. *info = -7;
  719. } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.) {
  720. *info = -8;
  721. } else if (*kl < 0) {
  722. *info = -10;
  723. } else if (*ku < 0 || isym != 1 && *kl != *ku) {
  724. *info = -11;
  725. } else if (ipack == -1 || isympk == 1 && isym == 1 || isympk == 2 && isym
  726. == 1 && *kl > 0 || isympk == 3 && isym == 1 && *ku > 0 || isympk
  727. != 0 && *m != *n) {
  728. *info = -12;
  729. } else if (*lda < f2cmax(1,minlda)) {
  730. *info = -14;
  731. }
  732. if (*info != 0) {
  733. i__1 = -(*info);
  734. xerbla_("DLATMS", &i__1, 6);
  735. return;
  736. }
  737. /* Initialize random number generator */
  738. for (i__ = 1; i__ <= 4; ++i__) {
  739. iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
  740. /* L10: */
  741. }
  742. if (iseed[4] % 2 != 1) {
  743. ++iseed[4];
  744. }
  745. /* 2) Set up D if indicated. */
  746. /* Compute D according to COND and MODE */
  747. dlatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, &iinfo);
  748. if (iinfo != 0) {
  749. *info = 1;
  750. return;
  751. }
  752. /* Choose Top-Down if D is (apparently) increasing, */
  753. /* Bottom-Up if D is (apparently) decreasing. */
  754. if (abs(d__[1]) <= (d__1 = d__[mnmin], abs(d__1))) {
  755. topdwn = TRUE_;
  756. } else {
  757. topdwn = FALSE_;
  758. }
  759. if (*mode != 0 && abs(*mode) != 6) {
  760. /* Scale by DMAX */
  761. temp = abs(d__[1]);
  762. i__1 = mnmin;
  763. for (i__ = 2; i__ <= i__1; ++i__) {
  764. /* Computing MAX */
  765. d__2 = temp, d__3 = (d__1 = d__[i__], abs(d__1));
  766. temp = f2cmax(d__2,d__3);
  767. /* L20: */
  768. }
  769. if (temp > 0.) {
  770. alpha = *dmax__ / temp;
  771. } else {
  772. *info = 2;
  773. return;
  774. }
  775. dscal_(&mnmin, &alpha, &d__[1], &c__1);
  776. }
  777. /* 3) Generate Banded Matrix using Givens rotations. */
  778. /* Also the special case of UUB=LLB=0 */
  779. /* Compute Addressing constants to cover all */
  780. /* storage formats. Whether GE, SY, GB, or SB, */
  781. /* upper or lower triangle or both, */
  782. /* the (i,j)-th element is in */
  783. /* A( i - ISKEW*j + IOFFST, j ) */
  784. if (ipack > 4) {
  785. ilda = *lda - 1;
  786. iskew = 1;
  787. if (ipack > 5) {
  788. ioffst = uub + 1;
  789. } else {
  790. ioffst = 1;
  791. }
  792. } else {
  793. ilda = *lda;
  794. iskew = 0;
  795. ioffst = 0;
  796. }
  797. /* IPACKG is the format that the matrix is generated in. If this is */
  798. /* different from IPACK, then the matrix must be repacked at the */
  799. /* end. It also signals how to compute the norm, for scaling. */
  800. ipackg = 0;
  801. dlaset_("Full", lda, n, &c_b22, &c_b22, &a[a_offset], lda);
  802. /* Diagonal Matrix -- We are done, unless it */
  803. /* is to be stored SP/PP/TP (PACK='R' or 'C') */
  804. if (llb == 0 && uub == 0) {
  805. i__1 = ilda + 1;
  806. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &i__1)
  807. ;
  808. if (ipack <= 2 || ipack >= 5) {
  809. ipackg = ipack;
  810. }
  811. } else if (givens) {
  812. /* Check whether to use Givens rotations, */
  813. /* Householder transformations, or nothing. */
  814. if (isym == 1) {
  815. /* Non-symmetric -- A = U D V */
  816. if (ipack > 4) {
  817. ipackg = ipack;
  818. } else {
  819. ipackg = 0;
  820. }
  821. i__1 = ilda + 1;
  822. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &
  823. i__1);
  824. if (topdwn) {
  825. jkl = 0;
  826. i__1 = uub;
  827. for (jku = 1; jku <= i__1; ++jku) {
  828. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  829. /* Last row actually rotated is M */
  830. /* Last column actually rotated is MIN( M+JKU, N ) */
  831. /* Computing MIN */
  832. i__3 = *m + jku;
  833. i__2 = f2cmin(i__3,*n) + jkl - 1;
  834. for (jr = 1; jr <= i__2; ++jr) {
  835. extra = 0.;
  836. angle = dlarnd_(&c__1, &iseed[1]) *
  837. 6.2831853071795864769252867663;
  838. c__ = cos(angle);
  839. s = sin(angle);
  840. /* Computing MAX */
  841. i__3 = 1, i__4 = jr - jkl;
  842. icol = f2cmax(i__3,i__4);
  843. if (jr < *m) {
  844. /* Computing MIN */
  845. i__3 = *n, i__4 = jr + jku;
  846. il = f2cmin(i__3,i__4) + 1 - icol;
  847. L__1 = jr > jkl;
  848. dlarot_(&c_true, &L__1, &c_false, &il, &c__, &s, &
  849. a[jr - iskew * icol + ioffst + icol *
  850. a_dim1], &ilda, &extra, &dummy);
  851. }
  852. /* Chase "EXTRA" back up */
  853. ir = jr;
  854. ic = icol;
  855. i__3 = -jkl - jku;
  856. for (jch = jr - jkl; i__3 < 0 ? jch >= 1 : jch <= 1;
  857. jch += i__3) {
  858. if (ir < *m) {
  859. dlartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  860. + (ic + 1) * a_dim1], &extra, &c__, &
  861. s, &dummy);
  862. }
  863. /* Computing MAX */
  864. i__4 = 1, i__5 = jch - jku;
  865. irow = f2cmax(i__4,i__5);
  866. il = ir + 2 - irow;
  867. temp = 0.;
  868. iltemp = jch > jku;
  869. d__1 = -s;
  870. dlarot_(&c_false, &iltemp, &c_true, &il, &c__, &
  871. d__1, &a[irow - iskew * ic + ioffst + ic *
  872. a_dim1], &ilda, &temp, &extra);
  873. if (iltemp) {
  874. dlartg_(&a[irow + 1 - iskew * (ic + 1) +
  875. ioffst + (ic + 1) * a_dim1], &temp, &
  876. c__, &s, &dummy);
  877. /* Computing MAX */
  878. i__4 = 1, i__5 = jch - jku - jkl;
  879. icol = f2cmax(i__4,i__5);
  880. il = ic + 2 - icol;
  881. extra = 0.;
  882. L__1 = jch > jku + jkl;
  883. d__1 = -s;
  884. dlarot_(&c_true, &L__1, &c_true, &il, &c__, &
  885. d__1, &a[irow - iskew * icol + ioffst
  886. + icol * a_dim1], &ilda, &extra, &
  887. temp);
  888. ic = icol;
  889. ir = irow;
  890. }
  891. /* L30: */
  892. }
  893. /* L40: */
  894. }
  895. /* L50: */
  896. }
  897. jku = uub;
  898. i__1 = llb;
  899. for (jkl = 1; jkl <= i__1; ++jkl) {
  900. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  901. /* Computing MIN */
  902. i__3 = *n + jkl;
  903. i__2 = f2cmin(i__3,*m) + jku - 1;
  904. for (jc = 1; jc <= i__2; ++jc) {
  905. extra = 0.;
  906. angle = dlarnd_(&c__1, &iseed[1]) *
  907. 6.2831853071795864769252867663;
  908. c__ = cos(angle);
  909. s = sin(angle);
  910. /* Computing MAX */
  911. i__3 = 1, i__4 = jc - jku;
  912. irow = f2cmax(i__3,i__4);
  913. if (jc < *n) {
  914. /* Computing MIN */
  915. i__3 = *m, i__4 = jc + jkl;
  916. il = f2cmin(i__3,i__4) + 1 - irow;
  917. L__1 = jc > jku;
  918. dlarot_(&c_false, &L__1, &c_false, &il, &c__, &s,
  919. &a[irow - iskew * jc + ioffst + jc *
  920. a_dim1], &ilda, &extra, &dummy);
  921. }
  922. /* Chase "EXTRA" back up */
  923. ic = jc;
  924. ir = irow;
  925. i__3 = -jkl - jku;
  926. for (jch = jc - jku; i__3 < 0 ? jch >= 1 : jch <= 1;
  927. jch += i__3) {
  928. if (ic < *n) {
  929. dlartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  930. + (ic + 1) * a_dim1], &extra, &c__, &
  931. s, &dummy);
  932. }
  933. /* Computing MAX */
  934. i__4 = 1, i__5 = jch - jkl;
  935. icol = f2cmax(i__4,i__5);
  936. il = ic + 2 - icol;
  937. temp = 0.;
  938. iltemp = jch > jkl;
  939. d__1 = -s;
  940. dlarot_(&c_true, &iltemp, &c_true, &il, &c__, &
  941. d__1, &a[ir - iskew * icol + ioffst +
  942. icol * a_dim1], &ilda, &temp, &extra);
  943. if (iltemp) {
  944. dlartg_(&a[ir + 1 - iskew * (icol + 1) +
  945. ioffst + (icol + 1) * a_dim1], &temp,
  946. &c__, &s, &dummy);
  947. /* Computing MAX */
  948. i__4 = 1, i__5 = jch - jkl - jku;
  949. irow = f2cmax(i__4,i__5);
  950. il = ir + 2 - irow;
  951. extra = 0.;
  952. L__1 = jch > jkl + jku;
  953. d__1 = -s;
  954. dlarot_(&c_false, &L__1, &c_true, &il, &c__, &
  955. d__1, &a[irow - iskew * icol + ioffst
  956. + icol * a_dim1], &ilda, &extra, &
  957. temp);
  958. ic = icol;
  959. ir = irow;
  960. }
  961. /* L60: */
  962. }
  963. /* L70: */
  964. }
  965. /* L80: */
  966. }
  967. } else {
  968. /* Bottom-Up -- Start at the bottom right. */
  969. jkl = 0;
  970. i__1 = uub;
  971. for (jku = 1; jku <= i__1; ++jku) {
  972. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  973. /* First row actually rotated is M */
  974. /* First column actually rotated is MIN( M+JKU, N ) */
  975. /* Computing MIN */
  976. i__2 = *m, i__3 = *n + jkl;
  977. iendch = f2cmin(i__2,i__3) - 1;
  978. /* Computing MIN */
  979. i__2 = *m + jku;
  980. i__3 = 1 - jkl;
  981. for (jc = f2cmin(i__2,*n) - 1; jc >= i__3; --jc) {
  982. extra = 0.;
  983. angle = dlarnd_(&c__1, &iseed[1]) *
  984. 6.2831853071795864769252867663;
  985. c__ = cos(angle);
  986. s = sin(angle);
  987. /* Computing MAX */
  988. i__2 = 1, i__4 = jc - jku + 1;
  989. irow = f2cmax(i__2,i__4);
  990. if (jc > 0) {
  991. /* Computing MIN */
  992. i__2 = *m, i__4 = jc + jkl + 1;
  993. il = f2cmin(i__2,i__4) + 1 - irow;
  994. L__1 = jc + jkl < *m;
  995. dlarot_(&c_false, &c_false, &L__1, &il, &c__, &s,
  996. &a[irow - iskew * jc + ioffst + jc *
  997. a_dim1], &ilda, &dummy, &extra);
  998. }
  999. /* Chase "EXTRA" back down */
  1000. ic = jc;
  1001. i__2 = iendch;
  1002. i__4 = jkl + jku;
  1003. for (jch = jc + jkl; i__4 < 0 ? jch >= i__2 : jch <=
  1004. i__2; jch += i__4) {
  1005. ilextr = ic > 0;
  1006. if (ilextr) {
  1007. dlartg_(&a[jch - iskew * ic + ioffst + ic *
  1008. a_dim1], &extra, &c__, &s, &dummy);
  1009. }
  1010. ic = f2cmax(1,ic);
  1011. /* Computing MIN */
  1012. i__5 = *n - 1, i__6 = jch + jku;
  1013. icol = f2cmin(i__5,i__6);
  1014. iltemp = jch + jku < *n;
  1015. temp = 0.;
  1016. i__5 = icol + 2 - ic;
  1017. dlarot_(&c_true, &ilextr, &iltemp, &i__5, &c__, &
  1018. s, &a[jch - iskew * ic + ioffst + ic *
  1019. a_dim1], &ilda, &extra, &temp);
  1020. if (iltemp) {
  1021. dlartg_(&a[jch - iskew * icol + ioffst + icol
  1022. * a_dim1], &temp, &c__, &s, &dummy);
  1023. /* Computing MIN */
  1024. i__5 = iendch, i__6 = jch + jkl + jku;
  1025. il = f2cmin(i__5,i__6) + 2 - jch;
  1026. extra = 0.;
  1027. L__1 = jch + jkl + jku <= iendch;
  1028. dlarot_(&c_false, &c_true, &L__1, &il, &c__, &
  1029. s, &a[jch - iskew * icol + ioffst +
  1030. icol * a_dim1], &ilda, &temp, &extra);
  1031. ic = icol;
  1032. }
  1033. /* L90: */
  1034. }
  1035. /* L100: */
  1036. }
  1037. /* L110: */
  1038. }
  1039. jku = uub;
  1040. i__1 = llb;
  1041. for (jkl = 1; jkl <= i__1; ++jkl) {
  1042. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  1043. /* First row actually rotated is MIN( N+JKL, M ) */
  1044. /* First column actually rotated is N */
  1045. /* Computing MIN */
  1046. i__3 = *n, i__4 = *m + jku;
  1047. iendch = f2cmin(i__3,i__4) - 1;
  1048. /* Computing MIN */
  1049. i__3 = *n + jkl;
  1050. i__4 = 1 - jku;
  1051. for (jr = f2cmin(i__3,*m) - 1; jr >= i__4; --jr) {
  1052. extra = 0.;
  1053. angle = dlarnd_(&c__1, &iseed[1]) *
  1054. 6.2831853071795864769252867663;
  1055. c__ = cos(angle);
  1056. s = sin(angle);
  1057. /* Computing MAX */
  1058. i__3 = 1, i__2 = jr - jkl + 1;
  1059. icol = f2cmax(i__3,i__2);
  1060. if (jr > 0) {
  1061. /* Computing MIN */
  1062. i__3 = *n, i__2 = jr + jku + 1;
  1063. il = f2cmin(i__3,i__2) + 1 - icol;
  1064. L__1 = jr + jku < *n;
  1065. dlarot_(&c_true, &c_false, &L__1, &il, &c__, &s, &
  1066. a[jr - iskew * icol + ioffst + icol *
  1067. a_dim1], &ilda, &dummy, &extra);
  1068. }
  1069. /* Chase "EXTRA" back down */
  1070. ir = jr;
  1071. i__3 = iendch;
  1072. i__2 = jkl + jku;
  1073. for (jch = jr + jku; i__2 < 0 ? jch >= i__3 : jch <=
  1074. i__3; jch += i__2) {
  1075. ilextr = ir > 0;
  1076. if (ilextr) {
  1077. dlartg_(&a[ir - iskew * jch + ioffst + jch *
  1078. a_dim1], &extra, &c__, &s, &dummy);
  1079. }
  1080. ir = f2cmax(1,ir);
  1081. /* Computing MIN */
  1082. i__5 = *m - 1, i__6 = jch + jkl;
  1083. irow = f2cmin(i__5,i__6);
  1084. iltemp = jch + jkl < *m;
  1085. temp = 0.;
  1086. i__5 = irow + 2 - ir;
  1087. dlarot_(&c_false, &ilextr, &iltemp, &i__5, &c__, &
  1088. s, &a[ir - iskew * jch + ioffst + jch *
  1089. a_dim1], &ilda, &extra, &temp);
  1090. if (iltemp) {
  1091. dlartg_(&a[irow - iskew * jch + ioffst + jch *
  1092. a_dim1], &temp, &c__, &s, &dummy);
  1093. /* Computing MIN */
  1094. i__5 = iendch, i__6 = jch + jkl + jku;
  1095. il = f2cmin(i__5,i__6) + 2 - jch;
  1096. extra = 0.;
  1097. L__1 = jch + jkl + jku <= iendch;
  1098. dlarot_(&c_true, &c_true, &L__1, &il, &c__, &
  1099. s, &a[irow - iskew * jch + ioffst +
  1100. jch * a_dim1], &ilda, &temp, &extra);
  1101. ir = irow;
  1102. }
  1103. /* L120: */
  1104. }
  1105. /* L130: */
  1106. }
  1107. /* L140: */
  1108. }
  1109. }
  1110. } else {
  1111. /* Symmetric -- A = U D U' */
  1112. ipackg = ipack;
  1113. ioffg = ioffst;
  1114. if (topdwn) {
  1115. /* Top-Down -- Generate Upper triangle only */
  1116. if (ipack >= 5) {
  1117. ipackg = 6;
  1118. ioffg = uub + 1;
  1119. } else {
  1120. ipackg = 1;
  1121. }
  1122. i__1 = ilda + 1;
  1123. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
  1124. &i__1);
  1125. i__1 = uub;
  1126. for (k = 1; k <= i__1; ++k) {
  1127. i__4 = *n - 1;
  1128. for (jc = 1; jc <= i__4; ++jc) {
  1129. /* Computing MAX */
  1130. i__2 = 1, i__3 = jc - k;
  1131. irow = f2cmax(i__2,i__3);
  1132. /* Computing MIN */
  1133. i__2 = jc + 1, i__3 = k + 2;
  1134. il = f2cmin(i__2,i__3);
  1135. extra = 0.;
  1136. temp = a[jc - iskew * (jc + 1) + ioffg + (jc + 1) *
  1137. a_dim1];
  1138. angle = dlarnd_(&c__1, &iseed[1]) *
  1139. 6.2831853071795864769252867663;
  1140. c__ = cos(angle);
  1141. s = sin(angle);
  1142. L__1 = jc > k;
  1143. dlarot_(&c_false, &L__1, &c_true, &il, &c__, &s, &a[
  1144. irow - iskew * jc + ioffg + jc * a_dim1], &
  1145. ilda, &extra, &temp);
  1146. /* Computing MIN */
  1147. i__3 = k, i__5 = *n - jc;
  1148. i__2 = f2cmin(i__3,i__5) + 1;
  1149. dlarot_(&c_true, &c_true, &c_false, &i__2, &c__, &s, &
  1150. a[(1 - iskew) * jc + ioffg + jc * a_dim1], &
  1151. ilda, &temp, &dummy);
  1152. /* Chase EXTRA back up the matrix */
  1153. icol = jc;
  1154. i__2 = -k;
  1155. for (jch = jc - k; i__2 < 0 ? jch >= 1 : jch <= 1;
  1156. jch += i__2) {
  1157. dlartg_(&a[jch + 1 - iskew * (icol + 1) + ioffg +
  1158. (icol + 1) * a_dim1], &extra, &c__, &s, &
  1159. dummy);
  1160. temp = a[jch - iskew * (jch + 1) + ioffg + (jch +
  1161. 1) * a_dim1];
  1162. i__3 = k + 2;
  1163. d__1 = -s;
  1164. dlarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1165. d__1, &a[(1 - iskew) * jch + ioffg + jch *
  1166. a_dim1], &ilda, &temp, &extra);
  1167. /* Computing MAX */
  1168. i__3 = 1, i__5 = jch - k;
  1169. irow = f2cmax(i__3,i__5);
  1170. /* Computing MIN */
  1171. i__3 = jch + 1, i__5 = k + 2;
  1172. il = f2cmin(i__3,i__5);
  1173. extra = 0.;
  1174. L__1 = jch > k;
  1175. d__1 = -s;
  1176. dlarot_(&c_false, &L__1, &c_true, &il, &c__, &
  1177. d__1, &a[irow - iskew * jch + ioffg + jch
  1178. * a_dim1], &ilda, &extra, &temp);
  1179. icol = jch;
  1180. /* L150: */
  1181. }
  1182. /* L160: */
  1183. }
  1184. /* L170: */
  1185. }
  1186. /* If we need lower triangle, copy from upper. Note that */
  1187. /* the order of copying is chosen to work for 'q' -> 'b' */
  1188. if (ipack != ipackg && ipack != 3) {
  1189. i__1 = *n;
  1190. for (jc = 1; jc <= i__1; ++jc) {
  1191. irow = ioffst - iskew * jc;
  1192. /* Computing MIN */
  1193. i__2 = *n, i__3 = jc + uub;
  1194. i__4 = f2cmin(i__2,i__3);
  1195. for (jr = jc; jr <= i__4; ++jr) {
  1196. a[jr + irow + jc * a_dim1] = a[jc - iskew * jr +
  1197. ioffg + jr * a_dim1];
  1198. /* L180: */
  1199. }
  1200. /* L190: */
  1201. }
  1202. if (ipack == 5) {
  1203. i__1 = *n;
  1204. for (jc = *n - uub + 1; jc <= i__1; ++jc) {
  1205. i__4 = uub + 1;
  1206. for (jr = *n + 2 - jc; jr <= i__4; ++jr) {
  1207. a[jr + jc * a_dim1] = 0.;
  1208. /* L200: */
  1209. }
  1210. /* L210: */
  1211. }
  1212. }
  1213. if (ipackg == 6) {
  1214. ipackg = ipack;
  1215. } else {
  1216. ipackg = 0;
  1217. }
  1218. }
  1219. } else {
  1220. /* Bottom-Up -- Generate Lower triangle only */
  1221. if (ipack >= 5) {
  1222. ipackg = 5;
  1223. if (ipack == 6) {
  1224. ioffg = 1;
  1225. }
  1226. } else {
  1227. ipackg = 2;
  1228. }
  1229. i__1 = ilda + 1;
  1230. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
  1231. &i__1);
  1232. i__1 = uub;
  1233. for (k = 1; k <= i__1; ++k) {
  1234. for (jc = *n - 1; jc >= 1; --jc) {
  1235. /* Computing MIN */
  1236. i__4 = *n + 1 - jc, i__2 = k + 2;
  1237. il = f2cmin(i__4,i__2);
  1238. extra = 0.;
  1239. temp = a[(1 - iskew) * jc + 1 + ioffg + jc * a_dim1];
  1240. angle = dlarnd_(&c__1, &iseed[1]) *
  1241. 6.2831853071795864769252867663;
  1242. c__ = cos(angle);
  1243. s = -sin(angle);
  1244. L__1 = *n - jc > k;
  1245. dlarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &a[(
  1246. 1 - iskew) * jc + ioffg + jc * a_dim1], &ilda,
  1247. &temp, &extra);
  1248. /* Computing MAX */
  1249. i__4 = 1, i__2 = jc - k + 1;
  1250. icol = f2cmax(i__4,i__2);
  1251. i__4 = jc + 2 - icol;
  1252. dlarot_(&c_true, &c_false, &c_true, &i__4, &c__, &s, &
  1253. a[jc - iskew * icol + ioffg + icol * a_dim1],
  1254. &ilda, &dummy, &temp);
  1255. /* Chase EXTRA back down the matrix */
  1256. icol = jc;
  1257. i__4 = *n - 1;
  1258. i__2 = k;
  1259. for (jch = jc + k; i__2 < 0 ? jch >= i__4 : jch <=
  1260. i__4; jch += i__2) {
  1261. dlartg_(&a[jch - iskew * icol + ioffg + icol *
  1262. a_dim1], &extra, &c__, &s, &dummy);
  1263. temp = a[(1 - iskew) * jch + 1 + ioffg + jch *
  1264. a_dim1];
  1265. i__3 = k + 2;
  1266. dlarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1267. s, &a[jch - iskew * icol + ioffg + icol *
  1268. a_dim1], &ilda, &extra, &temp);
  1269. /* Computing MIN */
  1270. i__3 = *n + 1 - jch, i__5 = k + 2;
  1271. il = f2cmin(i__3,i__5);
  1272. extra = 0.;
  1273. L__1 = *n - jch > k;
  1274. dlarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &
  1275. a[(1 - iskew) * jch + ioffg + jch *
  1276. a_dim1], &ilda, &temp, &extra);
  1277. icol = jch;
  1278. /* L220: */
  1279. }
  1280. /* L230: */
  1281. }
  1282. /* L240: */
  1283. }
  1284. /* If we need upper triangle, copy from lower. Note that */
  1285. /* the order of copying is chosen to work for 'b' -> 'q' */
  1286. if (ipack != ipackg && ipack != 4) {
  1287. for (jc = *n; jc >= 1; --jc) {
  1288. irow = ioffst - iskew * jc;
  1289. /* Computing MAX */
  1290. i__2 = 1, i__4 = jc - uub;
  1291. i__1 = f2cmax(i__2,i__4);
  1292. for (jr = jc; jr >= i__1; --jr) {
  1293. a[jr + irow + jc * a_dim1] = a[jc - iskew * jr +
  1294. ioffg + jr * a_dim1];
  1295. /* L250: */
  1296. }
  1297. /* L260: */
  1298. }
  1299. if (ipack == 6) {
  1300. i__1 = uub;
  1301. for (jc = 1; jc <= i__1; ++jc) {
  1302. i__2 = uub + 1 - jc;
  1303. for (jr = 1; jr <= i__2; ++jr) {
  1304. a[jr + jc * a_dim1] = 0.;
  1305. /* L270: */
  1306. }
  1307. /* L280: */
  1308. }
  1309. }
  1310. if (ipackg == 5) {
  1311. ipackg = ipack;
  1312. } else {
  1313. ipackg = 0;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. } else {
  1319. /* 4) Generate Banded Matrix by first */
  1320. /* Rotating by random Unitary matrices, */
  1321. /* then reducing the bandwidth using Householder */
  1322. /* transformations. */
  1323. /* Note: we should get here only if LDA .ge. N */
  1324. if (isym == 1) {
  1325. /* Non-symmetric -- A = U D V */
  1326. dlagge_(&mr, &nc, &llb, &uub, &d__[1], &a[a_offset], lda, &iseed[
  1327. 1], &work[1], &iinfo);
  1328. } else {
  1329. /* Symmetric -- A = U D U' */
  1330. dlagsy_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[1],
  1331. &iinfo);
  1332. }
  1333. if (iinfo != 0) {
  1334. *info = 3;
  1335. return;
  1336. }
  1337. }
  1338. /* 5) Pack the matrix */
  1339. if (ipack != ipackg) {
  1340. if (ipack == 1) {
  1341. /* 'U' -- Upper triangular, not packed */
  1342. i__1 = *m;
  1343. for (j = 1; j <= i__1; ++j) {
  1344. i__2 = *m;
  1345. for (i__ = j + 1; i__ <= i__2; ++i__) {
  1346. a[i__ + j * a_dim1] = 0.;
  1347. /* L290: */
  1348. }
  1349. /* L300: */
  1350. }
  1351. } else if (ipack == 2) {
  1352. /* 'L' -- Lower triangular, not packed */
  1353. i__1 = *m;
  1354. for (j = 2; j <= i__1; ++j) {
  1355. i__2 = j - 1;
  1356. for (i__ = 1; i__ <= i__2; ++i__) {
  1357. a[i__ + j * a_dim1] = 0.;
  1358. /* L310: */
  1359. }
  1360. /* L320: */
  1361. }
  1362. } else if (ipack == 3) {
  1363. /* 'C' -- Upper triangle packed Columnwise. */
  1364. icol = 1;
  1365. irow = 0;
  1366. i__1 = *m;
  1367. for (j = 1; j <= i__1; ++j) {
  1368. i__2 = j;
  1369. for (i__ = 1; i__ <= i__2; ++i__) {
  1370. ++irow;
  1371. if (irow > *lda) {
  1372. irow = 1;
  1373. ++icol;
  1374. }
  1375. a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
  1376. /* L330: */
  1377. }
  1378. /* L340: */
  1379. }
  1380. } else if (ipack == 4) {
  1381. /* 'R' -- Lower triangle packed Columnwise. */
  1382. icol = 1;
  1383. irow = 0;
  1384. i__1 = *m;
  1385. for (j = 1; j <= i__1; ++j) {
  1386. i__2 = *m;
  1387. for (i__ = j; i__ <= i__2; ++i__) {
  1388. ++irow;
  1389. if (irow > *lda) {
  1390. irow = 1;
  1391. ++icol;
  1392. }
  1393. a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
  1394. /* L350: */
  1395. }
  1396. /* L360: */
  1397. }
  1398. } else if (ipack >= 5) {
  1399. /* 'B' -- The lower triangle is packed as a band matrix. */
  1400. /* 'Q' -- The upper triangle is packed as a band matrix. */
  1401. /* 'Z' -- The whole matrix is packed as a band matrix. */
  1402. if (ipack == 5) {
  1403. uub = 0;
  1404. }
  1405. if (ipack == 6) {
  1406. llb = 0;
  1407. }
  1408. i__1 = uub;
  1409. for (j = 1; j <= i__1; ++j) {
  1410. /* Computing MIN */
  1411. i__2 = j + llb;
  1412. for (i__ = f2cmin(i__2,*m); i__ >= 1; --i__) {
  1413. a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
  1414. /* L370: */
  1415. }
  1416. /* L380: */
  1417. }
  1418. i__1 = *n;
  1419. for (j = uub + 2; j <= i__1; ++j) {
  1420. /* Computing MIN */
  1421. i__4 = j + llb;
  1422. i__2 = f2cmin(i__4,*m);
  1423. for (i__ = j - uub; i__ <= i__2; ++i__) {
  1424. a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
  1425. /* L390: */
  1426. }
  1427. /* L400: */
  1428. }
  1429. }
  1430. /* If packed, zero out extraneous elements. */
  1431. /* Symmetric/Triangular Packed -- */
  1432. /* zero out everything after A(IROW,ICOL) */
  1433. if (ipack == 3 || ipack == 4) {
  1434. i__1 = *m;
  1435. for (jc = icol; jc <= i__1; ++jc) {
  1436. i__2 = *lda;
  1437. for (jr = irow + 1; jr <= i__2; ++jr) {
  1438. a[jr + jc * a_dim1] = 0.;
  1439. /* L410: */
  1440. }
  1441. irow = 0;
  1442. /* L420: */
  1443. }
  1444. } else if (ipack >= 5) {
  1445. /* Packed Band -- */
  1446. /* 1st row is now in A( UUB+2-j, j), zero above it */
  1447. /* m-th row is now in A( M+UUB-j,j), zero below it */
  1448. /* last non-zero diagonal is now in A( UUB+LLB+1,j ), */
  1449. /* zero below it, too. */
  1450. ir1 = uub + llb + 2;
  1451. ir2 = uub + *m + 2;
  1452. i__1 = *n;
  1453. for (jc = 1; jc <= i__1; ++jc) {
  1454. i__2 = uub + 1 - jc;
  1455. for (jr = 1; jr <= i__2; ++jr) {
  1456. a[jr + jc * a_dim1] = 0.;
  1457. /* L430: */
  1458. }
  1459. /* Computing MAX */
  1460. /* Computing MIN */
  1461. i__3 = ir1, i__5 = ir2 - jc;
  1462. i__2 = 1, i__4 = f2cmin(i__3,i__5);
  1463. i__6 = *lda;
  1464. for (jr = f2cmax(i__2,i__4); jr <= i__6; ++jr) {
  1465. a[jr + jc * a_dim1] = 0.;
  1466. /* L440: */
  1467. }
  1468. /* L450: */
  1469. }
  1470. }
  1471. }
  1472. return;
  1473. /* End of DLATMS */
  1474. } /* dlatms_ */