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.

slatms.c 54 kB

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