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.

dtrevc3.c 61 kB

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