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.

stgevc.c 55 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  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_true = TRUE_;
  487. static integer c__2 = 2;
  488. static real c_b34 = 1.f;
  489. static integer c__1 = 1;
  490. static real c_b36 = 0.f;
  491. static logical c_false = FALSE_;
  492. /* > \brief \b STGEVC */
  493. /* =========== DOCUMENTATION =========== */
  494. /* Online html documentation available at */
  495. /* http://www.netlib.org/lapack/explore-html/ */
  496. /* > \htmlonly */
  497. /* > Download STGEVC + dependencies */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgevc.
  499. f"> */
  500. /* > [TGZ]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgevc.
  502. f"> */
  503. /* > [ZIP]</a> */
  504. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgevc.
  505. f"> */
  506. /* > [TXT]</a> */
  507. /* > \endhtmlonly */
  508. /* Definition: */
  509. /* =========== */
  510. /* SUBROUTINE STGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL, */
  511. /* LDVL, VR, LDVR, MM, M, WORK, INFO ) */
  512. /* CHARACTER HOWMNY, SIDE */
  513. /* INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N */
  514. /* LOGICAL SELECT( * ) */
  515. /* REAL P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
  516. /* $ VR( LDVR, * ), WORK( * ) */
  517. /* > \par Purpose: */
  518. /* ============= */
  519. /* > */
  520. /* > \verbatim */
  521. /* > */
  522. /* > STGEVC computes some or all of the right and/or left eigenvectors of */
  523. /* > a pair of real matrices (S,P), where S is a quasi-triangular matrix */
  524. /* > and P is upper triangular. Matrix pairs of this type are produced by */
  525. /* > the generalized Schur factorization of a matrix pair (A,B): */
  526. /* > */
  527. /* > A = Q*S*Z**T, B = Q*P*Z**T */
  528. /* > */
  529. /* > as computed by SGGHRD + SHGEQZ. */
  530. /* > */
  531. /* > The right eigenvector x and the left eigenvector y of (S,P) */
  532. /* > corresponding to an eigenvalue w are defined by: */
  533. /* > */
  534. /* > S*x = w*P*x, (y**H)*S = w*(y**H)*P, */
  535. /* > */
  536. /* > where y**H denotes the conjugate tranpose of y. */
  537. /* > The eigenvalues are not input to this routine, but are computed */
  538. /* > directly from the diagonal blocks of S and P. */
  539. /* > */
  540. /* > This routine returns the matrices X and/or Y of right and left */
  541. /* > eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
  542. /* > where Z and Q are input matrices. */
  543. /* > If Q and Z are the orthogonal factors from the generalized Schur */
  544. /* > factorization of a matrix pair (A,B), then Z*X and Q*Y */
  545. /* > are the matrices of right and left eigenvectors of (A,B). */
  546. /* > */
  547. /* > \endverbatim */
  548. /* Arguments: */
  549. /* ========== */
  550. /* > \param[in] SIDE */
  551. /* > \verbatim */
  552. /* > SIDE is CHARACTER*1 */
  553. /* > = 'R': compute right eigenvectors only; */
  554. /* > = 'L': compute left eigenvectors only; */
  555. /* > = 'B': compute both right and left eigenvectors. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in] HOWMNY */
  559. /* > \verbatim */
  560. /* > HOWMNY is CHARACTER*1 */
  561. /* > = 'A': compute all right and/or left eigenvectors; */
  562. /* > = 'B': compute all right and/or left eigenvectors, */
  563. /* > backtransformed by the matrices in VR and/or VL; */
  564. /* > = 'S': compute selected right and/or left eigenvectors, */
  565. /* > specified by the logical array SELECT. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[in] SELECT */
  569. /* > \verbatim */
  570. /* > SELECT is LOGICAL array, dimension (N) */
  571. /* > If HOWMNY='S', SELECT specifies the eigenvectors to be */
  572. /* > computed. If w(j) is a real eigenvalue, the corresponding */
  573. /* > real eigenvector is computed if SELECT(j) is .TRUE.. */
  574. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  575. /* > complex eigenvalue, the corresponding complex eigenvector */
  576. /* > is computed if either SELECT(j) or SELECT(j+1) is .TRUE., */
  577. /* > and on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is */
  578. /* > set to .FALSE.. */
  579. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] N */
  583. /* > \verbatim */
  584. /* > N is INTEGER */
  585. /* > The order of the matrices S and P. N >= 0. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] S */
  589. /* > \verbatim */
  590. /* > S is REAL array, dimension (LDS,N) */
  591. /* > The upper quasi-triangular matrix S from a generalized Schur */
  592. /* > factorization, as computed by SHGEQZ. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in] LDS */
  596. /* > \verbatim */
  597. /* > LDS is INTEGER */
  598. /* > The leading dimension of array S. LDS >= f2cmax(1,N). */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[in] P */
  602. /* > \verbatim */
  603. /* > P is REAL array, dimension (LDP,N) */
  604. /* > The upper triangular matrix P from a generalized Schur */
  605. /* > factorization, as computed by SHGEQZ. */
  606. /* > 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks */
  607. /* > of S must be in positive diagonal form. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in] LDP */
  611. /* > \verbatim */
  612. /* > LDP is INTEGER */
  613. /* > The leading dimension of array P. LDP >= f2cmax(1,N). */
  614. /* > \endverbatim */
  615. /* > */
  616. /* > \param[in,out] VL */
  617. /* > \verbatim */
  618. /* > VL is REAL array, dimension (LDVL,MM) */
  619. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  620. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  621. /* > of left Schur vectors returned by SHGEQZ). */
  622. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  623. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
  624. /* > if HOWMNY = 'B', the matrix Q*Y; */
  625. /* > if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
  626. /* > SELECT, stored consecutively in the columns of */
  627. /* > VL, in the same order as their eigenvalues. */
  628. /* > */
  629. /* > A complex eigenvector corresponding to a complex eigenvalue */
  630. /* > is stored in two consecutive columns, the first holding the */
  631. /* > real part, and the second the imaginary part. */
  632. /* > */
  633. /* > Not referenced if SIDE = 'R'. */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[in] LDVL */
  637. /* > \verbatim */
  638. /* > LDVL is INTEGER */
  639. /* > The leading dimension of array VL. LDVL >= 1, and if */
  640. /* > SIDE = 'L' or 'B', LDVL >= N. */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[in,out] VR */
  644. /* > \verbatim */
  645. /* > VR is REAL array, dimension (LDVR,MM) */
  646. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  647. /* > contain an N-by-N matrix Z (usually the orthogonal matrix Z */
  648. /* > of right Schur vectors returned by SHGEQZ). */
  649. /* > */
  650. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  651. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
  652. /* > if HOWMNY = 'B' or 'b', the matrix Z*X; */
  653. /* > if HOWMNY = 'S' or 's', the right eigenvectors of (S,P) */
  654. /* > specified by SELECT, stored consecutively in the */
  655. /* > columns of VR, in the same order as their */
  656. /* > eigenvalues. */
  657. /* > */
  658. /* > A complex eigenvector corresponding to a complex eigenvalue */
  659. /* > is stored in two consecutive columns, the first holding the */
  660. /* > real part and the second the imaginary part. */
  661. /* > */
  662. /* > Not referenced if SIDE = 'L'. */
  663. /* > \endverbatim */
  664. /* > */
  665. /* > \param[in] LDVR */
  666. /* > \verbatim */
  667. /* > LDVR is INTEGER */
  668. /* > The leading dimension of the array VR. LDVR >= 1, and if */
  669. /* > SIDE = 'R' or 'B', LDVR >= N. */
  670. /* > \endverbatim */
  671. /* > */
  672. /* > \param[in] MM */
  673. /* > \verbatim */
  674. /* > MM is INTEGER */
  675. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  676. /* > \endverbatim */
  677. /* > */
  678. /* > \param[out] M */
  679. /* > \verbatim */
  680. /* > M is INTEGER */
  681. /* > The number of columns in the arrays VL and/or VR actually */
  682. /* > used to store the eigenvectors. If HOWMNY = 'A' or 'B', M */
  683. /* > is set to N. Each selected real eigenvector occupies one */
  684. /* > column and each selected complex eigenvector occupies two */
  685. /* > columns. */
  686. /* > \endverbatim */
  687. /* > */
  688. /* > \param[out] WORK */
  689. /* > \verbatim */
  690. /* > WORK is REAL array, dimension (6*N) */
  691. /* > \endverbatim */
  692. /* > */
  693. /* > \param[out] INFO */
  694. /* > \verbatim */
  695. /* > INFO is INTEGER */
  696. /* > = 0: successful exit. */
  697. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  698. /* > > 0: the 2-by-2 block (INFO:INFO+1) does not have a complex */
  699. /* > eigenvalue. */
  700. /* > \endverbatim */
  701. /* Authors: */
  702. /* ======== */
  703. /* > \author Univ. of Tennessee */
  704. /* > \author Univ. of California Berkeley */
  705. /* > \author Univ. of Colorado Denver */
  706. /* > \author NAG Ltd. */
  707. /* > \date December 2016 */
  708. /* > \ingroup realGEcomputational */
  709. /* > \par Further Details: */
  710. /* ===================== */
  711. /* > */
  712. /* > \verbatim */
  713. /* > */
  714. /* > Allocation of workspace: */
  715. /* > ---------- -- --------- */
  716. /* > */
  717. /* > WORK( j ) = 1-norm of j-th column of A, above the diagonal */
  718. /* > WORK( N+j ) = 1-norm of j-th column of B, above the diagonal */
  719. /* > WORK( 2*N+1:3*N ) = real part of eigenvector */
  720. /* > WORK( 3*N+1:4*N ) = imaginary part of eigenvector */
  721. /* > WORK( 4*N+1:5*N ) = real part of back-transformed eigenvector */
  722. /* > WORK( 5*N+1:6*N ) = imaginary part of back-transformed eigenvector */
  723. /* > */
  724. /* > Rowwise vs. columnwise solution methods: */
  725. /* > ------- -- ---------- -------- ------- */
  726. /* > */
  727. /* > Finding a generalized eigenvector consists basically of solving the */
  728. /* > singular triangular system */
  729. /* > */
  730. /* > (A - w B) x = 0 (for right) or: (A - w B)**H y = 0 (for left) */
  731. /* > */
  732. /* > Consider finding the i-th right eigenvector (assume all eigenvalues */
  733. /* > are real). The equation to be solved is: */
  734. /* > n i */
  735. /* > 0 = sum C(j,k) v(k) = sum C(j,k) v(k) for j = i,. . .,1 */
  736. /* > k=j k=j */
  737. /* > */
  738. /* > where C = (A - w B) (The components v(i+1:n) are 0.) */
  739. /* > */
  740. /* > The "rowwise" method is: */
  741. /* > */
  742. /* > (1) v(i) := 1 */
  743. /* > for j = i-1,. . .,1: */
  744. /* > i */
  745. /* > (2) compute s = - sum C(j,k) v(k) and */
  746. /* > k=j+1 */
  747. /* > */
  748. /* > (3) v(j) := s / C(j,j) */
  749. /* > */
  750. /* > Step 2 is sometimes called the "dot product" step, since it is an */
  751. /* > inner product between the j-th row and the portion of the eigenvector */
  752. /* > that has been computed so far. */
  753. /* > */
  754. /* > The "columnwise" method consists basically in doing the sums */
  755. /* > for all the rows in parallel. As each v(j) is computed, the */
  756. /* > contribution of v(j) times the j-th column of C is added to the */
  757. /* > partial sums. Since FORTRAN arrays are stored columnwise, this has */
  758. /* > the advantage that at each step, the elements of C that are accessed */
  759. /* > are adjacent to one another, whereas with the rowwise method, the */
  760. /* > elements accessed at a step are spaced LDS (and LDP) words apart. */
  761. /* > */
  762. /* > When finding left eigenvectors, the matrix in question is the */
  763. /* > transpose of the one in storage, so the rowwise method then */
  764. /* > actually accesses columns of A and B at each step, and so is the */
  765. /* > preferred method. */
  766. /* > \endverbatim */
  767. /* > */
  768. /* ===================================================================== */
  769. /* Subroutine */ void stgevc_(char *side, char *howmny, logical *select,
  770. integer *n, real *s, integer *lds, real *p, integer *ldp, real *vl,
  771. integer *ldvl, real *vr, integer *ldvr, integer *mm, integer *m, real
  772. *work, integer *info)
  773. {
  774. /* System generated locals */
  775. integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1,
  776. vr_offset, i__1, i__2, i__3, i__4, i__5;
  777. real r__1, r__2, r__3, r__4, r__5, r__6;
  778. /* Local variables */
  779. integer ibeg, ieig, iend;
  780. real dmin__, temp, xmax, sump[4] /* was [2][2] */, sums[4] /*
  781. was [2][2] */, cim2a, cim2b, cre2a, cre2b;
  782. extern /* Subroutine */ void slag2_(real *, integer *, real *, integer *,
  783. real *, real *, real *, real *, real *, real *);
  784. real temp2, bdiag[2];
  785. integer i__, j;
  786. real acoef, scale;
  787. logical ilall;
  788. integer iside;
  789. real sbeta;
  790. extern logical lsame_(char *, char *);
  791. logical il2by2;
  792. integer iinfo;
  793. real small;
  794. logical compl;
  795. real anorm, bnorm;
  796. logical compr;
  797. extern /* Subroutine */ void sgemv_(char *, integer *, integer *, real *,
  798. real *, integer *, real *, integer *, real *, real *, integer *), slaln2_(logical *, integer *, integer *, real *, real *,
  799. real *, integer *, real *, real *, real *, integer *, real *,
  800. real *, real *, integer *, real *, real *, integer *);
  801. real temp2i, temp2r;
  802. integer ja;
  803. logical ilabad, ilbbad;
  804. integer jc, je, na;
  805. real acoefa, bcoefa, cimaga, cimagb;
  806. logical ilback;
  807. integer im;
  808. real bcoefi, ascale, bscale, creala;
  809. integer jr;
  810. real crealb;
  811. extern /* Subroutine */ void slabad_(real *, real *);
  812. real bcoefr;
  813. integer jw, nw;
  814. extern real slamch_(char *);
  815. real salfar, safmin;
  816. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  817. real xscale, bignum;
  818. logical ilcomp, ilcplx;
  819. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  820. integer *, real *, integer *);
  821. integer ihwmny;
  822. real big;
  823. logical lsa, lsb;
  824. real ulp, sum[4] /* was [2][2] */;
  825. /* -- LAPACK computational routine (version 3.7.0) -- */
  826. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  827. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  828. /* December 2016 */
  829. /* ===================================================================== */
  830. /* Decode and Test the input parameters */
  831. /* Parameter adjustments */
  832. --select;
  833. s_dim1 = *lds;
  834. s_offset = 1 + s_dim1 * 1;
  835. s -= s_offset;
  836. p_dim1 = *ldp;
  837. p_offset = 1 + p_dim1 * 1;
  838. p -= p_offset;
  839. vl_dim1 = *ldvl;
  840. vl_offset = 1 + vl_dim1 * 1;
  841. vl -= vl_offset;
  842. vr_dim1 = *ldvr;
  843. vr_offset = 1 + vr_dim1 * 1;
  844. vr -= vr_offset;
  845. --work;
  846. /* Function Body */
  847. if (lsame_(howmny, "A")) {
  848. ihwmny = 1;
  849. ilall = TRUE_;
  850. ilback = FALSE_;
  851. } else if (lsame_(howmny, "S")) {
  852. ihwmny = 2;
  853. ilall = FALSE_;
  854. ilback = FALSE_;
  855. } else if (lsame_(howmny, "B")) {
  856. ihwmny = 3;
  857. ilall = TRUE_;
  858. ilback = TRUE_;
  859. } else {
  860. ihwmny = -1;
  861. ilall = TRUE_;
  862. }
  863. if (lsame_(side, "R")) {
  864. iside = 1;
  865. compl = FALSE_;
  866. compr = TRUE_;
  867. } else if (lsame_(side, "L")) {
  868. iside = 2;
  869. compl = TRUE_;
  870. compr = FALSE_;
  871. } else if (lsame_(side, "B")) {
  872. iside = 3;
  873. compl = TRUE_;
  874. compr = TRUE_;
  875. } else {
  876. iside = -1;
  877. }
  878. *info = 0;
  879. if (iside < 0) {
  880. *info = -1;
  881. } else if (ihwmny < 0) {
  882. *info = -2;
  883. } else if (*n < 0) {
  884. *info = -4;
  885. } else if (*lds < f2cmax(1,*n)) {
  886. *info = -6;
  887. } else if (*ldp < f2cmax(1,*n)) {
  888. *info = -8;
  889. }
  890. if (*info != 0) {
  891. i__1 = -(*info);
  892. xerbla_("STGEVC", &i__1, (ftnlen)6);
  893. return;
  894. }
  895. /* Count the number of eigenvectors to be computed */
  896. if (! ilall) {
  897. im = 0;
  898. ilcplx = FALSE_;
  899. i__1 = *n;
  900. for (j = 1; j <= i__1; ++j) {
  901. if (ilcplx) {
  902. ilcplx = FALSE_;
  903. goto L10;
  904. }
  905. if (j < *n) {
  906. if (s[j + 1 + j * s_dim1] != 0.f) {
  907. ilcplx = TRUE_;
  908. }
  909. }
  910. if (ilcplx) {
  911. if (select[j] || select[j + 1]) {
  912. im += 2;
  913. }
  914. } else {
  915. if (select[j]) {
  916. ++im;
  917. }
  918. }
  919. L10:
  920. ;
  921. }
  922. } else {
  923. im = *n;
  924. }
  925. /* Check 2-by-2 diagonal blocks of A, B */
  926. ilabad = FALSE_;
  927. ilbbad = FALSE_;
  928. i__1 = *n - 1;
  929. for (j = 1; j <= i__1; ++j) {
  930. if (s[j + 1 + j * s_dim1] != 0.f) {
  931. if (p[j + j * p_dim1] == 0.f || p[j + 1 + (j + 1) * p_dim1] ==
  932. 0.f || p[j + (j + 1) * p_dim1] != 0.f) {
  933. ilbbad = TRUE_;
  934. }
  935. if (j < *n - 1) {
  936. if (s[j + 2 + (j + 1) * s_dim1] != 0.f) {
  937. ilabad = TRUE_;
  938. }
  939. }
  940. }
  941. /* L20: */
  942. }
  943. if (ilabad) {
  944. *info = -5;
  945. } else if (ilbbad) {
  946. *info = -7;
  947. } else if (compl && *ldvl < *n || *ldvl < 1) {
  948. *info = -10;
  949. } else if (compr && *ldvr < *n || *ldvr < 1) {
  950. *info = -12;
  951. } else if (*mm < im) {
  952. *info = -13;
  953. }
  954. if (*info != 0) {
  955. i__1 = -(*info);
  956. xerbla_("STGEVC", &i__1, (ftnlen)6);
  957. return;
  958. }
  959. /* Quick return if possible */
  960. *m = im;
  961. if (*n == 0) {
  962. return;
  963. }
  964. /* Machine Constants */
  965. safmin = slamch_("Safe minimum");
  966. big = 1.f / safmin;
  967. slabad_(&safmin, &big);
  968. ulp = slamch_("Epsilon") * slamch_("Base");
  969. small = safmin * *n / ulp;
  970. big = 1.f / small;
  971. bignum = 1.f / (safmin * *n);
  972. /* Compute the 1-norm of each column of the strictly upper triangular */
  973. /* part (i.e., excluding all elements belonging to the diagonal */
  974. /* blocks) of A and B to check for possible overflow in the */
  975. /* triangular solver. */
  976. anorm = (r__1 = s[s_dim1 + 1], abs(r__1));
  977. if (*n > 1) {
  978. anorm += (r__1 = s[s_dim1 + 2], abs(r__1));
  979. }
  980. bnorm = (r__1 = p[p_dim1 + 1], abs(r__1));
  981. work[1] = 0.f;
  982. work[*n + 1] = 0.f;
  983. i__1 = *n;
  984. for (j = 2; j <= i__1; ++j) {
  985. temp = 0.f;
  986. temp2 = 0.f;
  987. if (s[j + (j - 1) * s_dim1] == 0.f) {
  988. iend = j - 1;
  989. } else {
  990. iend = j - 2;
  991. }
  992. i__2 = iend;
  993. for (i__ = 1; i__ <= i__2; ++i__) {
  994. temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
  995. temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
  996. /* L30: */
  997. }
  998. work[j] = temp;
  999. work[*n + j] = temp2;
  1000. /* Computing MIN */
  1001. i__3 = j + 1;
  1002. i__2 = f2cmin(i__3,*n);
  1003. for (i__ = iend + 1; i__ <= i__2; ++i__) {
  1004. temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
  1005. temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
  1006. /* L40: */
  1007. }
  1008. anorm = f2cmax(anorm,temp);
  1009. bnorm = f2cmax(bnorm,temp2);
  1010. /* L50: */
  1011. }
  1012. ascale = 1.f / f2cmax(anorm,safmin);
  1013. bscale = 1.f / f2cmax(bnorm,safmin);
  1014. /* Left eigenvectors */
  1015. if (compl) {
  1016. ieig = 0;
  1017. /* Main loop over eigenvalues */
  1018. ilcplx = FALSE_;
  1019. i__1 = *n;
  1020. for (je = 1; je <= i__1; ++je) {
  1021. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1022. /* (b) this would be the second of a complex pair. */
  1023. /* Check for complex eigenvalue, so as to be sure of which */
  1024. /* entry(-ies) of SELECT to look at. */
  1025. if (ilcplx) {
  1026. ilcplx = FALSE_;
  1027. goto L220;
  1028. }
  1029. nw = 1;
  1030. if (je < *n) {
  1031. if (s[je + 1 + je * s_dim1] != 0.f) {
  1032. ilcplx = TRUE_;
  1033. nw = 2;
  1034. }
  1035. }
  1036. if (ilall) {
  1037. ilcomp = TRUE_;
  1038. } else if (ilcplx) {
  1039. ilcomp = select[je] || select[je + 1];
  1040. } else {
  1041. ilcomp = select[je];
  1042. }
  1043. if (! ilcomp) {
  1044. goto L220;
  1045. }
  1046. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1047. /* (c) complex eigenvalue. */
  1048. if (! ilcplx) {
  1049. if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
  1050. r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
  1051. /* Singular matrix pencil -- return unit eigenvector */
  1052. ++ieig;
  1053. i__2 = *n;
  1054. for (jr = 1; jr <= i__2; ++jr) {
  1055. vl[jr + ieig * vl_dim1] = 0.f;
  1056. /* L60: */
  1057. }
  1058. vl[ieig + ieig * vl_dim1] = 1.f;
  1059. goto L220;
  1060. }
  1061. }
  1062. /* Clear vector */
  1063. i__2 = nw * *n;
  1064. for (jr = 1; jr <= i__2; ++jr) {
  1065. work[(*n << 1) + jr] = 0.f;
  1066. /* L70: */
  1067. }
  1068. /* T */
  1069. /* Compute coefficients in ( a A - b B ) y = 0 */
  1070. /* a is ACOEF */
  1071. /* b is BCOEFR + i*BCOEFI */
  1072. if (! ilcplx) {
  1073. /* Real eigenvalue */
  1074. /* Computing MAX */
  1075. r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4
  1076. = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale,
  1077. r__3 = f2cmax(r__3,r__4);
  1078. temp = 1.f / f2cmax(r__3,safmin);
  1079. salfar = temp * s[je + je * s_dim1] * ascale;
  1080. sbeta = temp * p[je + je * p_dim1] * bscale;
  1081. acoef = sbeta * ascale;
  1082. bcoefr = salfar * bscale;
  1083. bcoefi = 0.f;
  1084. /* Scale to avoid underflow */
  1085. scale = 1.f;
  1086. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1087. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1088. if (lsa) {
  1089. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1090. }
  1091. if (lsb) {
  1092. /* Computing MAX */
  1093. r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1094. scale = f2cmax(r__1,r__2);
  1095. }
  1096. if (lsa || lsb) {
  1097. /* Computing MIN */
  1098. /* Computing MAX */
  1099. r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4),
  1100. r__4 = abs(bcoefr);
  1101. r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
  1102. scale = f2cmin(r__1,r__2);
  1103. if (lsa) {
  1104. acoef = ascale * (scale * sbeta);
  1105. } else {
  1106. acoef = scale * acoef;
  1107. }
  1108. if (lsb) {
  1109. bcoefr = bscale * (scale * salfar);
  1110. } else {
  1111. bcoefr = scale * bcoefr;
  1112. }
  1113. }
  1114. acoefa = abs(acoef);
  1115. bcoefa = abs(bcoefr);
  1116. /* First component is 1 */
  1117. work[(*n << 1) + je] = 1.f;
  1118. xmax = 1.f;
  1119. } else {
  1120. /* Complex eigenvalue */
  1121. r__1 = safmin * 100.f;
  1122. slag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
  1123. r__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
  1124. bcoefi = -bcoefi;
  1125. if (bcoefi == 0.f) {
  1126. *info = je;
  1127. return;
  1128. }
  1129. /* Scale to avoid over/underflow */
  1130. acoefa = abs(acoef);
  1131. bcoefa = abs(bcoefr) + abs(bcoefi);
  1132. scale = 1.f;
  1133. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1134. scale = safmin / ulp / acoefa;
  1135. }
  1136. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1137. /* Computing MAX */
  1138. r__1 = scale, r__2 = safmin / ulp / bcoefa;
  1139. scale = f2cmax(r__1,r__2);
  1140. }
  1141. if (safmin * acoefa > ascale) {
  1142. scale = ascale / (safmin * acoefa);
  1143. }
  1144. if (safmin * bcoefa > bscale) {
  1145. /* Computing MIN */
  1146. r__1 = scale, r__2 = bscale / (safmin * bcoefa);
  1147. scale = f2cmin(r__1,r__2);
  1148. }
  1149. if (scale != 1.f) {
  1150. acoef = scale * acoef;
  1151. acoefa = abs(acoef);
  1152. bcoefr = scale * bcoefr;
  1153. bcoefi = scale * bcoefi;
  1154. bcoefa = abs(bcoefr) + abs(bcoefi);
  1155. }
  1156. /* Compute first two components of eigenvector */
  1157. temp = acoef * s[je + 1 + je * s_dim1];
  1158. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1159. p_dim1];
  1160. temp2i = -bcoefi * p[je + je * p_dim1];
  1161. if (abs(temp) > abs(temp2r) + abs(temp2i)) {
  1162. work[(*n << 1) + je] = 1.f;
  1163. work[*n * 3 + je] = 0.f;
  1164. work[(*n << 1) + je + 1] = -temp2r / temp;
  1165. work[*n * 3 + je + 1] = -temp2i / temp;
  1166. } else {
  1167. work[(*n << 1) + je + 1] = 1.f;
  1168. work[*n * 3 + je + 1] = 0.f;
  1169. temp = acoef * s[je + (je + 1) * s_dim1];
  1170. work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) *
  1171. p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
  1172. temp;
  1173. work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
  1174. / temp;
  1175. }
  1176. /* Computing MAX */
  1177. r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 =
  1178. work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
  1179. n << 1) + je + 1], abs(r__3)) + (r__4 = work[*n * 3 +
  1180. je + 1], abs(r__4));
  1181. xmax = f2cmax(r__5,r__6);
  1182. }
  1183. /* Computing MAX */
  1184. r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 =
  1185. f2cmax(r__1,r__2);
  1186. dmin__ = f2cmax(r__1,safmin);
  1187. /* T */
  1188. /* Triangular solve of (a A - b B) y = 0 */
  1189. /* T */
  1190. /* (rowwise in (a A - b B) , or columnwise in (a A - b B) ) */
  1191. il2by2 = FALSE_;
  1192. i__2 = *n;
  1193. for (j = je + nw; j <= i__2; ++j) {
  1194. if (il2by2) {
  1195. il2by2 = FALSE_;
  1196. goto L160;
  1197. }
  1198. na = 1;
  1199. bdiag[0] = p[j + j * p_dim1];
  1200. if (j < *n) {
  1201. if (s[j + 1 + j * s_dim1] != 0.f) {
  1202. il2by2 = TRUE_;
  1203. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1204. na = 2;
  1205. }
  1206. }
  1207. /* Check whether scaling is necessary for dot products */
  1208. xscale = 1.f / f2cmax(1.f,xmax);
  1209. /* Computing MAX */
  1210. r__1 = work[j], r__2 = work[*n + j], r__1 = f2cmax(r__1,r__2),
  1211. r__2 = acoefa * work[j] + bcoefa * work[*n + j];
  1212. temp = f2cmax(r__1,r__2);
  1213. if (il2by2) {
  1214. /* Computing MAX */
  1215. r__1 = temp, r__2 = work[j + 1], r__1 = f2cmax(r__1,r__2),
  1216. r__2 = work[*n + j + 1], r__1 = f2cmax(r__1,r__2),
  1217. r__2 = acoefa * work[j + 1] + bcoefa * work[*n +
  1218. j + 1];
  1219. temp = f2cmax(r__1,r__2);
  1220. }
  1221. if (temp > bignum * xscale) {
  1222. i__3 = nw - 1;
  1223. for (jw = 0; jw <= i__3; ++jw) {
  1224. i__4 = j - 1;
  1225. for (jr = je; jr <= i__4; ++jr) {
  1226. work[(jw + 2) * *n + jr] = xscale * work[(jw + 2)
  1227. * *n + jr];
  1228. /* L80: */
  1229. }
  1230. /* L90: */
  1231. }
  1232. xmax *= xscale;
  1233. }
  1234. /* Compute dot products */
  1235. /* j-1 */
  1236. /* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k) */
  1237. /* k=je */
  1238. /* To reduce the op count, this is done as */
  1239. /* _ j-1 _ j-1 */
  1240. /* a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) ) */
  1241. /* k=je k=je */
  1242. /* which may cause underflow problems if A or B are close */
  1243. /* to underflow. (E.g., less than SMALL.) */
  1244. i__3 = nw;
  1245. for (jw = 1; jw <= i__3; ++jw) {
  1246. i__4 = na;
  1247. for (ja = 1; ja <= i__4; ++ja) {
  1248. sums[ja + (jw << 1) - 3] = 0.f;
  1249. sump[ja + (jw << 1) - 3] = 0.f;
  1250. i__5 = j - 1;
  1251. for (jr = je; jr <= i__5; ++jr) {
  1252. sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) *
  1253. s_dim1] * work[(jw + 1) * *n + jr];
  1254. sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) *
  1255. p_dim1] * work[(jw + 1) * *n + jr];
  1256. /* L100: */
  1257. }
  1258. /* L110: */
  1259. }
  1260. /* L120: */
  1261. }
  1262. i__3 = na;
  1263. for (ja = 1; ja <= i__3; ++ja) {
  1264. if (ilcplx) {
  1265. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1266. ja - 1] - bcoefi * sump[ja + 1];
  1267. sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
  1268. ja + 1] + bcoefi * sump[ja - 1];
  1269. } else {
  1270. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1271. ja - 1];
  1272. }
  1273. /* L130: */
  1274. }
  1275. /* T */
  1276. /* Solve ( a A - b B ) y = SUM(,) */
  1277. /* with scaling and perturbation of the denominator */
  1278. slaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
  1279. , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
  1280. &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
  1281. if (scale < 1.f) {
  1282. i__3 = nw - 1;
  1283. for (jw = 0; jw <= i__3; ++jw) {
  1284. i__4 = j - 1;
  1285. for (jr = je; jr <= i__4; ++jr) {
  1286. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1287. *n + jr];
  1288. /* L140: */
  1289. }
  1290. /* L150: */
  1291. }
  1292. xmax = scale * xmax;
  1293. }
  1294. xmax = f2cmax(xmax,temp);
  1295. L160:
  1296. ;
  1297. }
  1298. /* Copy eigenvector to VL, back transforming if */
  1299. /* HOWMNY='B'. */
  1300. ++ieig;
  1301. if (ilback) {
  1302. i__2 = nw - 1;
  1303. for (jw = 0; jw <= i__2; ++jw) {
  1304. i__3 = *n + 1 - je;
  1305. sgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
  1306. &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
  1307. jw + 4) * *n + 1], &c__1);
  1308. /* L170: */
  1309. }
  1310. slacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je *
  1311. vl_dim1 + 1], ldvl);
  1312. ibeg = 1;
  1313. } else {
  1314. slacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig *
  1315. vl_dim1 + 1], ldvl);
  1316. ibeg = je;
  1317. }
  1318. /* Scale eigenvector */
  1319. xmax = 0.f;
  1320. if (ilcplx) {
  1321. i__2 = *n;
  1322. for (j = ibeg; j <= i__2; ++j) {
  1323. /* Computing MAX */
  1324. r__3 = xmax, r__4 = (r__1 = vl[j + ieig * vl_dim1], abs(
  1325. r__1)) + (r__2 = vl[j + (ieig + 1) * vl_dim1],
  1326. abs(r__2));
  1327. xmax = f2cmax(r__3,r__4);
  1328. /* L180: */
  1329. }
  1330. } else {
  1331. i__2 = *n;
  1332. for (j = ibeg; j <= i__2; ++j) {
  1333. /* Computing MAX */
  1334. r__2 = xmax, r__3 = (r__1 = vl[j + ieig * vl_dim1], abs(
  1335. r__1));
  1336. xmax = f2cmax(r__2,r__3);
  1337. /* L190: */
  1338. }
  1339. }
  1340. if (xmax > safmin) {
  1341. xscale = 1.f / xmax;
  1342. i__2 = nw - 1;
  1343. for (jw = 0; jw <= i__2; ++jw) {
  1344. i__3 = *n;
  1345. for (jr = ibeg; jr <= i__3; ++jr) {
  1346. vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
  1347. ieig + jw) * vl_dim1];
  1348. /* L200: */
  1349. }
  1350. /* L210: */
  1351. }
  1352. }
  1353. ieig = ieig + nw - 1;
  1354. L220:
  1355. ;
  1356. }
  1357. }
  1358. /* Right eigenvectors */
  1359. if (compr) {
  1360. ieig = im + 1;
  1361. /* Main loop over eigenvalues */
  1362. ilcplx = FALSE_;
  1363. for (je = *n; je >= 1; --je) {
  1364. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1365. /* (b) this would be the second of a complex pair. */
  1366. /* Check for complex eigenvalue, so as to be sure of which */
  1367. /* entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
  1368. /* or SELECT(JE-1). */
  1369. /* If this is a complex pair, the 2-by-2 diagonal block */
  1370. /* corresponding to the eigenvalue is in rows/columns JE-1:JE */
  1371. if (ilcplx) {
  1372. ilcplx = FALSE_;
  1373. goto L500;
  1374. }
  1375. nw = 1;
  1376. if (je > 1) {
  1377. if (s[je + (je - 1) * s_dim1] != 0.f) {
  1378. ilcplx = TRUE_;
  1379. nw = 2;
  1380. }
  1381. }
  1382. if (ilall) {
  1383. ilcomp = TRUE_;
  1384. } else if (ilcplx) {
  1385. ilcomp = select[je] || select[je - 1];
  1386. } else {
  1387. ilcomp = select[je];
  1388. }
  1389. if (! ilcomp) {
  1390. goto L500;
  1391. }
  1392. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1393. /* (c) complex eigenvalue. */
  1394. if (! ilcplx) {
  1395. if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
  1396. r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
  1397. /* Singular matrix pencil -- unit eigenvector */
  1398. --ieig;
  1399. i__1 = *n;
  1400. for (jr = 1; jr <= i__1; ++jr) {
  1401. vr[jr + ieig * vr_dim1] = 0.f;
  1402. /* L230: */
  1403. }
  1404. vr[ieig + ieig * vr_dim1] = 1.f;
  1405. goto L500;
  1406. }
  1407. }
  1408. /* Clear vector */
  1409. i__1 = nw - 1;
  1410. for (jw = 0; jw <= i__1; ++jw) {
  1411. i__2 = *n;
  1412. for (jr = 1; jr <= i__2; ++jr) {
  1413. work[(jw + 2) * *n + jr] = 0.f;
  1414. /* L240: */
  1415. }
  1416. /* L250: */
  1417. }
  1418. /* Compute coefficients in ( a A - b B ) x = 0 */
  1419. /* a is ACOEF */
  1420. /* b is BCOEFR + i*BCOEFI */
  1421. if (! ilcplx) {
  1422. /* Real eigenvalue */
  1423. /* Computing MAX */
  1424. r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4
  1425. = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale,
  1426. r__3 = f2cmax(r__3,r__4);
  1427. temp = 1.f / f2cmax(r__3,safmin);
  1428. salfar = temp * s[je + je * s_dim1] * ascale;
  1429. sbeta = temp * p[je + je * p_dim1] * bscale;
  1430. acoef = sbeta * ascale;
  1431. bcoefr = salfar * bscale;
  1432. bcoefi = 0.f;
  1433. /* Scale to avoid underflow */
  1434. scale = 1.f;
  1435. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1436. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1437. if (lsa) {
  1438. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1439. }
  1440. if (lsb) {
  1441. /* Computing MAX */
  1442. r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1443. scale = f2cmax(r__1,r__2);
  1444. }
  1445. if (lsa || lsb) {
  1446. /* Computing MIN */
  1447. /* Computing MAX */
  1448. r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4),
  1449. r__4 = abs(bcoefr);
  1450. r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
  1451. scale = f2cmin(r__1,r__2);
  1452. if (lsa) {
  1453. acoef = ascale * (scale * sbeta);
  1454. } else {
  1455. acoef = scale * acoef;
  1456. }
  1457. if (lsb) {
  1458. bcoefr = bscale * (scale * salfar);
  1459. } else {
  1460. bcoefr = scale * bcoefr;
  1461. }
  1462. }
  1463. acoefa = abs(acoef);
  1464. bcoefa = abs(bcoefr);
  1465. /* First component is 1 */
  1466. work[(*n << 1) + je] = 1.f;
  1467. xmax = 1.f;
  1468. /* Compute contribution from column JE of A and B to sum */
  1469. /* (See "Further Details", above.) */
  1470. i__1 = je - 1;
  1471. for (jr = 1; jr <= i__1; ++jr) {
  1472. work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] -
  1473. acoef * s[jr + je * s_dim1];
  1474. /* L260: */
  1475. }
  1476. } else {
  1477. /* Complex eigenvalue */
  1478. r__1 = safmin * 100.f;
  1479. slag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je -
  1480. 1) * p_dim1], ldp, &r__1, &acoef, &temp, &bcoefr, &
  1481. temp2, &bcoefi);
  1482. if (bcoefi == 0.f) {
  1483. *info = je - 1;
  1484. return;
  1485. }
  1486. /* Scale to avoid over/underflow */
  1487. acoefa = abs(acoef);
  1488. bcoefa = abs(bcoefr) + abs(bcoefi);
  1489. scale = 1.f;
  1490. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1491. scale = safmin / ulp / acoefa;
  1492. }
  1493. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1494. /* Computing MAX */
  1495. r__1 = scale, r__2 = safmin / ulp / bcoefa;
  1496. scale = f2cmax(r__1,r__2);
  1497. }
  1498. if (safmin * acoefa > ascale) {
  1499. scale = ascale / (safmin * acoefa);
  1500. }
  1501. if (safmin * bcoefa > bscale) {
  1502. /* Computing MIN */
  1503. r__1 = scale, r__2 = bscale / (safmin * bcoefa);
  1504. scale = f2cmin(r__1,r__2);
  1505. }
  1506. if (scale != 1.f) {
  1507. acoef = scale * acoef;
  1508. acoefa = abs(acoef);
  1509. bcoefr = scale * bcoefr;
  1510. bcoefi = scale * bcoefi;
  1511. bcoefa = abs(bcoefr) + abs(bcoefi);
  1512. }
  1513. /* Compute first two components of eigenvector */
  1514. /* and contribution to sums */
  1515. temp = acoef * s[je + (je - 1) * s_dim1];
  1516. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1517. p_dim1];
  1518. temp2i = -bcoefi * p[je + je * p_dim1];
  1519. if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
  1520. work[(*n << 1) + je] = 1.f;
  1521. work[*n * 3 + je] = 0.f;
  1522. work[(*n << 1) + je - 1] = -temp2r / temp;
  1523. work[*n * 3 + je - 1] = -temp2i / temp;
  1524. } else {
  1525. work[(*n << 1) + je - 1] = 1.f;
  1526. work[*n * 3 + je - 1] = 0.f;
  1527. temp = acoef * s[je - 1 + je * s_dim1];
  1528. work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) *
  1529. p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
  1530. temp;
  1531. work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
  1532. / temp;
  1533. }
  1534. /* Computing MAX */
  1535. r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 =
  1536. work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
  1537. n << 1) + je - 1], abs(r__3)) + (r__4 = work[*n * 3 +
  1538. je - 1], abs(r__4));
  1539. xmax = f2cmax(r__5,r__6);
  1540. /* Compute contribution from columns JE and JE-1 */
  1541. /* of A and B to the sums. */
  1542. creala = acoef * work[(*n << 1) + je - 1];
  1543. cimaga = acoef * work[*n * 3 + je - 1];
  1544. crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n
  1545. * 3 + je - 1];
  1546. cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n
  1547. * 3 + je - 1];
  1548. cre2a = acoef * work[(*n << 1) + je];
  1549. cim2a = acoef * work[*n * 3 + je];
  1550. cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3
  1551. + je];
  1552. cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3
  1553. + je];
  1554. i__1 = je - 2;
  1555. for (jr = 1; jr <= i__1; ++jr) {
  1556. work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
  1557. + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
  1558. jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
  1559. work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] +
  1560. cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr
  1561. + je * s_dim1] + cim2b * p[jr + je * p_dim1];
  1562. /* L270: */
  1563. }
  1564. }
  1565. /* Computing MAX */
  1566. r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 =
  1567. f2cmax(r__1,r__2);
  1568. dmin__ = f2cmax(r__1,safmin);
  1569. /* Columnwise triangular solve of (a A - b B) x = 0 */
  1570. il2by2 = FALSE_;
  1571. for (j = je - nw; j >= 1; --j) {
  1572. /* If a 2-by-2 block, is in position j-1:j, wait until */
  1573. /* next iteration to process it (when it will be j:j+1) */
  1574. if (! il2by2 && j > 1) {
  1575. if (s[j + (j - 1) * s_dim1] != 0.f) {
  1576. il2by2 = TRUE_;
  1577. goto L370;
  1578. }
  1579. }
  1580. bdiag[0] = p[j + j * p_dim1];
  1581. if (il2by2) {
  1582. na = 2;
  1583. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1584. } else {
  1585. na = 1;
  1586. }
  1587. /* Compute x(j) (and x(j+1), if 2-by-2 block) */
  1588. slaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j *
  1589. s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j],
  1590. n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
  1591. iinfo);
  1592. if (scale < 1.f) {
  1593. i__1 = nw - 1;
  1594. for (jw = 0; jw <= i__1; ++jw) {
  1595. i__2 = je;
  1596. for (jr = 1; jr <= i__2; ++jr) {
  1597. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1598. *n + jr];
  1599. /* L280: */
  1600. }
  1601. /* L290: */
  1602. }
  1603. }
  1604. /* Computing MAX */
  1605. r__1 = scale * xmax;
  1606. xmax = f2cmax(r__1,temp);
  1607. i__1 = nw;
  1608. for (jw = 1; jw <= i__1; ++jw) {
  1609. i__2 = na;
  1610. for (ja = 1; ja <= i__2; ++ja) {
  1611. work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1)
  1612. - 3];
  1613. /* L300: */
  1614. }
  1615. /* L310: */
  1616. }
  1617. /* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
  1618. if (j > 1) {
  1619. /* Check whether scaling is necessary for sum. */
  1620. xscale = 1.f / f2cmax(1.f,xmax);
  1621. temp = acoefa * work[j] + bcoefa * work[*n + j];
  1622. if (il2by2) {
  1623. /* Computing MAX */
  1624. r__1 = temp, r__2 = acoefa * work[j + 1] + bcoefa *
  1625. work[*n + j + 1];
  1626. temp = f2cmax(r__1,r__2);
  1627. }
  1628. /* Computing MAX */
  1629. r__1 = f2cmax(temp,acoefa);
  1630. temp = f2cmax(r__1,bcoefa);
  1631. if (temp > bignum * xscale) {
  1632. i__1 = nw - 1;
  1633. for (jw = 0; jw <= i__1; ++jw) {
  1634. i__2 = je;
  1635. for (jr = 1; jr <= i__2; ++jr) {
  1636. work[(jw + 2) * *n + jr] = xscale * work[(jw
  1637. + 2) * *n + jr];
  1638. /* L320: */
  1639. }
  1640. /* L330: */
  1641. }
  1642. xmax *= xscale;
  1643. }
  1644. /* Compute the contributions of the off-diagonals of */
  1645. /* column j (and j+1, if 2-by-2 block) of A and B to the */
  1646. /* sums. */
  1647. i__1 = na;
  1648. for (ja = 1; ja <= i__1; ++ja) {
  1649. if (ilcplx) {
  1650. creala = acoef * work[(*n << 1) + j + ja - 1];
  1651. cimaga = acoef * work[*n * 3 + j + ja - 1];
  1652. crealb = bcoefr * work[(*n << 1) + j + ja - 1] -
  1653. bcoefi * work[*n * 3 + j + ja - 1];
  1654. cimagb = bcoefi * work[(*n << 1) + j + ja - 1] +
  1655. bcoefr * work[*n * 3 + j + ja - 1];
  1656. i__2 = j - 1;
  1657. for (jr = 1; jr <= i__2; ++jr) {
  1658. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1659. creala * s[jr + (j + ja - 1) * s_dim1]
  1660. + crealb * p[jr + (j + ja - 1) *
  1661. p_dim1];
  1662. work[*n * 3 + jr] = work[*n * 3 + jr] -
  1663. cimaga * s[jr + (j + ja - 1) * s_dim1]
  1664. + cimagb * p[jr + (j + ja - 1) *
  1665. p_dim1];
  1666. /* L340: */
  1667. }
  1668. } else {
  1669. creala = acoef * work[(*n << 1) + j + ja - 1];
  1670. crealb = bcoefr * work[(*n << 1) + j + ja - 1];
  1671. i__2 = j - 1;
  1672. for (jr = 1; jr <= i__2; ++jr) {
  1673. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1674. creala * s[jr + (j + ja - 1) * s_dim1]
  1675. + crealb * p[jr + (j + ja - 1) *
  1676. p_dim1];
  1677. /* L350: */
  1678. }
  1679. }
  1680. /* L360: */
  1681. }
  1682. }
  1683. il2by2 = FALSE_;
  1684. L370:
  1685. ;
  1686. }
  1687. /* Copy eigenvector to VR, back transforming if */
  1688. /* HOWMNY='B'. */
  1689. ieig -= nw;
  1690. if (ilback) {
  1691. i__1 = nw - 1;
  1692. for (jw = 0; jw <= i__1; ++jw) {
  1693. i__2 = *n;
  1694. for (jr = 1; jr <= i__2; ++jr) {
  1695. work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] *
  1696. vr[jr + vr_dim1];
  1697. /* L380: */
  1698. }
  1699. /* A series of compiler directives to defeat */
  1700. /* vectorization for the next loop */
  1701. i__2 = je;
  1702. for (jc = 2; jc <= i__2; ++jc) {
  1703. i__3 = *n;
  1704. for (jr = 1; jr <= i__3; ++jr) {
  1705. work[(jw + 4) * *n + jr] += work[(jw + 2) * *n +
  1706. jc] * vr[jr + jc * vr_dim1];
  1707. /* L390: */
  1708. }
  1709. /* L400: */
  1710. }
  1711. /* L410: */
  1712. }
  1713. i__1 = nw - 1;
  1714. for (jw = 0; jw <= i__1; ++jw) {
  1715. i__2 = *n;
  1716. for (jr = 1; jr <= i__2; ++jr) {
  1717. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n +
  1718. jr];
  1719. /* L420: */
  1720. }
  1721. /* L430: */
  1722. }
  1723. iend = *n;
  1724. } else {
  1725. i__1 = nw - 1;
  1726. for (jw = 0; jw <= i__1; ++jw) {
  1727. i__2 = *n;
  1728. for (jr = 1; jr <= i__2; ++jr) {
  1729. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n +
  1730. jr];
  1731. /* L440: */
  1732. }
  1733. /* L450: */
  1734. }
  1735. iend = je;
  1736. }
  1737. /* Scale eigenvector */
  1738. xmax = 0.f;
  1739. if (ilcplx) {
  1740. i__1 = iend;
  1741. for (j = 1; j <= i__1; ++j) {
  1742. /* Computing MAX */
  1743. r__3 = xmax, r__4 = (r__1 = vr[j + ieig * vr_dim1], abs(
  1744. r__1)) + (r__2 = vr[j + (ieig + 1) * vr_dim1],
  1745. abs(r__2));
  1746. xmax = f2cmax(r__3,r__4);
  1747. /* L460: */
  1748. }
  1749. } else {
  1750. i__1 = iend;
  1751. for (j = 1; j <= i__1; ++j) {
  1752. /* Computing MAX */
  1753. r__2 = xmax, r__3 = (r__1 = vr[j + ieig * vr_dim1], abs(
  1754. r__1));
  1755. xmax = f2cmax(r__2,r__3);
  1756. /* L470: */
  1757. }
  1758. }
  1759. if (xmax > safmin) {
  1760. xscale = 1.f / xmax;
  1761. i__1 = nw - 1;
  1762. for (jw = 0; jw <= i__1; ++jw) {
  1763. i__2 = iend;
  1764. for (jr = 1; jr <= i__2; ++jr) {
  1765. vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
  1766. ieig + jw) * vr_dim1];
  1767. /* L480: */
  1768. }
  1769. /* L490: */
  1770. }
  1771. }
  1772. L500:
  1773. ;
  1774. }
  1775. }
  1776. return;
  1777. /* End of STGEVC */
  1778. } /* stgevc_ */