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 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 logical c_false = FALSE_;
  487. static integer c__1 = 1;
  488. static real c_b22 = 1.f;
  489. static real c_b25 = 0.f;
  490. static integer c__2 = 2;
  491. static logical c_true = TRUE_;
  492. /* > \brief \b STREVC */
  493. /* =========== DOCUMENTATION =========== */
  494. /* Online html documentation available at */
  495. /* http://www.netlib.org/lapack/explore-html/ */
  496. /* > \htmlonly */
  497. /* > Download STREVC + dependencies */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/strevc.
  499. f"> */
  500. /* > [TGZ]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/strevc.
  502. f"> */
  503. /* > [ZIP]</a> */
  504. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/strevc.
  505. f"> */
  506. /* > [TXT]</a> */
  507. /* > \endhtmlonly */
  508. /* Definition: */
  509. /* =========== */
  510. /* SUBROUTINE STREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR, */
  511. /* LDVR, MM, M, WORK, INFO ) */
  512. /* CHARACTER HOWMNY, SIDE */
  513. /* INTEGER INFO, LDT, LDVL, LDVR, M, MM, N */
  514. /* LOGICAL SELECT( * ) */
  515. /* REAL T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ), */
  516. /* $ WORK( * ) */
  517. /* > \par Purpose: */
  518. /* ============= */
  519. /* > */
  520. /* > \verbatim */
  521. /* > */
  522. /* > STREVC computes some or all of the right and/or left eigenvectors of */
  523. /* > a real upper quasi-triangular matrix T. */
  524. /* > Matrices of this type are produced by the Schur factorization of */
  525. /* > a real general matrix: A = Q*T*Q**T, as computed by SHSEQR. */
  526. /* > */
  527. /* > The right eigenvector x and the left eigenvector y of T corresponding */
  528. /* > to an eigenvalue w are defined by: */
  529. /* > */
  530. /* > T*x = w*x, (y**H)*T = w*(y**H) */
  531. /* > */
  532. /* > where y**H denotes the conjugate transpose of y. */
  533. /* > The eigenvalues are not input to this routine, but are read directly */
  534. /* > from the diagonal blocks of T. */
  535. /* > */
  536. /* > This routine returns the matrices X and/or Y of right and left */
  537. /* > eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an */
  538. /* > input matrix. If Q is the orthogonal factor that reduces a matrix */
  539. /* > A to Schur form T, then Q*X and Q*Y are the matrices of right and */
  540. /* > left eigenvectors of A. */
  541. /* > \endverbatim */
  542. /* Arguments: */
  543. /* ========== */
  544. /* > \param[in] SIDE */
  545. /* > \verbatim */
  546. /* > SIDE is CHARACTER*1 */
  547. /* > = 'R': compute right eigenvectors only; */
  548. /* > = 'L': compute left eigenvectors only; */
  549. /* > = 'B': compute both right and left eigenvectors. */
  550. /* > \endverbatim */
  551. /* > */
  552. /* > \param[in] HOWMNY */
  553. /* > \verbatim */
  554. /* > HOWMNY is CHARACTER*1 */
  555. /* > = 'A': compute all right and/or left eigenvectors; */
  556. /* > = 'B': compute all right and/or left eigenvectors, */
  557. /* > backtransformed by the matrices in VR and/or VL; */
  558. /* > = 'S': compute selected right and/or left eigenvectors, */
  559. /* > as indicated by the logical array SELECT. */
  560. /* > \endverbatim */
  561. /* > */
  562. /* > \param[in,out] SELECT */
  563. /* > \verbatim */
  564. /* > SELECT is LOGICAL array, dimension (N) */
  565. /* > If HOWMNY = 'S', SELECT specifies the eigenvectors to be */
  566. /* > computed. */
  567. /* > If w(j) is a real eigenvalue, the corresponding real */
  568. /* > eigenvector is computed if SELECT(j) is .TRUE.. */
  569. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  570. /* > complex eigenvalue, the corresponding complex eigenvector is */
  571. /* > computed if either SELECT(j) or SELECT(j+1) is .TRUE., and */
  572. /* > on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to */
  573. /* > .FALSE.. */
  574. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in] N */
  578. /* > \verbatim */
  579. /* > N is INTEGER */
  580. /* > The order of the matrix T. N >= 0. */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[in] T */
  584. /* > \verbatim */
  585. /* > T is REAL array, dimension (LDT,N) */
  586. /* > The upper quasi-triangular matrix T in Schur canonical form. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] LDT */
  590. /* > \verbatim */
  591. /* > LDT is INTEGER */
  592. /* > The leading dimension of the array T. LDT >= f2cmax(1,N). */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in,out] VL */
  596. /* > \verbatim */
  597. /* > VL is REAL array, dimension (LDVL,MM) */
  598. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  599. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  600. /* > of Schur vectors returned by SHSEQR). */
  601. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  602. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of T; */
  603. /* > if HOWMNY = 'B', the matrix Q*Y; */
  604. /* > if HOWMNY = 'S', the left eigenvectors of T specified by */
  605. /* > SELECT, stored consecutively in the columns */
  606. /* > of VL, in the same order as their */
  607. /* > eigenvalues. */
  608. /* > A complex eigenvector corresponding to a complex eigenvalue */
  609. /* > is stored in two consecutive columns, the first holding the */
  610. /* > real part, and the second the imaginary part. */
  611. /* > Not referenced if SIDE = 'R'. */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in] LDVL */
  615. /* > \verbatim */
  616. /* > LDVL is INTEGER */
  617. /* > The leading dimension of the array VL. LDVL >= 1, and if */
  618. /* > SIDE = 'L' or 'B', LDVL >= N. */
  619. /* > \endverbatim */
  620. /* > */
  621. /* > \param[in,out] VR */
  622. /* > \verbatim */
  623. /* > VR is REAL array, dimension (LDVR,MM) */
  624. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  625. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  626. /* > of Schur vectors returned by SHSEQR). */
  627. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  628. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of T; */
  629. /* > if HOWMNY = 'B', the matrix Q*X; */
  630. /* > if HOWMNY = 'S', the right eigenvectors of T specified by */
  631. /* > SELECT, stored consecutively in the columns */
  632. /* > of VR, in the same order as their */
  633. /* > eigenvalues. */
  634. /* > A complex eigenvector corresponding to a complex eigenvalue */
  635. /* > is stored in two consecutive columns, the first holding the */
  636. /* > real part and the second the imaginary part. */
  637. /* > Not referenced if SIDE = 'L'. */
  638. /* > \endverbatim */
  639. /* > */
  640. /* > \param[in] LDVR */
  641. /* > \verbatim */
  642. /* > LDVR is INTEGER */
  643. /* > The leading dimension of the array VR. LDVR >= 1, and if */
  644. /* > SIDE = 'R' or 'B', LDVR >= N. */
  645. /* > \endverbatim */
  646. /* > */
  647. /* > \param[in] MM */
  648. /* > \verbatim */
  649. /* > MM is INTEGER */
  650. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  651. /* > \endverbatim */
  652. /* > */
  653. /* > \param[out] M */
  654. /* > \verbatim */
  655. /* > M is INTEGER */
  656. /* > The number of columns in the arrays VL and/or VR actually */
  657. /* > used to store the eigenvectors. */
  658. /* > If HOWMNY = 'A' or 'B', M is set to N. */
  659. /* > Each selected real eigenvector occupies one column and each */
  660. /* > selected complex eigenvector occupies two columns. */
  661. /* > \endverbatim */
  662. /* > */
  663. /* > \param[out] WORK */
  664. /* > \verbatim */
  665. /* > WORK is REAL array, dimension (3*N) */
  666. /* > \endverbatim */
  667. /* > */
  668. /* > \param[out] INFO */
  669. /* > \verbatim */
  670. /* > INFO is INTEGER */
  671. /* > = 0: successful exit */
  672. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  673. /* > \endverbatim */
  674. /* Authors: */
  675. /* ======== */
  676. /* > \author Univ. of Tennessee */
  677. /* > \author Univ. of California Berkeley */
  678. /* > \author Univ. of Colorado Denver */
  679. /* > \author NAG Ltd. */
  680. /* > \date December 2016 */
  681. /* > \ingroup realOTHERcomputational */
  682. /* > \par Further Details: */
  683. /* ===================== */
  684. /* > */
  685. /* > \verbatim */
  686. /* > */
  687. /* > The algorithm used in this program is basically backward (forward) */
  688. /* > substitution, with scaling to make the the code robust against */
  689. /* > possible overflow. */
  690. /* > */
  691. /* > Each eigenvector is normalized so that the element of largest */
  692. /* > magnitude has magnitude 1; here the magnitude of a complex number */
  693. /* > (x,y) is taken to be |x| + |y|. */
  694. /* > \endverbatim */
  695. /* > */
  696. /* ===================================================================== */
  697. /* Subroutine */ void strevc_(char *side, char *howmny, logical *select,
  698. integer *n, real *t, integer *ldt, real *vl, integer *ldvl, real *vr,
  699. integer *ldvr, integer *mm, integer *m, real *work, integer *info)
  700. {
  701. /* System generated locals */
  702. integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  703. i__2, i__3;
  704. real r__1, r__2, r__3, r__4;
  705. /* Local variables */
  706. real beta, emax;
  707. logical pair, allv;
  708. integer ierr;
  709. real unfl, ovfl, smin;
  710. extern real sdot_(integer *, real *, integer *, real *, integer *);
  711. logical over;
  712. real vmax;
  713. integer jnxt, i__, j, k;
  714. real scale, x[4] /* was [2][2] */;
  715. extern logical lsame_(char *, char *);
  716. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  717. real remax;
  718. logical leftv;
  719. extern /* Subroutine */ void sgemv_(char *, integer *, integer *, real *,
  720. real *, integer *, real *, integer *, real *, real *, integer *);
  721. logical bothv;
  722. real vcrit;
  723. logical somev;
  724. integer j1, j2;
  725. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  726. integer *);
  727. integer n2;
  728. real xnorm;
  729. extern /* Subroutine */ void saxpy_(integer *, real *, real *, integer *,
  730. real *, integer *), slaln2_(logical *, integer *, integer *, real
  731. *, real *, real *, integer *, real *, real *, real *, integer *,
  732. real *, real *, real *, integer *, real *, real *, integer *);
  733. integer ii, ki;
  734. extern /* Subroutine */ void slabad_(real *, real *);
  735. integer ip, is;
  736. real wi;
  737. extern real slamch_(char *);
  738. real wr;
  739. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  740. real bignum;
  741. extern integer isamax_(integer *, real *, integer *);
  742. logical rightv;
  743. real smlnum, rec, ulp;
  744. /* -- LAPACK computational routine (version 3.7.0) -- */
  745. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  746. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  747. /* December 2016 */
  748. /* ===================================================================== */
  749. /* Decode and test the input parameters */
  750. /* Parameter adjustments */
  751. --select;
  752. t_dim1 = *ldt;
  753. t_offset = 1 + t_dim1 * 1;
  754. t -= t_offset;
  755. vl_dim1 = *ldvl;
  756. vl_offset = 1 + vl_dim1 * 1;
  757. vl -= vl_offset;
  758. vr_dim1 = *ldvr;
  759. vr_offset = 1 + vr_dim1 * 1;
  760. vr -= vr_offset;
  761. --work;
  762. /* Function Body */
  763. bothv = lsame_(side, "B");
  764. rightv = lsame_(side, "R") || bothv;
  765. leftv = lsame_(side, "L") || bothv;
  766. allv = lsame_(howmny, "A");
  767. over = lsame_(howmny, "B");
  768. somev = lsame_(howmny, "S");
  769. *info = 0;
  770. if (! rightv && ! leftv) {
  771. *info = -1;
  772. } else if (! allv && ! over && ! somev) {
  773. *info = -2;
  774. } else if (*n < 0) {
  775. *info = -4;
  776. } else if (*ldt < f2cmax(1,*n)) {
  777. *info = -6;
  778. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  779. *info = -8;
  780. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  781. *info = -10;
  782. } else {
  783. /* Set M to the number of columns required to store the selected */
  784. /* eigenvectors, standardize the array SELECT if necessary, and */
  785. /* test MM. */
  786. if (somev) {
  787. *m = 0;
  788. pair = FALSE_;
  789. i__1 = *n;
  790. for (j = 1; j <= i__1; ++j) {
  791. if (pair) {
  792. pair = FALSE_;
  793. select[j] = FALSE_;
  794. } else {
  795. if (j < *n) {
  796. if (t[j + 1 + j * t_dim1] == 0.f) {
  797. if (select[j]) {
  798. ++(*m);
  799. }
  800. } else {
  801. pair = TRUE_;
  802. if (select[j] || select[j + 1]) {
  803. select[j] = TRUE_;
  804. *m += 2;
  805. }
  806. }
  807. } else {
  808. if (select[*n]) {
  809. ++(*m);
  810. }
  811. }
  812. }
  813. /* L10: */
  814. }
  815. } else {
  816. *m = *n;
  817. }
  818. if (*mm < *m) {
  819. *info = -11;
  820. }
  821. }
  822. if (*info != 0) {
  823. i__1 = -(*info);
  824. xerbla_("STREVC", &i__1, (ftnlen)6);
  825. return;
  826. }
  827. /* Quick return if possible. */
  828. if (*n == 0) {
  829. return;
  830. }
  831. /* Set the constants to control overflow. */
  832. unfl = slamch_("Safe minimum");
  833. ovfl = 1.f / unfl;
  834. slabad_(&unfl, &ovfl);
  835. ulp = slamch_("Precision");
  836. smlnum = unfl * (*n / ulp);
  837. bignum = (1.f - ulp) / smlnum;
  838. /* Compute 1-norm of each column of strictly upper triangular */
  839. /* part of T to control overflow in triangular solver. */
  840. work[1] = 0.f;
  841. i__1 = *n;
  842. for (j = 2; j <= i__1; ++j) {
  843. work[j] = 0.f;
  844. i__2 = j - 1;
  845. for (i__ = 1; i__ <= i__2; ++i__) {
  846. work[j] += (r__1 = t[i__ + j * t_dim1], abs(r__1));
  847. /* L20: */
  848. }
  849. /* L30: */
  850. }
  851. /* Index IP is used to specify the real or complex eigenvalue: */
  852. /* IP = 0, real eigenvalue, */
  853. /* 1, first of conjugate complex pair: (wr,wi) */
  854. /* -1, second of conjugate complex pair: (wr,wi) */
  855. n2 = *n << 1;
  856. if (rightv) {
  857. /* Compute right eigenvectors. */
  858. ip = 0;
  859. is = *m;
  860. for (ki = *n; ki >= 1; --ki) {
  861. if (ip == 1) {
  862. goto L130;
  863. }
  864. if (ki == 1) {
  865. goto L40;
  866. }
  867. if (t[ki + (ki - 1) * t_dim1] == 0.f) {
  868. goto L40;
  869. }
  870. ip = -1;
  871. L40:
  872. if (somev) {
  873. if (ip == 0) {
  874. if (! select[ki]) {
  875. goto L130;
  876. }
  877. } else {
  878. if (! select[ki - 1]) {
  879. goto L130;
  880. }
  881. }
  882. }
  883. /* Compute the KI-th eigenvalue (WR,WI). */
  884. wr = t[ki + ki * t_dim1];
  885. wi = 0.f;
  886. if (ip != 0) {
  887. wi = sqrt((r__1 = t[ki + (ki - 1) * t_dim1], abs(r__1))) *
  888. sqrt((r__2 = t[ki - 1 + ki * t_dim1], abs(r__2)));
  889. }
  890. /* Computing MAX */
  891. r__1 = ulp * (abs(wr) + abs(wi));
  892. smin = f2cmax(r__1,smlnum);
  893. if (ip == 0) {
  894. /* Real right eigenvector */
  895. work[ki + *n] = 1.f;
  896. /* Form right-hand side */
  897. i__1 = ki - 1;
  898. for (k = 1; k <= i__1; ++k) {
  899. work[k + *n] = -t[k + ki * t_dim1];
  900. /* L50: */
  901. }
  902. /* Solve the upper quasi-triangular system: */
  903. /* (T(1:KI-1,1:KI-1) - WR)*X = SCALE*WORK. */
  904. jnxt = ki - 1;
  905. for (j = ki - 1; j >= 1; --j) {
  906. if (j > jnxt) {
  907. goto L60;
  908. }
  909. j1 = j;
  910. j2 = j;
  911. jnxt = j - 1;
  912. if (j > 1) {
  913. if (t[j + (j - 1) * t_dim1] != 0.f) {
  914. j1 = j - 1;
  915. jnxt = j - 2;
  916. }
  917. }
  918. if (j1 == j2) {
  919. /* 1-by-1 diagonal block */
  920. slaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  921. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  922. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  923. &ierr);
  924. /* Scale X(1,1) to avoid overflow when updating */
  925. /* the right-hand side. */
  926. if (xnorm > 1.f) {
  927. if (work[j] > bignum / xnorm) {
  928. x[0] /= xnorm;
  929. scale /= xnorm;
  930. }
  931. }
  932. /* Scale if necessary */
  933. if (scale != 1.f) {
  934. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  935. }
  936. work[j + *n] = x[0];
  937. /* Update right-hand side */
  938. i__1 = j - 1;
  939. r__1 = -x[0];
  940. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  941. *n + 1], &c__1);
  942. } else {
  943. /* 2-by-2 diagonal block */
  944. slaln2_(&c_false, &c__2, &c__1, &smin, &c_b22, &t[j -
  945. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  946. work[j - 1 + *n], n, &wr, &c_b25, x, &c__2, &
  947. scale, &xnorm, &ierr);
  948. /* Scale X(1,1) and X(2,1) to avoid overflow when */
  949. /* updating the right-hand side. */
  950. if (xnorm > 1.f) {
  951. /* Computing MAX */
  952. r__1 = work[j - 1], r__2 = work[j];
  953. beta = f2cmax(r__1,r__2);
  954. if (beta > bignum / xnorm) {
  955. x[0] /= xnorm;
  956. x[1] /= xnorm;
  957. scale /= xnorm;
  958. }
  959. }
  960. /* Scale if necessary */
  961. if (scale != 1.f) {
  962. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  963. }
  964. work[j - 1 + *n] = x[0];
  965. work[j + *n] = x[1];
  966. /* Update right-hand side */
  967. i__1 = j - 2;
  968. r__1 = -x[0];
  969. saxpy_(&i__1, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  970. &work[*n + 1], &c__1);
  971. i__1 = j - 2;
  972. r__1 = -x[1];
  973. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  974. *n + 1], &c__1);
  975. }
  976. L60:
  977. ;
  978. }
  979. /* Copy the vector x or Q*x to VR and normalize. */
  980. if (! over) {
  981. scopy_(&ki, &work[*n + 1], &c__1, &vr[is * vr_dim1 + 1], &
  982. c__1);
  983. ii = isamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
  984. remax = 1.f / (r__1 = vr[ii + is * vr_dim1], abs(r__1));
  985. sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  986. i__1 = *n;
  987. for (k = ki + 1; k <= i__1; ++k) {
  988. vr[k + is * vr_dim1] = 0.f;
  989. /* L70: */
  990. }
  991. } else {
  992. if (ki > 1) {
  993. i__1 = ki - 1;
  994. sgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  995. work[*n + 1], &c__1, &work[ki + *n], &vr[ki *
  996. vr_dim1 + 1], &c__1);
  997. }
  998. ii = isamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
  999. remax = 1.f / (r__1 = vr[ii + ki * vr_dim1], abs(r__1));
  1000. sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1001. }
  1002. } else {
  1003. /* Complex right eigenvector. */
  1004. /* Initial solve */
  1005. /* [ (T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I* WI)]*X = 0. */
  1006. /* [ (T(KI,KI-1) T(KI,KI) ) ] */
  1007. if ((r__1 = t[ki - 1 + ki * t_dim1], abs(r__1)) >= (r__2 = t[
  1008. ki + (ki - 1) * t_dim1], abs(r__2))) {
  1009. work[ki - 1 + *n] = 1.f;
  1010. work[ki + n2] = wi / t[ki - 1 + ki * t_dim1];
  1011. } else {
  1012. work[ki - 1 + *n] = -wi / t[ki + (ki - 1) * t_dim1];
  1013. work[ki + n2] = 1.f;
  1014. }
  1015. work[ki + *n] = 0.f;
  1016. work[ki - 1 + n2] = 0.f;
  1017. /* Form right-hand side */
  1018. i__1 = ki - 2;
  1019. for (k = 1; k <= i__1; ++k) {
  1020. work[k + *n] = -work[ki - 1 + *n] * t[k + (ki - 1) *
  1021. t_dim1];
  1022. work[k + n2] = -work[ki + n2] * t[k + ki * t_dim1];
  1023. /* L80: */
  1024. }
  1025. /* Solve upper quasi-triangular system: */
  1026. /* (T(1:KI-2,1:KI-2) - (WR+i*WI))*X = SCALE*(WORK+i*WORK2) */
  1027. jnxt = ki - 2;
  1028. for (j = ki - 2; j >= 1; --j) {
  1029. if (j > jnxt) {
  1030. goto L90;
  1031. }
  1032. j1 = j;
  1033. j2 = j;
  1034. jnxt = j - 1;
  1035. if (j > 1) {
  1036. if (t[j + (j - 1) * t_dim1] != 0.f) {
  1037. j1 = j - 1;
  1038. jnxt = j - 2;
  1039. }
  1040. }
  1041. if (j1 == j2) {
  1042. /* 1-by-1 diagonal block */
  1043. slaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1044. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1045. n], n, &wr, &wi, x, &c__2, &scale, &xnorm, &
  1046. ierr);
  1047. /* Scale X(1,1) and X(1,2) to avoid overflow when */
  1048. /* updating the right-hand side. */
  1049. if (xnorm > 1.f) {
  1050. if (work[j] > bignum / xnorm) {
  1051. x[0] /= xnorm;
  1052. x[2] /= xnorm;
  1053. scale /= xnorm;
  1054. }
  1055. }
  1056. /* Scale if necessary */
  1057. if (scale != 1.f) {
  1058. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  1059. sscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1060. }
  1061. work[j + *n] = x[0];
  1062. work[j + n2] = x[2];
  1063. /* Update the right-hand side */
  1064. i__1 = j - 1;
  1065. r__1 = -x[0];
  1066. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1067. *n + 1], &c__1);
  1068. i__1 = j - 1;
  1069. r__1 = -x[2];
  1070. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1071. n2 + 1], &c__1);
  1072. } else {
  1073. /* 2-by-2 diagonal block */
  1074. slaln2_(&c_false, &c__2, &c__2, &smin, &c_b22, &t[j -
  1075. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  1076. work[j - 1 + *n], n, &wr, &wi, x, &c__2, &
  1077. scale, &xnorm, &ierr);
  1078. /* Scale X to avoid overflow when updating */
  1079. /* the right-hand side. */
  1080. if (xnorm > 1.f) {
  1081. /* Computing MAX */
  1082. r__1 = work[j - 1], r__2 = work[j];
  1083. beta = f2cmax(r__1,r__2);
  1084. if (beta > bignum / xnorm) {
  1085. rec = 1.f / xnorm;
  1086. x[0] *= rec;
  1087. x[2] *= rec;
  1088. x[1] *= rec;
  1089. x[3] *= rec;
  1090. scale *= rec;
  1091. }
  1092. }
  1093. /* Scale if necessary */
  1094. if (scale != 1.f) {
  1095. sscal_(&ki, &scale, &work[*n + 1], &c__1);
  1096. sscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1097. }
  1098. work[j - 1 + *n] = x[0];
  1099. work[j + *n] = x[1];
  1100. work[j - 1 + n2] = x[2];
  1101. work[j + n2] = x[3];
  1102. /* Update the right-hand side */
  1103. i__1 = j - 2;
  1104. r__1 = -x[0];
  1105. saxpy_(&i__1, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1106. &work[*n + 1], &c__1);
  1107. i__1 = j - 2;
  1108. r__1 = -x[1];
  1109. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1110. *n + 1], &c__1);
  1111. i__1 = j - 2;
  1112. r__1 = -x[2];
  1113. saxpy_(&i__1, &r__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1114. &work[n2 + 1], &c__1);
  1115. i__1 = j - 2;
  1116. r__1 = -x[3];
  1117. saxpy_(&i__1, &r__1, &t[j * t_dim1 + 1], &c__1, &work[
  1118. n2 + 1], &c__1);
  1119. }
  1120. L90:
  1121. ;
  1122. }
  1123. /* Copy the vector x or Q*x to VR and normalize. */
  1124. if (! over) {
  1125. scopy_(&ki, &work[*n + 1], &c__1, &vr[(is - 1) * vr_dim1
  1126. + 1], &c__1);
  1127. scopy_(&ki, &work[n2 + 1], &c__1, &vr[is * vr_dim1 + 1], &
  1128. c__1);
  1129. emax = 0.f;
  1130. i__1 = ki;
  1131. for (k = 1; k <= i__1; ++k) {
  1132. /* Computing MAX */
  1133. r__3 = emax, r__4 = (r__1 = vr[k + (is - 1) * vr_dim1]
  1134. , abs(r__1)) + (r__2 = vr[k + is * vr_dim1],
  1135. abs(r__2));
  1136. emax = f2cmax(r__3,r__4);
  1137. /* L100: */
  1138. }
  1139. remax = 1.f / emax;
  1140. sscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
  1141. sscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1142. i__1 = *n;
  1143. for (k = ki + 1; k <= i__1; ++k) {
  1144. vr[k + (is - 1) * vr_dim1] = 0.f;
  1145. vr[k + is * vr_dim1] = 0.f;
  1146. /* L110: */
  1147. }
  1148. } else {
  1149. if (ki > 2) {
  1150. i__1 = ki - 2;
  1151. sgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1152. work[*n + 1], &c__1, &work[ki - 1 + *n], &vr[(
  1153. ki - 1) * vr_dim1 + 1], &c__1);
  1154. i__1 = ki - 2;
  1155. sgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1156. work[n2 + 1], &c__1, &work[ki + n2], &vr[ki *
  1157. vr_dim1 + 1], &c__1);
  1158. } else {
  1159. sscal_(n, &work[ki - 1 + *n], &vr[(ki - 1) * vr_dim1
  1160. + 1], &c__1);
  1161. sscal_(n, &work[ki + n2], &vr[ki * vr_dim1 + 1], &
  1162. c__1);
  1163. }
  1164. emax = 0.f;
  1165. i__1 = *n;
  1166. for (k = 1; k <= i__1; ++k) {
  1167. /* Computing MAX */
  1168. r__3 = emax, r__4 = (r__1 = vr[k + (ki - 1) * vr_dim1]
  1169. , abs(r__1)) + (r__2 = vr[k + ki * vr_dim1],
  1170. abs(r__2));
  1171. emax = f2cmax(r__3,r__4);
  1172. /* L120: */
  1173. }
  1174. remax = 1.f / emax;
  1175. sscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
  1176. sscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1177. }
  1178. }
  1179. --is;
  1180. if (ip != 0) {
  1181. --is;
  1182. }
  1183. L130:
  1184. if (ip == 1) {
  1185. ip = 0;
  1186. }
  1187. if (ip == -1) {
  1188. ip = 1;
  1189. }
  1190. /* L140: */
  1191. }
  1192. }
  1193. if (leftv) {
  1194. /* Compute left eigenvectors. */
  1195. ip = 0;
  1196. is = 1;
  1197. i__1 = *n;
  1198. for (ki = 1; ki <= i__1; ++ki) {
  1199. if (ip == -1) {
  1200. goto L250;
  1201. }
  1202. if (ki == *n) {
  1203. goto L150;
  1204. }
  1205. if (t[ki + 1 + ki * t_dim1] == 0.f) {
  1206. goto L150;
  1207. }
  1208. ip = 1;
  1209. L150:
  1210. if (somev) {
  1211. if (! select[ki]) {
  1212. goto L250;
  1213. }
  1214. }
  1215. /* Compute the KI-th eigenvalue (WR,WI). */
  1216. wr = t[ki + ki * t_dim1];
  1217. wi = 0.f;
  1218. if (ip != 0) {
  1219. wi = sqrt((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1))) *
  1220. sqrt((r__2 = t[ki + 1 + ki * t_dim1], abs(r__2)));
  1221. }
  1222. /* Computing MAX */
  1223. r__1 = ulp * (abs(wr) + abs(wi));
  1224. smin = f2cmax(r__1,smlnum);
  1225. if (ip == 0) {
  1226. /* Real left eigenvector. */
  1227. work[ki + *n] = 1.f;
  1228. /* Form right-hand side */
  1229. i__2 = *n;
  1230. for (k = ki + 1; k <= i__2; ++k) {
  1231. work[k + *n] = -t[ki + k * t_dim1];
  1232. /* L160: */
  1233. }
  1234. /* Solve the quasi-triangular system: */
  1235. /* (T(KI+1:N,KI+1:N) - WR)**T*X = SCALE*WORK */
  1236. vmax = 1.f;
  1237. vcrit = bignum;
  1238. jnxt = ki + 1;
  1239. i__2 = *n;
  1240. for (j = ki + 1; j <= i__2; ++j) {
  1241. if (j < jnxt) {
  1242. goto L170;
  1243. }
  1244. j1 = j;
  1245. j2 = j;
  1246. jnxt = j + 1;
  1247. if (j < *n) {
  1248. if (t[j + 1 + j * t_dim1] != 0.f) {
  1249. j2 = j + 1;
  1250. jnxt = j + 2;
  1251. }
  1252. }
  1253. if (j1 == j2) {
  1254. /* 1-by-1 diagonal block */
  1255. /* Scale if necessary to avoid overflow when forming */
  1256. /* the right-hand side. */
  1257. if (work[j] > vcrit) {
  1258. rec = 1.f / vmax;
  1259. i__3 = *n - ki + 1;
  1260. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1261. vmax = 1.f;
  1262. vcrit = bignum;
  1263. }
  1264. i__3 = j - ki - 1;
  1265. work[j + *n] -= sdot_(&i__3, &t[ki + 1 + j * t_dim1],
  1266. &c__1, &work[ki + 1 + *n], &c__1);
  1267. /* Solve (T(J,J)-WR)**T*X = WORK */
  1268. slaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  1269. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1270. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1271. &ierr);
  1272. /* Scale if necessary */
  1273. if (scale != 1.f) {
  1274. i__3 = *n - ki + 1;
  1275. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1276. }
  1277. work[j + *n] = x[0];
  1278. /* Computing MAX */
  1279. r__2 = (r__1 = work[j + *n], abs(r__1));
  1280. vmax = f2cmax(r__2,vmax);
  1281. vcrit = bignum / vmax;
  1282. } else {
  1283. /* 2-by-2 diagonal block */
  1284. /* Scale if necessary to avoid overflow when forming */
  1285. /* the right-hand side. */
  1286. /* Computing MAX */
  1287. r__1 = work[j], r__2 = work[j + 1];
  1288. beta = f2cmax(r__1,r__2);
  1289. if (beta > vcrit) {
  1290. rec = 1.f / vmax;
  1291. i__3 = *n - ki + 1;
  1292. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1293. vmax = 1.f;
  1294. vcrit = bignum;
  1295. }
  1296. i__3 = j - ki - 1;
  1297. work[j + *n] -= sdot_(&i__3, &t[ki + 1 + j * t_dim1],
  1298. &c__1, &work[ki + 1 + *n], &c__1);
  1299. i__3 = j - ki - 1;
  1300. work[j + 1 + *n] -= sdot_(&i__3, &t[ki + 1 + (j + 1) *
  1301. t_dim1], &c__1, &work[ki + 1 + *n], &c__1);
  1302. /* Solve */
  1303. /* [T(J,J)-WR T(J,J+1) ]**T* X = SCALE*( WORK1 ) */
  1304. /* [T(J+1,J) T(J+1,J+1)-WR] ( WORK2 ) */
  1305. slaln2_(&c_true, &c__2, &c__1, &smin, &c_b22, &t[j +
  1306. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1307. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1308. &ierr);
  1309. /* Scale if necessary */
  1310. if (scale != 1.f) {
  1311. i__3 = *n - ki + 1;
  1312. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1313. }
  1314. work[j + *n] = x[0];
  1315. work[j + 1 + *n] = x[1];
  1316. /* Computing MAX */
  1317. r__3 = (r__1 = work[j + *n], abs(r__1)), r__4 = (r__2
  1318. = work[j + 1 + *n], abs(r__2)), r__3 = f2cmax(
  1319. r__3,r__4);
  1320. vmax = f2cmax(r__3,vmax);
  1321. vcrit = bignum / vmax;
  1322. }
  1323. L170:
  1324. ;
  1325. }
  1326. /* Copy the vector x or Q*x to VL and normalize. */
  1327. if (! over) {
  1328. i__2 = *n - ki + 1;
  1329. scopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1330. vl_dim1], &c__1);
  1331. i__2 = *n - ki + 1;
  1332. ii = isamax_(&i__2, &vl[ki + is * vl_dim1], &c__1) + ki -
  1333. 1;
  1334. remax = 1.f / (r__1 = vl[ii + is * vl_dim1], abs(r__1));
  1335. i__2 = *n - ki + 1;
  1336. sscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1337. i__2 = ki - 1;
  1338. for (k = 1; k <= i__2; ++k) {
  1339. vl[k + is * vl_dim1] = 0.f;
  1340. /* L180: */
  1341. }
  1342. } else {
  1343. if (ki < *n) {
  1344. i__2 = *n - ki;
  1345. sgemv_("N", n, &i__2, &c_b22, &vl[(ki + 1) * vl_dim1
  1346. + 1], ldvl, &work[ki + 1 + *n], &c__1, &work[
  1347. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1348. }
  1349. ii = isamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
  1350. remax = 1.f / (r__1 = vl[ii + ki * vl_dim1], abs(r__1));
  1351. sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1352. }
  1353. } else {
  1354. /* Complex left eigenvector. */
  1355. /* Initial solve: */
  1356. /* ((T(KI,KI) T(KI,KI+1) )**T - (WR - I* WI))*X = 0. */
  1357. /* ((T(KI+1,KI) T(KI+1,KI+1)) ) */
  1358. if ((r__1 = t[ki + (ki + 1) * t_dim1], abs(r__1)) >= (r__2 =
  1359. t[ki + 1 + ki * t_dim1], abs(r__2))) {
  1360. work[ki + *n] = wi / t[ki + (ki + 1) * t_dim1];
  1361. work[ki + 1 + n2] = 1.f;
  1362. } else {
  1363. work[ki + *n] = 1.f;
  1364. work[ki + 1 + n2] = -wi / t[ki + 1 + ki * t_dim1];
  1365. }
  1366. work[ki + 1 + *n] = 0.f;
  1367. work[ki + n2] = 0.f;
  1368. /* Form right-hand side */
  1369. i__2 = *n;
  1370. for (k = ki + 2; k <= i__2; ++k) {
  1371. work[k + *n] = -work[ki + *n] * t[ki + k * t_dim1];
  1372. work[k + n2] = -work[ki + 1 + n2] * t[ki + 1 + k * t_dim1]
  1373. ;
  1374. /* L190: */
  1375. }
  1376. /* Solve complex quasi-triangular system: */
  1377. /* ( T(KI+2,N:KI+2,N) - (WR-i*WI) )*X = WORK1+i*WORK2 */
  1378. vmax = 1.f;
  1379. vcrit = bignum;
  1380. jnxt = ki + 2;
  1381. i__2 = *n;
  1382. for (j = ki + 2; j <= i__2; ++j) {
  1383. if (j < jnxt) {
  1384. goto L200;
  1385. }
  1386. j1 = j;
  1387. j2 = j;
  1388. jnxt = j + 1;
  1389. if (j < *n) {
  1390. if (t[j + 1 + j * t_dim1] != 0.f) {
  1391. j2 = j + 1;
  1392. jnxt = j + 2;
  1393. }
  1394. }
  1395. if (j1 == j2) {
  1396. /* 1-by-1 diagonal block */
  1397. /* Scale if necessary to avoid overflow when */
  1398. /* forming the right-hand side elements. */
  1399. if (work[j] > vcrit) {
  1400. rec = 1.f / vmax;
  1401. i__3 = *n - ki + 1;
  1402. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1403. i__3 = *n - ki + 1;
  1404. sscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1405. vmax = 1.f;
  1406. vcrit = bignum;
  1407. }
  1408. i__3 = j - ki - 2;
  1409. work[j + *n] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1410. &c__1, &work[ki + 2 + *n], &c__1);
  1411. i__3 = j - ki - 2;
  1412. work[j + n2] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1413. &c__1, &work[ki + 2 + n2], &c__1);
  1414. /* Solve (T(J,J)-(WR-i*WI))*(X11+i*X12)= WK+I*WK2 */
  1415. r__1 = -wi;
  1416. slaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1417. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1418. n], n, &wr, &r__1, x, &c__2, &scale, &xnorm, &
  1419. ierr);
  1420. /* Scale if necessary */
  1421. if (scale != 1.f) {
  1422. i__3 = *n - ki + 1;
  1423. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1424. i__3 = *n - ki + 1;
  1425. sscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1426. }
  1427. work[j + *n] = x[0];
  1428. work[j + n2] = x[2];
  1429. /* Computing MAX */
  1430. r__3 = (r__1 = work[j + *n], abs(r__1)), r__4 = (r__2
  1431. = work[j + n2], abs(r__2)), r__3 = f2cmax(r__3,
  1432. r__4);
  1433. vmax = f2cmax(r__3,vmax);
  1434. vcrit = bignum / vmax;
  1435. } else {
  1436. /* 2-by-2 diagonal block */
  1437. /* Scale if necessary to avoid overflow when forming */
  1438. /* the right-hand side elements. */
  1439. /* Computing MAX */
  1440. r__1 = work[j], r__2 = work[j + 1];
  1441. beta = f2cmax(r__1,r__2);
  1442. if (beta > vcrit) {
  1443. rec = 1.f / vmax;
  1444. i__3 = *n - ki + 1;
  1445. sscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1446. i__3 = *n - ki + 1;
  1447. sscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1448. vmax = 1.f;
  1449. vcrit = bignum;
  1450. }
  1451. i__3 = j - ki - 2;
  1452. work[j + *n] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1453. &c__1, &work[ki + 2 + *n], &c__1);
  1454. i__3 = j - ki - 2;
  1455. work[j + n2] -= sdot_(&i__3, &t[ki + 2 + j * t_dim1],
  1456. &c__1, &work[ki + 2 + n2], &c__1);
  1457. i__3 = j - ki - 2;
  1458. work[j + 1 + *n] -= sdot_(&i__3, &t[ki + 2 + (j + 1) *
  1459. t_dim1], &c__1, &work[ki + 2 + *n], &c__1);
  1460. i__3 = j - ki - 2;
  1461. work[j + 1 + n2] -= sdot_(&i__3, &t[ki + 2 + (j + 1) *
  1462. t_dim1], &c__1, &work[ki + 2 + n2], &c__1);
  1463. /* Solve 2-by-2 complex linear equation */
  1464. /* ([T(j,j) T(j,j+1) ]**T-(wr-i*wi)*I)*X = SCALE*B */
  1465. /* ([T(j+1,j) T(j+1,j+1)] ) */
  1466. r__1 = -wi;
  1467. slaln2_(&c_true, &c__2, &c__2, &smin, &c_b22, &t[j +
  1468. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1469. n], n, &wr, &r__1, x, &c__2, &scale, &xnorm, &
  1470. ierr);
  1471. /* Scale if necessary */
  1472. if (scale != 1.f) {
  1473. i__3 = *n - ki + 1;
  1474. sscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1475. i__3 = *n - ki + 1;
  1476. sscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1477. }
  1478. work[j + *n] = x[0];
  1479. work[j + n2] = x[2];
  1480. work[j + 1 + *n] = x[1];
  1481. work[j + 1 + n2] = x[3];
  1482. /* Computing MAX */
  1483. r__1 = abs(x[0]), r__2 = abs(x[2]), r__1 = f2cmax(r__1,
  1484. r__2), r__2 = abs(x[1]), r__1 = f2cmax(r__1,r__2)
  1485. , r__2 = abs(x[3]), r__1 = f2cmax(r__1,r__2);
  1486. vmax = f2cmax(r__1,vmax);
  1487. vcrit = bignum / vmax;
  1488. }
  1489. L200:
  1490. ;
  1491. }
  1492. /* Copy the vector x or Q*x to VL and normalize. */
  1493. if (! over) {
  1494. i__2 = *n - ki + 1;
  1495. scopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1496. vl_dim1], &c__1);
  1497. i__2 = *n - ki + 1;
  1498. scopy_(&i__2, &work[ki + n2], &c__1, &vl[ki + (is + 1) *
  1499. vl_dim1], &c__1);
  1500. emax = 0.f;
  1501. i__2 = *n;
  1502. for (k = ki; k <= i__2; ++k) {
  1503. /* Computing MAX */
  1504. r__3 = emax, r__4 = (r__1 = vl[k + is * vl_dim1], abs(
  1505. r__1)) + (r__2 = vl[k + (is + 1) * vl_dim1],
  1506. abs(r__2));
  1507. emax = f2cmax(r__3,r__4);
  1508. /* L220: */
  1509. }
  1510. remax = 1.f / emax;
  1511. i__2 = *n - ki + 1;
  1512. sscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1513. i__2 = *n - ki + 1;
  1514. sscal_(&i__2, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
  1515. ;
  1516. i__2 = ki - 1;
  1517. for (k = 1; k <= i__2; ++k) {
  1518. vl[k + is * vl_dim1] = 0.f;
  1519. vl[k + (is + 1) * vl_dim1] = 0.f;
  1520. /* L230: */
  1521. }
  1522. } else {
  1523. if (ki < *n - 1) {
  1524. i__2 = *n - ki - 1;
  1525. sgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1526. + 1], ldvl, &work[ki + 2 + *n], &c__1, &work[
  1527. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1528. i__2 = *n - ki - 1;
  1529. sgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1530. + 1], ldvl, &work[ki + 2 + n2], &c__1, &work[
  1531. ki + 1 + n2], &vl[(ki + 1) * vl_dim1 + 1], &
  1532. c__1);
  1533. } else {
  1534. sscal_(n, &work[ki + *n], &vl[ki * vl_dim1 + 1], &
  1535. c__1);
  1536. sscal_(n, &work[ki + 1 + n2], &vl[(ki + 1) * vl_dim1
  1537. + 1], &c__1);
  1538. }
  1539. emax = 0.f;
  1540. i__2 = *n;
  1541. for (k = 1; k <= i__2; ++k) {
  1542. /* Computing MAX */
  1543. r__3 = emax, r__4 = (r__1 = vl[k + ki * vl_dim1], abs(
  1544. r__1)) + (r__2 = vl[k + (ki + 1) * vl_dim1],
  1545. abs(r__2));
  1546. emax = f2cmax(r__3,r__4);
  1547. /* L240: */
  1548. }
  1549. remax = 1.f / emax;
  1550. sscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1551. sscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
  1552. }
  1553. }
  1554. ++is;
  1555. if (ip != 0) {
  1556. ++is;
  1557. }
  1558. L250:
  1559. if (ip == -1) {
  1560. ip = 0;
  1561. }
  1562. if (ip == 1) {
  1563. ip = -1;
  1564. }
  1565. /* L260: */
  1566. }
  1567. }
  1568. return;
  1569. /* End of STREVC */
  1570. } /* strevc_ */