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.

zlatmt.c 59 kB

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