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.

strevc.c 49 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  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 blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #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]);}
  172. #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]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #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++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #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]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static logical c_false = FALSE_;
  485. static integer c__1 = 1;
  486. static real c_b22 = 1.f;
  487. static real c_b25 = 0.f;
  488. static integer c__2 = 2;
  489. static logical c_true = TRUE_;
  490. /* > \brief \b STREVC */
  491. /* =========== DOCUMENTATION =========== */
  492. /* Online html documentation available at */
  493. /* http://www.netlib.org/lapack/explore-html/ */
  494. /* > \htmlonly */
  495. /* > Download STREVC + dependencies */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/strevc.
  497. f"> */
  498. /* > [TGZ]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/strevc.
  500. f"> */
  501. /* > [ZIP]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/strevc.
  503. f"> */
  504. /* > [TXT]</a> */
  505. /* > \endhtmlonly */
  506. /* Definition: */
  507. /* =========== */
  508. /* SUBROUTINE STREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR, */
  509. /* LDVR, MM, M, WORK, INFO ) */
  510. /* CHARACTER HOWMNY, SIDE */
  511. /* INTEGER INFO, LDT, LDVL, LDVR, M, MM, N */
  512. /* LOGICAL SELECT( * ) */
  513. /* REAL T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ), */
  514. /* $ WORK( * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > STREVC computes some or all of the right and/or left eigenvectors of */
  521. /* > a real upper quasi-triangular matrix T. */
  522. /* > Matrices of this type are produced by the Schur factorization of */
  523. /* > a real general matrix: A = Q*T*Q**T, as computed by SHSEQR. */
  524. /* > */
  525. /* > The right eigenvector x and the left eigenvector y of T corresponding */
  526. /* > to an eigenvalue w are defined by: */
  527. /* > */
  528. /* > T*x = w*x, (y**H)*T = w*(y**H) */
  529. /* > */
  530. /* > where y**H denotes the conjugate transpose of y. */
  531. /* > The eigenvalues are not input to this routine, but are read directly */
  532. /* > from the diagonal blocks of T. */
  533. /* > */
  534. /* > This routine returns the matrices X and/or Y of right and left */
  535. /* > eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an */
  536. /* > input matrix. If Q is the orthogonal factor that reduces a matrix */
  537. /* > A to Schur form T, then Q*X and Q*Y are the matrices of right and */
  538. /* > left eigenvectors of A. */
  539. /* > \endverbatim */
  540. /* Arguments: */
  541. /* ========== */
  542. /* > \param[in] SIDE */
  543. /* > \verbatim */
  544. /* > SIDE is CHARACTER*1 */
  545. /* > = 'R': compute right eigenvectors only; */
  546. /* > = 'L': compute left eigenvectors only; */
  547. /* > = 'B': compute both right and left eigenvectors. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[in] HOWMNY */
  551. /* > \verbatim */
  552. /* > HOWMNY is CHARACTER*1 */
  553. /* > = 'A': compute all right and/or left eigenvectors; */
  554. /* > = 'B': compute all right and/or left eigenvectors, */
  555. /* > backtransformed by the matrices in VR and/or VL; */
  556. /* > = 'S': compute selected right and/or left eigenvectors, */
  557. /* > as indicated by the logical array SELECT. */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[in,out] SELECT */
  561. /* > \verbatim */
  562. /* > SELECT is LOGICAL array, dimension (N) */
  563. /* > If HOWMNY = 'S', SELECT specifies the eigenvectors to be */
  564. /* > computed. */
  565. /* > If w(j) is a real eigenvalue, the corresponding real */
  566. /* > eigenvector is computed if SELECT(j) is .TRUE.. */
  567. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  568. /* > complex eigenvalue, the corresponding complex eigenvector is */
  569. /* > computed if either SELECT(j) or SELECT(j+1) is .TRUE., and */
  570. /* > on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to */
  571. /* > .FALSE.. */
  572. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[in] N */
  576. /* > \verbatim */
  577. /* > N is INTEGER */
  578. /* > The order of the matrix T. N >= 0. */
  579. /* > \endverbatim */
  580. /* > */
  581. /* > \param[in] T */
  582. /* > \verbatim */
  583. /* > T is REAL array, dimension (LDT,N) */
  584. /* > The upper quasi-triangular matrix T in Schur canonical form. */
  585. /* > \endverbatim */
  586. /* > */
  587. /* > \param[in] LDT */
  588. /* > \verbatim */
  589. /* > LDT is INTEGER */
  590. /* > The leading dimension of the array T. LDT >= f2cmax(1,N). */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[in,out] VL */
  594. /* > \verbatim */
  595. /* > VL is REAL array, dimension (LDVL,MM) */
  596. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  597. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  598. /* > of Schur vectors returned by SHSEQR). */
  599. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  600. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of T; */
  601. /* > if HOWMNY = 'B', the matrix Q*Y; */
  602. /* > if HOWMNY = 'S', the left eigenvectors of T specified by */
  603. /* > SELECT, stored consecutively in the columns */
  604. /* > of VL, in the same order as their */
  605. /* > eigenvalues. */
  606. /* > A complex eigenvector corresponding to a complex eigenvalue */
  607. /* > is stored in two consecutive columns, the first holding the */
  608. /* > real part, and the second the imaginary part. */
  609. /* > Not referenced if SIDE = 'R'. */
  610. /* > \endverbatim */
  611. /* > */
  612. /* > \param[in] LDVL */
  613. /* > \verbatim */
  614. /* > LDVL is INTEGER */
  615. /* > The leading dimension of the array VL. LDVL >= 1, and if */
  616. /* > SIDE = 'L' or 'B', LDVL >= N. */
  617. /* > \endverbatim */
  618. /* > */
  619. /* > \param[in,out] VR */
  620. /* > \verbatim */
  621. /* > VR is REAL array, dimension (LDVR,MM) */
  622. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  623. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  624. /* > of Schur vectors returned by SHSEQR). */
  625. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  626. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of T; */
  627. /* > if HOWMNY = 'B', the matrix Q*X; */
  628. /* > if HOWMNY = 'S', the right eigenvectors of T specified by */
  629. /* > SELECT, stored consecutively in the columns */
  630. /* > of VR, in the same order as their */
  631. /* > eigenvalues. */
  632. /* > A complex eigenvector corresponding to a complex eigenvalue */
  633. /* > is stored in two consecutive columns, the first holding the */
  634. /* > real part and the second the imaginary part. */
  635. /* > Not referenced if SIDE = 'L'. */
  636. /* > \endverbatim */
  637. /* > */
  638. /* > \param[in] LDVR */
  639. /* > \verbatim */
  640. /* > LDVR is INTEGER */
  641. /* > The leading dimension of the array VR. LDVR >= 1, and if */
  642. /* > SIDE = 'R' or 'B', LDVR >= N. */
  643. /* > \endverbatim */
  644. /* > */
  645. /* > \param[in] MM */
  646. /* > \verbatim */
  647. /* > MM is INTEGER */
  648. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  649. /* > \endverbatim */
  650. /* > */
  651. /* > \param[out] M */
  652. /* > \verbatim */
  653. /* > M is INTEGER */
  654. /* > The number of columns in the arrays VL and/or VR actually */
  655. /* > used to store the eigenvectors. */
  656. /* > If HOWMNY = 'A' or 'B', M is set to N. */
  657. /* > Each selected real eigenvector occupies one column and each */
  658. /* > selected complex eigenvector occupies two columns. */
  659. /* > \endverbatim */
  660. /* > */
  661. /* > \param[out] WORK */
  662. /* > \verbatim */
  663. /* > WORK is REAL array, dimension (3*N) */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[out] INFO */
  667. /* > \verbatim */
  668. /* > INFO is INTEGER */
  669. /* > = 0: successful exit */
  670. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  671. /* > \endverbatim */
  672. /* Authors: */
  673. /* ======== */
  674. /* > \author Univ. of Tennessee */
  675. /* > \author Univ. of California Berkeley */
  676. /* > \author Univ. of Colorado Denver */
  677. /* > \author NAG Ltd. */
  678. /* > \date December 2016 */
  679. /* > \ingroup realOTHERcomputational */
  680. /* > \par Further Details: */
  681. /* ===================== */
  682. /* > */
  683. /* > \verbatim */
  684. /* > */
  685. /* > The algorithm used in this program is basically backward (forward) */
  686. /* > substitution, with scaling to make the the code robust against */
  687. /* > possible overflow. */
  688. /* > */
  689. /* > Each eigenvector is normalized so that the element of largest */
  690. /* > magnitude has magnitude 1; here the magnitude of a complex number */
  691. /* > (x,y) is taken to be |x| + |y|. */
  692. /* > \endverbatim */
  693. /* > */
  694. /* ===================================================================== */
  695. /* Subroutine */ void strevc_(char *side, char *howmny, logical *select,
  696. integer *n, real *t, integer *ldt, real *vl, integer *ldvl, real *vr,
  697. integer *ldvr, integer *mm, integer *m, real *work, integer *info)
  698. {
  699. /* System generated locals */
  700. integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  701. i__2, i__3;
  702. real r__1, r__2, r__3, r__4;
  703. /* Local variables */
  704. real beta, emax;
  705. logical pair, allv;
  706. integer ierr;
  707. real unfl, ovfl, smin;
  708. extern real sdot_(integer *, real *, integer *, real *, integer *);
  709. logical over;
  710. real vmax;
  711. integer jnxt, i__, j, k;
  712. real scale, x[4] /* was [2][2] */;
  713. extern logical lsame_(char *, char *);
  714. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  715. real remax;
  716. logical leftv;
  717. extern /* Subroutine */ void sgemv_(char *, integer *, integer *, real *,
  718. real *, integer *, real *, integer *, real *, real *, integer *);
  719. logical bothv;
  720. real vcrit;
  721. logical somev;
  722. integer j1, j2;
  723. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  724. integer *);
  725. integer n2;
  726. real xnorm;
  727. extern /* Subroutine */ void saxpy_(integer *, real *, real *, integer *,
  728. real *, integer *), slaln2_(logical *, integer *, integer *, real
  729. *, real *, real *, integer *, real *, real *, real *, integer *,
  730. real *, real *, real *, integer *, real *, real *, integer *);
  731. integer ii, ki;
  732. extern /* Subroutine */ void slabad_(real *, real *);
  733. integer ip, is;
  734. real wi;
  735. extern real slamch_(char *);
  736. real wr;
  737. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  738. real bignum;
  739. extern integer isamax_(integer *, real *, integer *);
  740. logical rightv;
  741. real smlnum, rec, ulp;
  742. /* -- LAPACK computational routine (version 3.7.0) -- */
  743. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  744. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  745. /* December 2016 */
  746. /* ===================================================================== */
  747. /* Decode and test the input parameters */
  748. /* Parameter adjustments */
  749. --select;
  750. t_dim1 = *ldt;
  751. t_offset = 1 + t_dim1 * 1;
  752. t -= t_offset;
  753. vl_dim1 = *ldvl;
  754. vl_offset = 1 + vl_dim1 * 1;
  755. vl -= vl_offset;
  756. vr_dim1 = *ldvr;
  757. vr_offset = 1 + vr_dim1 * 1;
  758. vr -= vr_offset;
  759. --work;
  760. /* Function Body */
  761. bothv = lsame_(side, "B");
  762. rightv = lsame_(side, "R") || bothv;
  763. leftv = lsame_(side, "L") || bothv;
  764. allv = lsame_(howmny, "A");
  765. over = lsame_(howmny, "B");
  766. somev = lsame_(howmny, "S");
  767. *info = 0;
  768. if (! rightv && ! leftv) {
  769. *info = -1;
  770. } else if (! allv && ! over && ! somev) {
  771. *info = -2;
  772. } else if (*n < 0) {
  773. *info = -4;
  774. } else if (*ldt < f2cmax(1,*n)) {
  775. *info = -6;
  776. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  777. *info = -8;
  778. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  779. *info = -10;
  780. } else {
  781. /* Set M to the number of columns required to store the selected */
  782. /* eigenvectors, standardize the array SELECT if necessary, and */
  783. /* test MM. */
  784. if (somev) {
  785. *m = 0;
  786. pair = FALSE_;
  787. i__1 = *n;
  788. for (j = 1; j <= i__1; ++j) {
  789. if (pair) {
  790. pair = FALSE_;
  791. select[j] = FALSE_;
  792. } else {
  793. if (j < *n) {
  794. if (t[j + 1 + j * t_dim1] == 0.f) {
  795. if (select[j]) {
  796. ++(*m);
  797. }
  798. } else {
  799. pair = TRUE_;
  800. if (select[j] || select[j + 1]) {
  801. select[j] = TRUE_;
  802. *m += 2;
  803. }
  804. }
  805. } else {
  806. if (select[*n]) {
  807. ++(*m);
  808. }
  809. }
  810. }
  811. /* L10: */
  812. }
  813. } else {
  814. *m = *n;
  815. }
  816. if (*mm < *m) {
  817. *info = -11;
  818. }
  819. }
  820. if (*info != 0) {
  821. i__1 = -(*info);
  822. xerbla_("STREVC", &i__1, (ftnlen)6);
  823. return;
  824. }
  825. /* Quick return if possible. */
  826. if (*n == 0) {
  827. return;
  828. }
  829. /* Set the constants to control overflow. */
  830. unfl = slamch_("Safe minimum");
  831. ovfl = 1.f / unfl;
  832. slabad_(&unfl, &ovfl);
  833. ulp = slamch_("Precision");
  834. smlnum = unfl * (*n / ulp);
  835. bignum = (1.f - ulp) / smlnum;
  836. /* Compute 1-norm of each column of strictly upper triangular */
  837. /* part of T to control overflow in triangular solver. */
  838. work[1] = 0.f;
  839. i__1 = *n;
  840. for (j = 2; j <= i__1; ++j) {
  841. work[j] = 0.f;
  842. i__2 = j - 1;
  843. for (i__ = 1; i__ <= i__2; ++i__) {
  844. work[j] += (r__1 = t[i__ + j * t_dim1], abs(r__1));
  845. /* L20: */
  846. }
  847. /* L30: */
  848. }
  849. /* Index IP is used to specify the real or complex eigenvalue: */
  850. /* IP = 0, real eigenvalue, */
  851. /* 1, first of conjugate complex pair: (wr,wi) */
  852. /* -1, second of conjugate complex pair: (wr,wi) */
  853. n2 = *n << 1;
  854. if (rightv) {
  855. /* Compute right eigenvectors. */
  856. ip = 0;
  857. is = *m;
  858. for (ki = *n; ki >= 1; --ki) {
  859. if (ip == 1) {
  860. goto L130;
  861. }
  862. if (ki == 1) {
  863. goto L40;
  864. }
  865. if (t[ki + (ki - 1) * t_dim1] == 0.f) {
  866. goto L40;
  867. }
  868. ip = -1;
  869. L40:
  870. if (somev) {
  871. if (ip == 0) {
  872. if (! select[ki]) {
  873. goto L130;
  874. }
  875. } else {
  876. if (! select[ki - 1]) {
  877. goto L130;
  878. }
  879. }
  880. }
  881. /* Compute the KI-th eigenvalue (WR,WI). */
  882. wr = t[ki + ki * t_dim1];
  883. wi = 0.f;
  884. if (ip != 0) {
  885. wi = sqrt((r__1 = t[ki + (ki - 1) * t_dim1], abs(r__1))) *
  886. sqrt((r__2 = t[ki - 1 + ki * t_dim1], abs(r__2)));
  887. }
  888. /* Computing MAX */
  889. r__1 = ulp * (abs(wr) + abs(wi));
  890. smin = f2cmax(r__1,smlnum);
  891. if (ip == 0) {
  892. /* Real right eigenvector */
  893. work[ki + *n] = 1.f;
  894. /* Form right-hand side */
  895. i__1 = ki - 1;
  896. for (k = 1; k <= i__1; ++k) {
  897. work[k + *n] = -t[k + ki * t_dim1];
  898. /* L50: */
  899. }
  900. /* Solve the upper quasi-triangular system: */
  901. /* (T(1:KI-1,1:KI-1) - WR)*X = SCALE*WORK. */
  902. jnxt = ki - 1;
  903. for (j = ki - 1; j >= 1; --j) {
  904. if (j > jnxt) {
  905. goto L60;
  906. }
  907. j1 = j;
  908. j2 = j;
  909. jnxt = j - 1;
  910. if (j > 1) {
  911. if (t[j + (j - 1) * t_dim1] != 0.f) {
  912. j1 = j - 1;
  913. jnxt = j - 2;
  914. }
  915. }
  916. if (j1 == j2) {
  917. /* 1-by-1 diagonal block */
  918. slaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  919. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  920. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  921. &ierr);
  922. /* Scale X(1,1) to avoid overflow when updating */
  923. /* the right-hand side. */
  924. if (xnorm > 1.f) {
  925. if (work[j] > bignum / xnorm) {
  926. x[0] /= xnorm;
  927. scale /= xnorm;
  928. }
  929. }
  930. /* Scale if necessary */
  931. if (scale != 1.f) {
  932. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  933. }
  934. work[j + *n] = x[0];
  935. /* Update right-hand side */
  936. i__1 = j - 1;
  937. r__1 = -x[0];
  938. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  939. *n + 1], &c__1);
  940. } else {
  941. /* 2-by-2 diagonal block */
  942. slaln2_(&c_false, &c__2, &c__1, &smin, &c_b22, &t[j -
  943. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  944. work[j - 1 + *n], n, &wr, &c_b25, x, &c__2, &
  945. scale, &xnorm, &ierr);
  946. /* Scale X(1,1) and X(2,1) to avoid overflow when */
  947. /* updating the right-hand side. */
  948. if (xnorm > 1.f) {
  949. /* Computing MAX */
  950. r__1 = work[j - 1], r__2 = work[j];
  951. beta = f2cmax(r__1,r__2);
  952. if (beta > bignum / xnorm) {
  953. x[0] /= xnorm;
  954. x[1] /= xnorm;
  955. scale /= xnorm;
  956. }
  957. }
  958. /* Scale if necessary */
  959. if (scale != 1.f) {
  960. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  961. }
  962. work[j - 1 + *n] = x[0];
  963. work[j + *n] = x[1];
  964. /* Update right-hand side */
  965. i__1 = j - 2;
  966. r__1 = -x[0];
  967. saxpy_(&i__1, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  968. &work[*n + 1], &c__1);
  969. i__1 = j - 2;
  970. r__1 = -x[1];
  971. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  972. *n + 1], &c__1);
  973. }
  974. L60:
  975. ;
  976. }
  977. /* Copy the vector x or Q*x to VR and normalize. */
  978. if (! over) {
  979. scopy_(&ki, &work[*n + 1], &c__1, &vr[is * vr_dim1 + 1], &
  980. c__1);
  981. ii = isamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
  982. remax = 1.f / (r__1 = vr[ii + is * vr_dim1], abs(r__1));
  983. sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  984. i__1 = *n;
  985. for (k = ki + 1; k <= i__1; ++k) {
  986. vr[k + is * vr_dim1] = 0.f;
  987. /* L70: */
  988. }
  989. } else {
  990. if (ki > 1) {
  991. i__1 = ki - 1;
  992. sgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  993. work[*n + 1], &c__1, &work[ki + *n], &vr[ki *
  994. vr_dim1 + 1], &c__1);
  995. }
  996. ii = isamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
  997. remax = 1.f / (r__1 = vr[ii + ki * vr_dim1], abs(r__1));
  998. sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  999. }
  1000. } else {
  1001. /* Complex right eigenvector. */
  1002. /* Initial solve */
  1003. /* [ (T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I* WI)]*X = 0. */
  1004. /* [ (T(KI,KI-1) T(KI,KI) ) ] */
  1005. if ((r__1 = t[ki - 1 + ki * t_dim1], abs(r__1)) >= (r__2 = t[
  1006. ki + (ki - 1) * t_dim1], abs(r__2))) {
  1007. work[ki - 1 + *n] = 1.f;
  1008. work[ki + n2] = wi / t[ki - 1 + ki * t_dim1];
  1009. } else {
  1010. work[ki - 1 + *n] = -wi / t[ki + (ki - 1) * t_dim1];
  1011. work[ki + n2] = 1.f;
  1012. }
  1013. work[ki + *n] = 0.f;
  1014. work[ki - 1 + n2] = 0.f;
  1015. /* Form right-hand side */
  1016. i__1 = ki - 2;
  1017. for (k = 1; k <= i__1; ++k) {
  1018. work[k + *n] = -work[ki - 1 + *n] * t[k + (ki - 1) *
  1019. t_dim1];
  1020. work[k + n2] = -work[ki + n2] * t[k + ki * t_dim1];
  1021. /* L80: */
  1022. }
  1023. /* Solve upper quasi-triangular system: */
  1024. /* (T(1:KI-2,1:KI-2) - (WR+i*WI))*X = SCALE*(WORK+i*WORK2) */
  1025. jnxt = ki - 2;
  1026. for (j = ki - 2; j >= 1; --j) {
  1027. if (j > jnxt) {
  1028. goto L90;
  1029. }
  1030. j1 = j;
  1031. j2 = j;
  1032. jnxt = j - 1;
  1033. if (j > 1) {
  1034. if (t[j + (j - 1) * t_dim1] != 0.f) {
  1035. j1 = j - 1;
  1036. jnxt = j - 2;
  1037. }
  1038. }
  1039. if (j1 == j2) {
  1040. /* 1-by-1 diagonal block */
  1041. slaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1042. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1043. n], n, &wr, &wi, x, &c__2, &scale, &xnorm, &
  1044. ierr);
  1045. /* Scale X(1,1) and X(1,2) to avoid overflow when */
  1046. /* updating the right-hand side. */
  1047. if (xnorm > 1.f) {
  1048. if (work[j] > bignum / xnorm) {
  1049. x[0] /= xnorm;
  1050. x[2] /= xnorm;
  1051. scale /= xnorm;
  1052. }
  1053. }
  1054. /* Scale if necessary */
  1055. if (scale != 1.f) {
  1056. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  1057. sscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1058. }
  1059. work[j + *n] = x[0];
  1060. work[j + n2] = x[2];
  1061. /* Update the right-hand side */
  1062. i__1 = j - 1;
  1063. r__1 = -x[0];
  1064. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1065. *n + 1], &c__1);
  1066. i__1 = j - 1;
  1067. r__1 = -x[2];
  1068. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1069. n2 + 1], &c__1);
  1070. } else {
  1071. /* 2-by-2 diagonal block */
  1072. slaln2_(&c_false, &c__2, &c__2, &smin, &c_b22, &t[j -
  1073. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  1074. work[j - 1 + *n], n, &wr, &wi, x, &c__2, &
  1075. scale, &xnorm, &ierr);
  1076. /* Scale X to avoid overflow when updating */
  1077. /* the right-hand side. */
  1078. if (xnorm > 1.f) {
  1079. /* Computing MAX */
  1080. r__1 = work[j - 1], r__2 = work[j];
  1081. beta = f2cmax(r__1,r__2);
  1082. if (beta > bignum / xnorm) {
  1083. rec = 1.f / xnorm;
  1084. x[0] *= rec;
  1085. x[2] *= rec;
  1086. x[1] *= rec;
  1087. x[3] *= rec;
  1088. scale *= rec;
  1089. }
  1090. }
  1091. /* Scale if necessary */
  1092. if (scale != 1.f) {
  1093. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  1094. sscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1095. }
  1096. work[j - 1 + *n] = x[0];
  1097. work[j + *n] = x[1];
  1098. work[j - 1 + n2] = x[2];
  1099. work[j + n2] = x[3];
  1100. /* Update the right-hand side */
  1101. i__1 = j - 2;
  1102. r__1 = -x[0];
  1103. saxpy_(&i__1, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1104. &work[*n + 1], &c__1);
  1105. i__1 = j - 2;
  1106. r__1 = -x[1];
  1107. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1108. *n + 1], &c__1);
  1109. i__1 = j - 2;
  1110. r__1 = -x[2];
  1111. saxpy_(&i__1, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1112. &work[n2 + 1], &c__1);
  1113. i__1 = j - 2;
  1114. r__1 = -x[3];
  1115. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1116. n2 + 1], &c__1);
  1117. }
  1118. L90:
  1119. ;
  1120. }
  1121. /* Copy the vector x or Q*x to VR and normalize. */
  1122. if (! over) {
  1123. scopy_(&ki, &work[*n + 1], &c__1, &vr[(is - 1) * vr_dim1
  1124. + 1], &c__1);
  1125. scopy_(&ki, &work[n2 + 1], &c__1, &vr[is * vr_dim1 + 1], &
  1126. c__1);
  1127. emax = 0.f;
  1128. i__1 = ki;
  1129. for (k = 1; k <= i__1; ++k) {
  1130. /* Computing MAX */
  1131. r__3 = emax, r__4 = (r__1 = vr[k + (is - 1) * vr_dim1]
  1132. , abs(r__1)) + (r__2 = vr[k + is * vr_dim1],
  1133. abs(r__2));
  1134. emax = f2cmax(r__3,r__4);
  1135. /* L100: */
  1136. }
  1137. remax = 1.f / emax;
  1138. sscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
  1139. sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1140. i__1 = *n;
  1141. for (k = ki + 1; k <= i__1; ++k) {
  1142. vr[k + (is - 1) * vr_dim1] = 0.f;
  1143. vr[k + is * vr_dim1] = 0.f;
  1144. /* L110: */
  1145. }
  1146. } else {
  1147. if (ki > 2) {
  1148. i__1 = ki - 2;
  1149. sgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1150. work[*n + 1], &c__1, &work[ki - 1 + *n], &vr[(
  1151. ki - 1) * vr_dim1 + 1], &c__1);
  1152. i__1 = ki - 2;
  1153. sgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1154. work[n2 + 1], &c__1, &work[ki + n2], &vr[ki *
  1155. vr_dim1 + 1], &c__1);
  1156. } else {
  1157. sscal_(n, &work[ki - 1 + *n], &vr[(ki - 1) * vr_dim1
  1158. + 1], &c__1);
  1159. sscal_(n, &work[ki + n2], &vr[ki * vr_dim1 + 1], &
  1160. c__1);
  1161. }
  1162. emax = 0.f;
  1163. i__1 = *n;
  1164. for (k = 1; k <= i__1; ++k) {
  1165. /* Computing MAX */
  1166. r__3 = emax, r__4 = (r__1 = vr[k + (ki - 1) * vr_dim1]
  1167. , abs(r__1)) + (r__2 = vr[k + ki * vr_dim1],
  1168. abs(r__2));
  1169. emax = f2cmax(r__3,r__4);
  1170. /* L120: */
  1171. }
  1172. remax = 1.f / emax;
  1173. sscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
  1174. sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1175. }
  1176. }
  1177. --is;
  1178. if (ip != 0) {
  1179. --is;
  1180. }
  1181. L130:
  1182. if (ip == 1) {
  1183. ip = 0;
  1184. }
  1185. if (ip == -1) {
  1186. ip = 1;
  1187. }
  1188. /* L140: */
  1189. }
  1190. }
  1191. if (leftv) {
  1192. /* Compute left eigenvectors. */
  1193. ip = 0;
  1194. is = 1;
  1195. i__1 = *n;
  1196. for (ki = 1; ki <= i__1; ++ki) {
  1197. if (ip == -1) {
  1198. goto L250;
  1199. }
  1200. if (ki == *n) {
  1201. goto L150;
  1202. }
  1203. if (t[ki + 1 + ki * t_dim1] == 0.f) {
  1204. goto L150;
  1205. }
  1206. ip = 1;
  1207. L150:
  1208. if (somev) {
  1209. if (! select[ki]) {
  1210. goto L250;
  1211. }
  1212. }
  1213. /* Compute the KI-th eigenvalue (WR,WI). */
  1214. wr = t[ki + ki * t_dim1];
  1215. wi = 0.f;
  1216. if (ip != 0) {
  1217. wi = sqrt((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1))) *
  1218. sqrt((r__2 = t[ki + 1 + ki * t_dim1], abs(r__2)));
  1219. }
  1220. /* Computing MAX */
  1221. r__1 = ulp * (abs(wr) + abs(wi));
  1222. smin = f2cmax(r__1,smlnum);
  1223. if (ip == 0) {
  1224. /* Real left eigenvector. */
  1225. work[ki + *n] = 1.f;
  1226. /* Form right-hand side */
  1227. i__2 = *n;
  1228. for (k = ki + 1; k <= i__2; ++k) {
  1229. work[k + *n] = -t[ki + k * t_dim1];
  1230. /* L160: */
  1231. }
  1232. /* Solve the quasi-triangular system: */
  1233. /* (T(KI+1:N,KI+1:N) - WR)**T*X = SCALE*WORK */
  1234. vmax = 1.f;
  1235. vcrit = bignum;
  1236. jnxt = ki + 1;
  1237. i__2 = *n;
  1238. for (j = ki + 1; j <= i__2; ++j) {
  1239. if (j < jnxt) {
  1240. goto L170;
  1241. }
  1242. j1 = j;
  1243. j2 = j;
  1244. jnxt = j + 1;
  1245. if (j < *n) {
  1246. if (t[j + 1 + j * t_dim1] != 0.f) {
  1247. j2 = j + 1;
  1248. jnxt = j + 2;
  1249. }
  1250. }
  1251. if (j1 == j2) {
  1252. /* 1-by-1 diagonal block */
  1253. /* Scale if necessary to avoid overflow when forming */
  1254. /* the right-hand side. */
  1255. if (work[j] > vcrit) {
  1256. rec = 1.f / vmax;
  1257. i__3 = *n - ki + 1;
  1258. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1259. vmax = 1.f;
  1260. vcrit = bignum;
  1261. }
  1262. i__3 = j - ki - 1;
  1263. work[j + *n] -= sdot_(&i__3, &t[ki + 1 + j * t_dim1],
  1264. &c__1, &work[ki + 1 + *n], &c__1);
  1265. /* Solve (T(J,J)-WR)**T*X = WORK */
  1266. slaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  1267. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1268. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1269. &ierr);
  1270. /* Scale if necessary */
  1271. if (scale != 1.f) {
  1272. i__3 = *n - ki + 1;
  1273. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1274. }
  1275. work[j + *n] = x[0];
  1276. /* Computing MAX */
  1277. r__2 = (r__1 = work[j + *n], abs(r__1));
  1278. vmax = f2cmax(r__2,vmax);
  1279. vcrit = bignum / vmax;
  1280. } else {
  1281. /* 2-by-2 diagonal block */
  1282. /* Scale if necessary to avoid overflow when forming */
  1283. /* the right-hand side. */
  1284. /* Computing MAX */
  1285. r__1 = work[j], r__2 = work[j + 1];
  1286. beta = f2cmax(r__1,r__2);
  1287. if (beta > vcrit) {
  1288. rec = 1.f / vmax;
  1289. i__3 = *n - ki + 1;
  1290. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1291. vmax = 1.f;
  1292. vcrit = bignum;
  1293. }
  1294. i__3 = j - ki - 1;
  1295. work[j + *n] -= sdot_(&i__3, &t[ki + 1 + j * t_dim1],
  1296. &c__1, &work[ki + 1 + *n], &c__1);
  1297. i__3 = j - ki - 1;
  1298. work[j + 1 + *n] -= sdot_(&i__3, &t[ki + 1 + (j + 1) *
  1299. t_dim1], &c__1, &work[ki + 1 + *n], &c__1);
  1300. /* Solve */
  1301. /* [T(J,J)-WR T(J,J+1) ]**T* X = SCALE*( WORK1 ) */
  1302. /* [T(J+1,J) T(J+1,J+1)-WR] ( WORK2 ) */
  1303. slaln2_(&c_true, &c__2, &c__1, &smin, &c_b22, &t[j +
  1304. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1305. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1306. &ierr);
  1307. /* Scale if necessary */
  1308. if (scale != 1.f) {
  1309. i__3 = *n - ki + 1;
  1310. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1311. }
  1312. work[j + *n] = x[0];
  1313. work[j + 1 + *n] = x[1];
  1314. /* Computing MAX */
  1315. r__3 = (r__1 = work[j + *n], abs(r__1)), r__4 = (r__2
  1316. = work[j + 1 + *n], abs(r__2)), r__3 = f2cmax(
  1317. r__3,r__4);
  1318. vmax = f2cmax(r__3,vmax);
  1319. vcrit = bignum / vmax;
  1320. }
  1321. L170:
  1322. ;
  1323. }
  1324. /* Copy the vector x or Q*x to VL and normalize. */
  1325. if (! over) {
  1326. i__2 = *n - ki + 1;
  1327. scopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1328. vl_dim1], &c__1);
  1329. i__2 = *n - ki + 1;
  1330. ii = isamax_(&i__2, &vl[ki + is * vl_dim1], &c__1) + ki -
  1331. 1;
  1332. remax = 1.f / (r__1 = vl[ii + is * vl_dim1], abs(r__1));
  1333. i__2 = *n - ki + 1;
  1334. sscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1335. i__2 = ki - 1;
  1336. for (k = 1; k <= i__2; ++k) {
  1337. vl[k + is * vl_dim1] = 0.f;
  1338. /* L180: */
  1339. }
  1340. } else {
  1341. if (ki < *n) {
  1342. i__2 = *n - ki;
  1343. sgemv_("N", n, &i__2, &c_b22, &vl[(ki + 1) * vl_dim1
  1344. + 1], ldvl, &work[ki + 1 + *n], &c__1, &work[
  1345. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1346. }
  1347. ii = isamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
  1348. remax = 1.f / (r__1 = vl[ii + ki * vl_dim1], abs(r__1));
  1349. sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1350. }
  1351. } else {
  1352. /* Complex left eigenvector. */
  1353. /* Initial solve: */
  1354. /* ((T(KI,KI) T(KI,KI+1) )**T - (WR - I* WI))*X = 0. */
  1355. /* ((T(KI+1,KI) T(KI+1,KI+1)) ) */
  1356. if ((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1)) >= (r__2 =
  1357. t[ki + 1 + ki * t_dim1], abs(r__2))) {
  1358. work[ki + *n] = wi / t[ki + (ki + 1) * t_dim1];
  1359. work[ki + 1 + n2] = 1.f;
  1360. } else {
  1361. work[ki + *n] = 1.f;
  1362. work[ki + 1 + n2] = -wi / t[ki + 1 + ki * t_dim1];
  1363. }
  1364. work[ki + 1 + *n] = 0.f;
  1365. work[ki + n2] = 0.f;
  1366. /* Form right-hand side */
  1367. i__2 = *n;
  1368. for (k = ki + 2; k <= i__2; ++k) {
  1369. work[k + *n] = -work[ki + *n] * t[ki + k * t_dim1];
  1370. work[k + n2] = -work[ki + 1 + n2] * t[ki + 1 + k * t_dim1]
  1371. ;
  1372. /* L190: */
  1373. }
  1374. /* Solve complex quasi-triangular system: */
  1375. /* ( T(KI+2,N:KI+2,N) - (WR-i*WI) )*X = WORK1+i*WORK2 */
  1376. vmax = 1.f;
  1377. vcrit = bignum;
  1378. jnxt = ki + 2;
  1379. i__2 = *n;
  1380. for (j = ki + 2; j <= i__2; ++j) {
  1381. if (j < jnxt) {
  1382. goto L200;
  1383. }
  1384. j1 = j;
  1385. j2 = j;
  1386. jnxt = j + 1;
  1387. if (j < *n) {
  1388. if (t[j + 1 + j * t_dim1] != 0.f) {
  1389. j2 = j + 1;
  1390. jnxt = j + 2;
  1391. }
  1392. }
  1393. if (j1 == j2) {
  1394. /* 1-by-1 diagonal block */
  1395. /* Scale if necessary to avoid overflow when */
  1396. /* forming the right-hand side elements. */
  1397. if (work[j] > vcrit) {
  1398. rec = 1.f / vmax;
  1399. i__3 = *n - ki + 1;
  1400. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1401. i__3 = *n - ki + 1;
  1402. sscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1403. vmax = 1.f;
  1404. vcrit = bignum;
  1405. }
  1406. i__3 = j - ki - 2;
  1407. work[j + *n] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1408. &c__1, &work[ki + 2 + *n], &c__1);
  1409. i__3 = j - ki - 2;
  1410. work[j + n2] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1411. &c__1, &work[ki + 2 + n2], &c__1);
  1412. /* Solve (T(J,J)-(WR-i*WI))*(X11+i*X12)= WK+I*WK2 */
  1413. r__1 = -wi;
  1414. slaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1415. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1416. n], n, &wr, &r__1, x, &c__2, &scale, &xnorm, &
  1417. ierr);
  1418. /* Scale if necessary */
  1419. if (scale != 1.f) {
  1420. i__3 = *n - ki + 1;
  1421. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1422. i__3 = *n - ki + 1;
  1423. sscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1424. }
  1425. work[j + *n] = x[0];
  1426. work[j + n2] = x[2];
  1427. /* Computing MAX */
  1428. r__3 = (r__1 = work[j + *n], abs(r__1)), r__4 = (r__2
  1429. = work[j + n2], abs(r__2)), r__3 = f2cmax(r__3,
  1430. r__4);
  1431. vmax = f2cmax(r__3,vmax);
  1432. vcrit = bignum / vmax;
  1433. } else {
  1434. /* 2-by-2 diagonal block */
  1435. /* Scale if necessary to avoid overflow when forming */
  1436. /* the right-hand side elements. */
  1437. /* Computing MAX */
  1438. r__1 = work[j], r__2 = work[j + 1];
  1439. beta = f2cmax(r__1,r__2);
  1440. if (beta > vcrit) {
  1441. rec = 1.f / vmax;
  1442. i__3 = *n - ki + 1;
  1443. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1444. i__3 = *n - ki + 1;
  1445. sscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1446. vmax = 1.f;
  1447. vcrit = bignum;
  1448. }
  1449. i__3 = j - ki - 2;
  1450. work[j + *n] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1451. &c__1, &work[ki + 2 + *n], &c__1);
  1452. i__3 = j - ki - 2;
  1453. work[j + n2] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1454. &c__1, &work[ki + 2 + n2], &c__1);
  1455. i__3 = j - ki - 2;
  1456. work[j + 1 + *n] -= sdot_(&i__3, &t[ki + 2 + (j + 1) *
  1457. t_dim1], &c__1, &work[ki + 2 + *n], &c__1);
  1458. i__3 = j - ki - 2;
  1459. work[j + 1 + n2] -= sdot_(&i__3, &t[ki + 2 + (j + 1) *
  1460. t_dim1], &c__1, &work[ki + 2 + n2], &c__1);
  1461. /* Solve 2-by-2 complex linear equation */
  1462. /* ([T(j,j) T(j,j+1) ]**T-(wr-i*wi)*I)*X = SCALE*B */
  1463. /* ([T(j+1,j) T(j+1,j+1)] ) */
  1464. r__1 = -wi;
  1465. slaln2_(&c_true, &c__2, &c__2, &smin, &c_b22, &t[j +
  1466. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1467. n], n, &wr, &r__1, x, &c__2, &scale, &xnorm, &
  1468. ierr);
  1469. /* Scale if necessary */
  1470. if (scale != 1.f) {
  1471. i__3 = *n - ki + 1;
  1472. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1473. i__3 = *n - ki + 1;
  1474. sscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1475. }
  1476. work[j + *n] = x[0];
  1477. work[j + n2] = x[2];
  1478. work[j + 1 + *n] = x[1];
  1479. work[j + 1 + n2] = x[3];
  1480. /* Computing MAX */
  1481. r__1 = abs(x[0]), r__2 = abs(x[2]), r__1 = f2cmax(r__1,
  1482. r__2), r__2 = abs(x[1]), r__1 = f2cmax(r__1,r__2)
  1483. , r__2 = abs(x[3]), r__1 = f2cmax(r__1,r__2);
  1484. vmax = f2cmax(r__1,vmax);
  1485. vcrit = bignum / vmax;
  1486. }
  1487. L200:
  1488. ;
  1489. }
  1490. /* Copy the vector x or Q*x to VL and normalize. */
  1491. if (! over) {
  1492. i__2 = *n - ki + 1;
  1493. scopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1494. vl_dim1], &c__1);
  1495. i__2 = *n - ki + 1;
  1496. scopy_(&i__2, &work[ki + n2], &c__1, &vl[ki + (is + 1) *
  1497. vl_dim1], &c__1);
  1498. emax = 0.f;
  1499. i__2 = *n;
  1500. for (k = ki; k <= i__2; ++k) {
  1501. /* Computing MAX */
  1502. r__3 = emax, r__4 = (r__1 = vl[k + is * vl_dim1], abs(
  1503. r__1)) + (r__2 = vl[k + (is + 1) * vl_dim1],
  1504. abs(r__2));
  1505. emax = f2cmax(r__3,r__4);
  1506. /* L220: */
  1507. }
  1508. remax = 1.f / emax;
  1509. i__2 = *n - ki + 1;
  1510. sscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1511. i__2 = *n - ki + 1;
  1512. sscal_(&i__2, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
  1513. ;
  1514. i__2 = ki - 1;
  1515. for (k = 1; k <= i__2; ++k) {
  1516. vl[k + is * vl_dim1] = 0.f;
  1517. vl[k + (is + 1) * vl_dim1] = 0.f;
  1518. /* L230: */
  1519. }
  1520. } else {
  1521. if (ki < *n - 1) {
  1522. i__2 = *n - ki - 1;
  1523. sgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1524. + 1], ldvl, &work[ki + 2 + *n], &c__1, &work[
  1525. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1526. i__2 = *n - ki - 1;
  1527. sgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1528. + 1], ldvl, &work[ki + 2 + n2], &c__1, &work[
  1529. ki + 1 + n2], &vl[(ki + 1) * vl_dim1 + 1], &
  1530. c__1);
  1531. } else {
  1532. sscal_(n, &work[ki + *n], &vl[ki * vl_dim1 + 1], &
  1533. c__1);
  1534. sscal_(n, &work[ki + 1 + n2], &vl[(ki + 1) * vl_dim1
  1535. + 1], &c__1);
  1536. }
  1537. emax = 0.f;
  1538. i__2 = *n;
  1539. for (k = 1; k <= i__2; ++k) {
  1540. /* Computing MAX */
  1541. r__3 = emax, r__4 = (r__1 = vl[k + ki * vl_dim1], abs(
  1542. r__1)) + (r__2 = vl[k + (ki + 1) * vl_dim1],
  1543. abs(r__2));
  1544. emax = f2cmax(r__3,r__4);
  1545. /* L240: */
  1546. }
  1547. remax = 1.f / emax;
  1548. sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1549. sscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
  1550. }
  1551. }
  1552. ++is;
  1553. if (ip != 0) {
  1554. ++is;
  1555. }
  1556. L250:
  1557. if (ip == -1) {
  1558. ip = 0;
  1559. }
  1560. if (ip == 1) {
  1561. ip = -1;
  1562. }
  1563. /* L260: */
  1564. }
  1565. }
  1566. return;
  1567. /* End of STREVC */
  1568. } /* strevc_ */