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.

clatms.c 58 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969
  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 complex c_b1 = {0.f,0.f};
  242. static integer c__1 = 1;
  243. static integer c__5 = 5;
  244. static logical c_true = TRUE_;
  245. static logical c_false = FALSE_;
  246. /* > \brief \b CLATMS */
  247. /* =========== DOCUMENTATION =========== */
  248. /* Online html documentation available at */
  249. /* http://www.netlib.org/lapack/explore-html/ */
  250. /* Definition: */
  251. /* =========== */
  252. /* SUBROUTINE CLATMS( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
  253. /* KL, KU, PACK, A, LDA, WORK, INFO ) */
  254. /* CHARACTER DIST, PACK, SYM */
  255. /* INTEGER INFO, KL, KU, LDA, M, MODE, N */
  256. /* REAL COND, DMAX */
  257. /* INTEGER ISEED( 4 ) */
  258. /* REAL D( * ) */
  259. /* COMPLEX A( LDA, * ), WORK( * ) */
  260. /* > \par Purpose: */
  261. /* ============= */
  262. /* > */
  263. /* > \verbatim */
  264. /* > */
  265. /* > CLATMS generates random matrices with specified singular values */
  266. /* > (or hermitian with specified eigenvalues) */
  267. /* > for testing LAPACK programs. */
  268. /* > */
  269. /* > CLATMS operates by applying the following sequence of */
  270. /* > operations: */
  271. /* > */
  272. /* > Set the diagonal to D, where D may be input or */
  273. /* > computed according to MODE, COND, DMAX, and SYM */
  274. /* > as described below. */
  275. /* > */
  276. /* > Generate a matrix with the appropriate band structure, by one */
  277. /* > of two methods: */
  278. /* > */
  279. /* > Method A: */
  280. /* > Generate a dense M x N matrix by multiplying D on the left */
  281. /* > and the right by random unitary matrices, then: */
  282. /* > */
  283. /* > Reduce the bandwidth according to KL and KU, using */
  284. /* > Householder transformations. */
  285. /* > */
  286. /* > Method B: */
  287. /* > Convert the bandwidth-0 (i.e., diagonal) matrix to a */
  288. /* > bandwidth-1 matrix using Givens rotations, "chasing" */
  289. /* > out-of-band elements back, much as in QR; then convert */
  290. /* > the bandwidth-1 to a bandwidth-2 matrix, etc. Note */
  291. /* > that for reasonably small bandwidths (relative to M and */
  292. /* > N) this requires less storage, as a dense matrix is not */
  293. /* > generated. Also, for hermitian or symmetric matrices, */
  294. /* > only one triangle is generated. */
  295. /* > */
  296. /* > Method A is chosen if the bandwidth is a large fraction of the */
  297. /* > order of the matrix, and LDA is at least M (so a dense */
  298. /* > matrix can be stored.) Method B is chosen if the bandwidth */
  299. /* > is small (< 1/2 N for hermitian or symmetric, < .3 N+M for */
  300. /* > non-symmetric), or LDA is less than M and not less than the */
  301. /* > bandwidth. */
  302. /* > */
  303. /* > Pack the matrix if desired. Options specified by PACK are: */
  304. /* > no packing */
  305. /* > zero out upper half (if hermitian) */
  306. /* > zero out lower half (if hermitian) */
  307. /* > store the upper half columnwise (if hermitian or upper */
  308. /* > triangular) */
  309. /* > store the lower half columnwise (if hermitian or lower */
  310. /* > triangular) */
  311. /* > store the lower triangle in banded format (if hermitian or */
  312. /* > lower triangular) */
  313. /* > store the upper triangle in banded format (if hermitian or */
  314. /* > upper triangular) */
  315. /* > store the entire matrix in banded format */
  316. /* > If Method B is chosen, and band format is specified, then the */
  317. /* > matrix will be generated in the band format, so no repacking */
  318. /* > will be necessary. */
  319. /* > \endverbatim */
  320. /* Arguments: */
  321. /* ========== */
  322. /* > \param[in] M */
  323. /* > \verbatim */
  324. /* > M is INTEGER */
  325. /* > The number of rows of A. Not modified. */
  326. /* > \endverbatim */
  327. /* > */
  328. /* > \param[in] N */
  329. /* > \verbatim */
  330. /* > N is INTEGER */
  331. /* > The number of columns of A. N must equal M if the matrix */
  332. /* > is symmetric or hermitian (i.e., if SYM is not 'N') */
  333. /* > Not modified. */
  334. /* > \endverbatim */
  335. /* > */
  336. /* > \param[in] DIST */
  337. /* > \verbatim */
  338. /* > DIST is CHARACTER*1 */
  339. /* > On entry, DIST specifies the type of distribution to be used */
  340. /* > to generate the random eigen-/singular values. */
  341. /* > 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */
  342. /* > 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
  343. /* > 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */
  344. /* > Not modified. */
  345. /* > \endverbatim */
  346. /* > */
  347. /* > \param[in,out] ISEED */
  348. /* > \verbatim */
  349. /* > ISEED is INTEGER array, dimension ( 4 ) */
  350. /* > On entry ISEED specifies the seed of the random number */
  351. /* > generator. They should lie between 0 and 4095 inclusive, */
  352. /* > and ISEED(4) should be odd. The random number generator */
  353. /* > uses a linear congruential sequence limited to small */
  354. /* > integers, and so should produce machine independent */
  355. /* > random numbers. The values of ISEED are changed on */
  356. /* > exit, and can be used in the next call to CLATMS */
  357. /* > to continue the same random number sequence. */
  358. /* > Changed on exit. */
  359. /* > \endverbatim */
  360. /* > */
  361. /* > \param[in] SYM */
  362. /* > \verbatim */
  363. /* > SYM is CHARACTER*1 */
  364. /* > If SYM='H', the generated matrix is hermitian, with */
  365. /* > eigenvalues specified by D, COND, MODE, and DMAX; they */
  366. /* > may be positive, negative, or zero. */
  367. /* > If SYM='P', the generated matrix is hermitian, with */
  368. /* > eigenvalues (= singular values) specified by D, COND, */
  369. /* > MODE, and DMAX; they will not be negative. */
  370. /* > If SYM='N', the generated matrix is nonsymmetric, with */
  371. /* > singular values specified by D, COND, MODE, and DMAX; */
  372. /* > they will not be negative. */
  373. /* > If SYM='S', the generated matrix is (complex) symmetric, */
  374. /* > with singular values specified by D, COND, MODE, and */
  375. /* > DMAX; they will not be negative. */
  376. /* > Not modified. */
  377. /* > \endverbatim */
  378. /* > */
  379. /* > \param[in,out] D */
  380. /* > \verbatim */
  381. /* > D is REAL array, dimension ( MIN( M, N ) ) */
  382. /* > This array is used to specify the singular values or */
  383. /* > eigenvalues of A (see SYM, above.) If MODE=0, then D is */
  384. /* > assumed to contain the singular/eigenvalues, otherwise */
  385. /* > they will be computed according to MODE, COND, and DMAX, */
  386. /* > and placed in D. */
  387. /* > Modified if MODE is nonzero. */
  388. /* > \endverbatim */
  389. /* > */
  390. /* > \param[in] MODE */
  391. /* > \verbatim */
  392. /* > MODE is INTEGER */
  393. /* > On entry this describes how the singular/eigenvalues are to */
  394. /* > be specified: */
  395. /* > MODE = 0 means use D as input */
  396. /* > MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
  397. /* > MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
  398. /* > MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
  399. /* > MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
  400. /* > MODE = 5 sets D to random numbers in the range */
  401. /* > ( 1/COND , 1 ) such that their logarithms */
  402. /* > are uniformly distributed. */
  403. /* > MODE = 6 set D to random numbers from same distribution */
  404. /* > as the rest of the matrix. */
  405. /* > MODE < 0 has the same meaning as ABS(MODE), except that */
  406. /* > the order of the elements of D is reversed. */
  407. /* > Thus if MODE is positive, D has entries ranging from */
  408. /* > 1 to 1/COND, if negative, from 1/COND to 1, */
  409. /* > If SYM='H', and MODE is neither 0, 6, nor -6, then */
  410. /* > the elements of D will also be multiplied by a random */
  411. /* > sign (i.e., +1 or -1.) */
  412. /* > Not modified. */
  413. /* > \endverbatim */
  414. /* > */
  415. /* > \param[in] COND */
  416. /* > \verbatim */
  417. /* > COND is REAL */
  418. /* > On entry, this is used as described under MODE above. */
  419. /* > If used, it must be >= 1. Not modified. */
  420. /* > \endverbatim */
  421. /* > */
  422. /* > \param[in] DMAX */
  423. /* > \verbatim */
  424. /* > DMAX is REAL */
  425. /* > If MODE is neither -6, 0 nor 6, the contents of D, as */
  426. /* > computed according to MODE and COND, will be scaled by */
  427. /* > DMAX / f2cmax(abs(D(i))); thus, the maximum absolute eigen- or */
  428. /* > singular value (which is to say the norm) will be abs(DMAX). */
  429. /* > Note that DMAX need not be positive: if DMAX is negative */
  430. /* > (or zero), D will be scaled by a negative number (or zero). */
  431. /* > Not modified. */
  432. /* > \endverbatim */
  433. /* > */
  434. /* > \param[in] KL */
  435. /* > \verbatim */
  436. /* > KL is INTEGER */
  437. /* > This specifies the lower bandwidth of the matrix. For */
  438. /* > example, KL=0 implies upper triangular, KL=1 implies upper */
  439. /* > Hessenberg, and KL being at least M-1 means that the matrix */
  440. /* > has full lower bandwidth. KL must equal KU if the matrix */
  441. /* > is symmetric or hermitian. */
  442. /* > Not modified. */
  443. /* > \endverbatim */
  444. /* > */
  445. /* > \param[in] KU */
  446. /* > \verbatim */
  447. /* > KU is INTEGER */
  448. /* > This specifies the upper bandwidth of the matrix. For */
  449. /* > example, KU=0 implies lower triangular, KU=1 implies lower */
  450. /* > Hessenberg, and KU being at least N-1 means that the matrix */
  451. /* > has full upper bandwidth. KL must equal KU if the matrix */
  452. /* > is symmetric or hermitian. */
  453. /* > Not modified. */
  454. /* > \endverbatim */
  455. /* > */
  456. /* > \param[in] PACK */
  457. /* > \verbatim */
  458. /* > PACK is CHARACTER*1 */
  459. /* > This specifies packing of matrix as follows: */
  460. /* > 'N' => no packing */
  461. /* > 'U' => zero out all subdiagonal entries (if symmetric */
  462. /* > or hermitian) */
  463. /* > 'L' => zero out all superdiagonal entries (if symmetric */
  464. /* > or hermitian) */
  465. /* > 'C' => store the upper triangle columnwise (only if the */
  466. /* > matrix is symmetric, hermitian, or upper triangular) */
  467. /* > 'R' => store the lower triangle columnwise (only if the */
  468. /* > matrix is symmetric, hermitian, or lower triangular) */
  469. /* > 'B' => store the lower triangle in band storage scheme */
  470. /* > (only if the matrix is symmetric, hermitian, or */
  471. /* > lower triangular) */
  472. /* > 'Q' => store the upper triangle in band storage scheme */
  473. /* > (only if the matrix is symmetric, hermitian, or */
  474. /* > upper triangular) */
  475. /* > 'Z' => store the entire matrix in band storage scheme */
  476. /* > (pivoting can be provided for by using this */
  477. /* > option to store A in the trailing rows of */
  478. /* > the allocated storage) */
  479. /* > */
  480. /* > Using these options, the various LAPACK packed and banded */
  481. /* > storage schemes can be obtained: */
  482. /* > GB - use 'Z' */
  483. /* > PB, SB, HB, or TB - use 'B' or 'Q' */
  484. /* > PP, SP, HB, or TP - use 'C' or 'R' */
  485. /* > */
  486. /* > If two calls to CLATMS differ only in the PACK parameter, */
  487. /* > they will generate mathematically equivalent matrices. */
  488. /* > Not modified. */
  489. /* > \endverbatim */
  490. /* > */
  491. /* > \param[in,out] A */
  492. /* > \verbatim */
  493. /* > A is COMPLEX array, dimension ( LDA, N ) */
  494. /* > On exit A is the desired test matrix. A is first generated */
  495. /* > in full (unpacked) form, and then packed, if so specified */
  496. /* > by PACK. Thus, the first M elements of the first N */
  497. /* > columns will always be modified. If PACK specifies a */
  498. /* > packed or banded storage scheme, all LDA elements of the */
  499. /* > first N columns will be modified; the elements of the */
  500. /* > array which do not correspond to elements of the generated */
  501. /* > matrix are set to zero. */
  502. /* > Modified. */
  503. /* > \endverbatim */
  504. /* > */
  505. /* > \param[in] LDA */
  506. /* > \verbatim */
  507. /* > LDA is INTEGER */
  508. /* > LDA specifies the first dimension of A as declared in the */
  509. /* > calling program. If PACK='N', 'U', 'L', 'C', or 'R', then */
  510. /* > LDA must be at least M. If PACK='B' or 'Q', then LDA must */
  511. /* > be at least MIN( KL, M-1) (which is equal to MIN(KU,N-1)). */
  512. /* > If PACK='Z', LDA must be large enough to hold the packed */
  513. /* > array: MIN( KU, N-1) + MIN( KL, M-1) + 1. */
  514. /* > Not modified. */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[out] WORK */
  518. /* > \verbatim */
  519. /* > WORK is COMPLEX array, dimension ( 3*MAX( N, M ) ) */
  520. /* > Workspace. */
  521. /* > Modified. */
  522. /* > \endverbatim */
  523. /* > */
  524. /* > \param[out] INFO */
  525. /* > \verbatim */
  526. /* > INFO is INTEGER */
  527. /* > Error code. On exit, INFO will be set to one of the */
  528. /* > following values: */
  529. /* > 0 => normal return */
  530. /* > -1 => M negative or unequal to N and SYM='S', 'H', or 'P' */
  531. /* > -2 => N negative */
  532. /* > -3 => DIST illegal string */
  533. /* > -5 => SYM illegal string */
  534. /* > -7 => MODE not in range -6 to 6 */
  535. /* > -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
  536. /* > -10 => KL negative */
  537. /* > -11 => KU negative, or SYM is not 'N' and KU is not equal to */
  538. /* > KL */
  539. /* > -12 => PACK illegal string, or PACK='U' or 'L', and SYM='N'; */
  540. /* > or PACK='C' or 'Q' and SYM='N' and KL is not zero; */
  541. /* > or PACK='R' or 'B' and SYM='N' and KU is not zero; */
  542. /* > or PACK='U', 'L', 'C', 'R', 'B', or 'Q', and M is not */
  543. /* > N. */
  544. /* > -14 => LDA is less than M, or PACK='Z' and LDA is less than */
  545. /* > MIN(KU,N-1) + MIN(KL,M-1) + 1. */
  546. /* > 1 => Error return from SLATM1 */
  547. /* > 2 => Cannot scale to DMAX (f2cmax. sing. value is 0) */
  548. /* > 3 => Error return from CLAGGE, CLAGHE or CLAGSY */
  549. /* > \endverbatim */
  550. /* Authors: */
  551. /* ======== */
  552. /* > \author Univ. of Tennessee */
  553. /* > \author Univ. of California Berkeley */
  554. /* > \author Univ. of Colorado Denver */
  555. /* > \author NAG Ltd. */
  556. /* > \date December 2016 */
  557. /* > \ingroup complex_matgen */
  558. /* ===================================================================== */
  559. /* Subroutine */ void clatms_(integer *m, integer *n, char *dist, integer *
  560. iseed, char *sym, real *d__, integer *mode, real *cond, real *dmax__,
  561. integer *kl, integer *ku, char *pack, complex *a, integer *lda,
  562. complex *work, integer *info)
  563. {
  564. /* System generated locals */
  565. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  566. real r__1, r__2, r__3;
  567. complex q__1, q__2, q__3;
  568. logical L__1;
  569. /* Local variables */
  570. integer ilda, icol;
  571. real temp;
  572. logical csym;
  573. integer irow, isym;
  574. complex c__;
  575. integer i__, j, k;
  576. complex s;
  577. real alpha, angle;
  578. integer ipack;
  579. real realc;
  580. integer ioffg;
  581. extern logical lsame_(char *, char *);
  582. integer iinfo;
  583. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  584. complex ctemp;
  585. integer idist, mnmin, iskew;
  586. complex extra, dummy;
  587. extern /* Subroutine */ void slatm1_(integer *, real *, integer *, integer
  588. *, integer *, real *, integer *, integer *);
  589. integer ic, jc, nc;
  590. extern /* Subroutine */ void clagge_(integer *, integer *, integer *,
  591. integer *, real *, complex *, integer *, integer *, complex *,
  592. integer *), claghe_(integer *, integer *, real *, complex *,
  593. integer *, integer *, complex *, integer *);
  594. integer il;
  595. complex ct;
  596. integer iendch, ir, jr, ipackg, mr;
  597. //extern /* Complex */ VOID clarnd_(complex *, integer *, integer *);
  598. extern complex clarnd_(integer *, integer *);
  599. integer minlda;
  600. complex st;
  601. extern /* Subroutine */ void claset_(char *, integer *, integer *, complex
  602. *, complex *, complex *, integer *), clartg_(complex *,
  603. complex *, real *, complex *, complex *);
  604. extern int xerbla_(char *, integer *, ftnlen);
  605. extern void clagsy_(integer *, integer *, real *, complex *,
  606. integer *, integer *, complex *, integer *);
  607. extern real slarnd_(integer *, integer *);
  608. extern /* Subroutine */ void clarot_(logical *, logical *, logical *,
  609. integer *, complex *, complex *, complex *, integer *, complex *,
  610. complex *);
  611. logical iltemp, givens;
  612. integer ioffst, irsign;
  613. logical ilextr, topdwn;
  614. integer ir1, ir2, isympk, jch, llb, jkl, jku, uub;
  615. /* -- LAPACK computational routine (version 3.7.0) -- */
  616. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  617. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  618. /* December 2016 */
  619. /* ===================================================================== */
  620. /* 1) Decode and Test the input parameters. */
  621. /* Initialize flags & seed. */
  622. /* Parameter adjustments */
  623. --iseed;
  624. --d__;
  625. a_dim1 = *lda;
  626. a_offset = 1 + a_dim1 * 1;
  627. a -= a_offset;
  628. --work;
  629. /* Function Body */
  630. *info = 0;
  631. /* Quick return if possible */
  632. if (*m == 0 || *n == 0) {
  633. return;
  634. }
  635. /* Decode DIST */
  636. if (lsame_(dist, "U")) {
  637. idist = 1;
  638. } else if (lsame_(dist, "S")) {
  639. idist = 2;
  640. } else if (lsame_(dist, "N")) {
  641. idist = 3;
  642. } else {
  643. idist = -1;
  644. }
  645. /* Decode SYM */
  646. if (lsame_(sym, "N")) {
  647. isym = 1;
  648. irsign = 0;
  649. csym = FALSE_;
  650. } else if (lsame_(sym, "P")) {
  651. isym = 2;
  652. irsign = 0;
  653. csym = FALSE_;
  654. } else if (lsame_(sym, "S")) {
  655. isym = 2;
  656. irsign = 0;
  657. csym = TRUE_;
  658. } else if (lsame_(sym, "H")) {
  659. isym = 2;
  660. irsign = 1;
  661. csym = FALSE_;
  662. } else {
  663. isym = -1;
  664. }
  665. /* Decode PACK */
  666. isympk = 0;
  667. if (lsame_(pack, "N")) {
  668. ipack = 0;
  669. } else if (lsame_(pack, "U")) {
  670. ipack = 1;
  671. isympk = 1;
  672. } else if (lsame_(pack, "L")) {
  673. ipack = 2;
  674. isympk = 1;
  675. } else if (lsame_(pack, "C")) {
  676. ipack = 3;
  677. isympk = 2;
  678. } else if (lsame_(pack, "R")) {
  679. ipack = 4;
  680. isympk = 3;
  681. } else if (lsame_(pack, "B")) {
  682. ipack = 5;
  683. isympk = 3;
  684. } else if (lsame_(pack, "Q")) {
  685. ipack = 6;
  686. isympk = 2;
  687. } else if (lsame_(pack, "Z")) {
  688. ipack = 7;
  689. } else {
  690. ipack = -1;
  691. }
  692. /* Set certain internal parameters */
  693. mnmin = f2cmin(*m,*n);
  694. /* Computing MIN */
  695. i__1 = *kl, i__2 = *m - 1;
  696. llb = f2cmin(i__1,i__2);
  697. /* Computing MIN */
  698. i__1 = *ku, i__2 = *n - 1;
  699. uub = f2cmin(i__1,i__2);
  700. /* Computing MIN */
  701. i__1 = *m, i__2 = *n + llb;
  702. mr = f2cmin(i__1,i__2);
  703. /* Computing MIN */
  704. i__1 = *n, i__2 = *m + uub;
  705. nc = f2cmin(i__1,i__2);
  706. if (ipack == 5 || ipack == 6) {
  707. minlda = uub + 1;
  708. } else if (ipack == 7) {
  709. minlda = llb + uub + 1;
  710. } else {
  711. minlda = *m;
  712. }
  713. /* Use Givens rotation method if bandwidth small enough, */
  714. /* or if LDA is too small to store the matrix unpacked. */
  715. givens = FALSE_;
  716. if (isym == 1) {
  717. /* Computing MAX */
  718. i__1 = 1, i__2 = mr + nc;
  719. if ((real) (llb + uub) < (real) f2cmax(i__1,i__2) * .3f) {
  720. givens = TRUE_;
  721. }
  722. } else {
  723. if (llb << 1 < *m) {
  724. givens = TRUE_;
  725. }
  726. }
  727. if (*lda < *m && *lda >= minlda) {
  728. givens = TRUE_;
  729. }
  730. /* Set INFO if an error */
  731. if (*m < 0) {
  732. *info = -1;
  733. } else if (*m != *n && isym != 1) {
  734. *info = -1;
  735. } else if (*n < 0) {
  736. *info = -2;
  737. } else if (idist == -1) {
  738. *info = -3;
  739. } else if (isym == -1) {
  740. *info = -5;
  741. } else if (abs(*mode) > 6) {
  742. *info = -7;
  743. } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) {
  744. *info = -8;
  745. } else if (*kl < 0) {
  746. *info = -10;
  747. } else if (*ku < 0 || isym != 1 && *kl != *ku) {
  748. *info = -11;
  749. } else if (ipack == -1 || isympk == 1 && isym == 1 || isympk == 2 && isym
  750. == 1 && *kl > 0 || isympk == 3 && isym == 1 && *ku > 0 || isympk
  751. != 0 && *m != *n) {
  752. *info = -12;
  753. } else if (*lda < f2cmax(1,minlda)) {
  754. *info = -14;
  755. }
  756. if (*info != 0) {
  757. i__1 = -(*info);
  758. xerbla_("CLATMS", &i__1, 6);
  759. return;
  760. }
  761. /* Initialize random number generator */
  762. for (i__ = 1; i__ <= 4; ++i__) {
  763. iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
  764. /* L10: */
  765. }
  766. if (iseed[4] % 2 != 1) {
  767. ++iseed[4];
  768. }
  769. /* 2) Set up D if indicated. */
  770. /* Compute D according to COND and MODE */
  771. slatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, &iinfo);
  772. if (iinfo != 0) {
  773. *info = 1;
  774. return;
  775. }
  776. /* Choose Top-Down if D is (apparently) increasing, */
  777. /* Bottom-Up if D is (apparently) decreasing. */
  778. if (abs(d__[1]) <= (r__1 = d__[mnmin], abs(r__1))) {
  779. topdwn = TRUE_;
  780. } else {
  781. topdwn = FALSE_;
  782. }
  783. if (*mode != 0 && abs(*mode) != 6) {
  784. /* Scale by DMAX */
  785. temp = abs(d__[1]);
  786. i__1 = mnmin;
  787. for (i__ = 2; i__ <= i__1; ++i__) {
  788. /* Computing MAX */
  789. r__2 = temp, r__3 = (r__1 = d__[i__], abs(r__1));
  790. temp = f2cmax(r__2,r__3);
  791. /* L20: */
  792. }
  793. if (temp > 0.f) {
  794. alpha = *dmax__ / temp;
  795. } else {
  796. *info = 2;
  797. return;
  798. }
  799. sscal_(&mnmin, &alpha, &d__[1], &c__1);
  800. }
  801. claset_("Full", lda, n, &c_b1, &c_b1, &a[a_offset], lda);
  802. /* 3) Generate Banded Matrix using Givens rotations. */
  803. /* Also the special case of UUB=LLB=0 */
  804. /* Compute Addressing constants to cover all */
  805. /* storage formats. Whether GE, HE, SY, GB, HB, or SB, */
  806. /* upper or lower triangle or both, */
  807. /* the (i,j)-th element is in */
  808. /* A( i - ISKEW*j + IOFFST, j ) */
  809. if (ipack > 4) {
  810. ilda = *lda - 1;
  811. iskew = 1;
  812. if (ipack > 5) {
  813. ioffst = uub + 1;
  814. } else {
  815. ioffst = 1;
  816. }
  817. } else {
  818. ilda = *lda;
  819. iskew = 0;
  820. ioffst = 0;
  821. }
  822. /* IPACKG is the format that the matrix is generated in. If this is */
  823. /* different from IPACK, then the matrix must be repacked at the */
  824. /* end. It also signals how to compute the norm, for scaling. */
  825. ipackg = 0;
  826. /* Diagonal Matrix -- We are done, unless it */
  827. /* is to be stored HP/SP/PP/TP (PACK='R' or 'C') */
  828. if (llb == 0 && uub == 0) {
  829. i__1 = mnmin;
  830. for (j = 1; j <= i__1; ++j) {
  831. i__2 = (1 - iskew) * j + ioffst + j * a_dim1;
  832. i__3 = j;
  833. q__1.r = d__[i__3], q__1.i = 0.f;
  834. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  835. /* L30: */
  836. }
  837. if (ipack <= 2 || ipack >= 5) {
  838. ipackg = ipack;
  839. }
  840. } else if (givens) {
  841. /* Check whether to use Givens rotations, */
  842. /* Householder transformations, or nothing. */
  843. if (isym == 1) {
  844. /* Non-symmetric -- A = U D V */
  845. if (ipack > 4) {
  846. ipackg = ipack;
  847. } else {
  848. ipackg = 0;
  849. }
  850. i__1 = mnmin;
  851. for (j = 1; j <= i__1; ++j) {
  852. i__2 = (1 - iskew) * j + ioffst + j * a_dim1;
  853. i__3 = j;
  854. q__1.r = d__[i__3], q__1.i = 0.f;
  855. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  856. /* L40: */
  857. }
  858. if (topdwn) {
  859. jkl = 0;
  860. i__1 = uub;
  861. for (jku = 1; jku <= i__1; ++jku) {
  862. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  863. /* Last row actually rotated is M */
  864. /* Last column actually rotated is MIN( M+JKU, N ) */
  865. /* Computing MIN */
  866. i__3 = *m + jku;
  867. i__2 = f2cmin(i__3,*n) + jkl - 1;
  868. for (jr = 1; jr <= i__2; ++jr) {
  869. extra.r = 0.f, extra.i = 0.f;
  870. angle = slarnd_(&c__1, &iseed[1]) *
  871. 6.2831853071795864769252867663f;
  872. r__1 = cos(angle);
  873. //clarnd_(&q__2, &c__5, &iseed[1]);
  874. q__2=clarnd_(&c__5, &iseed[1]);
  875. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  876. c__.r = q__1.r, c__.i = q__1.i;
  877. r__1 = sin(angle);
  878. //clarnd_(&q__2, &c__5, &iseed[1]);
  879. q__2=clarnd_(&c__5, &iseed[1]);
  880. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  881. s.r = q__1.r, s.i = q__1.i;
  882. /* Computing MAX */
  883. i__3 = 1, i__4 = jr - jkl;
  884. icol = f2cmax(i__3,i__4);
  885. if (jr < *m) {
  886. /* Computing MIN */
  887. i__3 = *n, i__4 = jr + jku;
  888. il = f2cmin(i__3,i__4) + 1 - icol;
  889. L__1 = jr > jkl;
  890. clarot_(&c_true, &L__1, &c_false, &il, &c__, &s, &
  891. a[jr - iskew * icol + ioffst + icol *
  892. a_dim1], &ilda, &extra, &dummy);
  893. }
  894. /* Chase "EXTRA" back up */
  895. ir = jr;
  896. ic = icol;
  897. i__3 = -jkl - jku;
  898. for (jch = jr - jkl; i__3 < 0 ? jch >= 1 : jch <= 1;
  899. jch += i__3) {
  900. if (ir < *m) {
  901. clartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  902. + (ic + 1) * a_dim1], &extra, &realc,
  903. &s, &dummy);
  904. //clarnd_(&q__1, &c__5, &iseed[1]);
  905. q__1=clarnd_(&c__5, &iseed[1]);
  906. dummy.r = q__1.r, dummy.i = q__1.i;
  907. q__2.r = realc * dummy.r, q__2.i = realc *
  908. dummy.i;
  909. r_cnjg(&q__1, &q__2);
  910. c__.r = q__1.r, c__.i = q__1.i;
  911. q__3.r = -s.r, q__3.i = -s.i;
  912. q__2.r = q__3.r * dummy.r - q__3.i * dummy.i,
  913. q__2.i = q__3.r * dummy.i + q__3.i *
  914. dummy.r;
  915. r_cnjg(&q__1, &q__2);
  916. s.r = q__1.r, s.i = q__1.i;
  917. }
  918. /* Computing MAX */
  919. i__4 = 1, i__5 = jch - jku;
  920. irow = f2cmax(i__4,i__5);
  921. il = ir + 2 - irow;
  922. ctemp.r = 0.f, ctemp.i = 0.f;
  923. iltemp = jch > jku;
  924. clarot_(&c_false, &iltemp, &c_true, &il, &c__, &s,
  925. &a[irow - iskew * ic + ioffst + ic *
  926. a_dim1], &ilda, &ctemp, &extra);
  927. if (iltemp) {
  928. clartg_(&a[irow + 1 - iskew * (ic + 1) +
  929. ioffst + (ic + 1) * a_dim1], &ctemp, &
  930. realc, &s, &dummy);
  931. //clarnd_(&q__1, &c__5, &iseed[1]);
  932. q__1=clarnd_(&c__5, &iseed[1]);
  933. dummy.r = q__1.r, dummy.i = q__1.i;
  934. q__2.r = realc * dummy.r, q__2.i = realc *
  935. dummy.i;
  936. r_cnjg(&q__1, &q__2);
  937. c__.r = q__1.r, c__.i = q__1.i;
  938. q__3.r = -s.r, q__3.i = -s.i;
  939. q__2.r = q__3.r * dummy.r - q__3.i * dummy.i,
  940. q__2.i = q__3.r * dummy.i + q__3.i *
  941. dummy.r;
  942. r_cnjg(&q__1, &q__2);
  943. s.r = q__1.r, s.i = q__1.i;
  944. /* Computing MAX */
  945. i__4 = 1, i__5 = jch - jku - jkl;
  946. icol = f2cmax(i__4,i__5);
  947. il = ic + 2 - icol;
  948. extra.r = 0.f, extra.i = 0.f;
  949. L__1 = jch > jku + jkl;
  950. clarot_(&c_true, &L__1, &c_true, &il, &c__, &
  951. s, &a[irow - iskew * icol + ioffst +
  952. icol * a_dim1], &ilda, &extra, &ctemp)
  953. ;
  954. ic = icol;
  955. ir = irow;
  956. }
  957. /* L50: */
  958. }
  959. /* L60: */
  960. }
  961. /* L70: */
  962. }
  963. jku = uub;
  964. i__1 = llb;
  965. for (jkl = 1; jkl <= i__1; ++jkl) {
  966. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  967. /* Computing MIN */
  968. i__3 = *n + jkl;
  969. i__2 = f2cmin(i__3,*m) + jku - 1;
  970. for (jc = 1; jc <= i__2; ++jc) {
  971. extra.r = 0.f, extra.i = 0.f;
  972. angle = slarnd_(&c__1, &iseed[1]) *
  973. 6.2831853071795864769252867663f;
  974. r__1 = cos(angle);
  975. //clarnd_(&q__2, &c__5, &iseed[1]);
  976. q__2=clarnd_(&c__5, &iseed[1]);
  977. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  978. c__.r = q__1.r, c__.i = q__1.i;
  979. r__1 = sin(angle);
  980. //clarnd_(&q__2, &c__5, &iseed[1]);
  981. q__2=clarnd_(&c__5, &iseed[1]);
  982. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  983. s.r = q__1.r, s.i = q__1.i;
  984. /* Computing MAX */
  985. i__3 = 1, i__4 = jc - jku;
  986. irow = f2cmax(i__3,i__4);
  987. if (jc < *n) {
  988. /* Computing MIN */
  989. i__3 = *m, i__4 = jc + jkl;
  990. il = f2cmin(i__3,i__4) + 1 - irow;
  991. L__1 = jc > jku;
  992. clarot_(&c_false, &L__1, &c_false, &il, &c__, &s,
  993. &a[irow - iskew * jc + ioffst + jc *
  994. a_dim1], &ilda, &extra, &dummy);
  995. }
  996. /* Chase "EXTRA" back up */
  997. ic = jc;
  998. ir = irow;
  999. i__3 = -jkl - jku;
  1000. for (jch = jc - jku; i__3 < 0 ? jch >= 1 : jch <= 1;
  1001. jch += i__3) {
  1002. if (ic < *n) {
  1003. clartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  1004. + (ic + 1) * a_dim1], &extra, &realc,
  1005. &s, &dummy);
  1006. //clarnd_(&q__1, &c__5, &iseed[1]);
  1007. q__1=clarnd_(&c__5, &iseed[1]);
  1008. dummy.r = q__1.r, dummy.i = q__1.i;
  1009. q__2.r = realc * dummy.r, q__2.i = realc *
  1010. dummy.i;
  1011. r_cnjg(&q__1, &q__2);
  1012. c__.r = q__1.r, c__.i = q__1.i;
  1013. q__3.r = -s.r, q__3.i = -s.i;
  1014. q__2.r = q__3.r * dummy.r - q__3.i * dummy.i,
  1015. q__2.i = q__3.r * dummy.i + q__3.i *
  1016. dummy.r;
  1017. r_cnjg(&q__1, &q__2);
  1018. s.r = q__1.r, s.i = q__1.i;
  1019. }
  1020. /* Computing MAX */
  1021. i__4 = 1, i__5 = jch - jkl;
  1022. icol = f2cmax(i__4,i__5);
  1023. il = ic + 2 - icol;
  1024. ctemp.r = 0.f, ctemp.i = 0.f;
  1025. iltemp = jch > jkl;
  1026. clarot_(&c_true, &iltemp, &c_true, &il, &c__, &s,
  1027. &a[ir - iskew * icol + ioffst + icol *
  1028. a_dim1], &ilda, &ctemp, &extra);
  1029. if (iltemp) {
  1030. clartg_(&a[ir + 1 - iskew * (icol + 1) +
  1031. ioffst + (icol + 1) * a_dim1], &ctemp,
  1032. &realc, &s, &dummy);
  1033. //clarnd_(&q__1, &c__5, &iseed[1]);
  1034. q__1=clarnd_(&c__5, &iseed[1]);
  1035. dummy.r = q__1.r, dummy.i = q__1.i;
  1036. q__2.r = realc * dummy.r, q__2.i = realc *
  1037. dummy.i;
  1038. r_cnjg(&q__1, &q__2);
  1039. c__.r = q__1.r, c__.i = q__1.i;
  1040. q__3.r = -s.r, q__3.i = -s.i;
  1041. q__2.r = q__3.r * dummy.r - q__3.i * dummy.i,
  1042. q__2.i = q__3.r * dummy.i + q__3.i *
  1043. dummy.r;
  1044. r_cnjg(&q__1, &q__2);
  1045. s.r = q__1.r, s.i = q__1.i;
  1046. /* Computing MAX */
  1047. i__4 = 1, i__5 = jch - jkl - jku;
  1048. irow = f2cmax(i__4,i__5);
  1049. il = ir + 2 - irow;
  1050. extra.r = 0.f, extra.i = 0.f;
  1051. L__1 = jch > jkl + jku;
  1052. clarot_(&c_false, &L__1, &c_true, &il, &c__, &
  1053. s, &a[irow - iskew * icol + ioffst +
  1054. icol * a_dim1], &ilda, &extra, &ctemp)
  1055. ;
  1056. ic = icol;
  1057. ir = irow;
  1058. }
  1059. /* L80: */
  1060. }
  1061. /* L90: */
  1062. }
  1063. /* L100: */
  1064. }
  1065. } else {
  1066. /* Bottom-Up -- Start at the bottom right. */
  1067. jkl = 0;
  1068. i__1 = uub;
  1069. for (jku = 1; jku <= i__1; ++jku) {
  1070. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  1071. /* First row actually rotated is M */
  1072. /* First column actually rotated is MIN( M+JKU, N ) */
  1073. /* Computing MIN */
  1074. i__2 = *m, i__3 = *n + jkl;
  1075. iendch = f2cmin(i__2,i__3) - 1;
  1076. /* Computing MIN */
  1077. i__2 = *m + jku;
  1078. i__3 = 1 - jkl;
  1079. for (jc = f2cmin(i__2,*n) - 1; jc >= i__3; --jc) {
  1080. extra.r = 0.f, extra.i = 0.f;
  1081. angle = slarnd_(&c__1, &iseed[1]) *
  1082. 6.2831853071795864769252867663f;
  1083. r__1 = cos(angle);
  1084. //clarnd_(&q__2, &c__5, &iseed[1]);
  1085. q__2=clarnd_(&c__5, &iseed[1]);
  1086. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1087. c__.r = q__1.r, c__.i = q__1.i;
  1088. r__1 = sin(angle);
  1089. //clarnd_(&q__2, &c__5, &iseed[1]);
  1090. q__2=clarnd_(&c__5, &iseed[1]);
  1091. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1092. s.r = q__1.r, s.i = q__1.i;
  1093. /* Computing MAX */
  1094. i__2 = 1, i__4 = jc - jku + 1;
  1095. irow = f2cmax(i__2,i__4);
  1096. if (jc > 0) {
  1097. /* Computing MIN */
  1098. i__2 = *m, i__4 = jc + jkl + 1;
  1099. il = f2cmin(i__2,i__4) + 1 - irow;
  1100. L__1 = jc + jkl < *m;
  1101. clarot_(&c_false, &c_false, &L__1, &il, &c__, &s,
  1102. &a[irow - iskew * jc + ioffst + jc *
  1103. a_dim1], &ilda, &dummy, &extra);
  1104. }
  1105. /* Chase "EXTRA" back down */
  1106. ic = jc;
  1107. i__2 = iendch;
  1108. i__4 = jkl + jku;
  1109. for (jch = jc + jkl; i__4 < 0 ? jch >= i__2 : jch <=
  1110. i__2; jch += i__4) {
  1111. ilextr = ic > 0;
  1112. if (ilextr) {
  1113. clartg_(&a[jch - iskew * ic + ioffst + ic *
  1114. a_dim1], &extra, &realc, &s, &dummy);
  1115. //clarnd_(&q__1, &c__5, &iseed[1]);
  1116. q__1=clarnd_(&c__5, &iseed[1]);
  1117. dummy.r = q__1.r, dummy.i = q__1.i;
  1118. q__1.r = realc * dummy.r, q__1.i = realc *
  1119. dummy.i;
  1120. c__.r = q__1.r, c__.i = q__1.i;
  1121. q__1.r = s.r * dummy.r - s.i * dummy.i,
  1122. q__1.i = s.r * dummy.i + s.i *
  1123. dummy.r;
  1124. s.r = q__1.r, s.i = q__1.i;
  1125. }
  1126. ic = f2cmax(1,ic);
  1127. /* Computing MIN */
  1128. i__5 = *n - 1, i__6 = jch + jku;
  1129. icol = f2cmin(i__5,i__6);
  1130. iltemp = jch + jku < *n;
  1131. ctemp.r = 0.f, ctemp.i = 0.f;
  1132. i__5 = icol + 2 - ic;
  1133. clarot_(&c_true, &ilextr, &iltemp, &i__5, &c__, &
  1134. s, &a[jch - iskew * ic + ioffst + ic *
  1135. a_dim1], &ilda, &extra, &ctemp);
  1136. if (iltemp) {
  1137. clartg_(&a[jch - iskew * icol + ioffst + icol
  1138. * a_dim1], &ctemp, &realc, &s, &dummy)
  1139. ;
  1140. //clarnd_(&q__1, &c__5, &iseed[1]);
  1141. q__1=clarnd_(&c__5, &iseed[1]);
  1142. dummy.r = q__1.r, dummy.i = q__1.i;
  1143. q__1.r = realc * dummy.r, q__1.i = realc *
  1144. dummy.i;
  1145. c__.r = q__1.r, c__.i = q__1.i;
  1146. q__1.r = s.r * dummy.r - s.i * dummy.i,
  1147. q__1.i = s.r * dummy.i + s.i *
  1148. dummy.r;
  1149. s.r = q__1.r, s.i = q__1.i;
  1150. /* Computing MIN */
  1151. i__5 = iendch, i__6 = jch + jkl + jku;
  1152. il = f2cmin(i__5,i__6) + 2 - jch;
  1153. extra.r = 0.f, extra.i = 0.f;
  1154. L__1 = jch + jkl + jku <= iendch;
  1155. clarot_(&c_false, &c_true, &L__1, &il, &c__, &
  1156. s, &a[jch - iskew * icol + ioffst +
  1157. icol * a_dim1], &ilda, &ctemp, &extra)
  1158. ;
  1159. ic = icol;
  1160. }
  1161. /* L110: */
  1162. }
  1163. /* L120: */
  1164. }
  1165. /* L130: */
  1166. }
  1167. jku = uub;
  1168. i__1 = llb;
  1169. for (jkl = 1; jkl <= i__1; ++jkl) {
  1170. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  1171. /* First row actually rotated is MIN( N+JKL, M ) */
  1172. /* First column actually rotated is N */
  1173. /* Computing MIN */
  1174. i__3 = *n, i__4 = *m + jku;
  1175. iendch = f2cmin(i__3,i__4) - 1;
  1176. /* Computing MIN */
  1177. i__3 = *n + jkl;
  1178. i__4 = 1 - jku;
  1179. for (jr = f2cmin(i__3,*m) - 1; jr >= i__4; --jr) {
  1180. extra.r = 0.f, extra.i = 0.f;
  1181. angle = slarnd_(&c__1, &iseed[1]) *
  1182. 6.2831853071795864769252867663f;
  1183. r__1 = cos(angle);
  1184. //clarnd_(&q__2, &c__5, &iseed[1]);
  1185. q__2=clarnd_(&c__5, &iseed[1]);
  1186. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1187. c__.r = q__1.r, c__.i = q__1.i;
  1188. r__1 = sin(angle);
  1189. //clarnd_(&q__2, &c__5, &iseed[1]);
  1190. q__2=clarnd_(&c__5, &iseed[1]);
  1191. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1192. s.r = q__1.r, s.i = q__1.i;
  1193. /* Computing MAX */
  1194. i__3 = 1, i__2 = jr - jkl + 1;
  1195. icol = f2cmax(i__3,i__2);
  1196. if (jr > 0) {
  1197. /* Computing MIN */
  1198. i__3 = *n, i__2 = jr + jku + 1;
  1199. il = f2cmin(i__3,i__2) + 1 - icol;
  1200. L__1 = jr + jku < *n;
  1201. clarot_(&c_true, &c_false, &L__1, &il, &c__, &s, &
  1202. a[jr - iskew * icol + ioffst + icol *
  1203. a_dim1], &ilda, &dummy, &extra);
  1204. }
  1205. /* Chase "EXTRA" back down */
  1206. ir = jr;
  1207. i__3 = iendch;
  1208. i__2 = jkl + jku;
  1209. for (jch = jr + jku; i__2 < 0 ? jch >= i__3 : jch <=
  1210. i__3; jch += i__2) {
  1211. ilextr = ir > 0;
  1212. if (ilextr) {
  1213. clartg_(&a[ir - iskew * jch + ioffst + jch *
  1214. a_dim1], &extra, &realc, &s, &dummy);
  1215. //clarnd_(&q__1, &c__5, &iseed[1]);
  1216. q__1=clarnd_(&c__5, &iseed[1]);
  1217. dummy.r = q__1.r, dummy.i = q__1.i;
  1218. q__1.r = realc * dummy.r, q__1.i = realc *
  1219. dummy.i;
  1220. c__.r = q__1.r, c__.i = q__1.i;
  1221. q__1.r = s.r * dummy.r - s.i * dummy.i,
  1222. q__1.i = s.r * dummy.i + s.i *
  1223. dummy.r;
  1224. s.r = q__1.r, s.i = q__1.i;
  1225. }
  1226. ir = f2cmax(1,ir);
  1227. /* Computing MIN */
  1228. i__5 = *m - 1, i__6 = jch + jkl;
  1229. irow = f2cmin(i__5,i__6);
  1230. iltemp = jch + jkl < *m;
  1231. ctemp.r = 0.f, ctemp.i = 0.f;
  1232. i__5 = irow + 2 - ir;
  1233. clarot_(&c_false, &ilextr, &iltemp, &i__5, &c__, &
  1234. s, &a[ir - iskew * jch + ioffst + jch *
  1235. a_dim1], &ilda, &extra, &ctemp);
  1236. if (iltemp) {
  1237. clartg_(&a[irow - iskew * jch + ioffst + jch *
  1238. a_dim1], &ctemp, &realc, &s, &dummy);
  1239. //clarnd_(&q__1, &c__5, &iseed[1]);
  1240. q__1=clarnd_(&c__5, &iseed[1]);
  1241. dummy.r = q__1.r, dummy.i = q__1.i;
  1242. q__1.r = realc * dummy.r, q__1.i = realc *
  1243. dummy.i;
  1244. c__.r = q__1.r, c__.i = q__1.i;
  1245. q__1.r = s.r * dummy.r - s.i * dummy.i,
  1246. q__1.i = s.r * dummy.i + s.i *
  1247. dummy.r;
  1248. s.r = q__1.r, s.i = q__1.i;
  1249. /* Computing MIN */
  1250. i__5 = iendch, i__6 = jch + jkl + jku;
  1251. il = f2cmin(i__5,i__6) + 2 - jch;
  1252. extra.r = 0.f, extra.i = 0.f;
  1253. L__1 = jch + jkl + jku <= iendch;
  1254. clarot_(&c_true, &c_true, &L__1, &il, &c__, &
  1255. s, &a[irow - iskew * jch + ioffst +
  1256. jch * a_dim1], &ilda, &ctemp, &extra);
  1257. ir = irow;
  1258. }
  1259. /* L140: */
  1260. }
  1261. /* L150: */
  1262. }
  1263. /* L160: */
  1264. }
  1265. }
  1266. } else {
  1267. /* Symmetric -- A = U D U' */
  1268. /* Hermitian -- A = U D U* */
  1269. ipackg = ipack;
  1270. ioffg = ioffst;
  1271. if (topdwn) {
  1272. /* Top-Down -- Generate Upper triangle only */
  1273. if (ipack >= 5) {
  1274. ipackg = 6;
  1275. ioffg = uub + 1;
  1276. } else {
  1277. ipackg = 1;
  1278. }
  1279. i__1 = mnmin;
  1280. for (j = 1; j <= i__1; ++j) {
  1281. i__4 = (1 - iskew) * j + ioffg + j * a_dim1;
  1282. i__2 = j;
  1283. q__1.r = d__[i__2], q__1.i = 0.f;
  1284. a[i__4].r = q__1.r, a[i__4].i = q__1.i;
  1285. /* L170: */
  1286. }
  1287. i__1 = uub;
  1288. for (k = 1; k <= i__1; ++k) {
  1289. i__4 = *n - 1;
  1290. for (jc = 1; jc <= i__4; ++jc) {
  1291. /* Computing MAX */
  1292. i__2 = 1, i__3 = jc - k;
  1293. irow = f2cmax(i__2,i__3);
  1294. /* Computing MIN */
  1295. i__2 = jc + 1, i__3 = k + 2;
  1296. il = f2cmin(i__2,i__3);
  1297. extra.r = 0.f, extra.i = 0.f;
  1298. i__2 = jc - iskew * (jc + 1) + ioffg + (jc + 1) *
  1299. a_dim1;
  1300. ctemp.r = a[i__2].r, ctemp.i = a[i__2].i;
  1301. angle = slarnd_(&c__1, &iseed[1]) *
  1302. 6.2831853071795864769252867663f;
  1303. r__1 = cos(angle);
  1304. //clarnd_(&q__2, &c__5, &iseed[1]);
  1305. q__2=clarnd_(&c__5, &iseed[1]);
  1306. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1307. c__.r = q__1.r, c__.i = q__1.i;
  1308. r__1 = sin(angle);
  1309. //clarnd_(&q__2, &c__5, &iseed[1]);
  1310. q__2=clarnd_(&c__5, &iseed[1]);
  1311. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1312. s.r = q__1.r, s.i = q__1.i;
  1313. if (csym) {
  1314. ct.r = c__.r, ct.i = c__.i;
  1315. st.r = s.r, st.i = s.i;
  1316. } else {
  1317. r_cnjg(&q__1, &ctemp);
  1318. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1319. r_cnjg(&q__1, &c__);
  1320. ct.r = q__1.r, ct.i = q__1.i;
  1321. r_cnjg(&q__1, &s);
  1322. st.r = q__1.r, st.i = q__1.i;
  1323. }
  1324. L__1 = jc > k;
  1325. clarot_(&c_false, &L__1, &c_true, &il, &c__, &s, &a[
  1326. irow - iskew * jc + ioffg + jc * a_dim1], &
  1327. ilda, &extra, &ctemp);
  1328. /* Computing MIN */
  1329. i__3 = k, i__5 = *n - jc;
  1330. i__2 = f2cmin(i__3,i__5) + 1;
  1331. clarot_(&c_true, &c_true, &c_false, &i__2, &ct, &st, &
  1332. a[(1 - iskew) * jc + ioffg + jc * a_dim1], &
  1333. ilda, &ctemp, &dummy);
  1334. /* Chase EXTRA back up the matrix */
  1335. icol = jc;
  1336. i__2 = -k;
  1337. for (jch = jc - k; i__2 < 0 ? jch >= 1 : jch <= 1;
  1338. jch += i__2) {
  1339. clartg_(&a[jch + 1 - iskew * (icol + 1) + ioffg +
  1340. (icol + 1) * a_dim1], &extra, &realc, &s,
  1341. &dummy);
  1342. //clarnd_(&q__1, &c__5, &iseed[1]);
  1343. q__1=clarnd_(&c__5, &iseed[1]);
  1344. dummy.r = q__1.r, dummy.i = q__1.i;
  1345. q__2.r = realc * dummy.r, q__2.i = realc *
  1346. dummy.i;
  1347. r_cnjg(&q__1, &q__2);
  1348. c__.r = q__1.r, c__.i = q__1.i;
  1349. q__3.r = -s.r, q__3.i = -s.i;
  1350. q__2.r = q__3.r * dummy.r - q__3.i * dummy.i,
  1351. q__2.i = q__3.r * dummy.i + q__3.i *
  1352. dummy.r;
  1353. r_cnjg(&q__1, &q__2);
  1354. s.r = q__1.r, s.i = q__1.i;
  1355. i__3 = jch - iskew * (jch + 1) + ioffg + (jch + 1)
  1356. * a_dim1;
  1357. ctemp.r = a[i__3].r, ctemp.i = a[i__3].i;
  1358. if (csym) {
  1359. ct.r = c__.r, ct.i = c__.i;
  1360. st.r = s.r, st.i = s.i;
  1361. } else {
  1362. r_cnjg(&q__1, &ctemp);
  1363. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1364. r_cnjg(&q__1, &c__);
  1365. ct.r = q__1.r, ct.i = q__1.i;
  1366. r_cnjg(&q__1, &s);
  1367. st.r = q__1.r, st.i = q__1.i;
  1368. }
  1369. i__3 = k + 2;
  1370. clarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1371. s, &a[(1 - iskew) * jch + ioffg + jch *
  1372. a_dim1], &ilda, &ctemp, &extra);
  1373. /* Computing MAX */
  1374. i__3 = 1, i__5 = jch - k;
  1375. irow = f2cmax(i__3,i__5);
  1376. /* Computing MIN */
  1377. i__3 = jch + 1, i__5 = k + 2;
  1378. il = f2cmin(i__3,i__5);
  1379. extra.r = 0.f, extra.i = 0.f;
  1380. L__1 = jch > k;
  1381. clarot_(&c_false, &L__1, &c_true, &il, &ct, &st, &
  1382. a[irow - iskew * jch + ioffg + jch *
  1383. a_dim1], &ilda, &extra, &ctemp);
  1384. icol = jch;
  1385. /* L180: */
  1386. }
  1387. /* L190: */
  1388. }
  1389. /* L200: */
  1390. }
  1391. /* If we need lower triangle, copy from upper. Note that */
  1392. /* the order of copying is chosen to work for 'q' -> 'b' */
  1393. if (ipack != ipackg && ipack != 3) {
  1394. i__1 = *n;
  1395. for (jc = 1; jc <= i__1; ++jc) {
  1396. irow = ioffst - iskew * jc;
  1397. if (csym) {
  1398. /* Computing MIN */
  1399. i__2 = *n, i__3 = jc + uub;
  1400. i__4 = f2cmin(i__2,i__3);
  1401. for (jr = jc; jr <= i__4; ++jr) {
  1402. i__2 = jr + irow + jc * a_dim1;
  1403. i__3 = jc - iskew * jr + ioffg + jr * a_dim1;
  1404. a[i__2].r = a[i__3].r, a[i__2].i = a[i__3].i;
  1405. /* L210: */
  1406. }
  1407. } else {
  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. r_cnjg(&q__1, &a[jc - iskew * jr + ioffg + jr
  1414. * a_dim1]);
  1415. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1416. /* L220: */
  1417. }
  1418. }
  1419. /* L230: */
  1420. }
  1421. if (ipack == 5) {
  1422. i__1 = *n;
  1423. for (jc = *n - uub + 1; jc <= i__1; ++jc) {
  1424. i__4 = uub + 1;
  1425. for (jr = *n + 2 - jc; jr <= i__4; ++jr) {
  1426. i__2 = jr + jc * a_dim1;
  1427. a[i__2].r = 0.f, a[i__2].i = 0.f;
  1428. /* L240: */
  1429. }
  1430. /* L250: */
  1431. }
  1432. }
  1433. if (ipackg == 6) {
  1434. ipackg = ipack;
  1435. } else {
  1436. ipackg = 0;
  1437. }
  1438. }
  1439. } else {
  1440. /* Bottom-Up -- Generate Lower triangle only */
  1441. if (ipack >= 5) {
  1442. ipackg = 5;
  1443. if (ipack == 6) {
  1444. ioffg = 1;
  1445. }
  1446. } else {
  1447. ipackg = 2;
  1448. }
  1449. i__1 = mnmin;
  1450. for (j = 1; j <= i__1; ++j) {
  1451. i__4 = (1 - iskew) * j + ioffg + j * a_dim1;
  1452. i__2 = j;
  1453. q__1.r = d__[i__2], q__1.i = 0.f;
  1454. a[i__4].r = q__1.r, a[i__4].i = q__1.i;
  1455. /* L260: */
  1456. }
  1457. i__1 = uub;
  1458. for (k = 1; k <= i__1; ++k) {
  1459. for (jc = *n - 1; jc >= 1; --jc) {
  1460. /* Computing MIN */
  1461. i__4 = *n + 1 - jc, i__2 = k + 2;
  1462. il = f2cmin(i__4,i__2);
  1463. extra.r = 0.f, extra.i = 0.f;
  1464. i__4 = (1 - iskew) * jc + 1 + ioffg + jc * a_dim1;
  1465. ctemp.r = a[i__4].r, ctemp.i = a[i__4].i;
  1466. angle = slarnd_(&c__1, &iseed[1]) *
  1467. 6.2831853071795864769252867663f;
  1468. r__1 = cos(angle);
  1469. //clarnd_(&q__2, &c__5, &iseed[1]);
  1470. q__2=clarnd_(&c__5, &iseed[1]);
  1471. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1472. c__.r = q__1.r, c__.i = q__1.i;
  1473. r__1 = sin(angle);
  1474. //clarnd_(&q__2, &c__5, &iseed[1]);
  1475. q__2=clarnd_(&c__5, &iseed[1]);
  1476. q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
  1477. s.r = q__1.r, s.i = q__1.i;
  1478. if (csym) {
  1479. ct.r = c__.r, ct.i = c__.i;
  1480. st.r = s.r, st.i = s.i;
  1481. } else {
  1482. r_cnjg(&q__1, &ctemp);
  1483. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1484. r_cnjg(&q__1, &c__);
  1485. ct.r = q__1.r, ct.i = q__1.i;
  1486. r_cnjg(&q__1, &s);
  1487. st.r = q__1.r, st.i = q__1.i;
  1488. }
  1489. L__1 = *n - jc > k;
  1490. clarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &a[(
  1491. 1 - iskew) * jc + ioffg + jc * a_dim1], &ilda,
  1492. &ctemp, &extra);
  1493. /* Computing MAX */
  1494. i__4 = 1, i__2 = jc - k + 1;
  1495. icol = f2cmax(i__4,i__2);
  1496. i__4 = jc + 2 - icol;
  1497. clarot_(&c_true, &c_false, &c_true, &i__4, &ct, &st, &
  1498. a[jc - iskew * icol + ioffg + icol * a_dim1],
  1499. &ilda, &dummy, &ctemp);
  1500. /* Chase EXTRA back down the matrix */
  1501. icol = jc;
  1502. i__4 = *n - 1;
  1503. i__2 = k;
  1504. for (jch = jc + k; i__2 < 0 ? jch >= i__4 : jch <=
  1505. i__4; jch += i__2) {
  1506. clartg_(&a[jch - iskew * icol + ioffg + icol *
  1507. a_dim1], &extra, &realc, &s, &dummy);
  1508. //clarnd_(&q__1, &c__5, &iseed[1]);
  1509. q__1=clarnd_(&c__5, &iseed[1]);
  1510. dummy.r = q__1.r, dummy.i = q__1.i;
  1511. q__1.r = realc * dummy.r, q__1.i = realc *
  1512. dummy.i;
  1513. c__.r = q__1.r, c__.i = q__1.i;
  1514. q__1.r = s.r * dummy.r - s.i * dummy.i, q__1.i =
  1515. s.r * dummy.i + s.i * dummy.r;
  1516. s.r = q__1.r, s.i = q__1.i;
  1517. i__3 = (1 - iskew) * jch + 1 + ioffg + jch *
  1518. a_dim1;
  1519. ctemp.r = a[i__3].r, ctemp.i = a[i__3].i;
  1520. if (csym) {
  1521. ct.r = c__.r, ct.i = c__.i;
  1522. st.r = s.r, st.i = s.i;
  1523. } else {
  1524. r_cnjg(&q__1, &ctemp);
  1525. ctemp.r = q__1.r, ctemp.i = q__1.i;
  1526. r_cnjg(&q__1, &c__);
  1527. ct.r = q__1.r, ct.i = q__1.i;
  1528. r_cnjg(&q__1, &s);
  1529. st.r = q__1.r, st.i = q__1.i;
  1530. }
  1531. i__3 = k + 2;
  1532. clarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1533. s, &a[jch - iskew * icol + ioffg + icol *
  1534. a_dim1], &ilda, &extra, &ctemp);
  1535. /* Computing MIN */
  1536. i__3 = *n + 1 - jch, i__5 = k + 2;
  1537. il = f2cmin(i__3,i__5);
  1538. extra.r = 0.f, extra.i = 0.f;
  1539. L__1 = *n - jch > k;
  1540. clarot_(&c_false, &c_true, &L__1, &il, &ct, &st, &
  1541. a[(1 - iskew) * jch + ioffg + jch *
  1542. a_dim1], &ilda, &ctemp, &extra);
  1543. icol = jch;
  1544. /* L270: */
  1545. }
  1546. /* L280: */
  1547. }
  1548. /* L290: */
  1549. }
  1550. /* If we need upper triangle, copy from lower. Note that */
  1551. /* the order of copying is chosen to work for 'b' -> 'q' */
  1552. if (ipack != ipackg && ipack != 4) {
  1553. for (jc = *n; jc >= 1; --jc) {
  1554. irow = ioffst - iskew * jc;
  1555. if (csym) {
  1556. /* Computing MAX */
  1557. i__2 = 1, i__4 = jc - uub;
  1558. i__1 = f2cmax(i__2,i__4);
  1559. for (jr = jc; jr >= i__1; --jr) {
  1560. i__2 = jr + irow + jc * a_dim1;
  1561. i__4 = jc - iskew * jr + ioffg + jr * a_dim1;
  1562. a[i__2].r = a[i__4].r, a[i__2].i = a[i__4].i;
  1563. /* L300: */
  1564. }
  1565. } else {
  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. r_cnjg(&q__1, &a[jc - iskew * jr + ioffg + jr
  1572. * a_dim1]);
  1573. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1574. /* L310: */
  1575. }
  1576. }
  1577. /* L320: */
  1578. }
  1579. if (ipack == 6) {
  1580. i__1 = uub;
  1581. for (jc = 1; jc <= i__1; ++jc) {
  1582. i__2 = uub + 1 - jc;
  1583. for (jr = 1; jr <= i__2; ++jr) {
  1584. i__4 = jr + jc * a_dim1;
  1585. a[i__4].r = 0.f, a[i__4].i = 0.f;
  1586. /* L330: */
  1587. }
  1588. /* L340: */
  1589. }
  1590. }
  1591. if (ipackg == 5) {
  1592. ipackg = ipack;
  1593. } else {
  1594. ipackg = 0;
  1595. }
  1596. }
  1597. }
  1598. /* Ensure that the diagonal is real if Hermitian */
  1599. if (! csym) {
  1600. i__1 = *n;
  1601. for (jc = 1; jc <= i__1; ++jc) {
  1602. irow = ioffst + (1 - iskew) * jc;
  1603. i__2 = irow + jc * a_dim1;
  1604. i__4 = irow + jc * a_dim1;
  1605. r__1 = a[i__4].r;
  1606. q__1.r = r__1, q__1.i = 0.f;
  1607. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1608. /* L350: */
  1609. }
  1610. }
  1611. }
  1612. } else {
  1613. /* 4) Generate Banded Matrix by first */
  1614. /* Rotating by random Unitary matrices, */
  1615. /* then reducing the bandwidth using Householder */
  1616. /* transformations. */
  1617. /* Note: we should get here only if LDA .ge. N */
  1618. if (isym == 1) {
  1619. /* Non-symmetric -- A = U D V */
  1620. clagge_(&mr, &nc, &llb, &uub, &d__[1], &a[a_offset], lda, &iseed[
  1621. 1], &work[1], &iinfo);
  1622. } else {
  1623. /* Symmetric -- A = U D U' or */
  1624. /* Hermitian -- A = U D U* */
  1625. if (csym) {
  1626. clagsy_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[
  1627. 1], &iinfo);
  1628. } else {
  1629. claghe_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[
  1630. 1], &iinfo);
  1631. }
  1632. }
  1633. if (iinfo != 0) {
  1634. *info = 3;
  1635. return;
  1636. }
  1637. }
  1638. /* 5) Pack the matrix */
  1639. if (ipack != ipackg) {
  1640. if (ipack == 1) {
  1641. /* 'U' -- Upper triangular, not packed */
  1642. i__1 = *m;
  1643. for (j = 1; j <= i__1; ++j) {
  1644. i__2 = *m;
  1645. for (i__ = j + 1; i__ <= i__2; ++i__) {
  1646. i__4 = i__ + j * a_dim1;
  1647. a[i__4].r = 0.f, a[i__4].i = 0.f;
  1648. /* L360: */
  1649. }
  1650. /* L370: */
  1651. }
  1652. } else if (ipack == 2) {
  1653. /* 'L' -- Lower triangular, not packed */
  1654. i__1 = *m;
  1655. for (j = 2; j <= i__1; ++j) {
  1656. i__2 = j - 1;
  1657. for (i__ = 1; i__ <= i__2; ++i__) {
  1658. i__4 = i__ + j * a_dim1;
  1659. a[i__4].r = 0.f, a[i__4].i = 0.f;
  1660. /* L380: */
  1661. }
  1662. /* L390: */
  1663. }
  1664. } else if (ipack == 3) {
  1665. /* 'C' -- Upper triangle packed Columnwise. */
  1666. icol = 1;
  1667. irow = 0;
  1668. i__1 = *m;
  1669. for (j = 1; j <= i__1; ++j) {
  1670. i__2 = j;
  1671. for (i__ = 1; i__ <= i__2; ++i__) {
  1672. ++irow;
  1673. if (irow > *lda) {
  1674. irow = 1;
  1675. ++icol;
  1676. }
  1677. i__4 = irow + icol * a_dim1;
  1678. i__3 = i__ + j * a_dim1;
  1679. a[i__4].r = a[i__3].r, a[i__4].i = a[i__3].i;
  1680. /* L400: */
  1681. }
  1682. /* L410: */
  1683. }
  1684. } else if (ipack == 4) {
  1685. /* 'R' -- Lower triangle packed Columnwise. */
  1686. icol = 1;
  1687. irow = 0;
  1688. i__1 = *m;
  1689. for (j = 1; j <= i__1; ++j) {
  1690. i__2 = *m;
  1691. for (i__ = j; i__ <= i__2; ++i__) {
  1692. ++irow;
  1693. if (irow > *lda) {
  1694. irow = 1;
  1695. ++icol;
  1696. }
  1697. i__4 = irow + icol * a_dim1;
  1698. i__3 = i__ + j * a_dim1;
  1699. a[i__4].r = a[i__3].r, a[i__4].i = a[i__3].i;
  1700. /* L420: */
  1701. }
  1702. /* L430: */
  1703. }
  1704. } else if (ipack >= 5) {
  1705. /* 'B' -- The lower triangle is packed as a band matrix. */
  1706. /* 'Q' -- The upper triangle is packed as a band matrix. */
  1707. /* 'Z' -- The whole matrix is packed as a band matrix. */
  1708. if (ipack == 5) {
  1709. uub = 0;
  1710. }
  1711. if (ipack == 6) {
  1712. llb = 0;
  1713. }
  1714. i__1 = uub;
  1715. for (j = 1; j <= i__1; ++j) {
  1716. /* Computing MIN */
  1717. i__2 = j + llb;
  1718. for (i__ = f2cmin(i__2,*m); i__ >= 1; --i__) {
  1719. i__2 = i__ - j + uub + 1 + j * a_dim1;
  1720. i__4 = i__ + j * a_dim1;
  1721. a[i__2].r = a[i__4].r, a[i__2].i = a[i__4].i;
  1722. /* L440: */
  1723. }
  1724. /* L450: */
  1725. }
  1726. i__1 = *n;
  1727. for (j = uub + 2; j <= i__1; ++j) {
  1728. /* Computing MIN */
  1729. i__4 = j + llb;
  1730. i__2 = f2cmin(i__4,*m);
  1731. for (i__ = j - uub; i__ <= i__2; ++i__) {
  1732. i__4 = i__ - j + uub + 1 + j * a_dim1;
  1733. i__3 = i__ + j * a_dim1;
  1734. a[i__4].r = a[i__3].r, a[i__4].i = a[i__3].i;
  1735. /* L460: */
  1736. }
  1737. /* L470: */
  1738. }
  1739. }
  1740. /* If packed, zero out extraneous elements. */
  1741. /* Symmetric/Triangular Packed -- */
  1742. /* zero out everything after A(IROW,ICOL) */
  1743. if (ipack == 3 || ipack == 4) {
  1744. i__1 = *m;
  1745. for (jc = icol; jc <= i__1; ++jc) {
  1746. i__2 = *lda;
  1747. for (jr = irow + 1; jr <= i__2; ++jr) {
  1748. i__4 = jr + jc * a_dim1;
  1749. a[i__4].r = 0.f, a[i__4].i = 0.f;
  1750. /* L480: */
  1751. }
  1752. irow = 0;
  1753. /* L490: */
  1754. }
  1755. } else if (ipack >= 5) {
  1756. /* Packed Band -- */
  1757. /* 1st row is now in A( UUB+2-j, j), zero above it */
  1758. /* m-th row is now in A( M+UUB-j,j), zero below it */
  1759. /* last non-zero diagonal is now in A( UUB+LLB+1,j ), */
  1760. /* zero below it, too. */
  1761. ir1 = uub + llb + 2;
  1762. ir2 = uub + *m + 2;
  1763. i__1 = *n;
  1764. for (jc = 1; jc <= i__1; ++jc) {
  1765. i__2 = uub + 1 - jc;
  1766. for (jr = 1; jr <= i__2; ++jr) {
  1767. i__4 = jr + jc * a_dim1;
  1768. a[i__4].r = 0.f, a[i__4].i = 0.f;
  1769. /* L500: */
  1770. }
  1771. /* Computing MAX */
  1772. /* Computing MIN */
  1773. i__3 = ir1, i__5 = ir2 - jc;
  1774. i__2 = 1, i__4 = f2cmin(i__3,i__5);
  1775. i__6 = *lda;
  1776. for (jr = f2cmax(i__2,i__4); jr <= i__6; ++jr) {
  1777. i__2 = jr + jc * a_dim1;
  1778. a[i__2].r = 0.f, a[i__2].i = 0.f;
  1779. /* L510: */
  1780. }
  1781. /* L520: */
  1782. }
  1783. }
  1784. }
  1785. return;
  1786. /* End of CLATMS */
  1787. } /* clatms_ */