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.

strevc3.c 60 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  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 integer c_n1 = -1;
  488. static integer c__2 = 2;
  489. static real c_b17 = 0.f;
  490. static logical c_false = FALSE_;
  491. static real c_b29 = 1.f;
  492. static logical c_true = TRUE_;
  493. /* > \brief \b STREVC3 */
  494. /* =========== DOCUMENTATION =========== */
  495. /* Online html documentation available at */
  496. /* http://www.netlib.org/lapack/explore-html/ */
  497. /* > \htmlonly */
  498. /* > Download STREVC3 + dependencies */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/strevc3
  500. .f"> */
  501. /* > [TGZ]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/strevc3
  503. .f"> */
  504. /* > [ZIP]</a> */
  505. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/strevc3
  506. .f"> */
  507. /* > [TXT]</a> */
  508. /* > \endhtmlonly */
  509. /* Definition: */
  510. /* =========== */
  511. /* SUBROUTINE STREVC3( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, */
  512. /* VR, LDVR, MM, M, WORK, LWORK, INFO ) */
  513. /* CHARACTER HOWMNY, SIDE */
  514. /* INTEGER INFO, LDT, LDVL, LDVR, LWORK, M, MM, N */
  515. /* LOGICAL SELECT( * ) */
  516. /* REAL T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ), */
  517. /* $ WORK( * ) */
  518. /* > \par Purpose: */
  519. /* ============= */
  520. /* > */
  521. /* > \verbatim */
  522. /* > */
  523. /* > STREVC3 computes some or all of the right and/or left eigenvectors of */
  524. /* > a real upper quasi-triangular matrix T. */
  525. /* > Matrices of this type are produced by the Schur factorization of */
  526. /* > a real general matrix: A = Q*T*Q**T, as computed by SHSEQR. */
  527. /* > */
  528. /* > The right eigenvector x and the left eigenvector y of T corresponding */
  529. /* > to an eigenvalue w are defined by: */
  530. /* > */
  531. /* > T*x = w*x, (y**T)*T = w*(y**T) */
  532. /* > */
  533. /* > where y**T denotes the transpose of the vector y. */
  534. /* > The eigenvalues are not input to this routine, but are read directly */
  535. /* > from the diagonal blocks of T. */
  536. /* > */
  537. /* > This routine returns the matrices X and/or Y of right and left */
  538. /* > eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an */
  539. /* > input matrix. If Q is the orthogonal factor that reduces a matrix */
  540. /* > A to Schur form T, then Q*X and Q*Y are the matrices of right and */
  541. /* > left eigenvectors of A. */
  542. /* > */
  543. /* > This uses a Level 3 BLAS version of the back transformation. */
  544. /* > \endverbatim */
  545. /* Arguments: */
  546. /* ========== */
  547. /* > \param[in] SIDE */
  548. /* > \verbatim */
  549. /* > SIDE is CHARACTER*1 */
  550. /* > = 'R': compute right eigenvectors only; */
  551. /* > = 'L': compute left eigenvectors only; */
  552. /* > = 'B': compute both right and left eigenvectors. */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] HOWMNY */
  556. /* > \verbatim */
  557. /* > HOWMNY is CHARACTER*1 */
  558. /* > = 'A': compute all right and/or left eigenvectors; */
  559. /* > = 'B': compute all right and/or left eigenvectors, */
  560. /* > backtransformed by the matrices in VR and/or VL; */
  561. /* > = 'S': compute selected right and/or left eigenvectors, */
  562. /* > as indicated by the logical array SELECT. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in,out] SELECT */
  566. /* > \verbatim */
  567. /* > SELECT is LOGICAL array, dimension (N) */
  568. /* > If HOWMNY = 'S', SELECT specifies the eigenvectors to be */
  569. /* > computed. */
  570. /* > If w(j) is a real eigenvalue, the corresponding real */
  571. /* > eigenvector is computed if SELECT(j) is .TRUE.. */
  572. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  573. /* > complex eigenvalue, the corresponding complex eigenvector is */
  574. /* > computed if either SELECT(j) or SELECT(j+1) is .TRUE., and */
  575. /* > on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to */
  576. /* > .FALSE.. */
  577. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in] N */
  581. /* > \verbatim */
  582. /* > N is INTEGER */
  583. /* > The order of the matrix T. N >= 0. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in] T */
  587. /* > \verbatim */
  588. /* > T is REAL array, dimension (LDT,N) */
  589. /* > The upper quasi-triangular matrix T in Schur canonical form. */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[in] LDT */
  593. /* > \verbatim */
  594. /* > LDT is INTEGER */
  595. /* > The leading dimension of the array T. LDT >= f2cmax(1,N). */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[in,out] VL */
  599. /* > \verbatim */
  600. /* > VL is REAL array, dimension (LDVL,MM) */
  601. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  602. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  603. /* > of Schur vectors returned by SHSEQR). */
  604. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  605. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of T; */
  606. /* > if HOWMNY = 'B', the matrix Q*Y; */
  607. /* > if HOWMNY = 'S', the left eigenvectors of T specified by */
  608. /* > SELECT, stored consecutively in the columns */
  609. /* > of VL, in the same order as their */
  610. /* > eigenvalues. */
  611. /* > A complex eigenvector corresponding to a complex eigenvalue */
  612. /* > is stored in two consecutive columns, the first holding the */
  613. /* > real part, and the second the imaginary part. */
  614. /* > Not referenced if SIDE = 'R'. */
  615. /* > \endverbatim */
  616. /* > */
  617. /* > \param[in] LDVL */
  618. /* > \verbatim */
  619. /* > LDVL is INTEGER */
  620. /* > The leading dimension of the array VL. */
  621. /* > LDVL >= 1, and if SIDE = 'L' or 'B', LDVL >= N. */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[in,out] VR */
  625. /* > \verbatim */
  626. /* > VR is REAL array, dimension (LDVR,MM) */
  627. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  628. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  629. /* > of Schur vectors returned by SHSEQR). */
  630. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  631. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of T; */
  632. /* > if HOWMNY = 'B', the matrix Q*X; */
  633. /* > if HOWMNY = 'S', the right eigenvectors of T specified by */
  634. /* > SELECT, stored consecutively in the columns */
  635. /* > of VR, in the same order as their */
  636. /* > eigenvalues. */
  637. /* > A complex eigenvector corresponding to a complex eigenvalue */
  638. /* > is stored in two consecutive columns, the first holding the */
  639. /* > real part and the second the imaginary part. */
  640. /* > Not referenced if SIDE = 'L'. */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[in] LDVR */
  644. /* > \verbatim */
  645. /* > LDVR is INTEGER */
  646. /* > The leading dimension of the array VR. */
  647. /* > LDVR >= 1, and if SIDE = 'R' or 'B', LDVR >= N. */
  648. /* > \endverbatim */
  649. /* > */
  650. /* > \param[in] MM */
  651. /* > \verbatim */
  652. /* > MM is INTEGER */
  653. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  654. /* > \endverbatim */
  655. /* > */
  656. /* > \param[out] M */
  657. /* > \verbatim */
  658. /* > M is INTEGER */
  659. /* > The number of columns in the arrays VL and/or VR actually */
  660. /* > used to store the eigenvectors. */
  661. /* > If HOWMNY = 'A' or 'B', M is set to N. */
  662. /* > Each selected real eigenvector occupies one column and each */
  663. /* > selected complex eigenvector occupies two columns. */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[out] WORK */
  667. /* > \verbatim */
  668. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  669. /* > \endverbatim */
  670. /* > */
  671. /* > \param[in] LWORK */
  672. /* > \verbatim */
  673. /* > LWORK is INTEGER */
  674. /* > The dimension of array WORK. LWORK >= f2cmax(1,3*N). */
  675. /* > For optimum performance, LWORK >= N + 2*N*NB, where NB is */
  676. /* > the optimal blocksize. */
  677. /* > */
  678. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  679. /* > only calculates the optimal size of the WORK array, returns */
  680. /* > this value as the first entry of the WORK array, and no error */
  681. /* > message related to LWORK is issued by XERBLA. */
  682. /* > \endverbatim */
  683. /* > */
  684. /* > \param[out] INFO */
  685. /* > \verbatim */
  686. /* > INFO is INTEGER */
  687. /* > = 0: successful exit */
  688. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  689. /* > \endverbatim */
  690. /* Authors: */
  691. /* ======== */
  692. /* > \author Univ. of Tennessee */
  693. /* > \author Univ. of California Berkeley */
  694. /* > \author Univ. of Colorado Denver */
  695. /* > \author NAG Ltd. */
  696. /* > \date November 2017 */
  697. /* @generated from dtrevc3.f, fortran d -> s, Tue Apr 19 01:47:44 2016 */
  698. /* > \ingroup realOTHERcomputational */
  699. /* > \par Further Details: */
  700. /* ===================== */
  701. /* > */
  702. /* > \verbatim */
  703. /* > */
  704. /* > The algorithm used in this program is basically backward (forward) */
  705. /* > substitution, with scaling to make the the code robust against */
  706. /* > possible overflow. */
  707. /* > */
  708. /* > Each eigenvector is normalized so that the element of largest */
  709. /* > magnitude has magnitude 1; here the magnitude of a complex number */
  710. /* > (x,y) is taken to be |x| + |y|. */
  711. /* > \endverbatim */
  712. /* > */
  713. /* ===================================================================== */
  714. /* Subroutine */ int strevc3_(char *side, char *howmny, logical *select,
  715. integer *n, real *t, integer *ldt, real *vl, integer *ldvl, real *vr,
  716. integer *ldvr, integer *mm, integer *m, real *work, integer *lwork,
  717. integer *info)
  718. {
  719. /* System generated locals */
  720. address a__1[2];
  721. integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1[2],
  722. i__2, i__3, i__4;
  723. real r__1, r__2, r__3, r__4;
  724. char ch__1[2];
  725. /* Local variables */
  726. real beta, emax;
  727. logical pair, allv;
  728. integer ierr;
  729. real unfl, ovfl, smin;
  730. extern real sdot_(integer *, real *, integer *, real *, integer *);
  731. logical over;
  732. real vmax;
  733. integer jnxt, i__, j, k;
  734. real scale, x[4] /* was [2][2] */;
  735. extern logical lsame_(char *, char *);
  736. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *),
  737. sgemm_(char *, char *, integer *, integer *, integer *, real *,
  738. real *, integer *, real *, integer *, real *, real *, integer *);
  739. real remax;
  740. logical leftv;
  741. extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *,
  742. real *, integer *, real *, integer *, real *, real *, integer *);
  743. logical bothv;
  744. real vcrit;
  745. logical somev;
  746. integer j1, j2;
  747. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  748. integer *);
  749. real xnorm;
  750. extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *,
  751. real *, integer *);
  752. integer iscomplex[128];
  753. extern /* Subroutine */ int slaln2_(logical *, integer *, integer *, real
  754. *, real *, real *, integer *, real *, real *, real *, integer *,
  755. real *, real *, real *, integer *, real *, real *, integer *);
  756. integer nb, ii, ki;
  757. extern /* Subroutine */ int slabad_(real *, real *);
  758. integer ip, is, iv;
  759. real wi;
  760. extern real slamch_(char *);
  761. real wr;
  762. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  763. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  764. integer *, integer *, ftnlen, ftnlen);
  765. real bignum;
  766. extern integer isamax_(integer *, real *, integer *);
  767. extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *,
  768. integer *, real *, integer *), slaset_(char *, integer *,
  769. integer *, real *, real *, real *, integer *);
  770. logical rightv;
  771. integer ki2, maxwrk;
  772. real smlnum;
  773. logical lquery;
  774. real rec, ulp;
  775. /* -- LAPACK computational routine (version 3.8.0) -- */
  776. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  777. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  778. /* November 2017 */
  779. /* ===================================================================== */
  780. /* Decode and test the input parameters */
  781. /* Parameter adjustments */
  782. --select;
  783. t_dim1 = *ldt;
  784. t_offset = 1 + t_dim1 * 1;
  785. t -= t_offset;
  786. vl_dim1 = *ldvl;
  787. vl_offset = 1 + vl_dim1 * 1;
  788. vl -= vl_offset;
  789. vr_dim1 = *ldvr;
  790. vr_offset = 1 + vr_dim1 * 1;
  791. vr -= vr_offset;
  792. --work;
  793. /* Function Body */
  794. bothv = lsame_(side, "B");
  795. rightv = lsame_(side, "R") || bothv;
  796. leftv = lsame_(side, "L") || bothv;
  797. allv = lsame_(howmny, "A");
  798. over = lsame_(howmny, "B");
  799. somev = lsame_(howmny, "S");
  800. *info = 0;
  801. /* Writing concatenation */
  802. i__1[0] = 1, a__1[0] = side;
  803. i__1[1] = 1, a__1[1] = howmny;
  804. s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
  805. nb = ilaenv_(&c__1, "STREVC", ch__1, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
  806. ftnlen)2);
  807. maxwrk = *n + (*n << 1) * nb;
  808. work[1] = (real) maxwrk;
  809. lquery = *lwork == -1;
  810. if (! rightv && ! leftv) {
  811. *info = -1;
  812. } else if (! allv && ! over && ! somev) {
  813. *info = -2;
  814. } else if (*n < 0) {
  815. *info = -4;
  816. } else if (*ldt < f2cmax(1,*n)) {
  817. *info = -6;
  818. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  819. *info = -8;
  820. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  821. *info = -10;
  822. } else /* if(complicated condition) */ {
  823. /* Computing MAX */
  824. i__2 = 1, i__3 = *n * 3;
  825. if (*lwork < f2cmax(i__2,i__3) && ! lquery) {
  826. *info = -14;
  827. } else {
  828. /* Set M to the number of columns required to store the selected */
  829. /* eigenvectors, standardize the array SELECT if necessary, and */
  830. /* test MM. */
  831. if (somev) {
  832. *m = 0;
  833. pair = FALSE_;
  834. i__2 = *n;
  835. for (j = 1; j <= i__2; ++j) {
  836. if (pair) {
  837. pair = FALSE_;
  838. select[j] = FALSE_;
  839. } else {
  840. if (j < *n) {
  841. if (t[j + 1 + j * t_dim1] == 0.f) {
  842. if (select[j]) {
  843. ++(*m);
  844. }
  845. } else {
  846. pair = TRUE_;
  847. if (select[j] || select[j + 1]) {
  848. select[j] = TRUE_;
  849. *m += 2;
  850. }
  851. }
  852. } else {
  853. if (select[*n]) {
  854. ++(*m);
  855. }
  856. }
  857. }
  858. /* L10: */
  859. }
  860. } else {
  861. *m = *n;
  862. }
  863. if (*mm < *m) {
  864. *info = -11;
  865. }
  866. }
  867. }
  868. if (*info != 0) {
  869. i__2 = -(*info);
  870. xerbla_("STREVC3", &i__2, (ftnlen)7);
  871. return 0;
  872. } else if (lquery) {
  873. return 0;
  874. }
  875. /* Quick return if possible. */
  876. if (*n == 0) {
  877. return 0;
  878. }
  879. /* Use blocked version of back-transformation if sufficient workspace. */
  880. /* Zero-out the workspace to avoid potential NaN propagation. */
  881. if (over && *lwork >= *n + (*n << 4)) {
  882. nb = (*lwork - *n) / (*n << 1);
  883. nb = f2cmin(nb,128);
  884. i__2 = (nb << 1) + 1;
  885. slaset_("F", n, &i__2, &c_b17, &c_b17, &work[1], n);
  886. } else {
  887. nb = 1;
  888. }
  889. /* Set the constants to control overflow. */
  890. unfl = slamch_("Safe minimum");
  891. ovfl = 1.f / unfl;
  892. slabad_(&unfl, &ovfl);
  893. ulp = slamch_("Precision");
  894. smlnum = unfl * (*n / ulp);
  895. bignum = (1.f - ulp) / smlnum;
  896. /* Compute 1-norm of each column of strictly upper triangular */
  897. /* part of T to control overflow in triangular solver. */
  898. work[1] = 0.f;
  899. i__2 = *n;
  900. for (j = 2; j <= i__2; ++j) {
  901. work[j] = 0.f;
  902. i__3 = j - 1;
  903. for (i__ = 1; i__ <= i__3; ++i__) {
  904. work[j] += (r__1 = t[i__ + j * t_dim1], abs(r__1));
  905. /* L20: */
  906. }
  907. /* L30: */
  908. }
  909. /* Index IP is used to specify the real or complex eigenvalue: */
  910. /* IP = 0, real eigenvalue, */
  911. /* 1, first of conjugate complex pair: (wr,wi) */
  912. /* -1, second of conjugate complex pair: (wr,wi) */
  913. /* ISCOMPLEX array stores IP for each column in current block. */
  914. if (rightv) {
  915. /* ============================================================ */
  916. /* Compute right eigenvectors. */
  917. /* IV is index of column in current block. */
  918. /* For complex right vector, uses IV-1 for real part and IV for complex part. */
  919. /* Non-blocked version always uses IV=2; */
  920. /* blocked version starts with IV=NB, goes down to 1 or 2. */
  921. /* (Note the "0-th" column is used for 1-norms computed above.) */
  922. iv = 2;
  923. if (nb > 2) {
  924. iv = nb;
  925. }
  926. ip = 0;
  927. is = *m;
  928. for (ki = *n; ki >= 1; --ki) {
  929. if (ip == -1) {
  930. /* previous iteration (ki+1) was second of conjugate pair, */
  931. /* so this ki is first of conjugate pair; skip to end of loop */
  932. ip = 1;
  933. goto L140;
  934. } else if (ki == 1) {
  935. /* last column, so this ki must be real eigenvalue */
  936. ip = 0;
  937. } else if (t[ki + (ki - 1) * t_dim1] == 0.f) {
  938. /* zero on sub-diagonal, so this ki is real eigenvalue */
  939. ip = 0;
  940. } else {
  941. /* non-zero on sub-diagonal, so this ki is second of conjugate pair */
  942. ip = -1;
  943. }
  944. if (somev) {
  945. if (ip == 0) {
  946. if (! select[ki]) {
  947. goto L140;
  948. }
  949. } else {
  950. if (! select[ki - 1]) {
  951. goto L140;
  952. }
  953. }
  954. }
  955. /* Compute the KI-th eigenvalue (WR,WI). */
  956. wr = t[ki + ki * t_dim1];
  957. wi = 0.f;
  958. if (ip != 0) {
  959. wi = sqrt((r__1 = t[ki + (ki - 1) * t_dim1], abs(r__1))) *
  960. sqrt((r__2 = t[ki - 1 + ki * t_dim1], abs(r__2)));
  961. }
  962. /* Computing MAX */
  963. r__1 = ulp * (abs(wr) + abs(wi));
  964. smin = f2cmax(r__1,smlnum);
  965. if (ip == 0) {
  966. /* -------------------------------------------------------- */
  967. /* Real right eigenvector */
  968. work[ki + iv * *n] = 1.f;
  969. /* Form right-hand side. */
  970. i__2 = ki - 1;
  971. for (k = 1; k <= i__2; ++k) {
  972. work[k + iv * *n] = -t[k + ki * t_dim1];
  973. /* L50: */
  974. }
  975. /* Solve upper quasi-triangular system: */
  976. /* [ T(1:KI-1,1:KI-1) - WR ]*X = SCALE*WORK. */
  977. jnxt = ki - 1;
  978. for (j = ki - 1; j >= 1; --j) {
  979. if (j > jnxt) {
  980. goto L60;
  981. }
  982. j1 = j;
  983. j2 = j;
  984. jnxt = j - 1;
  985. if (j > 1) {
  986. if (t[j + (j - 1) * t_dim1] != 0.f) {
  987. j1 = j - 1;
  988. jnxt = j - 2;
  989. }
  990. }
  991. if (j1 == j2) {
  992. /* 1-by-1 diagonal block */
  993. slaln2_(&c_false, &c__1, &c__1, &smin, &c_b29, &t[j +
  994. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  995. iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
  996. xnorm, &ierr);
  997. /* Scale X(1,1) to avoid overflow when updating */
  998. /* the right-hand side. */
  999. if (xnorm > 1.f) {
  1000. if (work[j] > bignum / xnorm) {
  1001. x[0] /= xnorm;
  1002. scale /= xnorm;
  1003. }
  1004. }
  1005. /* Scale if necessary */
  1006. if (scale != 1.f) {
  1007. sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1008. }
  1009. work[j + iv * *n] = x[0];
  1010. /* Update right-hand side */
  1011. i__2 = j - 1;
  1012. r__1 = -x[0];
  1013. saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1014. iv * *n + 1], &c__1);
  1015. } else {
  1016. /* 2-by-2 diagonal block */
  1017. slaln2_(&c_false, &c__2, &c__1, &smin, &c_b29, &t[j -
  1018. 1 + (j - 1) * t_dim1], ldt, &c_b29, &c_b29, &
  1019. work[j - 1 + iv * *n], n, &wr, &c_b17, x, &
  1020. c__2, &scale, &xnorm, &ierr);
  1021. /* Scale X(1,1) and X(2,1) to avoid overflow when */
  1022. /* updating the right-hand side. */
  1023. if (xnorm > 1.f) {
  1024. /* Computing MAX */
  1025. r__1 = work[j - 1], r__2 = work[j];
  1026. beta = f2cmax(r__1,r__2);
  1027. if (beta > bignum / xnorm) {
  1028. x[0] /= xnorm;
  1029. x[1] /= xnorm;
  1030. scale /= xnorm;
  1031. }
  1032. }
  1033. /* Scale if necessary */
  1034. if (scale != 1.f) {
  1035. sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1036. }
  1037. work[j - 1 + iv * *n] = x[0];
  1038. work[j + iv * *n] = x[1];
  1039. /* Update right-hand side */
  1040. i__2 = j - 2;
  1041. r__1 = -x[0];
  1042. saxpy_(&i__2, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1043. &work[iv * *n + 1], &c__1);
  1044. i__2 = j - 2;
  1045. r__1 = -x[1];
  1046. saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1047. iv * *n + 1], &c__1);
  1048. }
  1049. L60:
  1050. ;
  1051. }
  1052. /* Copy the vector x or Q*x to VR and normalize. */
  1053. if (! over) {
  1054. /* ------------------------------ */
  1055. /* no back-transform: copy x to VR and normalize. */
  1056. scopy_(&ki, &work[iv * *n + 1], &c__1, &vr[is * vr_dim1 +
  1057. 1], &c__1);
  1058. ii = isamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
  1059. remax = 1.f / (r__1 = vr[ii + is * vr_dim1], abs(r__1));
  1060. sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1061. i__2 = *n;
  1062. for (k = ki + 1; k <= i__2; ++k) {
  1063. vr[k + is * vr_dim1] = 0.f;
  1064. /* L70: */
  1065. }
  1066. } else if (nb == 1) {
  1067. /* ------------------------------ */
  1068. /* version 1: back-transform each vector with GEMV, Q*x. */
  1069. if (ki > 1) {
  1070. i__2 = ki - 1;
  1071. sgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
  1072. work[iv * *n + 1], &c__1, &work[ki + iv * *n],
  1073. &vr[ki * vr_dim1 + 1], &c__1);
  1074. }
  1075. ii = isamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
  1076. remax = 1.f / (r__1 = vr[ii + ki * vr_dim1], abs(r__1));
  1077. sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1078. } else {
  1079. /* ------------------------------ */
  1080. /* version 2: back-transform block of vectors with GEMM */
  1081. /* zero out below vector */
  1082. i__2 = *n;
  1083. for (k = ki + 1; k <= i__2; ++k) {
  1084. work[k + iv * *n] = 0.f;
  1085. }
  1086. iscomplex[iv - 1] = ip;
  1087. /* back-transform and normalization is done below */
  1088. }
  1089. } else {
  1090. /* -------------------------------------------------------- */
  1091. /* Complex right eigenvector. */
  1092. /* Initial solve */
  1093. /* [ ( T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I*WI) ]*X = 0. */
  1094. /* [ ( T(KI, KI-1) T(KI, KI) ) ] */
  1095. if ((r__1 = t[ki - 1 + ki * t_dim1], abs(r__1)) >= (r__2 = t[
  1096. ki + (ki - 1) * t_dim1], abs(r__2))) {
  1097. work[ki - 1 + (iv - 1) * *n] = 1.f;
  1098. work[ki + iv * *n] = wi / t[ki - 1 + ki * t_dim1];
  1099. } else {
  1100. work[ki - 1 + (iv - 1) * *n] = -wi / t[ki + (ki - 1) *
  1101. t_dim1];
  1102. work[ki + iv * *n] = 1.f;
  1103. }
  1104. work[ki + (iv - 1) * *n] = 0.f;
  1105. work[ki - 1 + iv * *n] = 0.f;
  1106. /* Form right-hand side. */
  1107. i__2 = ki - 2;
  1108. for (k = 1; k <= i__2; ++k) {
  1109. work[k + (iv - 1) * *n] = -work[ki - 1 + (iv - 1) * *n] *
  1110. t[k + (ki - 1) * t_dim1];
  1111. work[k + iv * *n] = -work[ki + iv * *n] * t[k + ki *
  1112. t_dim1];
  1113. /* L80: */
  1114. }
  1115. /* Solve upper quasi-triangular system: */
  1116. /* [ T(1:KI-2,1:KI-2) - (WR+i*WI) ]*X = SCALE*(WORK+i*WORK2) */
  1117. jnxt = ki - 2;
  1118. for (j = ki - 2; j >= 1; --j) {
  1119. if (j > jnxt) {
  1120. goto L90;
  1121. }
  1122. j1 = j;
  1123. j2 = j;
  1124. jnxt = j - 1;
  1125. if (j > 1) {
  1126. if (t[j + (j - 1) * t_dim1] != 0.f) {
  1127. j1 = j - 1;
  1128. jnxt = j - 2;
  1129. }
  1130. }
  1131. if (j1 == j2) {
  1132. /* 1-by-1 diagonal block */
  1133. slaln2_(&c_false, &c__1, &c__2, &smin, &c_b29, &t[j +
  1134. j * t_dim1], ldt, &c_b29, &c_b29, &work[j + (
  1135. iv - 1) * *n], n, &wr, &wi, x, &c__2, &scale,
  1136. &xnorm, &ierr);
  1137. /* Scale X(1,1) and X(1,2) to avoid overflow when */
  1138. /* updating the right-hand side. */
  1139. if (xnorm > 1.f) {
  1140. if (work[j] > bignum / xnorm) {
  1141. x[0] /= xnorm;
  1142. x[2] /= xnorm;
  1143. scale /= xnorm;
  1144. }
  1145. }
  1146. /* Scale if necessary */
  1147. if (scale != 1.f) {
  1148. sscal_(&ki, &scale, &work[(iv - 1) * *n + 1], &
  1149. c__1);
  1150. sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1151. }
  1152. work[j + (iv - 1) * *n] = x[0];
  1153. work[j + iv * *n] = x[2];
  1154. /* Update the right-hand side */
  1155. i__2 = j - 1;
  1156. r__1 = -x[0];
  1157. saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1158. (iv - 1) * *n + 1], &c__1);
  1159. i__2 = j - 1;
  1160. r__1 = -x[2];
  1161. saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1162. iv * *n + 1], &c__1);
  1163. } else {
  1164. /* 2-by-2 diagonal block */
  1165. slaln2_(&c_false, &c__2, &c__2, &smin, &c_b29, &t[j -
  1166. 1 + (j - 1) * t_dim1], ldt, &c_b29, &c_b29, &
  1167. work[j - 1 + (iv - 1) * *n], n, &wr, &wi, x, &
  1168. c__2, &scale, &xnorm, &ierr);
  1169. /* Scale X to avoid overflow when updating */
  1170. /* the right-hand side. */
  1171. if (xnorm > 1.f) {
  1172. /* Computing MAX */
  1173. r__1 = work[j - 1], r__2 = work[j];
  1174. beta = f2cmax(r__1,r__2);
  1175. if (beta > bignum / xnorm) {
  1176. rec = 1.f / xnorm;
  1177. x[0] *= rec;
  1178. x[2] *= rec;
  1179. x[1] *= rec;
  1180. x[3] *= rec;
  1181. scale *= rec;
  1182. }
  1183. }
  1184. /* Scale if necessary */
  1185. if (scale != 1.f) {
  1186. sscal_(&ki, &scale, &work[(iv - 1) * *n + 1], &
  1187. c__1);
  1188. sscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1189. }
  1190. work[j - 1 + (iv - 1) * *n] = x[0];
  1191. work[j + (iv - 1) * *n] = x[1];
  1192. work[j - 1 + iv * *n] = x[2];
  1193. work[j + iv * *n] = x[3];
  1194. /* Update the right-hand side */
  1195. i__2 = j - 2;
  1196. r__1 = -x[0];
  1197. saxpy_(&i__2, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1198. &work[(iv - 1) * *n + 1], &c__1);
  1199. i__2 = j - 2;
  1200. r__1 = -x[1];
  1201. saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1202. (iv - 1) * *n + 1], &c__1);
  1203. i__2 = j - 2;
  1204. r__1 = -x[2];
  1205. saxpy_(&i__2, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1206. &work[iv * *n + 1], &c__1);
  1207. i__2 = j - 2;
  1208. r__1 = -x[3];
  1209. saxpy_(&i__2, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1210. iv * *n + 1], &c__1);
  1211. }
  1212. L90:
  1213. ;
  1214. }
  1215. /* Copy the vector x or Q*x to VR and normalize. */
  1216. if (! over) {
  1217. /* ------------------------------ */
  1218. /* no back-transform: copy x to VR and normalize. */
  1219. scopy_(&ki, &work[(iv - 1) * *n + 1], &c__1, &vr[(is - 1)
  1220. * vr_dim1 + 1], &c__1);
  1221. scopy_(&ki, &work[iv * *n + 1], &c__1, &vr[is * vr_dim1 +
  1222. 1], &c__1);
  1223. emax = 0.f;
  1224. i__2 = ki;
  1225. for (k = 1; k <= i__2; ++k) {
  1226. /* Computing MAX */
  1227. r__3 = emax, r__4 = (r__1 = vr[k + (is - 1) * vr_dim1]
  1228. , abs(r__1)) + (r__2 = vr[k + is * vr_dim1],
  1229. abs(r__2));
  1230. emax = f2cmax(r__3,r__4);
  1231. /* L100: */
  1232. }
  1233. remax = 1.f / emax;
  1234. sscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
  1235. sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1236. i__2 = *n;
  1237. for (k = ki + 1; k <= i__2; ++k) {
  1238. vr[k + (is - 1) * vr_dim1] = 0.f;
  1239. vr[k + is * vr_dim1] = 0.f;
  1240. /* L110: */
  1241. }
  1242. } else if (nb == 1) {
  1243. /* ------------------------------ */
  1244. /* version 1: back-transform each vector with GEMV, Q*x. */
  1245. if (ki > 2) {
  1246. i__2 = ki - 2;
  1247. sgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
  1248. work[(iv - 1) * *n + 1], &c__1, &work[ki - 1
  1249. + (iv - 1) * *n], &vr[(ki - 1) * vr_dim1 + 1],
  1250. &c__1);
  1251. i__2 = ki - 2;
  1252. sgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
  1253. work[iv * *n + 1], &c__1, &work[ki + iv * *n],
  1254. &vr[ki * vr_dim1 + 1], &c__1);
  1255. } else {
  1256. sscal_(n, &work[ki - 1 + (iv - 1) * *n], &vr[(ki - 1)
  1257. * vr_dim1 + 1], &c__1);
  1258. sscal_(n, &work[ki + iv * *n], &vr[ki * vr_dim1 + 1],
  1259. &c__1);
  1260. }
  1261. emax = 0.f;
  1262. i__2 = *n;
  1263. for (k = 1; k <= i__2; ++k) {
  1264. /* Computing MAX */
  1265. r__3 = emax, r__4 = (r__1 = vr[k + (ki - 1) * vr_dim1]
  1266. , abs(r__1)) + (r__2 = vr[k + ki * vr_dim1],
  1267. abs(r__2));
  1268. emax = f2cmax(r__3,r__4);
  1269. /* L120: */
  1270. }
  1271. remax = 1.f / emax;
  1272. sscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
  1273. sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1274. } else {
  1275. /* ------------------------------ */
  1276. /* version 2: back-transform block of vectors with GEMM */
  1277. /* zero out below vector */
  1278. i__2 = *n;
  1279. for (k = ki + 1; k <= i__2; ++k) {
  1280. work[k + (iv - 1) * *n] = 0.f;
  1281. work[k + iv * *n] = 0.f;
  1282. }
  1283. iscomplex[iv - 2] = -ip;
  1284. iscomplex[iv - 1] = ip;
  1285. --iv;
  1286. /* back-transform and normalization is done below */
  1287. }
  1288. }
  1289. if (nb > 1) {
  1290. /* -------------------------------------------------------- */
  1291. /* Blocked version of back-transform */
  1292. /* For complex case, KI2 includes both vectors (KI-1 and KI) */
  1293. if (ip == 0) {
  1294. ki2 = ki;
  1295. } else {
  1296. ki2 = ki - 1;
  1297. }
  1298. /* Columns IV:NB of work are valid vectors. */
  1299. /* When the number of vectors stored reaches NB-1 or NB, */
  1300. /* or if this was last vector, do the GEMM */
  1301. if (iv <= 2 || ki2 == 1) {
  1302. i__2 = nb - iv + 1;
  1303. i__3 = ki2 + nb - iv;
  1304. sgemm_("N", "N", n, &i__2, &i__3, &c_b29, &vr[vr_offset],
  1305. ldvr, &work[iv * *n + 1], n, &c_b17, &work[(nb +
  1306. iv) * *n + 1], n);
  1307. /* normalize vectors */
  1308. i__2 = nb;
  1309. for (k = iv; k <= i__2; ++k) {
  1310. if (iscomplex[k - 1] == 0) {
  1311. /* real eigenvector */
  1312. ii = isamax_(n, &work[(nb + k) * *n + 1], &c__1);
  1313. remax = 1.f / (r__1 = work[ii + (nb + k) * *n],
  1314. abs(r__1));
  1315. } else if (iscomplex[k - 1] == 1) {
  1316. /* first eigenvector of conjugate pair */
  1317. emax = 0.f;
  1318. i__3 = *n;
  1319. for (ii = 1; ii <= i__3; ++ii) {
  1320. /* Computing MAX */
  1321. r__3 = emax, r__4 = (r__1 = work[ii + (nb + k)
  1322. * *n], abs(r__1)) + (r__2 = work[ii
  1323. + (nb + k + 1) * *n], abs(r__2));
  1324. emax = f2cmax(r__3,r__4);
  1325. }
  1326. remax = 1.f / emax;
  1327. /* else if ISCOMPLEX(K).EQ.-1 */
  1328. /* second eigenvector of conjugate pair */
  1329. /* reuse same REMAX as previous K */
  1330. }
  1331. sscal_(n, &remax, &work[(nb + k) * *n + 1], &c__1);
  1332. }
  1333. i__2 = nb - iv + 1;
  1334. slacpy_("F", n, &i__2, &work[(nb + iv) * *n + 1], n, &vr[
  1335. ki2 * vr_dim1 + 1], ldvr);
  1336. iv = nb;
  1337. } else {
  1338. --iv;
  1339. }
  1340. }
  1341. /* blocked back-transform */
  1342. --is;
  1343. if (ip != 0) {
  1344. --is;
  1345. }
  1346. L140:
  1347. ;
  1348. }
  1349. }
  1350. if (leftv) {
  1351. /* ============================================================ */
  1352. /* Compute left eigenvectors. */
  1353. /* IV is index of column in current block. */
  1354. /* For complex left vector, uses IV for real part and IV+1 for complex part. */
  1355. /* Non-blocked version always uses IV=1; */
  1356. /* blocked version starts with IV=1, goes up to NB-1 or NB. */
  1357. /* (Note the "0-th" column is used for 1-norms computed above.) */
  1358. iv = 1;
  1359. ip = 0;
  1360. is = 1;
  1361. i__2 = *n;
  1362. for (ki = 1; ki <= i__2; ++ki) {
  1363. if (ip == 1) {
  1364. /* previous iteration (ki-1) was first of conjugate pair, */
  1365. /* so this ki is second of conjugate pair; skip to end of loop */
  1366. ip = -1;
  1367. goto L260;
  1368. } else if (ki == *n) {
  1369. /* last column, so this ki must be real eigenvalue */
  1370. ip = 0;
  1371. } else if (t[ki + 1 + ki * t_dim1] == 0.f) {
  1372. /* zero on sub-diagonal, so this ki is real eigenvalue */
  1373. ip = 0;
  1374. } else {
  1375. /* non-zero on sub-diagonal, so this ki is first of conjugate pair */
  1376. ip = 1;
  1377. }
  1378. if (somev) {
  1379. if (! select[ki]) {
  1380. goto L260;
  1381. }
  1382. }
  1383. /* Compute the KI-th eigenvalue (WR,WI). */
  1384. wr = t[ki + ki * t_dim1];
  1385. wi = 0.f;
  1386. if (ip != 0) {
  1387. wi = sqrt((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1))) *
  1388. sqrt((r__2 = t[ki + 1 + ki * t_dim1], abs(r__2)));
  1389. }
  1390. /* Computing MAX */
  1391. r__1 = ulp * (abs(wr) + abs(wi));
  1392. smin = f2cmax(r__1,smlnum);
  1393. if (ip == 0) {
  1394. /* -------------------------------------------------------- */
  1395. /* Real left eigenvector */
  1396. work[ki + iv * *n] = 1.f;
  1397. /* Form right-hand side. */
  1398. i__3 = *n;
  1399. for (k = ki + 1; k <= i__3; ++k) {
  1400. work[k + iv * *n] = -t[ki + k * t_dim1];
  1401. /* L160: */
  1402. }
  1403. /* Solve transposed quasi-triangular system: */
  1404. /* [ T(KI+1:N,KI+1:N) - WR ]**T * X = SCALE*WORK */
  1405. vmax = 1.f;
  1406. vcrit = bignum;
  1407. jnxt = ki + 1;
  1408. i__3 = *n;
  1409. for (j = ki + 1; j <= i__3; ++j) {
  1410. if (j < jnxt) {
  1411. goto L170;
  1412. }
  1413. j1 = j;
  1414. j2 = j;
  1415. jnxt = j + 1;
  1416. if (j < *n) {
  1417. if (t[j + 1 + j * t_dim1] != 0.f) {
  1418. j2 = j + 1;
  1419. jnxt = j + 2;
  1420. }
  1421. }
  1422. if (j1 == j2) {
  1423. /* 1-by-1 diagonal block */
  1424. /* Scale if necessary to avoid overflow when forming */
  1425. /* the right-hand side. */
  1426. if (work[j] > vcrit) {
  1427. rec = 1.f / vmax;
  1428. i__4 = *n - ki + 1;
  1429. sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1430. vmax = 1.f;
  1431. vcrit = bignum;
  1432. }
  1433. i__4 = j - ki - 1;
  1434. work[j + iv * *n] -= sdot_(&i__4, &t[ki + 1 + j *
  1435. t_dim1], &c__1, &work[ki + 1 + iv * *n], &
  1436. c__1);
  1437. /* Solve [ T(J,J) - WR ]**T * X = WORK */
  1438. slaln2_(&c_false, &c__1, &c__1, &smin, &c_b29, &t[j +
  1439. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1440. iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
  1441. xnorm, &ierr);
  1442. /* Scale if necessary */
  1443. if (scale != 1.f) {
  1444. i__4 = *n - ki + 1;
  1445. sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1446. }
  1447. work[j + iv * *n] = x[0];
  1448. /* Computing MAX */
  1449. r__2 = (r__1 = work[j + iv * *n], abs(r__1));
  1450. vmax = f2cmax(r__2,vmax);
  1451. vcrit = bignum / vmax;
  1452. } else {
  1453. /* 2-by-2 diagonal block */
  1454. /* Scale if necessary to avoid overflow when forming */
  1455. /* the right-hand side. */
  1456. /* Computing MAX */
  1457. r__1 = work[j], r__2 = work[j + 1];
  1458. beta = f2cmax(r__1,r__2);
  1459. if (beta > vcrit) {
  1460. rec = 1.f / vmax;
  1461. i__4 = *n - ki + 1;
  1462. sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1463. vmax = 1.f;
  1464. vcrit = bignum;
  1465. }
  1466. i__4 = j - ki - 1;
  1467. work[j + iv * *n] -= sdot_(&i__4, &t[ki + 1 + j *
  1468. t_dim1], &c__1, &work[ki + 1 + iv * *n], &
  1469. c__1);
  1470. i__4 = j - ki - 1;
  1471. work[j + 1 + iv * *n] -= sdot_(&i__4, &t[ki + 1 + (j
  1472. + 1) * t_dim1], &c__1, &work[ki + 1 + iv * *n]
  1473. , &c__1);
  1474. /* Solve */
  1475. /* [ T(J,J)-WR T(J,J+1) ]**T * X = SCALE*( WORK1 ) */
  1476. /* [ T(J+1,J) T(J+1,J+1)-WR ] ( WORK2 ) */
  1477. slaln2_(&c_true, &c__2, &c__1, &smin, &c_b29, &t[j +
  1478. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1479. iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
  1480. xnorm, &ierr);
  1481. /* Scale if necessary */
  1482. if (scale != 1.f) {
  1483. i__4 = *n - ki + 1;
  1484. sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1485. }
  1486. work[j + iv * *n] = x[0];
  1487. work[j + 1 + iv * *n] = x[1];
  1488. /* Computing MAX */
  1489. r__3 = (r__1 = work[j + iv * *n], abs(r__1)), r__4 = (
  1490. r__2 = work[j + 1 + iv * *n], abs(r__2)),
  1491. r__3 = f2cmax(r__3,r__4);
  1492. vmax = f2cmax(r__3,vmax);
  1493. vcrit = bignum / vmax;
  1494. }
  1495. L170:
  1496. ;
  1497. }
  1498. /* Copy the vector x or Q*x to VL and normalize. */
  1499. if (! over) {
  1500. /* ------------------------------ */
  1501. /* no back-transform: copy x to VL and normalize. */
  1502. i__3 = *n - ki + 1;
  1503. scopy_(&i__3, &work[ki + iv * *n], &c__1, &vl[ki + is *
  1504. vl_dim1], &c__1);
  1505. i__3 = *n - ki + 1;
  1506. ii = isamax_(&i__3, &vl[ki + is * vl_dim1], &c__1) + ki -
  1507. 1;
  1508. remax = 1.f / (r__1 = vl[ii + is * vl_dim1], abs(r__1));
  1509. i__3 = *n - ki + 1;
  1510. sscal_(&i__3, &remax, &vl[ki + is * vl_dim1], &c__1);
  1511. i__3 = ki - 1;
  1512. for (k = 1; k <= i__3; ++k) {
  1513. vl[k + is * vl_dim1] = 0.f;
  1514. /* L180: */
  1515. }
  1516. } else if (nb == 1) {
  1517. /* ------------------------------ */
  1518. /* version 1: back-transform each vector with GEMV, Q*x. */
  1519. if (ki < *n) {
  1520. i__3 = *n - ki;
  1521. sgemv_("N", n, &i__3, &c_b29, &vl[(ki + 1) * vl_dim1
  1522. + 1], ldvl, &work[ki + 1 + iv * *n], &c__1, &
  1523. work[ki + iv * *n], &vl[ki * vl_dim1 + 1], &
  1524. c__1);
  1525. }
  1526. ii = isamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
  1527. remax = 1.f / (r__1 = vl[ii + ki * vl_dim1], abs(r__1));
  1528. sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1529. } else {
  1530. /* ------------------------------ */
  1531. /* version 2: back-transform block of vectors with GEMM */
  1532. /* zero out above vector */
  1533. /* could go from KI-NV+1 to KI-1 */
  1534. i__3 = ki - 1;
  1535. for (k = 1; k <= i__3; ++k) {
  1536. work[k + iv * *n] = 0.f;
  1537. }
  1538. iscomplex[iv - 1] = ip;
  1539. /* back-transform and normalization is done below */
  1540. }
  1541. } else {
  1542. /* -------------------------------------------------------- */
  1543. /* Complex left eigenvector. */
  1544. /* Initial solve: */
  1545. /* [ ( T(KI,KI) T(KI,KI+1) )**T - (WR - I* WI) ]*X = 0. */
  1546. /* [ ( T(KI+1,KI) T(KI+1,KI+1) ) ] */
  1547. if ((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1)) >= (r__2 =
  1548. t[ki + 1 + ki * t_dim1], abs(r__2))) {
  1549. work[ki + iv * *n] = wi / t[ki + (ki + 1) * t_dim1];
  1550. work[ki + 1 + (iv + 1) * *n] = 1.f;
  1551. } else {
  1552. work[ki + iv * *n] = 1.f;
  1553. work[ki + 1 + (iv + 1) * *n] = -wi / t[ki + 1 + ki *
  1554. t_dim1];
  1555. }
  1556. work[ki + 1 + iv * *n] = 0.f;
  1557. work[ki + (iv + 1) * *n] = 0.f;
  1558. /* Form right-hand side. */
  1559. i__3 = *n;
  1560. for (k = ki + 2; k <= i__3; ++k) {
  1561. work[k + iv * *n] = -work[ki + iv * *n] * t[ki + k *
  1562. t_dim1];
  1563. work[k + (iv + 1) * *n] = -work[ki + 1 + (iv + 1) * *n] *
  1564. t[ki + 1 + k * t_dim1];
  1565. /* L190: */
  1566. }
  1567. /* Solve transposed quasi-triangular system: */
  1568. /* [ T(KI+2:N,KI+2:N)**T - (WR-i*WI) ]*X = WORK1+i*WORK2 */
  1569. vmax = 1.f;
  1570. vcrit = bignum;
  1571. jnxt = ki + 2;
  1572. i__3 = *n;
  1573. for (j = ki + 2; j <= i__3; ++j) {
  1574. if (j < jnxt) {
  1575. goto L200;
  1576. }
  1577. j1 = j;
  1578. j2 = j;
  1579. jnxt = j + 1;
  1580. if (j < *n) {
  1581. if (t[j + 1 + j * t_dim1] != 0.f) {
  1582. j2 = j + 1;
  1583. jnxt = j + 2;
  1584. }
  1585. }
  1586. if (j1 == j2) {
  1587. /* 1-by-1 diagonal block */
  1588. /* Scale if necessary to avoid overflow when */
  1589. /* forming the right-hand side elements. */
  1590. if (work[j] > vcrit) {
  1591. rec = 1.f / vmax;
  1592. i__4 = *n - ki + 1;
  1593. sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1594. i__4 = *n - ki + 1;
  1595. sscal_(&i__4, &rec, &work[ki + (iv + 1) * *n], &
  1596. c__1);
  1597. vmax = 1.f;
  1598. vcrit = bignum;
  1599. }
  1600. i__4 = j - ki - 2;
  1601. work[j + iv * *n] -= sdot_(&i__4, &t[ki + 2 + j *
  1602. t_dim1], &c__1, &work[ki + 2 + iv * *n], &
  1603. c__1);
  1604. i__4 = j - ki - 2;
  1605. work[j + (iv + 1) * *n] -= sdot_(&i__4, &t[ki + 2 + j
  1606. * t_dim1], &c__1, &work[ki + 2 + (iv + 1) * *
  1607. n], &c__1);
  1608. /* Solve [ T(J,J)-(WR-i*WI) ]*(X11+i*X12)= WK+I*WK2 */
  1609. r__1 = -wi;
  1610. slaln2_(&c_false, &c__1, &c__2, &smin, &c_b29, &t[j +
  1611. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1612. iv * *n], n, &wr, &r__1, x, &c__2, &scale, &
  1613. xnorm, &ierr);
  1614. /* Scale if necessary */
  1615. if (scale != 1.f) {
  1616. i__4 = *n - ki + 1;
  1617. sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1618. i__4 = *n - ki + 1;
  1619. sscal_(&i__4, &scale, &work[ki + (iv + 1) * *n], &
  1620. c__1);
  1621. }
  1622. work[j + iv * *n] = x[0];
  1623. work[j + (iv + 1) * *n] = x[2];
  1624. /* Computing MAX */
  1625. r__3 = (r__1 = work[j + iv * *n], abs(r__1)), r__4 = (
  1626. r__2 = work[j + (iv + 1) * *n], abs(r__2)),
  1627. r__3 = f2cmax(r__3,r__4);
  1628. vmax = f2cmax(r__3,vmax);
  1629. vcrit = bignum / vmax;
  1630. } else {
  1631. /* 2-by-2 diagonal block */
  1632. /* Scale if necessary to avoid overflow when forming */
  1633. /* the right-hand side elements. */
  1634. /* Computing MAX */
  1635. r__1 = work[j], r__2 = work[j + 1];
  1636. beta = f2cmax(r__1,r__2);
  1637. if (beta > vcrit) {
  1638. rec = 1.f / vmax;
  1639. i__4 = *n - ki + 1;
  1640. sscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1641. i__4 = *n - ki + 1;
  1642. sscal_(&i__4, &rec, &work[ki + (iv + 1) * *n], &
  1643. c__1);
  1644. vmax = 1.f;
  1645. vcrit = bignum;
  1646. }
  1647. i__4 = j - ki - 2;
  1648. work[j + iv * *n] -= sdot_(&i__4, &t[ki + 2 + j *
  1649. t_dim1], &c__1, &work[ki + 2 + iv * *n], &
  1650. c__1);
  1651. i__4 = j - ki - 2;
  1652. work[j + (iv + 1) * *n] -= sdot_(&i__4, &t[ki + 2 + j
  1653. * t_dim1], &c__1, &work[ki + 2 + (iv + 1) * *
  1654. n], &c__1);
  1655. i__4 = j - ki - 2;
  1656. work[j + 1 + iv * *n] -= sdot_(&i__4, &t[ki + 2 + (j
  1657. + 1) * t_dim1], &c__1, &work[ki + 2 + iv * *n]
  1658. , &c__1);
  1659. i__4 = j - ki - 2;
  1660. work[j + 1 + (iv + 1) * *n] -= sdot_(&i__4, &t[ki + 2
  1661. + (j + 1) * t_dim1], &c__1, &work[ki + 2 + (
  1662. iv + 1) * *n], &c__1);
  1663. /* Solve 2-by-2 complex linear equation */
  1664. /* [ (T(j,j) T(j,j+1) )**T - (wr-i*wi)*I ]*X = SCALE*B */
  1665. /* [ (T(j+1,j) T(j+1,j+1)) ] */
  1666. r__1 = -wi;
  1667. slaln2_(&c_true, &c__2, &c__2, &smin, &c_b29, &t[j +
  1668. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1669. iv * *n], n, &wr, &r__1, x, &c__2, &scale, &
  1670. xnorm, &ierr);
  1671. /* Scale if necessary */
  1672. if (scale != 1.f) {
  1673. i__4 = *n - ki + 1;
  1674. sscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1675. i__4 = *n - ki + 1;
  1676. sscal_(&i__4, &scale, &work[ki + (iv + 1) * *n], &
  1677. c__1);
  1678. }
  1679. work[j + iv * *n] = x[0];
  1680. work[j + (iv + 1) * *n] = x[2];
  1681. work[j + 1 + iv * *n] = x[1];
  1682. work[j + 1 + (iv + 1) * *n] = x[3];
  1683. /* Computing MAX */
  1684. r__1 = abs(x[0]), r__2 = abs(x[2]), r__1 = f2cmax(r__1,
  1685. r__2), r__2 = abs(x[1]), r__1 = f2cmax(r__1,r__2)
  1686. , r__2 = abs(x[3]), r__1 = f2cmax(r__1,r__2);
  1687. vmax = f2cmax(r__1,vmax);
  1688. vcrit = bignum / vmax;
  1689. }
  1690. L200:
  1691. ;
  1692. }
  1693. /* Copy the vector x or Q*x to VL and normalize. */
  1694. if (! over) {
  1695. /* ------------------------------ */
  1696. /* no back-transform: copy x to VL and normalize. */
  1697. i__3 = *n - ki + 1;
  1698. scopy_(&i__3, &work[ki + iv * *n], &c__1, &vl[ki + is *
  1699. vl_dim1], &c__1);
  1700. i__3 = *n - ki + 1;
  1701. scopy_(&i__3, &work[ki + (iv + 1) * *n], &c__1, &vl[ki + (
  1702. is + 1) * vl_dim1], &c__1);
  1703. emax = 0.f;
  1704. i__3 = *n;
  1705. for (k = ki; k <= i__3; ++k) {
  1706. /* Computing MAX */
  1707. r__3 = emax, r__4 = (r__1 = vl[k + is * vl_dim1], abs(
  1708. r__1)) + (r__2 = vl[k + (is + 1) * vl_dim1],
  1709. abs(r__2));
  1710. emax = f2cmax(r__3,r__4);
  1711. /* L220: */
  1712. }
  1713. remax = 1.f / emax;
  1714. i__3 = *n - ki + 1;
  1715. sscal_(&i__3, &remax, &vl[ki + is * vl_dim1], &c__1);
  1716. i__3 = *n - ki + 1;
  1717. sscal_(&i__3, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
  1718. ;
  1719. i__3 = ki - 1;
  1720. for (k = 1; k <= i__3; ++k) {
  1721. vl[k + is * vl_dim1] = 0.f;
  1722. vl[k + (is + 1) * vl_dim1] = 0.f;
  1723. /* L230: */
  1724. }
  1725. } else if (nb == 1) {
  1726. /* ------------------------------ */
  1727. /* version 1: back-transform each vector with GEMV, Q*x. */
  1728. if (ki < *n - 1) {
  1729. i__3 = *n - ki - 1;
  1730. sgemv_("N", n, &i__3, &c_b29, &vl[(ki + 2) * vl_dim1
  1731. + 1], ldvl, &work[ki + 2 + iv * *n], &c__1, &
  1732. work[ki + iv * *n], &vl[ki * vl_dim1 + 1], &
  1733. c__1);
  1734. i__3 = *n - ki - 1;
  1735. sgemv_("N", n, &i__3, &c_b29, &vl[(ki + 2) * vl_dim1
  1736. + 1], ldvl, &work[ki + 2 + (iv + 1) * *n], &
  1737. c__1, &work[ki + 1 + (iv + 1) * *n], &vl[(ki
  1738. + 1) * vl_dim1 + 1], &c__1);
  1739. } else {
  1740. sscal_(n, &work[ki + iv * *n], &vl[ki * vl_dim1 + 1],
  1741. &c__1);
  1742. sscal_(n, &work[ki + 1 + (iv + 1) * *n], &vl[(ki + 1)
  1743. * vl_dim1 + 1], &c__1);
  1744. }
  1745. emax = 0.f;
  1746. i__3 = *n;
  1747. for (k = 1; k <= i__3; ++k) {
  1748. /* Computing MAX */
  1749. r__3 = emax, r__4 = (r__1 = vl[k + ki * vl_dim1], abs(
  1750. r__1)) + (r__2 = vl[k + (ki + 1) * vl_dim1],
  1751. abs(r__2));
  1752. emax = f2cmax(r__3,r__4);
  1753. /* L240: */
  1754. }
  1755. remax = 1.f / emax;
  1756. sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1757. sscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
  1758. } else {
  1759. /* ------------------------------ */
  1760. /* version 2: back-transform block of vectors with GEMM */
  1761. /* zero out above vector */
  1762. /* could go from KI-NV+1 to KI-1 */
  1763. i__3 = ki - 1;
  1764. for (k = 1; k <= i__3; ++k) {
  1765. work[k + iv * *n] = 0.f;
  1766. work[k + (iv + 1) * *n] = 0.f;
  1767. }
  1768. iscomplex[iv - 1] = ip;
  1769. iscomplex[iv] = -ip;
  1770. ++iv;
  1771. /* back-transform and normalization is done below */
  1772. }
  1773. }
  1774. if (nb > 1) {
  1775. /* -------------------------------------------------------- */
  1776. /* Blocked version of back-transform */
  1777. /* For complex case, KI2 includes both vectors (KI and KI+1) */
  1778. if (ip == 0) {
  1779. ki2 = ki;
  1780. } else {
  1781. ki2 = ki + 1;
  1782. }
  1783. /* Columns 1:IV of work are valid vectors. */
  1784. /* When the number of vectors stored reaches NB-1 or NB, */
  1785. /* or if this was last vector, do the GEMM */
  1786. if (iv >= nb - 1 || ki2 == *n) {
  1787. i__3 = *n - ki2 + iv;
  1788. sgemm_("N", "N", n, &iv, &i__3, &c_b29, &vl[(ki2 - iv + 1)
  1789. * vl_dim1 + 1], ldvl, &work[ki2 - iv + 1 + *n],
  1790. n, &c_b17, &work[(nb + 1) * *n + 1], n);
  1791. /* normalize vectors */
  1792. i__3 = iv;
  1793. for (k = 1; k <= i__3; ++k) {
  1794. if (iscomplex[k - 1] == 0) {
  1795. /* real eigenvector */
  1796. ii = isamax_(n, &work[(nb + k) * *n + 1], &c__1);
  1797. remax = 1.f / (r__1 = work[ii + (nb + k) * *n],
  1798. abs(r__1));
  1799. } else if (iscomplex[k - 1] == 1) {
  1800. /* first eigenvector of conjugate pair */
  1801. emax = 0.f;
  1802. i__4 = *n;
  1803. for (ii = 1; ii <= i__4; ++ii) {
  1804. /* Computing MAX */
  1805. r__3 = emax, r__4 = (r__1 = work[ii + (nb + k)
  1806. * *n], abs(r__1)) + (r__2 = work[ii
  1807. + (nb + k + 1) * *n], abs(r__2));
  1808. emax = f2cmax(r__3,r__4);
  1809. }
  1810. remax = 1.f / emax;
  1811. /* else if ISCOMPLEX(K).EQ.-1 */
  1812. /* second eigenvector of conjugate pair */
  1813. /* reuse same REMAX as previous K */
  1814. }
  1815. sscal_(n, &remax, &work[(nb + k) * *n + 1], &c__1);
  1816. }
  1817. slacpy_("F", n, &iv, &work[(nb + 1) * *n + 1], n, &vl[(
  1818. ki2 - iv + 1) * vl_dim1 + 1], ldvl);
  1819. iv = 1;
  1820. } else {
  1821. ++iv;
  1822. }
  1823. }
  1824. /* blocked back-transform */
  1825. ++is;
  1826. if (ip != 0) {
  1827. ++is;
  1828. }
  1829. L260:
  1830. ;
  1831. }
  1832. }
  1833. return 0;
  1834. /* End of STREVC3 */
  1835. } /* strevc3_ */