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.

slatmt.c 55 kB

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