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.

zlatms.c 59 kB

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