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.

dtrevc.c 49 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  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 doublereal c_b22 = 1.;
  489. static doublereal c_b25 = 0.;
  490. static integer c__2 = 2;
  491. static logical c_true = TRUE_;
  492. /* > \brief \b DTREVC */
  493. /* =========== DOCUMENTATION =========== */
  494. /* Online html documentation available at */
  495. /* http://www.netlib.org/lapack/explore-html/ */
  496. /* > \htmlonly */
  497. /* > Download DTREVC + dependencies */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrevc.
  499. f"> */
  500. /* > [TGZ]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrevc.
  502. f"> */
  503. /* > [ZIP]</a> */
  504. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrevc.
  505. f"> */
  506. /* > [TXT]</a> */
  507. /* > \endhtmlonly */
  508. /* Definition: */
  509. /* =========== */
  510. /* SUBROUTINE DTREVC( 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. /* DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ), */
  516. /* $ WORK( * ) */
  517. /* > \par Purpose: */
  518. /* ============= */
  519. /* > */
  520. /* > \verbatim */
  521. /* > */
  522. /* > DTREVC 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 DHSEQR. */
  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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DHSEQR). */
  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 DOUBLE PRECISION 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 DHSEQR). */
  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 DOUBLE PRECISION 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 November 2017 */
  681. /* > \ingroup doubleOTHERcomputational */
  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 dtrevc_(char *side, char *howmny, logical *select,
  698. integer *n, doublereal *t, integer *ldt, doublereal *vl, integer *
  699. ldvl, doublereal *vr, integer *ldvr, integer *mm, integer *m,
  700. doublereal *work, integer *info)
  701. {
  702. /* System generated locals */
  703. integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  704. i__2, i__3;
  705. doublereal d__1, d__2, d__3, d__4;
  706. /* Local variables */
  707. doublereal beta, emax;
  708. logical pair;
  709. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  710. integer *);
  711. logical allv;
  712. integer ierr;
  713. doublereal unfl, ovfl, smin;
  714. logical over;
  715. doublereal vmax;
  716. integer jnxt, i__, j, k;
  717. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  718. integer *);
  719. doublereal scale, x[4] /* was [2][2] */;
  720. extern logical lsame_(char *, char *);
  721. extern /* Subroutine */ void dgemv_(char *, integer *, integer *,
  722. doublereal *, doublereal *, integer *, doublereal *, integer *,
  723. doublereal *, doublereal *, integer *);
  724. doublereal remax;
  725. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  726. doublereal *, integer *);
  727. logical leftv, bothv;
  728. extern /* Subroutine */ void daxpy_(integer *, doublereal *, doublereal *,
  729. integer *, doublereal *, integer *);
  730. doublereal vcrit;
  731. logical somev;
  732. integer j1, j2, n2;
  733. doublereal xnorm;
  734. extern /* Subroutine */ void dlaln2_(logical *, integer *, integer *,
  735. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  736. doublereal *, doublereal *, integer *, doublereal *, doublereal *
  737. , doublereal *, integer *, doublereal *, doublereal *, integer *),
  738. dlabad_(doublereal *, doublereal *);
  739. integer ii, ki;
  740. extern doublereal dlamch_(char *);
  741. integer ip, is;
  742. doublereal wi;
  743. extern integer idamax_(integer *, doublereal *, integer *);
  744. doublereal wr;
  745. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  746. doublereal bignum;
  747. logical rightv;
  748. doublereal smlnum, rec, ulp;
  749. /* -- LAPACK computational routine (version 3.8.0) -- */
  750. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  751. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  752. /* November 2017 */
  753. /* ===================================================================== */
  754. /* Decode and test the input parameters */
  755. /* Parameter adjustments */
  756. --select;
  757. t_dim1 = *ldt;
  758. t_offset = 1 + t_dim1 * 1;
  759. t -= t_offset;
  760. vl_dim1 = *ldvl;
  761. vl_offset = 1 + vl_dim1 * 1;
  762. vl -= vl_offset;
  763. vr_dim1 = *ldvr;
  764. vr_offset = 1 + vr_dim1 * 1;
  765. vr -= vr_offset;
  766. --work;
  767. /* Function Body */
  768. bothv = lsame_(side, "B");
  769. rightv = lsame_(side, "R") || bothv;
  770. leftv = lsame_(side, "L") || bothv;
  771. allv = lsame_(howmny, "A");
  772. over = lsame_(howmny, "B");
  773. somev = lsame_(howmny, "S");
  774. *info = 0;
  775. if (! rightv && ! leftv) {
  776. *info = -1;
  777. } else if (! allv && ! over && ! somev) {
  778. *info = -2;
  779. } else if (*n < 0) {
  780. *info = -4;
  781. } else if (*ldt < f2cmax(1,*n)) {
  782. *info = -6;
  783. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  784. *info = -8;
  785. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  786. *info = -10;
  787. } else {
  788. /* Set M to the number of columns required to store the selected */
  789. /* eigenvectors, standardize the array SELECT if necessary, and */
  790. /* test MM. */
  791. if (somev) {
  792. *m = 0;
  793. pair = FALSE_;
  794. i__1 = *n;
  795. for (j = 1; j <= i__1; ++j) {
  796. if (pair) {
  797. pair = FALSE_;
  798. select[j] = FALSE_;
  799. } else {
  800. if (j < *n) {
  801. if (t[j + 1 + j * t_dim1] == 0.) {
  802. if (select[j]) {
  803. ++(*m);
  804. }
  805. } else {
  806. pair = TRUE_;
  807. if (select[j] || select[j + 1]) {
  808. select[j] = TRUE_;
  809. *m += 2;
  810. }
  811. }
  812. } else {
  813. if (select[*n]) {
  814. ++(*m);
  815. }
  816. }
  817. }
  818. /* L10: */
  819. }
  820. } else {
  821. *m = *n;
  822. }
  823. if (*mm < *m) {
  824. *info = -11;
  825. }
  826. }
  827. if (*info != 0) {
  828. i__1 = -(*info);
  829. xerbla_("DTREVC", &i__1, (ftnlen)6);
  830. return;
  831. }
  832. /* Quick return if possible. */
  833. if (*n == 0) {
  834. return;
  835. }
  836. /* Set the constants to control overflow. */
  837. unfl = dlamch_("Safe minimum");
  838. ovfl = 1. / unfl;
  839. dlabad_(&unfl, &ovfl);
  840. ulp = dlamch_("Precision");
  841. smlnum = unfl * (*n / ulp);
  842. bignum = (1. - ulp) / smlnum;
  843. /* Compute 1-norm of each column of strictly upper triangular */
  844. /* part of T to control overflow in triangular solver. */
  845. work[1] = 0.;
  846. i__1 = *n;
  847. for (j = 2; j <= i__1; ++j) {
  848. work[j] = 0.;
  849. i__2 = j - 1;
  850. for (i__ = 1; i__ <= i__2; ++i__) {
  851. work[j] += (d__1 = t[i__ + j * t_dim1], abs(d__1));
  852. /* L20: */
  853. }
  854. /* L30: */
  855. }
  856. /* Index IP is used to specify the real or complex eigenvalue: */
  857. /* IP = 0, real eigenvalue, */
  858. /* 1, first of conjugate complex pair: (wr,wi) */
  859. /* -1, second of conjugate complex pair: (wr,wi) */
  860. n2 = *n << 1;
  861. if (rightv) {
  862. /* Compute right eigenvectors. */
  863. ip = 0;
  864. is = *m;
  865. for (ki = *n; ki >= 1; --ki) {
  866. if (ip == 1) {
  867. goto L130;
  868. }
  869. if (ki == 1) {
  870. goto L40;
  871. }
  872. if (t[ki + (ki - 1) * t_dim1] == 0.) {
  873. goto L40;
  874. }
  875. ip = -1;
  876. L40:
  877. if (somev) {
  878. if (ip == 0) {
  879. if (! select[ki]) {
  880. goto L130;
  881. }
  882. } else {
  883. if (! select[ki - 1]) {
  884. goto L130;
  885. }
  886. }
  887. }
  888. /* Compute the KI-th eigenvalue (WR,WI). */
  889. wr = t[ki + ki * t_dim1];
  890. wi = 0.;
  891. if (ip != 0) {
  892. wi = sqrt((d__1 = t[ki + (ki - 1) * t_dim1], abs(d__1))) *
  893. sqrt((d__2 = t[ki - 1 + ki * t_dim1], abs(d__2)));
  894. }
  895. /* Computing MAX */
  896. d__1 = ulp * (abs(wr) + abs(wi));
  897. smin = f2cmax(d__1,smlnum);
  898. if (ip == 0) {
  899. /* Real right eigenvector */
  900. work[ki + *n] = 1.;
  901. /* Form right-hand side */
  902. i__1 = ki - 1;
  903. for (k = 1; k <= i__1; ++k) {
  904. work[k + *n] = -t[k + ki * t_dim1];
  905. /* L50: */
  906. }
  907. /* Solve the upper quasi-triangular system: */
  908. /* (T(1:KI-1,1:KI-1) - WR)*X = SCALE*WORK. */
  909. jnxt = ki - 1;
  910. for (j = ki - 1; j >= 1; --j) {
  911. if (j > jnxt) {
  912. goto L60;
  913. }
  914. j1 = j;
  915. j2 = j;
  916. jnxt = j - 1;
  917. if (j > 1) {
  918. if (t[j + (j - 1) * t_dim1] != 0.) {
  919. j1 = j - 1;
  920. jnxt = j - 2;
  921. }
  922. }
  923. if (j1 == j2) {
  924. /* 1-by-1 diagonal block */
  925. dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  926. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  927. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  928. &ierr);
  929. /* Scale X(1,1) to avoid overflow when updating */
  930. /* the right-hand side. */
  931. if (xnorm > 1.) {
  932. if (work[j] > bignum / xnorm) {
  933. x[0] /= xnorm;
  934. scale /= xnorm;
  935. }
  936. }
  937. /* Scale if necessary */
  938. if (scale != 1.) {
  939. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  940. }
  941. work[j + *n] = x[0];
  942. /* Update right-hand side */
  943. i__1 = j - 1;
  944. d__1 = -x[0];
  945. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  946. *n + 1], &c__1);
  947. } else {
  948. /* 2-by-2 diagonal block */
  949. dlaln2_(&c_false, &c__2, &c__1, &smin, &c_b22, &t[j -
  950. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  951. work[j - 1 + *n], n, &wr, &c_b25, x, &c__2, &
  952. scale, &xnorm, &ierr);
  953. /* Scale X(1,1) and X(2,1) to avoid overflow when */
  954. /* updating the right-hand side. */
  955. if (xnorm > 1.) {
  956. /* Computing MAX */
  957. d__1 = work[j - 1], d__2 = work[j];
  958. beta = f2cmax(d__1,d__2);
  959. if (beta > bignum / xnorm) {
  960. x[0] /= xnorm;
  961. x[1] /= xnorm;
  962. scale /= xnorm;
  963. }
  964. }
  965. /* Scale if necessary */
  966. if (scale != 1.) {
  967. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  968. }
  969. work[j - 1 + *n] = x[0];
  970. work[j + *n] = x[1];
  971. /* Update right-hand side */
  972. i__1 = j - 2;
  973. d__1 = -x[0];
  974. daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  975. &work[*n + 1], &c__1);
  976. i__1 = j - 2;
  977. d__1 = -x[1];
  978. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  979. *n + 1], &c__1);
  980. }
  981. L60:
  982. ;
  983. }
  984. /* Copy the vector x or Q*x to VR and normalize. */
  985. if (! over) {
  986. dcopy_(&ki, &work[*n + 1], &c__1, &vr[is * vr_dim1 + 1], &
  987. c__1);
  988. ii = idamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
  989. remax = 1. / (d__1 = vr[ii + is * vr_dim1], abs(d__1));
  990. dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  991. i__1 = *n;
  992. for (k = ki + 1; k <= i__1; ++k) {
  993. vr[k + is * vr_dim1] = 0.;
  994. /* L70: */
  995. }
  996. } else {
  997. if (ki > 1) {
  998. i__1 = ki - 1;
  999. dgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1000. work[*n + 1], &c__1, &work[ki + *n], &vr[ki *
  1001. vr_dim1 + 1], &c__1);
  1002. }
  1003. ii = idamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
  1004. remax = 1. / (d__1 = vr[ii + ki * vr_dim1], abs(d__1));
  1005. dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1006. }
  1007. } else {
  1008. /* Complex right eigenvector. */
  1009. /* Initial solve */
  1010. /* [ (T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I* WI)]*X = 0. */
  1011. /* [ (T(KI,KI-1) T(KI,KI) ) ] */
  1012. if ((d__1 = t[ki - 1 + ki * t_dim1], abs(d__1)) >= (d__2 = t[
  1013. ki + (ki - 1) * t_dim1], abs(d__2))) {
  1014. work[ki - 1 + *n] = 1.;
  1015. work[ki + n2] = wi / t[ki - 1 + ki * t_dim1];
  1016. } else {
  1017. work[ki - 1 + *n] = -wi / t[ki + (ki - 1) * t_dim1];
  1018. work[ki + n2] = 1.;
  1019. }
  1020. work[ki + *n] = 0.;
  1021. work[ki - 1 + n2] = 0.;
  1022. /* Form right-hand side */
  1023. i__1 = ki - 2;
  1024. for (k = 1; k <= i__1; ++k) {
  1025. work[k + *n] = -work[ki - 1 + *n] * t[k + (ki - 1) *
  1026. t_dim1];
  1027. work[k + n2] = -work[ki + n2] * t[k + ki * t_dim1];
  1028. /* L80: */
  1029. }
  1030. /* Solve upper quasi-triangular system: */
  1031. /* (T(1:KI-2,1:KI-2) - (WR+i*WI))*X = SCALE*(WORK+i*WORK2) */
  1032. jnxt = ki - 2;
  1033. for (j = ki - 2; j >= 1; --j) {
  1034. if (j > jnxt) {
  1035. goto L90;
  1036. }
  1037. j1 = j;
  1038. j2 = j;
  1039. jnxt = j - 1;
  1040. if (j > 1) {
  1041. if (t[j + (j - 1) * t_dim1] != 0.) {
  1042. j1 = j - 1;
  1043. jnxt = j - 2;
  1044. }
  1045. }
  1046. if (j1 == j2) {
  1047. /* 1-by-1 diagonal block */
  1048. dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1049. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1050. n], n, &wr, &wi, x, &c__2, &scale, &xnorm, &
  1051. ierr);
  1052. /* Scale X(1,1) and X(1,2) to avoid overflow when */
  1053. /* updating the right-hand side. */
  1054. if (xnorm > 1.) {
  1055. if (work[j] > bignum / xnorm) {
  1056. x[0] /= xnorm;
  1057. x[2] /= xnorm;
  1058. scale /= xnorm;
  1059. }
  1060. }
  1061. /* Scale if necessary */
  1062. if (scale != 1.) {
  1063. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  1064. dscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1065. }
  1066. work[j + *n] = x[0];
  1067. work[j + n2] = x[2];
  1068. /* Update the right-hand side */
  1069. i__1 = j - 1;
  1070. d__1 = -x[0];
  1071. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1072. *n + 1], &c__1);
  1073. i__1 = j - 1;
  1074. d__1 = -x[2];
  1075. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1076. n2 + 1], &c__1);
  1077. } else {
  1078. /* 2-by-2 diagonal block */
  1079. dlaln2_(&c_false, &c__2, &c__2, &smin, &c_b22, &t[j -
  1080. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  1081. work[j - 1 + *n], n, &wr, &wi, x, &c__2, &
  1082. scale, &xnorm, &ierr);
  1083. /* Scale X to avoid overflow when updating */
  1084. /* the right-hand side. */
  1085. if (xnorm > 1.) {
  1086. /* Computing MAX */
  1087. d__1 = work[j - 1], d__2 = work[j];
  1088. beta = f2cmax(d__1,d__2);
  1089. if (beta > bignum / xnorm) {
  1090. rec = 1. / xnorm;
  1091. x[0] *= rec;
  1092. x[2] *= rec;
  1093. x[1] *= rec;
  1094. x[3] *= rec;
  1095. scale *= rec;
  1096. }
  1097. }
  1098. /* Scale if necessary */
  1099. if (scale != 1.) {
  1100. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  1101. dscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1102. }
  1103. work[j - 1 + *n] = x[0];
  1104. work[j + *n] = x[1];
  1105. work[j - 1 + n2] = x[2];
  1106. work[j + n2] = x[3];
  1107. /* Update the right-hand side */
  1108. i__1 = j - 2;
  1109. d__1 = -x[0];
  1110. daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1111. &work[*n + 1], &c__1);
  1112. i__1 = j - 2;
  1113. d__1 = -x[1];
  1114. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1115. *n + 1], &c__1);
  1116. i__1 = j - 2;
  1117. d__1 = -x[2];
  1118. daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1119. &work[n2 + 1], &c__1);
  1120. i__1 = j - 2;
  1121. d__1 = -x[3];
  1122. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1123. n2 + 1], &c__1);
  1124. }
  1125. L90:
  1126. ;
  1127. }
  1128. /* Copy the vector x or Q*x to VR and normalize. */
  1129. if (! over) {
  1130. dcopy_(&ki, &work[*n + 1], &c__1, &vr[(is - 1) * vr_dim1
  1131. + 1], &c__1);
  1132. dcopy_(&ki, &work[n2 + 1], &c__1, &vr[is * vr_dim1 + 1], &
  1133. c__1);
  1134. emax = 0.;
  1135. i__1 = ki;
  1136. for (k = 1; k <= i__1; ++k) {
  1137. /* Computing MAX */
  1138. d__3 = emax, d__4 = (d__1 = vr[k + (is - 1) * vr_dim1]
  1139. , abs(d__1)) + (d__2 = vr[k + is * vr_dim1],
  1140. abs(d__2));
  1141. emax = f2cmax(d__3,d__4);
  1142. /* L100: */
  1143. }
  1144. remax = 1. / emax;
  1145. dscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
  1146. dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1147. i__1 = *n;
  1148. for (k = ki + 1; k <= i__1; ++k) {
  1149. vr[k + (is - 1) * vr_dim1] = 0.;
  1150. vr[k + is * vr_dim1] = 0.;
  1151. /* L110: */
  1152. }
  1153. } else {
  1154. if (ki > 2) {
  1155. i__1 = ki - 2;
  1156. dgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1157. work[*n + 1], &c__1, &work[ki - 1 + *n], &vr[(
  1158. ki - 1) * vr_dim1 + 1], &c__1);
  1159. i__1 = ki - 2;
  1160. dgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1161. work[n2 + 1], &c__1, &work[ki + n2], &vr[ki *
  1162. vr_dim1 + 1], &c__1);
  1163. } else {
  1164. dscal_(n, &work[ki - 1 + *n], &vr[(ki - 1) * vr_dim1
  1165. + 1], &c__1);
  1166. dscal_(n, &work[ki + n2], &vr[ki * vr_dim1 + 1], &
  1167. c__1);
  1168. }
  1169. emax = 0.;
  1170. i__1 = *n;
  1171. for (k = 1; k <= i__1; ++k) {
  1172. /* Computing MAX */
  1173. d__3 = emax, d__4 = (d__1 = vr[k + (ki - 1) * vr_dim1]
  1174. , abs(d__1)) + (d__2 = vr[k + ki * vr_dim1],
  1175. abs(d__2));
  1176. emax = f2cmax(d__3,d__4);
  1177. /* L120: */
  1178. }
  1179. remax = 1. / emax;
  1180. dscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
  1181. dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1182. }
  1183. }
  1184. --is;
  1185. if (ip != 0) {
  1186. --is;
  1187. }
  1188. L130:
  1189. if (ip == 1) {
  1190. ip = 0;
  1191. }
  1192. if (ip == -1) {
  1193. ip = 1;
  1194. }
  1195. /* L140: */
  1196. }
  1197. }
  1198. if (leftv) {
  1199. /* Compute left eigenvectors. */
  1200. ip = 0;
  1201. is = 1;
  1202. i__1 = *n;
  1203. for (ki = 1; ki <= i__1; ++ki) {
  1204. if (ip == -1) {
  1205. goto L250;
  1206. }
  1207. if (ki == *n) {
  1208. goto L150;
  1209. }
  1210. if (t[ki + 1 + ki * t_dim1] == 0.) {
  1211. goto L150;
  1212. }
  1213. ip = 1;
  1214. L150:
  1215. if (somev) {
  1216. if (! select[ki]) {
  1217. goto L250;
  1218. }
  1219. }
  1220. /* Compute the KI-th eigenvalue (WR,WI). */
  1221. wr = t[ki + ki * t_dim1];
  1222. wi = 0.;
  1223. if (ip != 0) {
  1224. wi = sqrt((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1))) *
  1225. sqrt((d__2 = t[ki + 1 + ki * t_dim1], abs(d__2)));
  1226. }
  1227. /* Computing MAX */
  1228. d__1 = ulp * (abs(wr) + abs(wi));
  1229. smin = f2cmax(d__1,smlnum);
  1230. if (ip == 0) {
  1231. /* Real left eigenvector. */
  1232. work[ki + *n] = 1.;
  1233. /* Form right-hand side */
  1234. i__2 = *n;
  1235. for (k = ki + 1; k <= i__2; ++k) {
  1236. work[k + *n] = -t[ki + k * t_dim1];
  1237. /* L160: */
  1238. }
  1239. /* Solve the quasi-triangular system: */
  1240. /* (T(KI+1:N,KI+1:N) - WR)**T*X = SCALE*WORK */
  1241. vmax = 1.;
  1242. vcrit = bignum;
  1243. jnxt = ki + 1;
  1244. i__2 = *n;
  1245. for (j = ki + 1; j <= i__2; ++j) {
  1246. if (j < jnxt) {
  1247. goto L170;
  1248. }
  1249. j1 = j;
  1250. j2 = j;
  1251. jnxt = j + 1;
  1252. if (j < *n) {
  1253. if (t[j + 1 + j * t_dim1] != 0.) {
  1254. j2 = j + 1;
  1255. jnxt = j + 2;
  1256. }
  1257. }
  1258. if (j1 == j2) {
  1259. /* 1-by-1 diagonal block */
  1260. /* Scale if necessary to avoid overflow when forming */
  1261. /* the right-hand side. */
  1262. if (work[j] > vcrit) {
  1263. rec = 1. / vmax;
  1264. i__3 = *n - ki + 1;
  1265. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1266. vmax = 1.;
  1267. vcrit = bignum;
  1268. }
  1269. i__3 = j - ki - 1;
  1270. work[j + *n] -= ddot_(&i__3, &t[ki + 1 + j * t_dim1],
  1271. &c__1, &work[ki + 1 + *n], &c__1);
  1272. /* Solve (T(J,J)-WR)**T*X = WORK */
  1273. dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  1274. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1275. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1276. &ierr);
  1277. /* Scale if necessary */
  1278. if (scale != 1.) {
  1279. i__3 = *n - ki + 1;
  1280. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1281. }
  1282. work[j + *n] = x[0];
  1283. /* Computing MAX */
  1284. d__2 = (d__1 = work[j + *n], abs(d__1));
  1285. vmax = f2cmax(d__2,vmax);
  1286. vcrit = bignum / vmax;
  1287. } else {
  1288. /* 2-by-2 diagonal block */
  1289. /* Scale if necessary to avoid overflow when forming */
  1290. /* the right-hand side. */
  1291. /* Computing MAX */
  1292. d__1 = work[j], d__2 = work[j + 1];
  1293. beta = f2cmax(d__1,d__2);
  1294. if (beta > vcrit) {
  1295. rec = 1. / vmax;
  1296. i__3 = *n - ki + 1;
  1297. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1298. vmax = 1.;
  1299. vcrit = bignum;
  1300. }
  1301. i__3 = j - ki - 1;
  1302. work[j + *n] -= ddot_(&i__3, &t[ki + 1 + j * t_dim1],
  1303. &c__1, &work[ki + 1 + *n], &c__1);
  1304. i__3 = j - ki - 1;
  1305. work[j + 1 + *n] -= ddot_(&i__3, &t[ki + 1 + (j + 1) *
  1306. t_dim1], &c__1, &work[ki + 1 + *n], &c__1);
  1307. /* Solve */
  1308. /* [T(J,J)-WR T(J,J+1) ]**T * X = SCALE*( WORK1 ) */
  1309. /* [T(J+1,J) T(J+1,J+1)-WR] ( WORK2 ) */
  1310. dlaln2_(&c_true, &c__2, &c__1, &smin, &c_b22, &t[j +
  1311. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1312. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1313. &ierr);
  1314. /* Scale if necessary */
  1315. if (scale != 1.) {
  1316. i__3 = *n - ki + 1;
  1317. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1318. }
  1319. work[j + *n] = x[0];
  1320. work[j + 1 + *n] = x[1];
  1321. /* Computing MAX */
  1322. d__3 = (d__1 = work[j + *n], abs(d__1)), d__4 = (d__2
  1323. = work[j + 1 + *n], abs(d__2)), d__3 = f2cmax(
  1324. d__3,d__4);
  1325. vmax = f2cmax(d__3,vmax);
  1326. vcrit = bignum / vmax;
  1327. }
  1328. L170:
  1329. ;
  1330. }
  1331. /* Copy the vector x or Q*x to VL and normalize. */
  1332. if (! over) {
  1333. i__2 = *n - ki + 1;
  1334. dcopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1335. vl_dim1], &c__1);
  1336. i__2 = *n - ki + 1;
  1337. ii = idamax_(&i__2, &vl[ki + is * vl_dim1], &c__1) + ki -
  1338. 1;
  1339. remax = 1. / (d__1 = vl[ii + is * vl_dim1], abs(d__1));
  1340. i__2 = *n - ki + 1;
  1341. dscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1342. i__2 = ki - 1;
  1343. for (k = 1; k <= i__2; ++k) {
  1344. vl[k + is * vl_dim1] = 0.;
  1345. /* L180: */
  1346. }
  1347. } else {
  1348. if (ki < *n) {
  1349. i__2 = *n - ki;
  1350. dgemv_("N", n, &i__2, &c_b22, &vl[(ki + 1) * vl_dim1
  1351. + 1], ldvl, &work[ki + 1 + *n], &c__1, &work[
  1352. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1353. }
  1354. ii = idamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
  1355. remax = 1. / (d__1 = vl[ii + ki * vl_dim1], abs(d__1));
  1356. dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1357. }
  1358. } else {
  1359. /* Complex left eigenvector. */
  1360. /* Initial solve: */
  1361. /* ((T(KI,KI) T(KI,KI+1) )**T - (WR - I* WI))*X = 0. */
  1362. /* ((T(KI+1,KI) T(KI+1,KI+1)) ) */
  1363. if ((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1)) >= (d__2 =
  1364. t[ki + 1 + ki * t_dim1], abs(d__2))) {
  1365. work[ki + *n] = wi / t[ki + (ki + 1) * t_dim1];
  1366. work[ki + 1 + n2] = 1.;
  1367. } else {
  1368. work[ki + *n] = 1.;
  1369. work[ki + 1 + n2] = -wi / t[ki + 1 + ki * t_dim1];
  1370. }
  1371. work[ki + 1 + *n] = 0.;
  1372. work[ki + n2] = 0.;
  1373. /* Form right-hand side */
  1374. i__2 = *n;
  1375. for (k = ki + 2; k <= i__2; ++k) {
  1376. work[k + *n] = -work[ki + *n] * t[ki + k * t_dim1];
  1377. work[k + n2] = -work[ki + 1 + n2] * t[ki + 1 + k * t_dim1]
  1378. ;
  1379. /* L190: */
  1380. }
  1381. /* Solve complex quasi-triangular system: */
  1382. /* ( T(KI+2,N:KI+2,N) - (WR-i*WI) )*X = WORK1+i*WORK2 */
  1383. vmax = 1.;
  1384. vcrit = bignum;
  1385. jnxt = ki + 2;
  1386. i__2 = *n;
  1387. for (j = ki + 2; j <= i__2; ++j) {
  1388. if (j < jnxt) {
  1389. goto L200;
  1390. }
  1391. j1 = j;
  1392. j2 = j;
  1393. jnxt = j + 1;
  1394. if (j < *n) {
  1395. if (t[j + 1 + j * t_dim1] != 0.) {
  1396. j2 = j + 1;
  1397. jnxt = j + 2;
  1398. }
  1399. }
  1400. if (j1 == j2) {
  1401. /* 1-by-1 diagonal block */
  1402. /* Scale if necessary to avoid overflow when */
  1403. /* forming the right-hand side elements. */
  1404. if (work[j] > vcrit) {
  1405. rec = 1. / vmax;
  1406. i__3 = *n - ki + 1;
  1407. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1408. i__3 = *n - ki + 1;
  1409. dscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1410. vmax = 1.;
  1411. vcrit = bignum;
  1412. }
  1413. i__3 = j - ki - 2;
  1414. work[j + *n] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1415. &c__1, &work[ki + 2 + *n], &c__1);
  1416. i__3 = j - ki - 2;
  1417. work[j + n2] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1418. &c__1, &work[ki + 2 + n2], &c__1);
  1419. /* Solve (T(J,J)-(WR-i*WI))*(X11+i*X12)= WK+I*WK2 */
  1420. d__1 = -wi;
  1421. dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1422. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1423. n], n, &wr, &d__1, x, &c__2, &scale, &xnorm, &
  1424. ierr);
  1425. /* Scale if necessary */
  1426. if (scale != 1.) {
  1427. i__3 = *n - ki + 1;
  1428. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1429. i__3 = *n - ki + 1;
  1430. dscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1431. }
  1432. work[j + *n] = x[0];
  1433. work[j + n2] = x[2];
  1434. /* Computing MAX */
  1435. d__3 = (d__1 = work[j + *n], abs(d__1)), d__4 = (d__2
  1436. = work[j + n2], abs(d__2)), d__3 = f2cmax(d__3,
  1437. d__4);
  1438. vmax = f2cmax(d__3,vmax);
  1439. vcrit = bignum / vmax;
  1440. } else {
  1441. /* 2-by-2 diagonal block */
  1442. /* Scale if necessary to avoid overflow when forming */
  1443. /* the right-hand side elements. */
  1444. /* Computing MAX */
  1445. d__1 = work[j], d__2 = work[j + 1];
  1446. beta = f2cmax(d__1,d__2);
  1447. if (beta > vcrit) {
  1448. rec = 1. / vmax;
  1449. i__3 = *n - ki + 1;
  1450. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1451. i__3 = *n - ki + 1;
  1452. dscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1453. vmax = 1.;
  1454. vcrit = bignum;
  1455. }
  1456. i__3 = j - ki - 2;
  1457. work[j + *n] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1458. &c__1, &work[ki + 2 + *n], &c__1);
  1459. i__3 = j - ki - 2;
  1460. work[j + n2] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1461. &c__1, &work[ki + 2 + n2], &c__1);
  1462. i__3 = j - ki - 2;
  1463. work[j + 1 + *n] -= ddot_(&i__3, &t[ki + 2 + (j + 1) *
  1464. t_dim1], &c__1, &work[ki + 2 + *n], &c__1);
  1465. i__3 = j - ki - 2;
  1466. work[j + 1 + n2] -= ddot_(&i__3, &t[ki + 2 + (j + 1) *
  1467. t_dim1], &c__1, &work[ki + 2 + n2], &c__1);
  1468. /* Solve 2-by-2 complex linear equation */
  1469. /* ([T(j,j) T(j,j+1) ]**T-(wr-i*wi)*I)*X = SCALE*B */
  1470. /* ([T(j+1,j) T(j+1,j+1)] ) */
  1471. d__1 = -wi;
  1472. dlaln2_(&c_true, &c__2, &c__2, &smin, &c_b22, &t[j +
  1473. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1474. n], n, &wr, &d__1, x, &c__2, &scale, &xnorm, &
  1475. ierr);
  1476. /* Scale if necessary */
  1477. if (scale != 1.) {
  1478. i__3 = *n - ki + 1;
  1479. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1480. i__3 = *n - ki + 1;
  1481. dscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1482. }
  1483. work[j + *n] = x[0];
  1484. work[j + n2] = x[2];
  1485. work[j + 1 + *n] = x[1];
  1486. work[j + 1 + n2] = x[3];
  1487. /* Computing MAX */
  1488. d__1 = abs(x[0]), d__2 = abs(x[2]), d__1 = f2cmax(d__1,
  1489. d__2), d__2 = abs(x[1]), d__1 = f2cmax(d__1,d__2)
  1490. , d__2 = abs(x[3]), d__1 = f2cmax(d__1,d__2);
  1491. vmax = f2cmax(d__1,vmax);
  1492. vcrit = bignum / vmax;
  1493. }
  1494. L200:
  1495. ;
  1496. }
  1497. /* Copy the vector x or Q*x to VL and normalize. */
  1498. if (! over) {
  1499. i__2 = *n - ki + 1;
  1500. dcopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1501. vl_dim1], &c__1);
  1502. i__2 = *n - ki + 1;
  1503. dcopy_(&i__2, &work[ki + n2], &c__1, &vl[ki + (is + 1) *
  1504. vl_dim1], &c__1);
  1505. emax = 0.;
  1506. i__2 = *n;
  1507. for (k = ki; k <= i__2; ++k) {
  1508. /* Computing MAX */
  1509. d__3 = emax, d__4 = (d__1 = vl[k + is * vl_dim1], abs(
  1510. d__1)) + (d__2 = vl[k + (is + 1) * vl_dim1],
  1511. abs(d__2));
  1512. emax = f2cmax(d__3,d__4);
  1513. /* L220: */
  1514. }
  1515. remax = 1. / emax;
  1516. i__2 = *n - ki + 1;
  1517. dscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1518. i__2 = *n - ki + 1;
  1519. dscal_(&i__2, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
  1520. ;
  1521. i__2 = ki - 1;
  1522. for (k = 1; k <= i__2; ++k) {
  1523. vl[k + is * vl_dim1] = 0.;
  1524. vl[k + (is + 1) * vl_dim1] = 0.;
  1525. /* L230: */
  1526. }
  1527. } else {
  1528. if (ki < *n - 1) {
  1529. i__2 = *n - ki - 1;
  1530. dgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1531. + 1], ldvl, &work[ki + 2 + *n], &c__1, &work[
  1532. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1533. i__2 = *n - ki - 1;
  1534. dgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1535. + 1], ldvl, &work[ki + 2 + n2], &c__1, &work[
  1536. ki + 1 + n2], &vl[(ki + 1) * vl_dim1 + 1], &
  1537. c__1);
  1538. } else {
  1539. dscal_(n, &work[ki + *n], &vl[ki * vl_dim1 + 1], &
  1540. c__1);
  1541. dscal_(n, &work[ki + 1 + n2], &vl[(ki + 1) * vl_dim1
  1542. + 1], &c__1);
  1543. }
  1544. emax = 0.;
  1545. i__2 = *n;
  1546. for (k = 1; k <= i__2; ++k) {
  1547. /* Computing MAX */
  1548. d__3 = emax, d__4 = (d__1 = vl[k + ki * vl_dim1], abs(
  1549. d__1)) + (d__2 = vl[k + (ki + 1) * vl_dim1],
  1550. abs(d__2));
  1551. emax = f2cmax(d__3,d__4);
  1552. /* L240: */
  1553. }
  1554. remax = 1. / emax;
  1555. dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1556. dscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
  1557. }
  1558. }
  1559. ++is;
  1560. if (ip != 0) {
  1561. ++is;
  1562. }
  1563. L250:
  1564. if (ip == -1) {
  1565. ip = 0;
  1566. }
  1567. if (ip == 1) {
  1568. ip = -1;
  1569. }
  1570. /* L260: */
  1571. }
  1572. }
  1573. return;
  1574. /* End of DTREVC */
  1575. } /* dtrevc_ */