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

dlatms.c 55 kB

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