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.

dlatmt.c 48 kB

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