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 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 integer c__1 = 1;
  487. static integer c_n1 = -1;
  488. static integer c__2 = 2;
  489. static doublereal c_b17 = 0.;
  490. static logical c_false = FALSE_;
  491. static doublereal c_b29 = 1.;
  492. static logical c_true = TRUE_;
  493. /* > \brief \b DTREVC3 */
  494. /* =========== DOCUMENTATION =========== */
  495. /* Online html documentation available at */
  496. /* http://www.netlib.org/lapack/explore-html/ */
  497. /* > \htmlonly */
  498. /* > Download DTREVC3 + dependencies */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrevc3
  500. .f"> */
  501. /* > [TGZ]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrevc3
  503. .f"> */
  504. /* > [ZIP]</a> */
  505. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrevc3
  506. .f"> */
  507. /* > [TXT]</a> */
  508. /* > \endhtmlonly */
  509. /* Definition: */
  510. /* =========== */
  511. /* SUBROUTINE DTREVC3( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, */
  512. /* VR, LDVR, MM, M, WORK, LWORK, INFO ) */
  513. /* CHARACTER HOWMNY, SIDE */
  514. /* INTEGER INFO, LDT, LDVL, LDVR, LWORK, M, MM, N */
  515. /* LOGICAL SELECT( * ) */
  516. /* DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ), */
  517. /* $ WORK( * ) */
  518. /* > \par Purpose: */
  519. /* ============= */
  520. /* > */
  521. /* > \verbatim */
  522. /* > */
  523. /* > DTREVC3 computes some or all of the right and/or left eigenvectors of */
  524. /* > a real upper quasi-triangular matrix T. */
  525. /* > Matrices of this type are produced by the Schur factorization of */
  526. /* > a real general matrix: A = Q*T*Q**T, as computed by DHSEQR. */
  527. /* > */
  528. /* > The right eigenvector x and the left eigenvector y of T corresponding */
  529. /* > to an eigenvalue w are defined by: */
  530. /* > */
  531. /* > T*x = w*x, (y**T)*T = w*(y**T) */
  532. /* > */
  533. /* > where y**T denotes the transpose of the vector y. */
  534. /* > The eigenvalues are not input to this routine, but are read directly */
  535. /* > from the diagonal blocks of T. */
  536. /* > */
  537. /* > This routine returns the matrices X and/or Y of right and left */
  538. /* > eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an */
  539. /* > input matrix. If Q is the orthogonal factor that reduces a matrix */
  540. /* > A to Schur form T, then Q*X and Q*Y are the matrices of right and */
  541. /* > left eigenvectors of A. */
  542. /* > */
  543. /* > This uses a Level 3 BLAS version of the back transformation. */
  544. /* > \endverbatim */
  545. /* Arguments: */
  546. /* ========== */
  547. /* > \param[in] SIDE */
  548. /* > \verbatim */
  549. /* > SIDE is CHARACTER*1 */
  550. /* > = 'R': compute right eigenvectors only; */
  551. /* > = 'L': compute left eigenvectors only; */
  552. /* > = 'B': compute both right and left eigenvectors. */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] HOWMNY */
  556. /* > \verbatim */
  557. /* > HOWMNY is CHARACTER*1 */
  558. /* > = 'A': compute all right and/or left eigenvectors; */
  559. /* > = 'B': compute all right and/or left eigenvectors, */
  560. /* > backtransformed by the matrices in VR and/or VL; */
  561. /* > = 'S': compute selected right and/or left eigenvectors, */
  562. /* > as indicated by the logical array SELECT. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in,out] SELECT */
  566. /* > \verbatim */
  567. /* > SELECT is LOGICAL array, dimension (N) */
  568. /* > If HOWMNY = 'S', SELECT specifies the eigenvectors to be */
  569. /* > computed. */
  570. /* > If w(j) is a real eigenvalue, the corresponding real */
  571. /* > eigenvector is computed if SELECT(j) is .TRUE.. */
  572. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  573. /* > complex eigenvalue, the corresponding complex eigenvector is */
  574. /* > computed if either SELECT(j) or SELECT(j+1) is .TRUE., and */
  575. /* > on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to */
  576. /* > .FALSE.. */
  577. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in] N */
  581. /* > \verbatim */
  582. /* > N is INTEGER */
  583. /* > The order of the matrix T. N >= 0. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in] T */
  587. /* > \verbatim */
  588. /* > T is DOUBLE PRECISION array, dimension (LDT,N) */
  589. /* > The upper quasi-triangular matrix T in Schur canonical form. */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[in] LDT */
  593. /* > \verbatim */
  594. /* > LDT is INTEGER */
  595. /* > The leading dimension of the array T. LDT >= f2cmax(1,N). */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[in,out] VL */
  599. /* > \verbatim */
  600. /* > VL is DOUBLE PRECISION array, dimension (LDVL,MM) */
  601. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  602. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  603. /* > of Schur vectors returned by DHSEQR). */
  604. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  605. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of T; */
  606. /* > if HOWMNY = 'B', the matrix Q*Y; */
  607. /* > if HOWMNY = 'S', the left eigenvectors of T specified by */
  608. /* > SELECT, stored consecutively in the columns */
  609. /* > of VL, in the same order as their */
  610. /* > eigenvalues. */
  611. /* > A complex eigenvector corresponding to a complex eigenvalue */
  612. /* > is stored in two consecutive columns, the first holding the */
  613. /* > real part, and the second the imaginary part. */
  614. /* > Not referenced if SIDE = 'R'. */
  615. /* > \endverbatim */
  616. /* > */
  617. /* > \param[in] LDVL */
  618. /* > \verbatim */
  619. /* > LDVL is INTEGER */
  620. /* > The leading dimension of the array VL. */
  621. /* > LDVL >= 1, and if SIDE = 'L' or 'B', LDVL >= N. */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[in,out] VR */
  625. /* > \verbatim */
  626. /* > VR is DOUBLE PRECISION array, dimension (LDVR,MM) */
  627. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  628. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  629. /* > of Schur vectors returned by DHSEQR). */
  630. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  631. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of T; */
  632. /* > if HOWMNY = 'B', the matrix Q*X; */
  633. /* > if HOWMNY = 'S', the right eigenvectors of T specified by */
  634. /* > SELECT, stored consecutively in the columns */
  635. /* > of VR, in the same order as their */
  636. /* > eigenvalues. */
  637. /* > A complex eigenvector corresponding to a complex eigenvalue */
  638. /* > is stored in two consecutive columns, the first holding the */
  639. /* > real part and the second the imaginary part. */
  640. /* > Not referenced if SIDE = 'L'. */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[in] LDVR */
  644. /* > \verbatim */
  645. /* > LDVR is INTEGER */
  646. /* > The leading dimension of the array VR. */
  647. /* > LDVR >= 1, and if SIDE = 'R' or 'B', LDVR >= N. */
  648. /* > \endverbatim */
  649. /* > */
  650. /* > \param[in] MM */
  651. /* > \verbatim */
  652. /* > MM is INTEGER */
  653. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  654. /* > \endverbatim */
  655. /* > */
  656. /* > \param[out] M */
  657. /* > \verbatim */
  658. /* > M is INTEGER */
  659. /* > The number of columns in the arrays VL and/or VR actually */
  660. /* > used to store the eigenvectors. */
  661. /* > If HOWMNY = 'A' or 'B', M is set to N. */
  662. /* > Each selected real eigenvector occupies one column and each */
  663. /* > selected complex eigenvector occupies two columns. */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[out] WORK */
  667. /* > \verbatim */
  668. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  669. /* > \endverbatim */
  670. /* > */
  671. /* > \param[in] LWORK */
  672. /* > \verbatim */
  673. /* > LWORK is INTEGER */
  674. /* > The dimension of array WORK. LWORK >= f2cmax(1,3*N). */
  675. /* > For optimum performance, LWORK >= N + 2*N*NB, where NB is */
  676. /* > the optimal blocksize. */
  677. /* > */
  678. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  679. /* > only calculates the optimal size of the WORK array, returns */
  680. /* > this value as the first entry of the WORK array, and no error */
  681. /* > message related to LWORK is issued by XERBLA. */
  682. /* > \endverbatim */
  683. /* > */
  684. /* > \param[out] INFO */
  685. /* > \verbatim */
  686. /* > INFO is INTEGER */
  687. /* > = 0: successful exit */
  688. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  689. /* > \endverbatim */
  690. /* Authors: */
  691. /* ======== */
  692. /* > \author Univ. of Tennessee */
  693. /* > \author Univ. of California Berkeley */
  694. /* > \author Univ. of Colorado Denver */
  695. /* > \author NAG Ltd. */
  696. /* > \date November 2017 */
  697. /* @precisions fortran d -> s */
  698. /* > \ingroup doubleOTHERcomputational */
  699. /* > \par Further Details: */
  700. /* ===================== */
  701. /* > */
  702. /* > \verbatim */
  703. /* > */
  704. /* > The algorithm used in this program is basically backward (forward) */
  705. /* > substitution, with scaling to make the the code robust against */
  706. /* > possible overflow. */
  707. /* > */
  708. /* > Each eigenvector is normalized so that the element of largest */
  709. /* > magnitude has magnitude 1; here the magnitude of a complex number */
  710. /* > (x,y) is taken to be |x| + |y|. */
  711. /* > \endverbatim */
  712. /* > */
  713. /* ===================================================================== */
  714. /* Subroutine */ void dtrevc3_(char *side, char *howmny, logical *select,
  715. integer *n, doublereal *t, integer *ldt, doublereal *vl, integer *
  716. ldvl, doublereal *vr, integer *ldvr, integer *mm, integer *m,
  717. doublereal *work, integer *lwork, integer *info)
  718. {
  719. /* System generated locals */
  720. address a__1[2];
  721. integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1[2],
  722. i__2, i__3, i__4;
  723. doublereal d__1, d__2, d__3, d__4;
  724. char ch__1[2];
  725. /* Local variables */
  726. doublereal beta, emax;
  727. logical pair;
  728. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  729. integer *);
  730. logical allv;
  731. integer ierr;
  732. doublereal unfl, ovfl, smin;
  733. logical over;
  734. doublereal vmax;
  735. integer jnxt, i__, j, k;
  736. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  737. integer *);
  738. doublereal scale, x[4] /* was [2][2] */;
  739. extern /* Subroutine */ void dgemm_(char *, char *, integer *, integer *,
  740. integer *, doublereal *, doublereal *, integer *, doublereal *,
  741. integer *, doublereal *, doublereal *, integer *);
  742. extern logical lsame_(char *, char *);
  743. extern /* Subroutine */ void dgemv_(char *, integer *, integer *,
  744. doublereal *, doublereal *, integer *, doublereal *, integer *,
  745. doublereal *, doublereal *, integer *);
  746. doublereal remax;
  747. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  748. doublereal *, integer *);
  749. logical leftv, bothv;
  750. extern /* Subroutine */ void daxpy_(integer *, doublereal *, doublereal *,
  751. integer *, doublereal *, integer *);
  752. doublereal vcrit;
  753. logical somev;
  754. integer j1, j2;
  755. doublereal xnorm;
  756. extern /* Subroutine */ void dlaln2_(logical *, integer *, integer *,
  757. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  758. doublereal *, doublereal *, integer *, doublereal *, doublereal *
  759. , doublereal *, integer *, doublereal *, doublereal *, integer *);
  760. integer iscomplex[128];
  761. extern /* Subroutine */ void dlabad_(doublereal *, doublereal *);
  762. integer nb, ii, ki;
  763. extern doublereal dlamch_(char *);
  764. integer ip, is, iv;
  765. doublereal wi;
  766. extern integer idamax_(integer *, doublereal *, integer *);
  767. doublereal wr;
  768. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  769. doublereal *, doublereal *, doublereal *, integer *);
  770. extern int xerbla_(char *, integer *, ftnlen);
  771. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  772. integer *, integer *, ftnlen, ftnlen);
  773. extern /* Subroutine */ void dlacpy_(char *, integer *, integer *,
  774. doublereal *, integer *, doublereal *, integer *);
  775. doublereal bignum;
  776. logical rightv;
  777. integer ki2, maxwrk;
  778. doublereal smlnum;
  779. logical lquery;
  780. doublereal rec, ulp;
  781. /* -- LAPACK computational routine (version 3.8.0) -- */
  782. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  783. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  784. /* November 2017 */
  785. /* ===================================================================== */
  786. /* Decode and test the input parameters */
  787. /* Parameter adjustments */
  788. --select;
  789. t_dim1 = *ldt;
  790. t_offset = 1 + t_dim1 * 1;
  791. t -= t_offset;
  792. vl_dim1 = *ldvl;
  793. vl_offset = 1 + vl_dim1 * 1;
  794. vl -= vl_offset;
  795. vr_dim1 = *ldvr;
  796. vr_offset = 1 + vr_dim1 * 1;
  797. vr -= vr_offset;
  798. --work;
  799. /* Function Body */
  800. bothv = lsame_(side, "B");
  801. rightv = lsame_(side, "R") || bothv;
  802. leftv = lsame_(side, "L") || bothv;
  803. allv = lsame_(howmny, "A");
  804. over = lsame_(howmny, "B");
  805. somev = lsame_(howmny, "S");
  806. *info = 0;
  807. /* Writing concatenation */
  808. i__1[0] = 1, a__1[0] = side;
  809. i__1[1] = 1, a__1[1] = howmny;
  810. s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
  811. nb = ilaenv_(&c__1, "DTREVC", ch__1, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
  812. ftnlen)2);
  813. maxwrk = *n + (*n << 1) * nb;
  814. work[1] = (doublereal) maxwrk;
  815. lquery = *lwork == -1;
  816. if (! rightv && ! leftv) {
  817. *info = -1;
  818. } else if (! allv && ! over && ! somev) {
  819. *info = -2;
  820. } else if (*n < 0) {
  821. *info = -4;
  822. } else if (*ldt < f2cmax(1,*n)) {
  823. *info = -6;
  824. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  825. *info = -8;
  826. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  827. *info = -10;
  828. } else /* if(complicated condition) */ {
  829. /* Computing MAX */
  830. i__2 = 1, i__3 = *n * 3;
  831. if (*lwork < f2cmax(i__2,i__3) && ! lquery) {
  832. *info = -14;
  833. } else {
  834. /* Set M to the number of columns required to store the selected */
  835. /* eigenvectors, standardize the array SELECT if necessary, and */
  836. /* test MM. */
  837. if (somev) {
  838. *m = 0;
  839. pair = FALSE_;
  840. i__2 = *n;
  841. for (j = 1; j <= i__2; ++j) {
  842. if (pair) {
  843. pair = FALSE_;
  844. select[j] = FALSE_;
  845. } else {
  846. if (j < *n) {
  847. if (t[j + 1 + j * t_dim1] == 0.) {
  848. if (select[j]) {
  849. ++(*m);
  850. }
  851. } else {
  852. pair = TRUE_;
  853. if (select[j] || select[j + 1]) {
  854. select[j] = TRUE_;
  855. *m += 2;
  856. }
  857. }
  858. } else {
  859. if (select[*n]) {
  860. ++(*m);
  861. }
  862. }
  863. }
  864. /* L10: */
  865. }
  866. } else {
  867. *m = *n;
  868. }
  869. if (*mm < *m) {
  870. *info = -11;
  871. }
  872. }
  873. }
  874. if (*info != 0) {
  875. i__2 = -(*info);
  876. xerbla_("DTREVC3", &i__2, (ftnlen)7);
  877. return;
  878. } else if (lquery) {
  879. return;
  880. }
  881. /* Quick return if possible. */
  882. if (*n == 0) {
  883. return;
  884. }
  885. /* Use blocked version of back-transformation if sufficient workspace. */
  886. /* Zero-out the workspace to avoid potential NaN propagation. */
  887. if (over && *lwork >= *n + (*n << 4)) {
  888. nb = (*lwork - *n) / (*n << 1);
  889. nb = f2cmin(nb,128);
  890. i__2 = (nb << 1) + 1;
  891. dlaset_("F", n, &i__2, &c_b17, &c_b17, &work[1], n);
  892. } else {
  893. nb = 1;
  894. }
  895. /* Set the constants to control overflow. */
  896. unfl = dlamch_("Safe minimum");
  897. ovfl = 1. / unfl;
  898. dlabad_(&unfl, &ovfl);
  899. ulp = dlamch_("Precision");
  900. smlnum = unfl * (*n / ulp);
  901. bignum = (1. - ulp) / smlnum;
  902. /* Compute 1-norm of each column of strictly upper triangular */
  903. /* part of T to control overflow in triangular solver. */
  904. work[1] = 0.;
  905. i__2 = *n;
  906. for (j = 2; j <= i__2; ++j) {
  907. work[j] = 0.;
  908. i__3 = j - 1;
  909. for (i__ = 1; i__ <= i__3; ++i__) {
  910. work[j] += (d__1 = t[i__ + j * t_dim1], abs(d__1));
  911. /* L20: */
  912. }
  913. /* L30: */
  914. }
  915. /* Index IP is used to specify the real or complex eigenvalue: */
  916. /* IP = 0, real eigenvalue, */
  917. /* 1, first of conjugate complex pair: (wr,wi) */
  918. /* -1, second of conjugate complex pair: (wr,wi) */
  919. /* ISCOMPLEX array stores IP for each column in current block. */
  920. if (rightv) {
  921. /* ============================================================ */
  922. /* Compute right eigenvectors. */
  923. /* IV is index of column in current block. */
  924. /* For complex right vector, uses IV-1 for real part and IV for complex part. */
  925. /* Non-blocked version always uses IV=2; */
  926. /* blocked version starts with IV=NB, goes down to 1 or 2. */
  927. /* (Note the "0-th" column is used for 1-norms computed above.) */
  928. iv = 2;
  929. if (nb > 2) {
  930. iv = nb;
  931. }
  932. ip = 0;
  933. is = *m;
  934. for (ki = *n; ki >= 1; --ki) {
  935. if (ip == -1) {
  936. /* previous iteration (ki+1) was second of conjugate pair, */
  937. /* so this ki is first of conjugate pair; skip to end of loop */
  938. ip = 1;
  939. goto L140;
  940. } else if (ki == 1) {
  941. /* last column, so this ki must be real eigenvalue */
  942. ip = 0;
  943. } else if (t[ki + (ki - 1) * t_dim1] == 0.) {
  944. /* zero on sub-diagonal, so this ki is real eigenvalue */
  945. ip = 0;
  946. } else {
  947. /* non-zero on sub-diagonal, so this ki is second of conjugate pair */
  948. ip = -1;
  949. }
  950. if (somev) {
  951. if (ip == 0) {
  952. if (! select[ki]) {
  953. goto L140;
  954. }
  955. } else {
  956. if (! select[ki - 1]) {
  957. goto L140;
  958. }
  959. }
  960. }
  961. /* Compute the KI-th eigenvalue (WR,WI). */
  962. wr = t[ki + ki * t_dim1];
  963. wi = 0.;
  964. if (ip != 0) {
  965. wi = sqrt((d__1 = t[ki + (ki - 1) * t_dim1], abs(d__1))) *
  966. sqrt((d__2 = t[ki - 1 + ki * t_dim1], abs(d__2)));
  967. }
  968. /* Computing MAX */
  969. d__1 = ulp * (abs(wr) + abs(wi));
  970. smin = f2cmax(d__1,smlnum);
  971. if (ip == 0) {
  972. /* -------------------------------------------------------- */
  973. /* Real right eigenvector */
  974. work[ki + iv * *n] = 1.;
  975. /* Form right-hand side. */
  976. i__2 = ki - 1;
  977. for (k = 1; k <= i__2; ++k) {
  978. work[k + iv * *n] = -t[k + ki * t_dim1];
  979. /* L50: */
  980. }
  981. /* Solve upper quasi-triangular system: */
  982. /* [ T(1:KI-1,1:KI-1) - WR ]*X = SCALE*WORK. */
  983. jnxt = ki - 1;
  984. for (j = ki - 1; j >= 1; --j) {
  985. if (j > jnxt) {
  986. goto L60;
  987. }
  988. j1 = j;
  989. j2 = j;
  990. jnxt = j - 1;
  991. if (j > 1) {
  992. if (t[j + (j - 1) * t_dim1] != 0.) {
  993. j1 = j - 1;
  994. jnxt = j - 2;
  995. }
  996. }
  997. if (j1 == j2) {
  998. /* 1-by-1 diagonal block */
  999. dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b29, &t[j +
  1000. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1001. iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
  1002. xnorm, &ierr);
  1003. /* Scale X(1,1) to avoid overflow when updating */
  1004. /* the right-hand side. */
  1005. if (xnorm > 1.) {
  1006. if (work[j] > bignum / xnorm) {
  1007. x[0] /= xnorm;
  1008. scale /= xnorm;
  1009. }
  1010. }
  1011. /* Scale if necessary */
  1012. if (scale != 1.) {
  1013. dscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1014. }
  1015. work[j + iv * *n] = x[0];
  1016. /* Update right-hand side */
  1017. i__2 = j - 1;
  1018. d__1 = -x[0];
  1019. daxpy_(&i__2, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1020. iv * *n + 1], &c__1);
  1021. } else {
  1022. /* 2-by-2 diagonal block */
  1023. dlaln2_(&c_false, &c__2, &c__1, &smin, &c_b29, &t[j -
  1024. 1 + (j - 1) * t_dim1], ldt, &c_b29, &c_b29, &
  1025. work[j - 1 + iv * *n], n, &wr, &c_b17, x, &
  1026. c__2, &scale, &xnorm, &ierr);
  1027. /* Scale X(1,1) and X(2,1) to avoid overflow when */
  1028. /* updating the right-hand side. */
  1029. if (xnorm > 1.) {
  1030. /* Computing MAX */
  1031. d__1 = work[j - 1], d__2 = work[j];
  1032. beta = f2cmax(d__1,d__2);
  1033. if (beta > bignum / xnorm) {
  1034. x[0] /= xnorm;
  1035. x[1] /= xnorm;
  1036. scale /= xnorm;
  1037. }
  1038. }
  1039. /* Scale if necessary */
  1040. if (scale != 1.) {
  1041. dscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1042. }
  1043. work[j - 1 + iv * *n] = x[0];
  1044. work[j + iv * *n] = x[1];
  1045. /* Update right-hand side */
  1046. i__2 = j - 2;
  1047. d__1 = -x[0];
  1048. daxpy_(&i__2, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1049. &work[iv * *n + 1], &c__1);
  1050. i__2 = j - 2;
  1051. d__1 = -x[1];
  1052. daxpy_(&i__2, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1053. iv * *n + 1], &c__1);
  1054. }
  1055. L60:
  1056. ;
  1057. }
  1058. /* Copy the vector x or Q*x to VR and normalize. */
  1059. if (! over) {
  1060. /* ------------------------------ */
  1061. /* no back-transform: copy x to VR and normalize. */
  1062. dcopy_(&ki, &work[iv * *n + 1], &c__1, &vr[is * vr_dim1 +
  1063. 1], &c__1);
  1064. ii = idamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
  1065. remax = 1. / (d__1 = vr[ii + is * vr_dim1], abs(d__1));
  1066. dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1067. i__2 = *n;
  1068. for (k = ki + 1; k <= i__2; ++k) {
  1069. vr[k + is * vr_dim1] = 0.;
  1070. /* L70: */
  1071. }
  1072. } else if (nb == 1) {
  1073. /* ------------------------------ */
  1074. /* version 1: back-transform each vector with GEMV, Q*x. */
  1075. if (ki > 1) {
  1076. i__2 = ki - 1;
  1077. dgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
  1078. work[iv * *n + 1], &c__1, &work[ki + iv * *n],
  1079. &vr[ki * vr_dim1 + 1], &c__1);
  1080. }
  1081. ii = idamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
  1082. remax = 1. / (d__1 = vr[ii + ki * vr_dim1], abs(d__1));
  1083. dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1084. } else {
  1085. /* ------------------------------ */
  1086. /* version 2: back-transform block of vectors with GEMM */
  1087. /* zero out below vector */
  1088. i__2 = *n;
  1089. for (k = ki + 1; k <= i__2; ++k) {
  1090. work[k + iv * *n] = 0.;
  1091. }
  1092. iscomplex[iv - 1] = ip;
  1093. /* back-transform and normalization is done below */
  1094. }
  1095. } else {
  1096. /* -------------------------------------------------------- */
  1097. /* Complex right eigenvector. */
  1098. /* Initial solve */
  1099. /* [ ( T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I*WI) ]*X = 0. */
  1100. /* [ ( T(KI, KI-1) T(KI, KI) ) ] */
  1101. if ((d__1 = t[ki - 1 + ki * t_dim1], abs(d__1)) >= (d__2 = t[
  1102. ki + (ki - 1) * t_dim1], abs(d__2))) {
  1103. work[ki - 1 + (iv - 1) * *n] = 1.;
  1104. work[ki + iv * *n] = wi / t[ki - 1 + ki * t_dim1];
  1105. } else {
  1106. work[ki - 1 + (iv - 1) * *n] = -wi / t[ki + (ki - 1) *
  1107. t_dim1];
  1108. work[ki + iv * *n] = 1.;
  1109. }
  1110. work[ki + (iv - 1) * *n] = 0.;
  1111. work[ki - 1 + iv * *n] = 0.;
  1112. /* Form right-hand side. */
  1113. i__2 = ki - 2;
  1114. for (k = 1; k <= i__2; ++k) {
  1115. work[k + (iv - 1) * *n] = -work[ki - 1 + (iv - 1) * *n] *
  1116. t[k + (ki - 1) * t_dim1];
  1117. work[k + iv * *n] = -work[ki + iv * *n] * t[k + ki *
  1118. t_dim1];
  1119. /* L80: */
  1120. }
  1121. /* Solve upper quasi-triangular system: */
  1122. /* [ T(1:KI-2,1:KI-2) - (WR+i*WI) ]*X = SCALE*(WORK+i*WORK2) */
  1123. jnxt = ki - 2;
  1124. for (j = ki - 2; j >= 1; --j) {
  1125. if (j > jnxt) {
  1126. goto L90;
  1127. }
  1128. j1 = j;
  1129. j2 = j;
  1130. jnxt = j - 1;
  1131. if (j > 1) {
  1132. if (t[j + (j - 1) * t_dim1] != 0.) {
  1133. j1 = j - 1;
  1134. jnxt = j - 2;
  1135. }
  1136. }
  1137. if (j1 == j2) {
  1138. /* 1-by-1 diagonal block */
  1139. dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b29, &t[j +
  1140. j * t_dim1], ldt, &c_b29, &c_b29, &work[j + (
  1141. iv - 1) * *n], n, &wr, &wi, x, &c__2, &scale,
  1142. &xnorm, &ierr);
  1143. /* Scale X(1,1) and X(1,2) to avoid overflow when */
  1144. /* updating the right-hand side. */
  1145. if (xnorm > 1.) {
  1146. if (work[j] > bignum / xnorm) {
  1147. x[0] /= xnorm;
  1148. x[2] /= xnorm;
  1149. scale /= xnorm;
  1150. }
  1151. }
  1152. /* Scale if necessary */
  1153. if (scale != 1.) {
  1154. dscal_(&ki, &scale, &work[(iv - 1) * *n + 1], &
  1155. c__1);
  1156. dscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1157. }
  1158. work[j + (iv - 1) * *n] = x[0];
  1159. work[j + iv * *n] = x[2];
  1160. /* Update the right-hand side */
  1161. i__2 = j - 1;
  1162. d__1 = -x[0];
  1163. daxpy_(&i__2, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1164. (iv - 1) * *n + 1], &c__1);
  1165. i__2 = j - 1;
  1166. d__1 = -x[2];
  1167. daxpy_(&i__2, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1168. iv * *n + 1], &c__1);
  1169. } else {
  1170. /* 2-by-2 diagonal block */
  1171. dlaln2_(&c_false, &c__2, &c__2, &smin, &c_b29, &t[j -
  1172. 1 + (j - 1) * t_dim1], ldt, &c_b29, &c_b29, &
  1173. work[j - 1 + (iv - 1) * *n], n, &wr, &wi, x, &
  1174. c__2, &scale, &xnorm, &ierr);
  1175. /* Scale X to avoid overflow when updating */
  1176. /* the right-hand side. */
  1177. if (xnorm > 1.) {
  1178. /* Computing MAX */
  1179. d__1 = work[j - 1], d__2 = work[j];
  1180. beta = f2cmax(d__1,d__2);
  1181. if (beta > bignum / xnorm) {
  1182. rec = 1. / xnorm;
  1183. x[0] *= rec;
  1184. x[2] *= rec;
  1185. x[1] *= rec;
  1186. x[3] *= rec;
  1187. scale *= rec;
  1188. }
  1189. }
  1190. /* Scale if necessary */
  1191. if (scale != 1.) {
  1192. dscal_(&ki, &scale, &work[(iv - 1) * *n + 1], &
  1193. c__1);
  1194. dscal_(&ki, &scale, &work[iv * *n + 1], &c__1);
  1195. }
  1196. work[j - 1 + (iv - 1) * *n] = x[0];
  1197. work[j + (iv - 1) * *n] = x[1];
  1198. work[j - 1 + iv * *n] = x[2];
  1199. work[j + iv * *n] = x[3];
  1200. /* Update the right-hand side */
  1201. i__2 = j - 2;
  1202. d__1 = -x[0];
  1203. daxpy_(&i__2, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1204. &work[(iv - 1) * *n + 1], &c__1);
  1205. i__2 = j - 2;
  1206. d__1 = -x[1];
  1207. daxpy_(&i__2, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1208. (iv - 1) * *n + 1], &c__1);
  1209. i__2 = j - 2;
  1210. d__1 = -x[2];
  1211. daxpy_(&i__2, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1212. &work[iv * *n + 1], &c__1);
  1213. i__2 = j - 2;
  1214. d__1 = -x[3];
  1215. daxpy_(&i__2, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1216. iv * *n + 1], &c__1);
  1217. }
  1218. L90:
  1219. ;
  1220. }
  1221. /* Copy the vector x or Q*x to VR and normalize. */
  1222. if (! over) {
  1223. /* ------------------------------ */
  1224. /* no back-transform: copy x to VR and normalize. */
  1225. dcopy_(&ki, &work[(iv - 1) * *n + 1], &c__1, &vr[(is - 1)
  1226. * vr_dim1 + 1], &c__1);
  1227. dcopy_(&ki, &work[iv * *n + 1], &c__1, &vr[is * vr_dim1 +
  1228. 1], &c__1);
  1229. emax = 0.;
  1230. i__2 = ki;
  1231. for (k = 1; k <= i__2; ++k) {
  1232. /* Computing MAX */
  1233. d__3 = emax, d__4 = (d__1 = vr[k + (is - 1) * vr_dim1]
  1234. , abs(d__1)) + (d__2 = vr[k + is * vr_dim1],
  1235. abs(d__2));
  1236. emax = f2cmax(d__3,d__4);
  1237. /* L100: */
  1238. }
  1239. remax = 1. / emax;
  1240. dscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
  1241. dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1242. i__2 = *n;
  1243. for (k = ki + 1; k <= i__2; ++k) {
  1244. vr[k + (is - 1) * vr_dim1] = 0.;
  1245. vr[k + is * vr_dim1] = 0.;
  1246. /* L110: */
  1247. }
  1248. } else if (nb == 1) {
  1249. /* ------------------------------ */
  1250. /* version 1: back-transform each vector with GEMV, Q*x. */
  1251. if (ki > 2) {
  1252. i__2 = ki - 2;
  1253. dgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
  1254. work[(iv - 1) * *n + 1], &c__1, &work[ki - 1
  1255. + (iv - 1) * *n], &vr[(ki - 1) * vr_dim1 + 1],
  1256. &c__1);
  1257. i__2 = ki - 2;
  1258. dgemv_("N", n, &i__2, &c_b29, &vr[vr_offset], ldvr, &
  1259. work[iv * *n + 1], &c__1, &work[ki + iv * *n],
  1260. &vr[ki * vr_dim1 + 1], &c__1);
  1261. } else {
  1262. dscal_(n, &work[ki - 1 + (iv - 1) * *n], &vr[(ki - 1)
  1263. * vr_dim1 + 1], &c__1);
  1264. dscal_(n, &work[ki + iv * *n], &vr[ki * vr_dim1 + 1],
  1265. &c__1);
  1266. }
  1267. emax = 0.;
  1268. i__2 = *n;
  1269. for (k = 1; k <= i__2; ++k) {
  1270. /* Computing MAX */
  1271. d__3 = emax, d__4 = (d__1 = vr[k + (ki - 1) * vr_dim1]
  1272. , abs(d__1)) + (d__2 = vr[k + ki * vr_dim1],
  1273. abs(d__2));
  1274. emax = f2cmax(d__3,d__4);
  1275. /* L120: */
  1276. }
  1277. remax = 1. / emax;
  1278. dscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
  1279. dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1280. } else {
  1281. /* ------------------------------ */
  1282. /* version 2: back-transform block of vectors with GEMM */
  1283. /* zero out below vector */
  1284. i__2 = *n;
  1285. for (k = ki + 1; k <= i__2; ++k) {
  1286. work[k + (iv - 1) * *n] = 0.;
  1287. work[k + iv * *n] = 0.;
  1288. }
  1289. iscomplex[iv - 2] = -ip;
  1290. iscomplex[iv - 1] = ip;
  1291. --iv;
  1292. /* back-transform and normalization is done below */
  1293. }
  1294. }
  1295. if (nb > 1) {
  1296. /* -------------------------------------------------------- */
  1297. /* Blocked version of back-transform */
  1298. /* For complex case, KI2 includes both vectors (KI-1 and KI) */
  1299. if (ip == 0) {
  1300. ki2 = ki;
  1301. } else {
  1302. ki2 = ki - 1;
  1303. }
  1304. /* Columns IV:NB of work are valid vectors. */
  1305. /* When the number of vectors stored reaches NB-1 or NB, */
  1306. /* or if this was last vector, do the GEMM */
  1307. if (iv <= 2 || ki2 == 1) {
  1308. i__2 = nb - iv + 1;
  1309. i__3 = ki2 + nb - iv;
  1310. dgemm_("N", "N", n, &i__2, &i__3, &c_b29, &vr[vr_offset],
  1311. ldvr, &work[iv * *n + 1], n, &c_b17, &work[(nb +
  1312. iv) * *n + 1], n);
  1313. /* normalize vectors */
  1314. i__2 = nb;
  1315. for (k = iv; k <= i__2; ++k) {
  1316. if (iscomplex[k - 1] == 0) {
  1317. /* real eigenvector */
  1318. ii = idamax_(n, &work[(nb + k) * *n + 1], &c__1);
  1319. remax = 1. / (d__1 = work[ii + (nb + k) * *n],
  1320. abs(d__1));
  1321. } else if (iscomplex[k - 1] == 1) {
  1322. /* first eigenvector of conjugate pair */
  1323. emax = 0.;
  1324. i__3 = *n;
  1325. for (ii = 1; ii <= i__3; ++ii) {
  1326. /* Computing MAX */
  1327. d__3 = emax, d__4 = (d__1 = work[ii + (nb + k)
  1328. * *n], abs(d__1)) + (d__2 = work[ii
  1329. + (nb + k + 1) * *n], abs(d__2));
  1330. emax = f2cmax(d__3,d__4);
  1331. }
  1332. remax = 1. / emax;
  1333. /* else if ISCOMPLEX(K).EQ.-1 */
  1334. /* second eigenvector of conjugate pair */
  1335. /* reuse same REMAX as previous K */
  1336. }
  1337. dscal_(n, &remax, &work[(nb + k) * *n + 1], &c__1);
  1338. }
  1339. i__2 = nb - iv + 1;
  1340. dlacpy_("F", n, &i__2, &work[(nb + iv) * *n + 1], n, &vr[
  1341. ki2 * vr_dim1 + 1], ldvr);
  1342. iv = nb;
  1343. } else {
  1344. --iv;
  1345. }
  1346. }
  1347. /* blocked back-transform */
  1348. --is;
  1349. if (ip != 0) {
  1350. --is;
  1351. }
  1352. L140:
  1353. ;
  1354. }
  1355. }
  1356. if (leftv) {
  1357. /* ============================================================ */
  1358. /* Compute left eigenvectors. */
  1359. /* IV is index of column in current block. */
  1360. /* For complex left vector, uses IV for real part and IV+1 for complex part. */
  1361. /* Non-blocked version always uses IV=1; */
  1362. /* blocked version starts with IV=1, goes up to NB-1 or NB. */
  1363. /* (Note the "0-th" column is used for 1-norms computed above.) */
  1364. iv = 1;
  1365. ip = 0;
  1366. is = 1;
  1367. i__2 = *n;
  1368. for (ki = 1; ki <= i__2; ++ki) {
  1369. if (ip == 1) {
  1370. /* previous iteration (ki-1) was first of conjugate pair, */
  1371. /* so this ki is second of conjugate pair; skip to end of loop */
  1372. ip = -1;
  1373. goto L260;
  1374. } else if (ki == *n) {
  1375. /* last column, so this ki must be real eigenvalue */
  1376. ip = 0;
  1377. } else if (t[ki + 1 + ki * t_dim1] == 0.) {
  1378. /* zero on sub-diagonal, so this ki is real eigenvalue */
  1379. ip = 0;
  1380. } else {
  1381. /* non-zero on sub-diagonal, so this ki is first of conjugate pair */
  1382. ip = 1;
  1383. }
  1384. if (somev) {
  1385. if (! select[ki]) {
  1386. goto L260;
  1387. }
  1388. }
  1389. /* Compute the KI-th eigenvalue (WR,WI). */
  1390. wr = t[ki + ki * t_dim1];
  1391. wi = 0.;
  1392. if (ip != 0) {
  1393. wi = sqrt((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1))) *
  1394. sqrt((d__2 = t[ki + 1 + ki * t_dim1], abs(d__2)));
  1395. }
  1396. /* Computing MAX */
  1397. d__1 = ulp * (abs(wr) + abs(wi));
  1398. smin = f2cmax(d__1,smlnum);
  1399. if (ip == 0) {
  1400. /* -------------------------------------------------------- */
  1401. /* Real left eigenvector */
  1402. work[ki + iv * *n] = 1.;
  1403. /* Form right-hand side. */
  1404. i__3 = *n;
  1405. for (k = ki + 1; k <= i__3; ++k) {
  1406. work[k + iv * *n] = -t[ki + k * t_dim1];
  1407. /* L160: */
  1408. }
  1409. /* Solve transposed quasi-triangular system: */
  1410. /* [ T(KI+1:N,KI+1:N) - WR ]**T * X = SCALE*WORK */
  1411. vmax = 1.;
  1412. vcrit = bignum;
  1413. jnxt = ki + 1;
  1414. i__3 = *n;
  1415. for (j = ki + 1; j <= i__3; ++j) {
  1416. if (j < jnxt) {
  1417. goto L170;
  1418. }
  1419. j1 = j;
  1420. j2 = j;
  1421. jnxt = j + 1;
  1422. if (j < *n) {
  1423. if (t[j + 1 + j * t_dim1] != 0.) {
  1424. j2 = j + 1;
  1425. jnxt = j + 2;
  1426. }
  1427. }
  1428. if (j1 == j2) {
  1429. /* 1-by-1 diagonal block */
  1430. /* Scale if necessary to avoid overflow when forming */
  1431. /* the right-hand side. */
  1432. if (work[j] > vcrit) {
  1433. rec = 1. / vmax;
  1434. i__4 = *n - ki + 1;
  1435. dscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1436. vmax = 1.;
  1437. vcrit = bignum;
  1438. }
  1439. i__4 = j - ki - 1;
  1440. work[j + iv * *n] -= ddot_(&i__4, &t[ki + 1 + j *
  1441. t_dim1], &c__1, &work[ki + 1 + iv * *n], &
  1442. c__1);
  1443. /* Solve [ T(J,J) - WR ]**T * X = WORK */
  1444. dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b29, &t[j +
  1445. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1446. iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
  1447. xnorm, &ierr);
  1448. /* Scale if necessary */
  1449. if (scale != 1.) {
  1450. i__4 = *n - ki + 1;
  1451. dscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1452. }
  1453. work[j + iv * *n] = x[0];
  1454. /* Computing MAX */
  1455. d__2 = (d__1 = work[j + iv * *n], abs(d__1));
  1456. vmax = f2cmax(d__2,vmax);
  1457. vcrit = bignum / vmax;
  1458. } else {
  1459. /* 2-by-2 diagonal block */
  1460. /* Scale if necessary to avoid overflow when forming */
  1461. /* the right-hand side. */
  1462. /* Computing MAX */
  1463. d__1 = work[j], d__2 = work[j + 1];
  1464. beta = f2cmax(d__1,d__2);
  1465. if (beta > vcrit) {
  1466. rec = 1. / vmax;
  1467. i__4 = *n - ki + 1;
  1468. dscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1469. vmax = 1.;
  1470. vcrit = bignum;
  1471. }
  1472. i__4 = j - ki - 1;
  1473. work[j + iv * *n] -= ddot_(&i__4, &t[ki + 1 + j *
  1474. t_dim1], &c__1, &work[ki + 1 + iv * *n], &
  1475. c__1);
  1476. i__4 = j - ki - 1;
  1477. work[j + 1 + iv * *n] -= ddot_(&i__4, &t[ki + 1 + (j
  1478. + 1) * t_dim1], &c__1, &work[ki + 1 + iv * *n]
  1479. , &c__1);
  1480. /* Solve */
  1481. /* [ T(J,J)-WR T(J,J+1) ]**T * X = SCALE*( WORK1 ) */
  1482. /* [ T(J+1,J) T(J+1,J+1)-WR ] ( WORK2 ) */
  1483. dlaln2_(&c_true, &c__2, &c__1, &smin, &c_b29, &t[j +
  1484. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1485. iv * *n], n, &wr, &c_b17, x, &c__2, &scale, &
  1486. xnorm, &ierr);
  1487. /* Scale if necessary */
  1488. if (scale != 1.) {
  1489. i__4 = *n - ki + 1;
  1490. dscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1491. }
  1492. work[j + iv * *n] = x[0];
  1493. work[j + 1 + iv * *n] = x[1];
  1494. /* Computing MAX */
  1495. d__3 = (d__1 = work[j + iv * *n], abs(d__1)), d__4 = (
  1496. d__2 = work[j + 1 + iv * *n], abs(d__2)),
  1497. d__3 = f2cmax(d__3,d__4);
  1498. vmax = f2cmax(d__3,vmax);
  1499. vcrit = bignum / vmax;
  1500. }
  1501. L170:
  1502. ;
  1503. }
  1504. /* Copy the vector x or Q*x to VL and normalize. */
  1505. if (! over) {
  1506. /* ------------------------------ */
  1507. /* no back-transform: copy x to VL and normalize. */
  1508. i__3 = *n - ki + 1;
  1509. dcopy_(&i__3, &work[ki + iv * *n], &c__1, &vl[ki + is *
  1510. vl_dim1], &c__1);
  1511. i__3 = *n - ki + 1;
  1512. ii = idamax_(&i__3, &vl[ki + is * vl_dim1], &c__1) + ki -
  1513. 1;
  1514. remax = 1. / (d__1 = vl[ii + is * vl_dim1], abs(d__1));
  1515. i__3 = *n - ki + 1;
  1516. dscal_(&i__3, &remax, &vl[ki + is * vl_dim1], &c__1);
  1517. i__3 = ki - 1;
  1518. for (k = 1; k <= i__3; ++k) {
  1519. vl[k + is * vl_dim1] = 0.;
  1520. /* L180: */
  1521. }
  1522. } else if (nb == 1) {
  1523. /* ------------------------------ */
  1524. /* version 1: back-transform each vector with GEMV, Q*x. */
  1525. if (ki < *n) {
  1526. i__3 = *n - ki;
  1527. dgemv_("N", n, &i__3, &c_b29, &vl[(ki + 1) * vl_dim1
  1528. + 1], ldvl, &work[ki + 1 + iv * *n], &c__1, &
  1529. work[ki + iv * *n], &vl[ki * vl_dim1 + 1], &
  1530. c__1);
  1531. }
  1532. ii = idamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
  1533. remax = 1. / (d__1 = vl[ii + ki * vl_dim1], abs(d__1));
  1534. dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1535. } else {
  1536. /* ------------------------------ */
  1537. /* version 2: back-transform block of vectors with GEMM */
  1538. /* zero out above vector */
  1539. /* could go from KI-NV+1 to KI-1 */
  1540. i__3 = ki - 1;
  1541. for (k = 1; k <= i__3; ++k) {
  1542. work[k + iv * *n] = 0.;
  1543. }
  1544. iscomplex[iv - 1] = ip;
  1545. /* back-transform and normalization is done below */
  1546. }
  1547. } else {
  1548. /* -------------------------------------------------------- */
  1549. /* Complex left eigenvector. */
  1550. /* Initial solve: */
  1551. /* [ ( T(KI,KI) T(KI,KI+1) )**T - (WR - I* WI) ]*X = 0. */
  1552. /* [ ( T(KI+1,KI) T(KI+1,KI+1) ) ] */
  1553. if ((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1)) >= (d__2 =
  1554. t[ki + 1 + ki * t_dim1], abs(d__2))) {
  1555. work[ki + iv * *n] = wi / t[ki + (ki + 1) * t_dim1];
  1556. work[ki + 1 + (iv + 1) * *n] = 1.;
  1557. } else {
  1558. work[ki + iv * *n] = 1.;
  1559. work[ki + 1 + (iv + 1) * *n] = -wi / t[ki + 1 + ki *
  1560. t_dim1];
  1561. }
  1562. work[ki + 1 + iv * *n] = 0.;
  1563. work[ki + (iv + 1) * *n] = 0.;
  1564. /* Form right-hand side. */
  1565. i__3 = *n;
  1566. for (k = ki + 2; k <= i__3; ++k) {
  1567. work[k + iv * *n] = -work[ki + iv * *n] * t[ki + k *
  1568. t_dim1];
  1569. work[k + (iv + 1) * *n] = -work[ki + 1 + (iv + 1) * *n] *
  1570. t[ki + 1 + k * t_dim1];
  1571. /* L190: */
  1572. }
  1573. /* Solve transposed quasi-triangular system: */
  1574. /* [ T(KI+2:N,KI+2:N)**T - (WR-i*WI) ]*X = WORK1+i*WORK2 */
  1575. vmax = 1.;
  1576. vcrit = bignum;
  1577. jnxt = ki + 2;
  1578. i__3 = *n;
  1579. for (j = ki + 2; j <= i__3; ++j) {
  1580. if (j < jnxt) {
  1581. goto L200;
  1582. }
  1583. j1 = j;
  1584. j2 = j;
  1585. jnxt = j + 1;
  1586. if (j < *n) {
  1587. if (t[j + 1 + j * t_dim1] != 0.) {
  1588. j2 = j + 1;
  1589. jnxt = j + 2;
  1590. }
  1591. }
  1592. if (j1 == j2) {
  1593. /* 1-by-1 diagonal block */
  1594. /* Scale if necessary to avoid overflow when */
  1595. /* forming the right-hand side elements. */
  1596. if (work[j] > vcrit) {
  1597. rec = 1. / vmax;
  1598. i__4 = *n - ki + 1;
  1599. dscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1600. i__4 = *n - ki + 1;
  1601. dscal_(&i__4, &rec, &work[ki + (iv + 1) * *n], &
  1602. c__1);
  1603. vmax = 1.;
  1604. vcrit = bignum;
  1605. }
  1606. i__4 = j - ki - 2;
  1607. work[j + iv * *n] -= ddot_(&i__4, &t[ki + 2 + j *
  1608. t_dim1], &c__1, &work[ki + 2 + iv * *n], &
  1609. c__1);
  1610. i__4 = j - ki - 2;
  1611. work[j + (iv + 1) * *n] -= ddot_(&i__4, &t[ki + 2 + j
  1612. * t_dim1], &c__1, &work[ki + 2 + (iv + 1) * *
  1613. n], &c__1);
  1614. /* Solve [ T(J,J)-(WR-i*WI) ]*(X11+i*X12)= WK+I*WK2 */
  1615. d__1 = -wi;
  1616. dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b29, &t[j +
  1617. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1618. iv * *n], n, &wr, &d__1, x, &c__2, &scale, &
  1619. xnorm, &ierr);
  1620. /* Scale if necessary */
  1621. if (scale != 1.) {
  1622. i__4 = *n - ki + 1;
  1623. dscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1624. i__4 = *n - ki + 1;
  1625. dscal_(&i__4, &scale, &work[ki + (iv + 1) * *n], &
  1626. c__1);
  1627. }
  1628. work[j + iv * *n] = x[0];
  1629. work[j + (iv + 1) * *n] = x[2];
  1630. /* Computing MAX */
  1631. d__3 = (d__1 = work[j + iv * *n], abs(d__1)), d__4 = (
  1632. d__2 = work[j + (iv + 1) * *n], abs(d__2)),
  1633. d__3 = f2cmax(d__3,d__4);
  1634. vmax = f2cmax(d__3,vmax);
  1635. vcrit = bignum / vmax;
  1636. } else {
  1637. /* 2-by-2 diagonal block */
  1638. /* Scale if necessary to avoid overflow when forming */
  1639. /* the right-hand side elements. */
  1640. /* Computing MAX */
  1641. d__1 = work[j], d__2 = work[j + 1];
  1642. beta = f2cmax(d__1,d__2);
  1643. if (beta > vcrit) {
  1644. rec = 1. / vmax;
  1645. i__4 = *n - ki + 1;
  1646. dscal_(&i__4, &rec, &work[ki + iv * *n], &c__1);
  1647. i__4 = *n - ki + 1;
  1648. dscal_(&i__4, &rec, &work[ki + (iv + 1) * *n], &
  1649. c__1);
  1650. vmax = 1.;
  1651. vcrit = bignum;
  1652. }
  1653. i__4 = j - ki - 2;
  1654. work[j + iv * *n] -= ddot_(&i__4, &t[ki + 2 + j *
  1655. t_dim1], &c__1, &work[ki + 2 + iv * *n], &
  1656. c__1);
  1657. i__4 = j - ki - 2;
  1658. work[j + (iv + 1) * *n] -= ddot_(&i__4, &t[ki + 2 + j
  1659. * t_dim1], &c__1, &work[ki + 2 + (iv + 1) * *
  1660. n], &c__1);
  1661. i__4 = j - ki - 2;
  1662. work[j + 1 + iv * *n] -= ddot_(&i__4, &t[ki + 2 + (j
  1663. + 1) * t_dim1], &c__1, &work[ki + 2 + iv * *n]
  1664. , &c__1);
  1665. i__4 = j - ki - 2;
  1666. work[j + 1 + (iv + 1) * *n] -= ddot_(&i__4, &t[ki + 2
  1667. + (j + 1) * t_dim1], &c__1, &work[ki + 2 + (
  1668. iv + 1) * *n], &c__1);
  1669. /* Solve 2-by-2 complex linear equation */
  1670. /* [ (T(j,j) T(j,j+1) )**T - (wr-i*wi)*I ]*X = SCALE*B */
  1671. /* [ (T(j+1,j) T(j+1,j+1)) ] */
  1672. d__1 = -wi;
  1673. dlaln2_(&c_true, &c__2, &c__2, &smin, &c_b29, &t[j +
  1674. j * t_dim1], ldt, &c_b29, &c_b29, &work[j +
  1675. iv * *n], n, &wr, &d__1, x, &c__2, &scale, &
  1676. xnorm, &ierr);
  1677. /* Scale if necessary */
  1678. if (scale != 1.) {
  1679. i__4 = *n - ki + 1;
  1680. dscal_(&i__4, &scale, &work[ki + iv * *n], &c__1);
  1681. i__4 = *n - ki + 1;
  1682. dscal_(&i__4, &scale, &work[ki + (iv + 1) * *n], &
  1683. c__1);
  1684. }
  1685. work[j + iv * *n] = x[0];
  1686. work[j + (iv + 1) * *n] = x[2];
  1687. work[j + 1 + iv * *n] = x[1];
  1688. work[j + 1 + (iv + 1) * *n] = x[3];
  1689. /* Computing MAX */
  1690. d__1 = abs(x[0]), d__2 = abs(x[2]), d__1 = f2cmax(d__1,
  1691. d__2), d__2 = abs(x[1]), d__1 = f2cmax(d__1,d__2)
  1692. , d__2 = abs(x[3]), d__1 = f2cmax(d__1,d__2);
  1693. vmax = f2cmax(d__1,vmax);
  1694. vcrit = bignum / vmax;
  1695. }
  1696. L200:
  1697. ;
  1698. }
  1699. /* Copy the vector x or Q*x to VL and normalize. */
  1700. if (! over) {
  1701. /* ------------------------------ */
  1702. /* no back-transform: copy x to VL and normalize. */
  1703. i__3 = *n - ki + 1;
  1704. dcopy_(&i__3, &work[ki + iv * *n], &c__1, &vl[ki + is *
  1705. vl_dim1], &c__1);
  1706. i__3 = *n - ki + 1;
  1707. dcopy_(&i__3, &work[ki + (iv + 1) * *n], &c__1, &vl[ki + (
  1708. is + 1) * vl_dim1], &c__1);
  1709. emax = 0.;
  1710. i__3 = *n;
  1711. for (k = ki; k <= i__3; ++k) {
  1712. /* Computing MAX */
  1713. d__3 = emax, d__4 = (d__1 = vl[k + is * vl_dim1], abs(
  1714. d__1)) + (d__2 = vl[k + (is + 1) * vl_dim1],
  1715. abs(d__2));
  1716. emax = f2cmax(d__3,d__4);
  1717. /* L220: */
  1718. }
  1719. remax = 1. / emax;
  1720. i__3 = *n - ki + 1;
  1721. dscal_(&i__3, &remax, &vl[ki + is * vl_dim1], &c__1);
  1722. i__3 = *n - ki + 1;
  1723. dscal_(&i__3, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
  1724. ;
  1725. i__3 = ki - 1;
  1726. for (k = 1; k <= i__3; ++k) {
  1727. vl[k + is * vl_dim1] = 0.;
  1728. vl[k + (is + 1) * vl_dim1] = 0.;
  1729. /* L230: */
  1730. }
  1731. } else if (nb == 1) {
  1732. /* ------------------------------ */
  1733. /* version 1: back-transform each vector with GEMV, Q*x. */
  1734. if (ki < *n - 1) {
  1735. i__3 = *n - ki - 1;
  1736. dgemv_("N", n, &i__3, &c_b29, &vl[(ki + 2) * vl_dim1
  1737. + 1], ldvl, &work[ki + 2 + iv * *n], &c__1, &
  1738. work[ki + iv * *n], &vl[ki * vl_dim1 + 1], &
  1739. c__1);
  1740. i__3 = *n - ki - 1;
  1741. dgemv_("N", n, &i__3, &c_b29, &vl[(ki + 2) * vl_dim1
  1742. + 1], ldvl, &work[ki + 2 + (iv + 1) * *n], &
  1743. c__1, &work[ki + 1 + (iv + 1) * *n], &vl[(ki
  1744. + 1) * vl_dim1 + 1], &c__1);
  1745. } else {
  1746. dscal_(n, &work[ki + iv * *n], &vl[ki * vl_dim1 + 1],
  1747. &c__1);
  1748. dscal_(n, &work[ki + 1 + (iv + 1) * *n], &vl[(ki + 1)
  1749. * vl_dim1 + 1], &c__1);
  1750. }
  1751. emax = 0.;
  1752. i__3 = *n;
  1753. for (k = 1; k <= i__3; ++k) {
  1754. /* Computing MAX */
  1755. d__3 = emax, d__4 = (d__1 = vl[k + ki * vl_dim1], abs(
  1756. d__1)) + (d__2 = vl[k + (ki + 1) * vl_dim1],
  1757. abs(d__2));
  1758. emax = f2cmax(d__3,d__4);
  1759. /* L240: */
  1760. }
  1761. remax = 1. / emax;
  1762. dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1763. dscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
  1764. } else {
  1765. /* ------------------------------ */
  1766. /* version 2: back-transform block of vectors with GEMM */
  1767. /* zero out above vector */
  1768. /* could go from KI-NV+1 to KI-1 */
  1769. i__3 = ki - 1;
  1770. for (k = 1; k <= i__3; ++k) {
  1771. work[k + iv * *n] = 0.;
  1772. work[k + (iv + 1) * *n] = 0.;
  1773. }
  1774. iscomplex[iv - 1] = ip;
  1775. iscomplex[iv] = -ip;
  1776. ++iv;
  1777. /* back-transform and normalization is done below */
  1778. }
  1779. }
  1780. if (nb > 1) {
  1781. /* -------------------------------------------------------- */
  1782. /* Blocked version of back-transform */
  1783. /* For complex case, KI2 includes both vectors (KI and KI+1) */
  1784. if (ip == 0) {
  1785. ki2 = ki;
  1786. } else {
  1787. ki2 = ki + 1;
  1788. }
  1789. /* Columns 1:IV of work are valid vectors. */
  1790. /* When the number of vectors stored reaches NB-1 or NB, */
  1791. /* or if this was last vector, do the GEMM */
  1792. if (iv >= nb - 1 || ki2 == *n) {
  1793. i__3 = *n - ki2 + iv;
  1794. dgemm_("N", "N", n, &iv, &i__3, &c_b29, &vl[(ki2 - iv + 1)
  1795. * vl_dim1 + 1], ldvl, &work[ki2 - iv + 1 + *n],
  1796. n, &c_b17, &work[(nb + 1) * *n + 1], n);
  1797. /* normalize vectors */
  1798. i__3 = iv;
  1799. for (k = 1; k <= i__3; ++k) {
  1800. if (iscomplex[k - 1] == 0) {
  1801. /* real eigenvector */
  1802. ii = idamax_(n, &work[(nb + k) * *n + 1], &c__1);
  1803. remax = 1. / (d__1 = work[ii + (nb + k) * *n],
  1804. abs(d__1));
  1805. } else if (iscomplex[k - 1] == 1) {
  1806. /* first eigenvector of conjugate pair */
  1807. emax = 0.;
  1808. i__4 = *n;
  1809. for (ii = 1; ii <= i__4; ++ii) {
  1810. /* Computing MAX */
  1811. d__3 = emax, d__4 = (d__1 = work[ii + (nb + k)
  1812. * *n], abs(d__1)) + (d__2 = work[ii
  1813. + (nb + k + 1) * *n], abs(d__2));
  1814. emax = f2cmax(d__3,d__4);
  1815. }
  1816. remax = 1. / emax;
  1817. /* else if ISCOMPLEX(K).EQ.-1 */
  1818. /* second eigenvector of conjugate pair */
  1819. /* reuse same REMAX as previous K */
  1820. }
  1821. dscal_(n, &remax, &work[(nb + k) * *n + 1], &c__1);
  1822. }
  1823. dlacpy_("F", n, &iv, &work[(nb + 1) * *n + 1], n, &vl[(
  1824. ki2 - iv + 1) * vl_dim1 + 1], ldvl);
  1825. iv = 1;
  1826. } else {
  1827. ++iv;
  1828. }
  1829. }
  1830. /* blocked back-transform */
  1831. ++is;
  1832. if (ip != 0) {
  1833. ++is;
  1834. }
  1835. L260:
  1836. ;
  1837. }
  1838. }
  1839. return;
  1840. /* End of DTREVC3 */
  1841. } /* dtrevc3_ */