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.

dsbgst.c 65 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334
  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 doublereal c_b8 = 0.;
  485. static doublereal c_b9 = 1.;
  486. static integer c__1 = 1;
  487. static doublereal c_b20 = -1.;
  488. /* > \brief \b DSBGST */
  489. /* =========== DOCUMENTATION =========== */
  490. /* Online html documentation available at */
  491. /* http://www.netlib.org/lapack/explore-html/ */
  492. /* > \htmlonly */
  493. /* > Download DSBGST + dependencies */
  494. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsbgst.
  495. f"> */
  496. /* > [TGZ]</a> */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsbgst.
  498. f"> */
  499. /* > [ZIP]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsbgst.
  501. f"> */
  502. /* > [TXT]</a> */
  503. /* > \endhtmlonly */
  504. /* Definition: */
  505. /* =========== */
  506. /* SUBROUTINE DSBGST( VECT, UPLO, N, KA, KB, AB, LDAB, BB, LDBB, X, */
  507. /* LDX, WORK, INFO ) */
  508. /* CHARACTER UPLO, VECT */
  509. /* INTEGER INFO, KA, KB, LDAB, LDBB, LDX, N */
  510. /* DOUBLE PRECISION AB( LDAB, * ), BB( LDBB, * ), WORK( * ), */
  511. /* $ X( LDX, * ) */
  512. /* > \par Purpose: */
  513. /* ============= */
  514. /* > */
  515. /* > \verbatim */
  516. /* > */
  517. /* > DSBGST reduces a real symmetric-definite banded generalized */
  518. /* > eigenproblem A*x = lambda*B*x to standard form C*y = lambda*y, */
  519. /* > such that C has the same bandwidth as A. */
  520. /* > */
  521. /* > B must have been previously factorized as S**T*S by DPBSTF, using a */
  522. /* > split Cholesky factorization. A is overwritten by C = X**T*A*X, where */
  523. /* > X = S**(-1)*Q and Q is an orthogonal matrix chosen to preserve the */
  524. /* > bandwidth of A. */
  525. /* > \endverbatim */
  526. /* Arguments: */
  527. /* ========== */
  528. /* > \param[in] VECT */
  529. /* > \verbatim */
  530. /* > VECT is CHARACTER*1 */
  531. /* > = 'N': do not form the transformation matrix X; */
  532. /* > = 'V': form X. */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[in] UPLO */
  536. /* > \verbatim */
  537. /* > UPLO is CHARACTER*1 */
  538. /* > = 'U': Upper triangle of A is stored; */
  539. /* > = 'L': Lower triangle of A is stored. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[in] N */
  543. /* > \verbatim */
  544. /* > N is INTEGER */
  545. /* > The order of the matrices A and B. N >= 0. */
  546. /* > \endverbatim */
  547. /* > */
  548. /* > \param[in] KA */
  549. /* > \verbatim */
  550. /* > KA is INTEGER */
  551. /* > The number of superdiagonals of the matrix A if UPLO = 'U', */
  552. /* > or the number of subdiagonals if UPLO = 'L'. KA >= 0. */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] KB */
  556. /* > \verbatim */
  557. /* > KB is INTEGER */
  558. /* > The number of superdiagonals of the matrix B if UPLO = 'U', */
  559. /* > or the number of subdiagonals if UPLO = 'L'. KA >= KB >= 0. */
  560. /* > \endverbatim */
  561. /* > */
  562. /* > \param[in,out] AB */
  563. /* > \verbatim */
  564. /* > AB is DOUBLE PRECISION array, dimension (LDAB,N) */
  565. /* > On entry, the upper or lower triangle of the symmetric band */
  566. /* > matrix A, stored in the first ka+1 rows of the array. The */
  567. /* > j-th column of A is stored in the j-th column of the array AB */
  568. /* > as follows: */
  569. /* > if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for f2cmax(1,j-ka)<=i<=j; */
  570. /* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(n,j+ka). */
  571. /* > */
  572. /* > On exit, the transformed matrix X**T*A*X, stored in the same */
  573. /* > format as A. */
  574. /* > \endverbatim */
  575. /* > */
  576. /* > \param[in] LDAB */
  577. /* > \verbatim */
  578. /* > LDAB is INTEGER */
  579. /* > The leading dimension of the array AB. LDAB >= KA+1. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] BB */
  583. /* > \verbatim */
  584. /* > BB is DOUBLE PRECISION array, dimension (LDBB,N) */
  585. /* > The banded factor S from the split Cholesky factorization of */
  586. /* > B, as returned by DPBSTF, stored in the first KB+1 rows of */
  587. /* > the array. */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[in] LDBB */
  591. /* > \verbatim */
  592. /* > LDBB is INTEGER */
  593. /* > The leading dimension of the array BB. LDBB >= KB+1. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[out] X */
  597. /* > \verbatim */
  598. /* > X is DOUBLE PRECISION array, dimension (LDX,N) */
  599. /* > If VECT = 'V', the n-by-n matrix X. */
  600. /* > If VECT = 'N', the array X is not referenced. */
  601. /* > \endverbatim */
  602. /* > */
  603. /* > \param[in] LDX */
  604. /* > \verbatim */
  605. /* > LDX is INTEGER */
  606. /* > The leading dimension of the array X. */
  607. /* > LDX >= f2cmax(1,N) if VECT = 'V'; LDX >= 1 otherwise. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[out] WORK */
  611. /* > \verbatim */
  612. /* > WORK is DOUBLE PRECISION array, dimension (2*N) */
  613. /* > \endverbatim */
  614. /* > */
  615. /* > \param[out] INFO */
  616. /* > \verbatim */
  617. /* > INFO is INTEGER */
  618. /* > = 0: successful exit */
  619. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  620. /* > \endverbatim */
  621. /* Authors: */
  622. /* ======== */
  623. /* > \author Univ. of Tennessee */
  624. /* > \author Univ. of California Berkeley */
  625. /* > \author Univ. of Colorado Denver */
  626. /* > \author NAG Ltd. */
  627. /* > \date December 2016 */
  628. /* > \ingroup doubleOTHERcomputational */
  629. /* ===================================================================== */
  630. /* Subroutine */ void dsbgst_(char *vect, char *uplo, integer *n, integer *ka,
  631. integer *kb, doublereal *ab, integer *ldab, doublereal *bb, integer *
  632. ldbb, doublereal *x, integer *ldx, doublereal *work, integer *info)
  633. {
  634. /* System generated locals */
  635. integer ab_dim1, ab_offset, bb_dim1, bb_offset, x_dim1, x_offset, i__1,
  636. i__2, i__3, i__4;
  637. doublereal d__1;
  638. /* Local variables */
  639. integer inca;
  640. extern /* Subroutine */ void dger_(integer *, integer *, doublereal *,
  641. doublereal *, integer *, doublereal *, integer *, doublereal *,
  642. integer *), drot_(integer *, doublereal *, integer *, doublereal *
  643. , integer *, doublereal *, doublereal *);
  644. integer i__, j, k, l, m;
  645. doublereal t;
  646. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  647. integer *);
  648. extern logical lsame_(char *, char *);
  649. integer i0, i1;
  650. logical upper;
  651. integer i2, j1, j2;
  652. logical wantx;
  653. extern /* Subroutine */ void dlar2v_(integer *, doublereal *, doublereal *,
  654. doublereal *, integer *, doublereal *, doublereal *, integer *);
  655. doublereal ra;
  656. integer nr, nx;
  657. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  658. doublereal *, doublereal *, doublereal *, integer *),
  659. dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  660. doublereal *);
  661. extern int xerbla_(char *, integer *, ftnlen);
  662. extern void dlargv_(
  663. integer *, doublereal *, integer *, doublereal *, integer *,
  664. doublereal *, integer *);
  665. logical update;
  666. extern /* Subroutine */ void dlartv_(integer *, doublereal *, integer *,
  667. doublereal *, integer *, doublereal *, doublereal *, integer *);
  668. integer ka1, kb1;
  669. doublereal ra1;
  670. integer j1t, j2t;
  671. doublereal bii;
  672. integer kbt, nrt;
  673. /* -- LAPACK computational routine (version 3.7.0) -- */
  674. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  675. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  676. /* December 2016 */
  677. /* ===================================================================== */
  678. /* Test the input parameters */
  679. /* Parameter adjustments */
  680. ab_dim1 = *ldab;
  681. ab_offset = 1 + ab_dim1 * 1;
  682. ab -= ab_offset;
  683. bb_dim1 = *ldbb;
  684. bb_offset = 1 + bb_dim1 * 1;
  685. bb -= bb_offset;
  686. x_dim1 = *ldx;
  687. x_offset = 1 + x_dim1 * 1;
  688. x -= x_offset;
  689. --work;
  690. /* Function Body */
  691. wantx = lsame_(vect, "V");
  692. upper = lsame_(uplo, "U");
  693. ka1 = *ka + 1;
  694. kb1 = *kb + 1;
  695. *info = 0;
  696. if (! wantx && ! lsame_(vect, "N")) {
  697. *info = -1;
  698. } else if (! upper && ! lsame_(uplo, "L")) {
  699. *info = -2;
  700. } else if (*n < 0) {
  701. *info = -3;
  702. } else if (*ka < 0) {
  703. *info = -4;
  704. } else if (*kb < 0 || *kb > *ka) {
  705. *info = -5;
  706. } else if (*ldab < *ka + 1) {
  707. *info = -7;
  708. } else if (*ldbb < *kb + 1) {
  709. *info = -9;
  710. } else if (*ldx < 1 || wantx && *ldx < f2cmax(1,*n)) {
  711. *info = -11;
  712. }
  713. if (*info != 0) {
  714. i__1 = -(*info);
  715. xerbla_("DSBGST", &i__1, (ftnlen)6);
  716. return;
  717. }
  718. /* Quick return if possible */
  719. if (*n == 0) {
  720. return;
  721. }
  722. inca = *ldab * ka1;
  723. /* Initialize X to the unit matrix, if needed */
  724. if (wantx) {
  725. dlaset_("Full", n, n, &c_b8, &c_b9, &x[x_offset], ldx);
  726. }
  727. /* Set M to the splitting point m. It must be the same value as is */
  728. /* used in DPBSTF. The chosen value allows the arrays WORK and RWORK */
  729. /* to be of dimension (N). */
  730. m = (*n + *kb) / 2;
  731. /* The routine works in two phases, corresponding to the two halves */
  732. /* of the split Cholesky factorization of B as S**T*S where */
  733. /* S = ( U ) */
  734. /* ( M L ) */
  735. /* with U upper triangular of order m, and L lower triangular of */
  736. /* order n-m. S has the same bandwidth as B. */
  737. /* S is treated as a product of elementary matrices: */
  738. /* S = S(m)*S(m-1)*...*S(2)*S(1)*S(m+1)*S(m+2)*...*S(n-1)*S(n) */
  739. /* where S(i) is determined by the i-th row of S. */
  740. /* In phase 1, the index i takes the values n, n-1, ... , m+1; */
  741. /* in phase 2, it takes the values 1, 2, ... , m. */
  742. /* For each value of i, the current matrix A is updated by forming */
  743. /* inv(S(i))**T*A*inv(S(i)). This creates a triangular bulge outside */
  744. /* the band of A. The bulge is then pushed down toward the bottom of */
  745. /* A in phase 1, and up toward the top of A in phase 2, by applying */
  746. /* plane rotations. */
  747. /* There are kb*(kb+1)/2 elements in the bulge, but at most 2*kb-1 */
  748. /* of them are linearly independent, so annihilating a bulge requires */
  749. /* only 2*kb-1 plane rotations. The rotations are divided into a 1st */
  750. /* set of kb-1 rotations, and a 2nd set of kb rotations. */
  751. /* Wherever possible, rotations are generated and applied in vector */
  752. /* operations of length NR between the indices J1 and J2 (sometimes */
  753. /* replaced by modified values NRT, J1T or J2T). */
  754. /* The cosines and sines of the rotations are stored in the array */
  755. /* WORK. The cosines of the 1st set of rotations are stored in */
  756. /* elements n+2:n+m-kb-1 and the sines of the 1st set in elements */
  757. /* 2:m-kb-1; the cosines of the 2nd set are stored in elements */
  758. /* n+m-kb+1:2*n and the sines of the second set in elements m-kb+1:n. */
  759. /* The bulges are not formed explicitly; nonzero elements outside the */
  760. /* band are created only when they are required for generating new */
  761. /* rotations; they are stored in the array WORK, in positions where */
  762. /* they are later overwritten by the sines of the rotations which */
  763. /* annihilate them. */
  764. /* **************************** Phase 1 ***************************** */
  765. /* The logical structure of this phase is: */
  766. /* UPDATE = .TRUE. */
  767. /* DO I = N, M + 1, -1 */
  768. /* use S(i) to update A and create a new bulge */
  769. /* apply rotations to push all bulges KA positions downward */
  770. /* END DO */
  771. /* UPDATE = .FALSE. */
  772. /* DO I = M + KA + 1, N - 1 */
  773. /* apply rotations to push all bulges KA positions downward */
  774. /* END DO */
  775. /* To avoid duplicating code, the two loops are merged. */
  776. update = TRUE_;
  777. i__ = *n + 1;
  778. L10:
  779. if (update) {
  780. --i__;
  781. /* Computing MIN */
  782. i__1 = *kb, i__2 = i__ - 1;
  783. kbt = f2cmin(i__1,i__2);
  784. i0 = i__ - 1;
  785. /* Computing MIN */
  786. i__1 = *n, i__2 = i__ + *ka;
  787. i1 = f2cmin(i__1,i__2);
  788. i2 = i__ - kbt + ka1;
  789. if (i__ < m + 1) {
  790. update = FALSE_;
  791. ++i__;
  792. i0 = m;
  793. if (*ka == 0) {
  794. goto L480;
  795. }
  796. goto L10;
  797. }
  798. } else {
  799. i__ += *ka;
  800. if (i__ > *n - 1) {
  801. goto L480;
  802. }
  803. }
  804. if (upper) {
  805. /* Transform A, working with the upper triangle */
  806. if (update) {
  807. /* Form inv(S(i))**T * A * inv(S(i)) */
  808. bii = bb[kb1 + i__ * bb_dim1];
  809. i__1 = i1;
  810. for (j = i__; j <= i__1; ++j) {
  811. ab[i__ - j + ka1 + j * ab_dim1] /= bii;
  812. /* L20: */
  813. }
  814. /* Computing MAX */
  815. i__1 = 1, i__2 = i__ - *ka;
  816. i__3 = i__;
  817. for (j = f2cmax(i__1,i__2); j <= i__3; ++j) {
  818. ab[j - i__ + ka1 + i__ * ab_dim1] /= bii;
  819. /* L30: */
  820. }
  821. i__3 = i__ - 1;
  822. for (k = i__ - kbt; k <= i__3; ++k) {
  823. i__1 = k;
  824. for (j = i__ - kbt; j <= i__1; ++j) {
  825. ab[j - k + ka1 + k * ab_dim1] = ab[j - k + ka1 + k *
  826. ab_dim1] - bb[j - i__ + kb1 + i__ * bb_dim1] * ab[
  827. k - i__ + ka1 + i__ * ab_dim1] - bb[k - i__ + kb1
  828. + i__ * bb_dim1] * ab[j - i__ + ka1 + i__ *
  829. ab_dim1] + ab[ka1 + i__ * ab_dim1] * bb[j - i__ +
  830. kb1 + i__ * bb_dim1] * bb[k - i__ + kb1 + i__ *
  831. bb_dim1];
  832. /* L40: */
  833. }
  834. /* Computing MAX */
  835. i__1 = 1, i__2 = i__ - *ka;
  836. i__4 = i__ - kbt - 1;
  837. for (j = f2cmax(i__1,i__2); j <= i__4; ++j) {
  838. ab[j - k + ka1 + k * ab_dim1] -= bb[k - i__ + kb1 + i__ *
  839. bb_dim1] * ab[j - i__ + ka1 + i__ * ab_dim1];
  840. /* L50: */
  841. }
  842. /* L60: */
  843. }
  844. i__3 = i1;
  845. for (j = i__; j <= i__3; ++j) {
  846. /* Computing MAX */
  847. i__4 = j - *ka, i__1 = i__ - kbt;
  848. i__2 = i__ - 1;
  849. for (k = f2cmax(i__4,i__1); k <= i__2; ++k) {
  850. ab[k - j + ka1 + j * ab_dim1] -= bb[k - i__ + kb1 + i__ *
  851. bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1];
  852. /* L70: */
  853. }
  854. /* L80: */
  855. }
  856. if (wantx) {
  857. /* post-multiply X by inv(S(i)) */
  858. i__3 = *n - m;
  859. d__1 = 1. / bii;
  860. dscal_(&i__3, &d__1, &x[m + 1 + i__ * x_dim1], &c__1);
  861. if (kbt > 0) {
  862. i__3 = *n - m;
  863. dger_(&i__3, &kbt, &c_b20, &x[m + 1 + i__ * x_dim1], &
  864. c__1, &bb[kb1 - kbt + i__ * bb_dim1], &c__1, &x[m
  865. + 1 + (i__ - kbt) * x_dim1], ldx);
  866. }
  867. }
  868. /* store a(i,i1) in RA1 for use in next loop over K */
  869. ra1 = ab[i__ - i1 + ka1 + i1 * ab_dim1];
  870. }
  871. /* Generate and apply vectors of rotations to chase all the */
  872. /* existing bulges KA positions down toward the bottom of the */
  873. /* band */
  874. i__3 = *kb - 1;
  875. for (k = 1; k <= i__3; ++k) {
  876. if (update) {
  877. /* Determine the rotations which would annihilate the bulge */
  878. /* which has in theory just been created */
  879. if (i__ - k + *ka < *n && i__ - k > 1) {
  880. /* generate rotation to annihilate a(i,i-k+ka+1) */
  881. dlartg_(&ab[k + 1 + (i__ - k + *ka) * ab_dim1], &ra1, &
  882. work[*n + i__ - k + *ka - m], &work[i__ - k + *ka
  883. - m], &ra);
  884. /* create nonzero element a(i-k,i-k+ka+1) outside the */
  885. /* band and store it in WORK(i-k) */
  886. t = -bb[kb1 - k + i__ * bb_dim1] * ra1;
  887. work[i__ - k] = work[*n + i__ - k + *ka - m] * t - work[
  888. i__ - k + *ka - m] * ab[(i__ - k + *ka) * ab_dim1
  889. + 1];
  890. ab[(i__ - k + *ka) * ab_dim1 + 1] = work[i__ - k + *ka -
  891. m] * t + work[*n + i__ - k + *ka - m] * ab[(i__ -
  892. k + *ka) * ab_dim1 + 1];
  893. ra1 = ra;
  894. }
  895. }
  896. /* Computing MAX */
  897. i__2 = 1, i__4 = k - i0 + 2;
  898. j2 = i__ - k - 1 + f2cmax(i__2,i__4) * ka1;
  899. nr = (*n - j2 + *ka) / ka1;
  900. j1 = j2 + (nr - 1) * ka1;
  901. if (update) {
  902. /* Computing MAX */
  903. i__2 = j2, i__4 = i__ + (*ka << 1) - k + 1;
  904. j2t = f2cmax(i__2,i__4);
  905. } else {
  906. j2t = j2;
  907. }
  908. nrt = (*n - j2t + *ka) / ka1;
  909. i__2 = j1;
  910. i__4 = ka1;
  911. for (j = j2t; i__4 < 0 ? j >= i__2 : j <= i__2; j += i__4) {
  912. /* create nonzero element a(j-ka,j+1) outside the band */
  913. /* and store it in WORK(j-m) */
  914. work[j - m] *= ab[(j + 1) * ab_dim1 + 1];
  915. ab[(j + 1) * ab_dim1 + 1] = work[*n + j - m] * ab[(j + 1) *
  916. ab_dim1 + 1];
  917. /* L90: */
  918. }
  919. /* generate rotations in 1st set to annihilate elements which */
  920. /* have been created outside the band */
  921. if (nrt > 0) {
  922. dlargv_(&nrt, &ab[j2t * ab_dim1 + 1], &inca, &work[j2t - m], &
  923. ka1, &work[*n + j2t - m], &ka1);
  924. }
  925. if (nr > 0) {
  926. /* apply rotations in 1st set from the right */
  927. i__4 = *ka - 1;
  928. for (l = 1; l <= i__4; ++l) {
  929. dlartv_(&nr, &ab[ka1 - l + j2 * ab_dim1], &inca, &ab[*ka
  930. - l + (j2 + 1) * ab_dim1], &inca, &work[*n + j2 -
  931. m], &work[j2 - m], &ka1);
  932. /* L100: */
  933. }
  934. /* apply rotations in 1st set from both sides to diagonal */
  935. /* blocks */
  936. dlar2v_(&nr, &ab[ka1 + j2 * ab_dim1], &ab[ka1 + (j2 + 1) *
  937. ab_dim1], &ab[*ka + (j2 + 1) * ab_dim1], &inca, &work[
  938. *n + j2 - m], &work[j2 - m], &ka1);
  939. }
  940. /* start applying rotations in 1st set from the left */
  941. i__4 = *kb - k + 1;
  942. for (l = *ka - 1; l >= i__4; --l) {
  943. nrt = (*n - j2 + l) / ka1;
  944. if (nrt > 0) {
  945. dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, &
  946. ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, &
  947. work[*n + j2 - m], &work[j2 - m], &ka1);
  948. }
  949. /* L110: */
  950. }
  951. if (wantx) {
  952. /* post-multiply X by product of rotations in 1st set */
  953. i__4 = j1;
  954. i__2 = ka1;
  955. for (j = j2; i__2 < 0 ? j >= i__4 : j <= i__4; j += i__2) {
  956. i__1 = *n - m;
  957. drot_(&i__1, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j
  958. + 1) * x_dim1], &c__1, &work[*n + j - m], &work[j
  959. - m]);
  960. /* L120: */
  961. }
  962. }
  963. /* L130: */
  964. }
  965. if (update) {
  966. if (i2 <= *n && kbt > 0) {
  967. /* create nonzero element a(i-kbt,i-kbt+ka+1) outside the */
  968. /* band and store it in WORK(i-kbt) */
  969. work[i__ - kbt] = -bb[kb1 - kbt + i__ * bb_dim1] * ra1;
  970. }
  971. }
  972. for (k = *kb; k >= 1; --k) {
  973. if (update) {
  974. /* Computing MAX */
  975. i__3 = 2, i__2 = k - i0 + 1;
  976. j2 = i__ - k - 1 + f2cmax(i__3,i__2) * ka1;
  977. } else {
  978. /* Computing MAX */
  979. i__3 = 1, i__2 = k - i0 + 1;
  980. j2 = i__ - k - 1 + f2cmax(i__3,i__2) * ka1;
  981. }
  982. /* finish applying rotations in 2nd set from the left */
  983. for (l = *kb - k; l >= 1; --l) {
  984. nrt = (*n - j2 + *ka + l) / ka1;
  985. if (nrt > 0) {
  986. dlartv_(&nrt, &ab[l + (j2 - l + 1) * ab_dim1], &inca, &ab[
  987. l + 1 + (j2 - l + 1) * ab_dim1], &inca, &work[*n
  988. + j2 - *ka], &work[j2 - *ka], &ka1);
  989. }
  990. /* L140: */
  991. }
  992. nr = (*n - j2 + *ka) / ka1;
  993. j1 = j2 + (nr - 1) * ka1;
  994. i__3 = j2;
  995. i__2 = -ka1;
  996. for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) {
  997. work[j] = work[j - *ka];
  998. work[*n + j] = work[*n + j - *ka];
  999. /* L150: */
  1000. }
  1001. i__2 = j1;
  1002. i__3 = ka1;
  1003. for (j = j2; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) {
  1004. /* create nonzero element a(j-ka,j+1) outside the band */
  1005. /* and store it in WORK(j) */
  1006. work[j] *= ab[(j + 1) * ab_dim1 + 1];
  1007. ab[(j + 1) * ab_dim1 + 1] = work[*n + j] * ab[(j + 1) *
  1008. ab_dim1 + 1];
  1009. /* L160: */
  1010. }
  1011. if (update) {
  1012. if (i__ - k < *n - *ka && k <= kbt) {
  1013. work[i__ - k + *ka] = work[i__ - k];
  1014. }
  1015. }
  1016. /* L170: */
  1017. }
  1018. for (k = *kb; k >= 1; --k) {
  1019. /* Computing MAX */
  1020. i__3 = 1, i__2 = k - i0 + 1;
  1021. j2 = i__ - k - 1 + f2cmax(i__3,i__2) * ka1;
  1022. nr = (*n - j2 + *ka) / ka1;
  1023. j1 = j2 + (nr - 1) * ka1;
  1024. if (nr > 0) {
  1025. /* generate rotations in 2nd set to annihilate elements */
  1026. /* which have been created outside the band */
  1027. dlargv_(&nr, &ab[j2 * ab_dim1 + 1], &inca, &work[j2], &ka1, &
  1028. work[*n + j2], &ka1);
  1029. /* apply rotations in 2nd set from the right */
  1030. i__3 = *ka - 1;
  1031. for (l = 1; l <= i__3; ++l) {
  1032. dlartv_(&nr, &ab[ka1 - l + j2 * ab_dim1], &inca, &ab[*ka
  1033. - l + (j2 + 1) * ab_dim1], &inca, &work[*n + j2],
  1034. &work[j2], &ka1);
  1035. /* L180: */
  1036. }
  1037. /* apply rotations in 2nd set from both sides to diagonal */
  1038. /* blocks */
  1039. dlar2v_(&nr, &ab[ka1 + j2 * ab_dim1], &ab[ka1 + (j2 + 1) *
  1040. ab_dim1], &ab[*ka + (j2 + 1) * ab_dim1], &inca, &work[
  1041. *n + j2], &work[j2], &ka1);
  1042. }
  1043. /* start applying rotations in 2nd set from the left */
  1044. i__3 = *kb - k + 1;
  1045. for (l = *ka - 1; l >= i__3; --l) {
  1046. nrt = (*n - j2 + l) / ka1;
  1047. if (nrt > 0) {
  1048. dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, &
  1049. ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, &
  1050. work[*n + j2], &work[j2], &ka1);
  1051. }
  1052. /* L190: */
  1053. }
  1054. if (wantx) {
  1055. /* post-multiply X by product of rotations in 2nd set */
  1056. i__3 = j1;
  1057. i__2 = ka1;
  1058. for (j = j2; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) {
  1059. i__4 = *n - m;
  1060. drot_(&i__4, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j
  1061. + 1) * x_dim1], &c__1, &work[*n + j], &work[j]);
  1062. /* L200: */
  1063. }
  1064. }
  1065. /* L210: */
  1066. }
  1067. i__2 = *kb - 1;
  1068. for (k = 1; k <= i__2; ++k) {
  1069. /* Computing MAX */
  1070. i__3 = 1, i__4 = k - i0 + 2;
  1071. j2 = i__ - k - 1 + f2cmax(i__3,i__4) * ka1;
  1072. /* finish applying rotations in 1st set from the left */
  1073. for (l = *kb - k; l >= 1; --l) {
  1074. nrt = (*n - j2 + l) / ka1;
  1075. if (nrt > 0) {
  1076. dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, &
  1077. ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, &
  1078. work[*n + j2 - m], &work[j2 - m], &ka1);
  1079. }
  1080. /* L220: */
  1081. }
  1082. /* L230: */
  1083. }
  1084. if (*kb > 1) {
  1085. i__2 = i__ - *kb + (*ka << 1) + 1;
  1086. for (j = *n - 1; j >= i__2; --j) {
  1087. work[*n + j - m] = work[*n + j - *ka - m];
  1088. work[j - m] = work[j - *ka - m];
  1089. /* L240: */
  1090. }
  1091. }
  1092. } else {
  1093. /* Transform A, working with the lower triangle */
  1094. if (update) {
  1095. /* Form inv(S(i))**T * A * inv(S(i)) */
  1096. bii = bb[i__ * bb_dim1 + 1];
  1097. i__2 = i1;
  1098. for (j = i__; j <= i__2; ++j) {
  1099. ab[j - i__ + 1 + i__ * ab_dim1] /= bii;
  1100. /* L250: */
  1101. }
  1102. /* Computing MAX */
  1103. i__2 = 1, i__3 = i__ - *ka;
  1104. i__4 = i__;
  1105. for (j = f2cmax(i__2,i__3); j <= i__4; ++j) {
  1106. ab[i__ - j + 1 + j * ab_dim1] /= bii;
  1107. /* L260: */
  1108. }
  1109. i__4 = i__ - 1;
  1110. for (k = i__ - kbt; k <= i__4; ++k) {
  1111. i__2 = k;
  1112. for (j = i__ - kbt; j <= i__2; ++j) {
  1113. ab[k - j + 1 + j * ab_dim1] = ab[k - j + 1 + j * ab_dim1]
  1114. - bb[i__ - j + 1 + j * bb_dim1] * ab[i__ - k + 1
  1115. + k * ab_dim1] - bb[i__ - k + 1 + k * bb_dim1] *
  1116. ab[i__ - j + 1 + j * ab_dim1] + ab[i__ * ab_dim1
  1117. + 1] * bb[i__ - j + 1 + j * bb_dim1] * bb[i__ - k
  1118. + 1 + k * bb_dim1];
  1119. /* L270: */
  1120. }
  1121. /* Computing MAX */
  1122. i__2 = 1, i__3 = i__ - *ka;
  1123. i__1 = i__ - kbt - 1;
  1124. for (j = f2cmax(i__2,i__3); j <= i__1; ++j) {
  1125. ab[k - j + 1 + j * ab_dim1] -= bb[i__ - k + 1 + k *
  1126. bb_dim1] * ab[i__ - j + 1 + j * ab_dim1];
  1127. /* L280: */
  1128. }
  1129. /* L290: */
  1130. }
  1131. i__4 = i1;
  1132. for (j = i__; j <= i__4; ++j) {
  1133. /* Computing MAX */
  1134. i__1 = j - *ka, i__2 = i__ - kbt;
  1135. i__3 = i__ - 1;
  1136. for (k = f2cmax(i__1,i__2); k <= i__3; ++k) {
  1137. ab[j - k + 1 + k * ab_dim1] -= bb[i__ - k + 1 + k *
  1138. bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1];
  1139. /* L300: */
  1140. }
  1141. /* L310: */
  1142. }
  1143. if (wantx) {
  1144. /* post-multiply X by inv(S(i)) */
  1145. i__4 = *n - m;
  1146. d__1 = 1. / bii;
  1147. dscal_(&i__4, &d__1, &x[m + 1 + i__ * x_dim1], &c__1);
  1148. if (kbt > 0) {
  1149. i__4 = *n - m;
  1150. i__3 = *ldbb - 1;
  1151. dger_(&i__4, &kbt, &c_b20, &x[m + 1 + i__ * x_dim1], &
  1152. c__1, &bb[kbt + 1 + (i__ - kbt) * bb_dim1], &i__3,
  1153. &x[m + 1 + (i__ - kbt) * x_dim1], ldx);
  1154. }
  1155. }
  1156. /* store a(i1,i) in RA1 for use in next loop over K */
  1157. ra1 = ab[i1 - i__ + 1 + i__ * ab_dim1];
  1158. }
  1159. /* Generate and apply vectors of rotations to chase all the */
  1160. /* existing bulges KA positions down toward the bottom of the */
  1161. /* band */
  1162. i__4 = *kb - 1;
  1163. for (k = 1; k <= i__4; ++k) {
  1164. if (update) {
  1165. /* Determine the rotations which would annihilate the bulge */
  1166. /* which has in theory just been created */
  1167. if (i__ - k + *ka < *n && i__ - k > 1) {
  1168. /* generate rotation to annihilate a(i-k+ka+1,i) */
  1169. dlartg_(&ab[ka1 - k + i__ * ab_dim1], &ra1, &work[*n +
  1170. i__ - k + *ka - m], &work[i__ - k + *ka - m], &ra)
  1171. ;
  1172. /* create nonzero element a(i-k+ka+1,i-k) outside the */
  1173. /* band and store it in WORK(i-k) */
  1174. t = -bb[k + 1 + (i__ - k) * bb_dim1] * ra1;
  1175. work[i__ - k] = work[*n + i__ - k + *ka - m] * t - work[
  1176. i__ - k + *ka - m] * ab[ka1 + (i__ - k) * ab_dim1]
  1177. ;
  1178. ab[ka1 + (i__ - k) * ab_dim1] = work[i__ - k + *ka - m] *
  1179. t + work[*n + i__ - k + *ka - m] * ab[ka1 + (i__
  1180. - k) * ab_dim1];
  1181. ra1 = ra;
  1182. }
  1183. }
  1184. /* Computing MAX */
  1185. i__3 = 1, i__1 = k - i0 + 2;
  1186. j2 = i__ - k - 1 + f2cmax(i__3,i__1) * ka1;
  1187. nr = (*n - j2 + *ka) / ka1;
  1188. j1 = j2 + (nr - 1) * ka1;
  1189. if (update) {
  1190. /* Computing MAX */
  1191. i__3 = j2, i__1 = i__ + (*ka << 1) - k + 1;
  1192. j2t = f2cmax(i__3,i__1);
  1193. } else {
  1194. j2t = j2;
  1195. }
  1196. nrt = (*n - j2t + *ka) / ka1;
  1197. i__3 = j1;
  1198. i__1 = ka1;
  1199. for (j = j2t; i__1 < 0 ? j >= i__3 : j <= i__3; j += i__1) {
  1200. /* create nonzero element a(j+1,j-ka) outside the band */
  1201. /* and store it in WORK(j-m) */
  1202. work[j - m] *= ab[ka1 + (j - *ka + 1) * ab_dim1];
  1203. ab[ka1 + (j - *ka + 1) * ab_dim1] = work[*n + j - m] * ab[ka1
  1204. + (j - *ka + 1) * ab_dim1];
  1205. /* L320: */
  1206. }
  1207. /* generate rotations in 1st set to annihilate elements which */
  1208. /* have been created outside the band */
  1209. if (nrt > 0) {
  1210. dlargv_(&nrt, &ab[ka1 + (j2t - *ka) * ab_dim1], &inca, &work[
  1211. j2t - m], &ka1, &work[*n + j2t - m], &ka1);
  1212. }
  1213. if (nr > 0) {
  1214. /* apply rotations in 1st set from the left */
  1215. i__1 = *ka - 1;
  1216. for (l = 1; l <= i__1; ++l) {
  1217. dlartv_(&nr, &ab[l + 1 + (j2 - l) * ab_dim1], &inca, &ab[
  1218. l + 2 + (j2 - l) * ab_dim1], &inca, &work[*n + j2
  1219. - m], &work[j2 - m], &ka1);
  1220. /* L330: */
  1221. }
  1222. /* apply rotations in 1st set from both sides to diagonal */
  1223. /* blocks */
  1224. dlar2v_(&nr, &ab[j2 * ab_dim1 + 1], &ab[(j2 + 1) * ab_dim1 +
  1225. 1], &ab[j2 * ab_dim1 + 2], &inca, &work[*n + j2 - m],
  1226. &work[j2 - m], &ka1);
  1227. }
  1228. /* start applying rotations in 1st set from the right */
  1229. i__1 = *kb - k + 1;
  1230. for (l = *ka - 1; l >= i__1; --l) {
  1231. nrt = (*n - j2 + l) / ka1;
  1232. if (nrt > 0) {
  1233. dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[
  1234. ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n +
  1235. j2 - m], &work[j2 - m], &ka1);
  1236. }
  1237. /* L340: */
  1238. }
  1239. if (wantx) {
  1240. /* post-multiply X by product of rotations in 1st set */
  1241. i__1 = j1;
  1242. i__3 = ka1;
  1243. for (j = j2; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) {
  1244. i__2 = *n - m;
  1245. drot_(&i__2, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j
  1246. + 1) * x_dim1], &c__1, &work[*n + j - m], &work[j
  1247. - m]);
  1248. /* L350: */
  1249. }
  1250. }
  1251. /* L360: */
  1252. }
  1253. if (update) {
  1254. if (i2 <= *n && kbt > 0) {
  1255. /* create nonzero element a(i-kbt+ka+1,i-kbt) outside the */
  1256. /* band and store it in WORK(i-kbt) */
  1257. work[i__ - kbt] = -bb[kbt + 1 + (i__ - kbt) * bb_dim1] * ra1;
  1258. }
  1259. }
  1260. for (k = *kb; k >= 1; --k) {
  1261. if (update) {
  1262. /* Computing MAX */
  1263. i__4 = 2, i__3 = k - i0 + 1;
  1264. j2 = i__ - k - 1 + f2cmax(i__4,i__3) * ka1;
  1265. } else {
  1266. /* Computing MAX */
  1267. i__4 = 1, i__3 = k - i0 + 1;
  1268. j2 = i__ - k - 1 + f2cmax(i__4,i__3) * ka1;
  1269. }
  1270. /* finish applying rotations in 2nd set from the right */
  1271. for (l = *kb - k; l >= 1; --l) {
  1272. nrt = (*n - j2 + *ka + l) / ka1;
  1273. if (nrt > 0) {
  1274. dlartv_(&nrt, &ab[ka1 - l + 1 + (j2 - *ka) * ab_dim1], &
  1275. inca, &ab[ka1 - l + (j2 - *ka + 1) * ab_dim1], &
  1276. inca, &work[*n + j2 - *ka], &work[j2 - *ka], &ka1)
  1277. ;
  1278. }
  1279. /* L370: */
  1280. }
  1281. nr = (*n - j2 + *ka) / ka1;
  1282. j1 = j2 + (nr - 1) * ka1;
  1283. i__4 = j2;
  1284. i__3 = -ka1;
  1285. for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
  1286. work[j] = work[j - *ka];
  1287. work[*n + j] = work[*n + j - *ka];
  1288. /* L380: */
  1289. }
  1290. i__3 = j1;
  1291. i__4 = ka1;
  1292. for (j = j2; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
  1293. /* create nonzero element a(j+1,j-ka) outside the band */
  1294. /* and store it in WORK(j) */
  1295. work[j] *= ab[ka1 + (j - *ka + 1) * ab_dim1];
  1296. ab[ka1 + (j - *ka + 1) * ab_dim1] = work[*n + j] * ab[ka1 + (
  1297. j - *ka + 1) * ab_dim1];
  1298. /* L390: */
  1299. }
  1300. if (update) {
  1301. if (i__ - k < *n - *ka && k <= kbt) {
  1302. work[i__ - k + *ka] = work[i__ - k];
  1303. }
  1304. }
  1305. /* L400: */
  1306. }
  1307. for (k = *kb; k >= 1; --k) {
  1308. /* Computing MAX */
  1309. i__4 = 1, i__3 = k - i0 + 1;
  1310. j2 = i__ - k - 1 + f2cmax(i__4,i__3) * ka1;
  1311. nr = (*n - j2 + *ka) / ka1;
  1312. j1 = j2 + (nr - 1) * ka1;
  1313. if (nr > 0) {
  1314. /* generate rotations in 2nd set to annihilate elements */
  1315. /* which have been created outside the band */
  1316. dlargv_(&nr, &ab[ka1 + (j2 - *ka) * ab_dim1], &inca, &work[j2]
  1317. , &ka1, &work[*n + j2], &ka1);
  1318. /* apply rotations in 2nd set from the left */
  1319. i__4 = *ka - 1;
  1320. for (l = 1; l <= i__4; ++l) {
  1321. dlartv_(&nr, &ab[l + 1 + (j2 - l) * ab_dim1], &inca, &ab[
  1322. l + 2 + (j2 - l) * ab_dim1], &inca, &work[*n + j2]
  1323. , &work[j2], &ka1);
  1324. /* L410: */
  1325. }
  1326. /* apply rotations in 2nd set from both sides to diagonal */
  1327. /* blocks */
  1328. dlar2v_(&nr, &ab[j2 * ab_dim1 + 1], &ab[(j2 + 1) * ab_dim1 +
  1329. 1], &ab[j2 * ab_dim1 + 2], &inca, &work[*n + j2], &
  1330. work[j2], &ka1);
  1331. }
  1332. /* start applying rotations in 2nd set from the right */
  1333. i__4 = *kb - k + 1;
  1334. for (l = *ka - 1; l >= i__4; --l) {
  1335. nrt = (*n - j2 + l) / ka1;
  1336. if (nrt > 0) {
  1337. dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[
  1338. ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n +
  1339. j2], &work[j2], &ka1);
  1340. }
  1341. /* L420: */
  1342. }
  1343. if (wantx) {
  1344. /* post-multiply X by product of rotations in 2nd set */
  1345. i__4 = j1;
  1346. i__3 = ka1;
  1347. for (j = j2; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
  1348. i__1 = *n - m;
  1349. drot_(&i__1, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j
  1350. + 1) * x_dim1], &c__1, &work[*n + j], &work[j]);
  1351. /* L430: */
  1352. }
  1353. }
  1354. /* L440: */
  1355. }
  1356. i__3 = *kb - 1;
  1357. for (k = 1; k <= i__3; ++k) {
  1358. /* Computing MAX */
  1359. i__4 = 1, i__1 = k - i0 + 2;
  1360. j2 = i__ - k - 1 + f2cmax(i__4,i__1) * ka1;
  1361. /* finish applying rotations in 1st set from the right */
  1362. for (l = *kb - k; l >= 1; --l) {
  1363. nrt = (*n - j2 + l) / ka1;
  1364. if (nrt > 0) {
  1365. dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[
  1366. ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n +
  1367. j2 - m], &work[j2 - m], &ka1);
  1368. }
  1369. /* L450: */
  1370. }
  1371. /* L460: */
  1372. }
  1373. if (*kb > 1) {
  1374. i__3 = i__ - *kb + (*ka << 1) + 1;
  1375. for (j = *n - 1; j >= i__3; --j) {
  1376. work[*n + j - m] = work[*n + j - *ka - m];
  1377. work[j - m] = work[j - *ka - m];
  1378. /* L470: */
  1379. }
  1380. }
  1381. }
  1382. goto L10;
  1383. L480:
  1384. /* **************************** Phase 2 ***************************** */
  1385. /* The logical structure of this phase is: */
  1386. /* UPDATE = .TRUE. */
  1387. /* DO I = 1, M */
  1388. /* use S(i) to update A and create a new bulge */
  1389. /* apply rotations to push all bulges KA positions upward */
  1390. /* END DO */
  1391. /* UPDATE = .FALSE. */
  1392. /* DO I = M - KA - 1, 2, -1 */
  1393. /* apply rotations to push all bulges KA positions upward */
  1394. /* END DO */
  1395. /* To avoid duplicating code, the two loops are merged. */
  1396. update = TRUE_;
  1397. i__ = 0;
  1398. L490:
  1399. if (update) {
  1400. ++i__;
  1401. /* Computing MIN */
  1402. i__3 = *kb, i__4 = m - i__;
  1403. kbt = f2cmin(i__3,i__4);
  1404. i0 = i__ + 1;
  1405. /* Computing MAX */
  1406. i__3 = 1, i__4 = i__ - *ka;
  1407. i1 = f2cmax(i__3,i__4);
  1408. i2 = i__ + kbt - ka1;
  1409. if (i__ > m) {
  1410. update = FALSE_;
  1411. --i__;
  1412. i0 = m + 1;
  1413. if (*ka == 0) {
  1414. return;
  1415. }
  1416. goto L490;
  1417. }
  1418. } else {
  1419. i__ -= *ka;
  1420. if (i__ < 2) {
  1421. return;
  1422. }
  1423. }
  1424. if (i__ < m - kbt) {
  1425. nx = m;
  1426. } else {
  1427. nx = *n;
  1428. }
  1429. if (upper) {
  1430. /* Transform A, working with the upper triangle */
  1431. if (update) {
  1432. /* Form inv(S(i))**T * A * inv(S(i)) */
  1433. bii = bb[kb1 + i__ * bb_dim1];
  1434. i__3 = i__;
  1435. for (j = i1; j <= i__3; ++j) {
  1436. ab[j - i__ + ka1 + i__ * ab_dim1] /= bii;
  1437. /* L500: */
  1438. }
  1439. /* Computing MIN */
  1440. i__4 = *n, i__1 = i__ + *ka;
  1441. i__3 = f2cmin(i__4,i__1);
  1442. for (j = i__; j <= i__3; ++j) {
  1443. ab[i__ - j + ka1 + j * ab_dim1] /= bii;
  1444. /* L510: */
  1445. }
  1446. i__3 = i__ + kbt;
  1447. for (k = i__ + 1; k <= i__3; ++k) {
  1448. i__4 = i__ + kbt;
  1449. for (j = k; j <= i__4; ++j) {
  1450. ab[k - j + ka1 + j * ab_dim1] = ab[k - j + ka1 + j *
  1451. ab_dim1] - bb[i__ - j + kb1 + j * bb_dim1] * ab[
  1452. i__ - k + ka1 + k * ab_dim1] - bb[i__ - k + kb1 +
  1453. k * bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1] +
  1454. ab[ka1 + i__ * ab_dim1] * bb[i__ - j + kb1 + j *
  1455. bb_dim1] * bb[i__ - k + kb1 + k * bb_dim1];
  1456. /* L520: */
  1457. }
  1458. /* Computing MIN */
  1459. i__1 = *n, i__2 = i__ + *ka;
  1460. i__4 = f2cmin(i__1,i__2);
  1461. for (j = i__ + kbt + 1; j <= i__4; ++j) {
  1462. ab[k - j + ka1 + j * ab_dim1] -= bb[i__ - k + kb1 + k *
  1463. bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1];
  1464. /* L530: */
  1465. }
  1466. /* L540: */
  1467. }
  1468. i__3 = i__;
  1469. for (j = i1; j <= i__3; ++j) {
  1470. /* Computing MIN */
  1471. i__1 = j + *ka, i__2 = i__ + kbt;
  1472. i__4 = f2cmin(i__1,i__2);
  1473. for (k = i__ + 1; k <= i__4; ++k) {
  1474. ab[j - k + ka1 + k * ab_dim1] -= bb[i__ - k + kb1 + k *
  1475. bb_dim1] * ab[j - i__ + ka1 + i__ * ab_dim1];
  1476. /* L550: */
  1477. }
  1478. /* L560: */
  1479. }
  1480. if (wantx) {
  1481. /* post-multiply X by inv(S(i)) */
  1482. d__1 = 1. / bii;
  1483. dscal_(&nx, &d__1, &x[i__ * x_dim1 + 1], &c__1);
  1484. if (kbt > 0) {
  1485. i__3 = *ldbb - 1;
  1486. dger_(&nx, &kbt, &c_b20, &x[i__ * x_dim1 + 1], &c__1, &bb[
  1487. *kb + (i__ + 1) * bb_dim1], &i__3, &x[(i__ + 1) *
  1488. x_dim1 + 1], ldx);
  1489. }
  1490. }
  1491. /* store a(i1,i) in RA1 for use in next loop over K */
  1492. ra1 = ab[i1 - i__ + ka1 + i__ * ab_dim1];
  1493. }
  1494. /* Generate and apply vectors of rotations to chase all the */
  1495. /* existing bulges KA positions up toward the top of the band */
  1496. i__3 = *kb - 1;
  1497. for (k = 1; k <= i__3; ++k) {
  1498. if (update) {
  1499. /* Determine the rotations which would annihilate the bulge */
  1500. /* which has in theory just been created */
  1501. if (i__ + k - ka1 > 0 && i__ + k < m) {
  1502. /* generate rotation to annihilate a(i+k-ka-1,i) */
  1503. dlartg_(&ab[k + 1 + i__ * ab_dim1], &ra1, &work[*n + i__
  1504. + k - *ka], &work[i__ + k - *ka], &ra);
  1505. /* create nonzero element a(i+k-ka-1,i+k) outside the */
  1506. /* band and store it in WORK(m-kb+i+k) */
  1507. t = -bb[kb1 - k + (i__ + k) * bb_dim1] * ra1;
  1508. work[m - *kb + i__ + k] = work[*n + i__ + k - *ka] * t -
  1509. work[i__ + k - *ka] * ab[(i__ + k) * ab_dim1 + 1];
  1510. ab[(i__ + k) * ab_dim1 + 1] = work[i__ + k - *ka] * t +
  1511. work[*n + i__ + k - *ka] * ab[(i__ + k) * ab_dim1
  1512. + 1];
  1513. ra1 = ra;
  1514. }
  1515. }
  1516. /* Computing MAX */
  1517. i__4 = 1, i__1 = k + i0 - m + 1;
  1518. j2 = i__ + k + 1 - f2cmax(i__4,i__1) * ka1;
  1519. nr = (j2 + *ka - 1) / ka1;
  1520. j1 = j2 - (nr - 1) * ka1;
  1521. if (update) {
  1522. /* Computing MIN */
  1523. i__4 = j2, i__1 = i__ - (*ka << 1) + k - 1;
  1524. j2t = f2cmin(i__4,i__1);
  1525. } else {
  1526. j2t = j2;
  1527. }
  1528. nrt = (j2t + *ka - 1) / ka1;
  1529. i__4 = j2t;
  1530. i__1 = ka1;
  1531. for (j = j1; i__1 < 0 ? j >= i__4 : j <= i__4; j += i__1) {
  1532. /* create nonzero element a(j-1,j+ka) outside the band */
  1533. /* and store it in WORK(j) */
  1534. work[j] *= ab[(j + *ka - 1) * ab_dim1 + 1];
  1535. ab[(j + *ka - 1) * ab_dim1 + 1] = work[*n + j] * ab[(j + *ka
  1536. - 1) * ab_dim1 + 1];
  1537. /* L570: */
  1538. }
  1539. /* generate rotations in 1st set to annihilate elements which */
  1540. /* have been created outside the band */
  1541. if (nrt > 0) {
  1542. dlargv_(&nrt, &ab[(j1 + *ka) * ab_dim1 + 1], &inca, &work[j1],
  1543. &ka1, &work[*n + j1], &ka1);
  1544. }
  1545. if (nr > 0) {
  1546. /* apply rotations in 1st set from the left */
  1547. i__1 = *ka - 1;
  1548. for (l = 1; l <= i__1; ++l) {
  1549. dlartv_(&nr, &ab[ka1 - l + (j1 + l) * ab_dim1], &inca, &
  1550. ab[*ka - l + (j1 + l) * ab_dim1], &inca, &work[*n
  1551. + j1], &work[j1], &ka1);
  1552. /* L580: */
  1553. }
  1554. /* apply rotations in 1st set from both sides to diagonal */
  1555. /* blocks */
  1556. dlar2v_(&nr, &ab[ka1 + j1 * ab_dim1], &ab[ka1 + (j1 - 1) *
  1557. ab_dim1], &ab[*ka + j1 * ab_dim1], &inca, &work[*n +
  1558. j1], &work[j1], &ka1);
  1559. }
  1560. /* start applying rotations in 1st set from the right */
  1561. i__1 = *kb - k + 1;
  1562. for (l = *ka - 1; l >= i__1; --l) {
  1563. nrt = (j2 + l - 1) / ka1;
  1564. j1t = j2 - (nrt - 1) * ka1;
  1565. if (nrt > 0) {
  1566. dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + (
  1567. j1t - 1) * ab_dim1], &inca, &work[*n + j1t], &
  1568. work[j1t], &ka1);
  1569. }
  1570. /* L590: */
  1571. }
  1572. if (wantx) {
  1573. /* post-multiply X by product of rotations in 1st set */
  1574. i__1 = j2;
  1575. i__4 = ka1;
  1576. for (j = j1; i__4 < 0 ? j >= i__1 : j <= i__1; j += i__4) {
  1577. drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1
  1578. + 1], &c__1, &work[*n + j], &work[j]);
  1579. /* L600: */
  1580. }
  1581. }
  1582. /* L610: */
  1583. }
  1584. if (update) {
  1585. if (i2 > 0 && kbt > 0) {
  1586. /* create nonzero element a(i+kbt-ka-1,i+kbt) outside the */
  1587. /* band and store it in WORK(m-kb+i+kbt) */
  1588. work[m - *kb + i__ + kbt] = -bb[kb1 - kbt + (i__ + kbt) *
  1589. bb_dim1] * ra1;
  1590. }
  1591. }
  1592. for (k = *kb; k >= 1; --k) {
  1593. if (update) {
  1594. /* Computing MAX */
  1595. i__3 = 2, i__4 = k + i0 - m;
  1596. j2 = i__ + k + 1 - f2cmax(i__3,i__4) * ka1;
  1597. } else {
  1598. /* Computing MAX */
  1599. i__3 = 1, i__4 = k + i0 - m;
  1600. j2 = i__ + k + 1 - f2cmax(i__3,i__4) * ka1;
  1601. }
  1602. /* finish applying rotations in 2nd set from the right */
  1603. for (l = *kb - k; l >= 1; --l) {
  1604. nrt = (j2 + *ka + l - 1) / ka1;
  1605. j1t = j2 - (nrt - 1) * ka1;
  1606. if (nrt > 0) {
  1607. dlartv_(&nrt, &ab[l + (j1t + *ka) * ab_dim1], &inca, &ab[
  1608. l + 1 + (j1t + *ka - 1) * ab_dim1], &inca, &work[*
  1609. n + m - *kb + j1t + *ka], &work[m - *kb + j1t + *
  1610. ka], &ka1);
  1611. }
  1612. /* L620: */
  1613. }
  1614. nr = (j2 + *ka - 1) / ka1;
  1615. j1 = j2 - (nr - 1) * ka1;
  1616. i__3 = j2;
  1617. i__4 = ka1;
  1618. for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
  1619. work[m - *kb + j] = work[m - *kb + j + *ka];
  1620. work[*n + m - *kb + j] = work[*n + m - *kb + j + *ka];
  1621. /* L630: */
  1622. }
  1623. i__4 = j2;
  1624. i__3 = ka1;
  1625. for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
  1626. /* create nonzero element a(j-1,j+ka) outside the band */
  1627. /* and store it in WORK(m-kb+j) */
  1628. work[m - *kb + j] *= ab[(j + *ka - 1) * ab_dim1 + 1];
  1629. ab[(j + *ka - 1) * ab_dim1 + 1] = work[*n + m - *kb + j] * ab[
  1630. (j + *ka - 1) * ab_dim1 + 1];
  1631. /* L640: */
  1632. }
  1633. if (update) {
  1634. if (i__ + k > ka1 && k <= kbt) {
  1635. work[m - *kb + i__ + k - *ka] = work[m - *kb + i__ + k];
  1636. }
  1637. }
  1638. /* L650: */
  1639. }
  1640. for (k = *kb; k >= 1; --k) {
  1641. /* Computing MAX */
  1642. i__3 = 1, i__4 = k + i0 - m;
  1643. j2 = i__ + k + 1 - f2cmax(i__3,i__4) * ka1;
  1644. nr = (j2 + *ka - 1) / ka1;
  1645. j1 = j2 - (nr - 1) * ka1;
  1646. if (nr > 0) {
  1647. /* generate rotations in 2nd set to annihilate elements */
  1648. /* which have been created outside the band */
  1649. dlargv_(&nr, &ab[(j1 + *ka) * ab_dim1 + 1], &inca, &work[m - *
  1650. kb + j1], &ka1, &work[*n + m - *kb + j1], &ka1);
  1651. /* apply rotations in 2nd set from the left */
  1652. i__3 = *ka - 1;
  1653. for (l = 1; l <= i__3; ++l) {
  1654. dlartv_(&nr, &ab[ka1 - l + (j1 + l) * ab_dim1], &inca, &
  1655. ab[*ka - l + (j1 + l) * ab_dim1], &inca, &work[*n
  1656. + m - *kb + j1], &work[m - *kb + j1], &ka1);
  1657. /* L660: */
  1658. }
  1659. /* apply rotations in 2nd set from both sides to diagonal */
  1660. /* blocks */
  1661. dlar2v_(&nr, &ab[ka1 + j1 * ab_dim1], &ab[ka1 + (j1 - 1) *
  1662. ab_dim1], &ab[*ka + j1 * ab_dim1], &inca, &work[*n +
  1663. m - *kb + j1], &work[m - *kb + j1], &ka1);
  1664. }
  1665. /* start applying rotations in 2nd set from the right */
  1666. i__3 = *kb - k + 1;
  1667. for (l = *ka - 1; l >= i__3; --l) {
  1668. nrt = (j2 + l - 1) / ka1;
  1669. j1t = j2 - (nrt - 1) * ka1;
  1670. if (nrt > 0) {
  1671. dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + (
  1672. j1t - 1) * ab_dim1], &inca, &work[*n + m - *kb +
  1673. j1t], &work[m - *kb + j1t], &ka1);
  1674. }
  1675. /* L670: */
  1676. }
  1677. if (wantx) {
  1678. /* post-multiply X by product of rotations in 2nd set */
  1679. i__3 = j2;
  1680. i__4 = ka1;
  1681. for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
  1682. drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1
  1683. + 1], &c__1, &work[*n + m - *kb + j], &work[m - *
  1684. kb + j]);
  1685. /* L680: */
  1686. }
  1687. }
  1688. /* L690: */
  1689. }
  1690. i__4 = *kb - 1;
  1691. for (k = 1; k <= i__4; ++k) {
  1692. /* Computing MAX */
  1693. i__3 = 1, i__1 = k + i0 - m + 1;
  1694. j2 = i__ + k + 1 - f2cmax(i__3,i__1) * ka1;
  1695. /* finish applying rotations in 1st set from the right */
  1696. for (l = *kb - k; l >= 1; --l) {
  1697. nrt = (j2 + l - 1) / ka1;
  1698. j1t = j2 - (nrt - 1) * ka1;
  1699. if (nrt > 0) {
  1700. dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + (
  1701. j1t - 1) * ab_dim1], &inca, &work[*n + j1t], &
  1702. work[j1t], &ka1);
  1703. }
  1704. /* L700: */
  1705. }
  1706. /* L710: */
  1707. }
  1708. if (*kb > 1) {
  1709. /* Computing MIN */
  1710. i__3 = i__ + *kb;
  1711. i__4 = f2cmin(i__3,m) - (*ka << 1) - 1;
  1712. for (j = 2; j <= i__4; ++j) {
  1713. work[*n + j] = work[*n + j + *ka];
  1714. work[j] = work[j + *ka];
  1715. /* L720: */
  1716. }
  1717. }
  1718. } else {
  1719. /* Transform A, working with the lower triangle */
  1720. if (update) {
  1721. /* Form inv(S(i))**T * A * inv(S(i)) */
  1722. bii = bb[i__ * bb_dim1 + 1];
  1723. i__4 = i__;
  1724. for (j = i1; j <= i__4; ++j) {
  1725. ab[i__ - j + 1 + j * ab_dim1] /= bii;
  1726. /* L730: */
  1727. }
  1728. /* Computing MIN */
  1729. i__3 = *n, i__1 = i__ + *ka;
  1730. i__4 = f2cmin(i__3,i__1);
  1731. for (j = i__; j <= i__4; ++j) {
  1732. ab[j - i__ + 1 + i__ * ab_dim1] /= bii;
  1733. /* L740: */
  1734. }
  1735. i__4 = i__ + kbt;
  1736. for (k = i__ + 1; k <= i__4; ++k) {
  1737. i__3 = i__ + kbt;
  1738. for (j = k; j <= i__3; ++j) {
  1739. ab[j - k + 1 + k * ab_dim1] = ab[j - k + 1 + k * ab_dim1]
  1740. - bb[j - i__ + 1 + i__ * bb_dim1] * ab[k - i__ +
  1741. 1 + i__ * ab_dim1] - bb[k - i__ + 1 + i__ *
  1742. bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1] + ab[
  1743. i__ * ab_dim1 + 1] * bb[j - i__ + 1 + i__ *
  1744. bb_dim1] * bb[k - i__ + 1 + i__ * bb_dim1];
  1745. /* L750: */
  1746. }
  1747. /* Computing MIN */
  1748. i__1 = *n, i__2 = i__ + *ka;
  1749. i__3 = f2cmin(i__1,i__2);
  1750. for (j = i__ + kbt + 1; j <= i__3; ++j) {
  1751. ab[j - k + 1 + k * ab_dim1] -= bb[k - i__ + 1 + i__ *
  1752. bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1];
  1753. /* L760: */
  1754. }
  1755. /* L770: */
  1756. }
  1757. i__4 = i__;
  1758. for (j = i1; j <= i__4; ++j) {
  1759. /* Computing MIN */
  1760. i__1 = j + *ka, i__2 = i__ + kbt;
  1761. i__3 = f2cmin(i__1,i__2);
  1762. for (k = i__ + 1; k <= i__3; ++k) {
  1763. ab[k - j + 1 + j * ab_dim1] -= bb[k - i__ + 1 + i__ *
  1764. bb_dim1] * ab[i__ - j + 1 + j * ab_dim1];
  1765. /* L780: */
  1766. }
  1767. /* L790: */
  1768. }
  1769. if (wantx) {
  1770. /* post-multiply X by inv(S(i)) */
  1771. d__1 = 1. / bii;
  1772. dscal_(&nx, &d__1, &x[i__ * x_dim1 + 1], &c__1);
  1773. if (kbt > 0) {
  1774. dger_(&nx, &kbt, &c_b20, &x[i__ * x_dim1 + 1], &c__1, &bb[
  1775. i__ * bb_dim1 + 2], &c__1, &x[(i__ + 1) * x_dim1
  1776. + 1], ldx);
  1777. }
  1778. }
  1779. /* store a(i,i1) in RA1 for use in next loop over K */
  1780. ra1 = ab[i__ - i1 + 1 + i1 * ab_dim1];
  1781. }
  1782. /* Generate and apply vectors of rotations to chase all the */
  1783. /* existing bulges KA positions up toward the top of the band */
  1784. i__4 = *kb - 1;
  1785. for (k = 1; k <= i__4; ++k) {
  1786. if (update) {
  1787. /* Determine the rotations which would annihilate the bulge */
  1788. /* which has in theory just been created */
  1789. if (i__ + k - ka1 > 0 && i__ + k < m) {
  1790. /* generate rotation to annihilate a(i,i+k-ka-1) */
  1791. dlartg_(&ab[ka1 - k + (i__ + k - *ka) * ab_dim1], &ra1, &
  1792. work[*n + i__ + k - *ka], &work[i__ + k - *ka], &
  1793. ra);
  1794. /* create nonzero element a(i+k,i+k-ka-1) outside the */
  1795. /* band and store it in WORK(m-kb+i+k) */
  1796. t = -bb[k + 1 + i__ * bb_dim1] * ra1;
  1797. work[m - *kb + i__ + k] = work[*n + i__ + k - *ka] * t -
  1798. work[i__ + k - *ka] * ab[ka1 + (i__ + k - *ka) *
  1799. ab_dim1];
  1800. ab[ka1 + (i__ + k - *ka) * ab_dim1] = work[i__ + k - *ka]
  1801. * t + work[*n + i__ + k - *ka] * ab[ka1 + (i__ +
  1802. k - *ka) * ab_dim1];
  1803. ra1 = ra;
  1804. }
  1805. }
  1806. /* Computing MAX */
  1807. i__3 = 1, i__1 = k + i0 - m + 1;
  1808. j2 = i__ + k + 1 - f2cmax(i__3,i__1) * ka1;
  1809. nr = (j2 + *ka - 1) / ka1;
  1810. j1 = j2 - (nr - 1) * ka1;
  1811. if (update) {
  1812. /* Computing MIN */
  1813. i__3 = j2, i__1 = i__ - (*ka << 1) + k - 1;
  1814. j2t = f2cmin(i__3,i__1);
  1815. } else {
  1816. j2t = j2;
  1817. }
  1818. nrt = (j2t + *ka - 1) / ka1;
  1819. i__3 = j2t;
  1820. i__1 = ka1;
  1821. for (j = j1; i__1 < 0 ? j >= i__3 : j <= i__3; j += i__1) {
  1822. /* create nonzero element a(j+ka,j-1) outside the band */
  1823. /* and store it in WORK(j) */
  1824. work[j] *= ab[ka1 + (j - 1) * ab_dim1];
  1825. ab[ka1 + (j - 1) * ab_dim1] = work[*n + j] * ab[ka1 + (j - 1)
  1826. * ab_dim1];
  1827. /* L800: */
  1828. }
  1829. /* generate rotations in 1st set to annihilate elements which */
  1830. /* have been created outside the band */
  1831. if (nrt > 0) {
  1832. dlargv_(&nrt, &ab[ka1 + j1 * ab_dim1], &inca, &work[j1], &ka1,
  1833. &work[*n + j1], &ka1);
  1834. }
  1835. if (nr > 0) {
  1836. /* apply rotations in 1st set from the right */
  1837. i__1 = *ka - 1;
  1838. for (l = 1; l <= i__1; ++l) {
  1839. dlartv_(&nr, &ab[l + 1 + j1 * ab_dim1], &inca, &ab[l + 2
  1840. + (j1 - 1) * ab_dim1], &inca, &work[*n + j1], &
  1841. work[j1], &ka1);
  1842. /* L810: */
  1843. }
  1844. /* apply rotations in 1st set from both sides to diagonal */
  1845. /* blocks */
  1846. dlar2v_(&nr, &ab[j1 * ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 +
  1847. 1], &ab[(j1 - 1) * ab_dim1 + 2], &inca, &work[*n + j1]
  1848. , &work[j1], &ka1);
  1849. }
  1850. /* start applying rotations in 1st set from the left */
  1851. i__1 = *kb - k + 1;
  1852. for (l = *ka - 1; l >= i__1; --l) {
  1853. nrt = (j2 + l - 1) / ka1;
  1854. j1t = j2 - (nrt - 1) * ka1;
  1855. if (nrt > 0) {
  1856. dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1]
  1857. , &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1],
  1858. &inca, &work[*n + j1t], &work[j1t], &ka1);
  1859. }
  1860. /* L820: */
  1861. }
  1862. if (wantx) {
  1863. /* post-multiply X by product of rotations in 1st set */
  1864. i__1 = j2;
  1865. i__3 = ka1;
  1866. for (j = j1; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) {
  1867. drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1
  1868. + 1], &c__1, &work[*n + j], &work[j]);
  1869. /* L830: */
  1870. }
  1871. }
  1872. /* L840: */
  1873. }
  1874. if (update) {
  1875. if (i2 > 0 && kbt > 0) {
  1876. /* create nonzero element a(i+kbt,i+kbt-ka-1) outside the */
  1877. /* band and store it in WORK(m-kb+i+kbt) */
  1878. work[m - *kb + i__ + kbt] = -bb[kbt + 1 + i__ * bb_dim1] *
  1879. ra1;
  1880. }
  1881. }
  1882. for (k = *kb; k >= 1; --k) {
  1883. if (update) {
  1884. /* Computing MAX */
  1885. i__4 = 2, i__3 = k + i0 - m;
  1886. j2 = i__ + k + 1 - f2cmax(i__4,i__3) * ka1;
  1887. } else {
  1888. /* Computing MAX */
  1889. i__4 = 1, i__3 = k + i0 - m;
  1890. j2 = i__ + k + 1 - f2cmax(i__4,i__3) * ka1;
  1891. }
  1892. /* finish applying rotations in 2nd set from the left */
  1893. for (l = *kb - k; l >= 1; --l) {
  1894. nrt = (j2 + *ka + l - 1) / ka1;
  1895. j1t = j2 - (nrt - 1) * ka1;
  1896. if (nrt > 0) {
  1897. dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t + l - 1) * ab_dim1],
  1898. &inca, &ab[ka1 - l + (j1t + l - 1) * ab_dim1], &
  1899. inca, &work[*n + m - *kb + j1t + *ka], &work[m - *
  1900. kb + j1t + *ka], &ka1);
  1901. }
  1902. /* L850: */
  1903. }
  1904. nr = (j2 + *ka - 1) / ka1;
  1905. j1 = j2 - (nr - 1) * ka1;
  1906. i__4 = j2;
  1907. i__3 = ka1;
  1908. for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
  1909. work[m - *kb + j] = work[m - *kb + j + *ka];
  1910. work[*n + m - *kb + j] = work[*n + m - *kb + j + *ka];
  1911. /* L860: */
  1912. }
  1913. i__3 = j2;
  1914. i__4 = ka1;
  1915. for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
  1916. /* create nonzero element a(j+ka,j-1) outside the band */
  1917. /* and store it in WORK(m-kb+j) */
  1918. work[m - *kb + j] *= ab[ka1 + (j - 1) * ab_dim1];
  1919. ab[ka1 + (j - 1) * ab_dim1] = work[*n + m - *kb + j] * ab[ka1
  1920. + (j - 1) * ab_dim1];
  1921. /* L870: */
  1922. }
  1923. if (update) {
  1924. if (i__ + k > ka1 && k <= kbt) {
  1925. work[m - *kb + i__ + k - *ka] = work[m - *kb + i__ + k];
  1926. }
  1927. }
  1928. /* L880: */
  1929. }
  1930. for (k = *kb; k >= 1; --k) {
  1931. /* Computing MAX */
  1932. i__4 = 1, i__3 = k + i0 - m;
  1933. j2 = i__ + k + 1 - f2cmax(i__4,i__3) * ka1;
  1934. nr = (j2 + *ka - 1) / ka1;
  1935. j1 = j2 - (nr - 1) * ka1;
  1936. if (nr > 0) {
  1937. /* generate rotations in 2nd set to annihilate elements */
  1938. /* which have been created outside the band */
  1939. dlargv_(&nr, &ab[ka1 + j1 * ab_dim1], &inca, &work[m - *kb +
  1940. j1], &ka1, &work[*n + m - *kb + j1], &ka1);
  1941. /* apply rotations in 2nd set from the right */
  1942. i__4 = *ka - 1;
  1943. for (l = 1; l <= i__4; ++l) {
  1944. dlartv_(&nr, &ab[l + 1 + j1 * ab_dim1], &inca, &ab[l + 2
  1945. + (j1 - 1) * ab_dim1], &inca, &work[*n + m - *kb
  1946. + j1], &work[m - *kb + j1], &ka1);
  1947. /* L890: */
  1948. }
  1949. /* apply rotations in 2nd set from both sides to diagonal */
  1950. /* blocks */
  1951. dlar2v_(&nr, &ab[j1 * ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 +
  1952. 1], &ab[(j1 - 1) * ab_dim1 + 2], &inca, &work[*n + m
  1953. - *kb + j1], &work[m - *kb + j1], &ka1);
  1954. }
  1955. /* start applying rotations in 2nd set from the left */
  1956. i__4 = *kb - k + 1;
  1957. for (l = *ka - 1; l >= i__4; --l) {
  1958. nrt = (j2 + l - 1) / ka1;
  1959. j1t = j2 - (nrt - 1) * ka1;
  1960. if (nrt > 0) {
  1961. dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1]
  1962. , &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1],
  1963. &inca, &work[*n + m - *kb + j1t], &work[m - *kb
  1964. + j1t], &ka1);
  1965. }
  1966. /* L900: */
  1967. }
  1968. if (wantx) {
  1969. /* post-multiply X by product of rotations in 2nd set */
  1970. i__4 = j2;
  1971. i__3 = ka1;
  1972. for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) {
  1973. drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1
  1974. + 1], &c__1, &work[*n + m - *kb + j], &work[m - *
  1975. kb + j]);
  1976. /* L910: */
  1977. }
  1978. }
  1979. /* L920: */
  1980. }
  1981. i__3 = *kb - 1;
  1982. for (k = 1; k <= i__3; ++k) {
  1983. /* Computing MAX */
  1984. i__4 = 1, i__1 = k + i0 - m + 1;
  1985. j2 = i__ + k + 1 - f2cmax(i__4,i__1) * ka1;
  1986. /* finish applying rotations in 1st set from the left */
  1987. for (l = *kb - k; l >= 1; --l) {
  1988. nrt = (j2 + l - 1) / ka1;
  1989. j1t = j2 - (nrt - 1) * ka1;
  1990. if (nrt > 0) {
  1991. dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1]
  1992. , &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1],
  1993. &inca, &work[*n + j1t], &work[j1t], &ka1);
  1994. }
  1995. /* L930: */
  1996. }
  1997. /* L940: */
  1998. }
  1999. if (*kb > 1) {
  2000. /* Computing MIN */
  2001. i__4 = i__ + *kb;
  2002. i__3 = f2cmin(i__4,m) - (*ka << 1) - 1;
  2003. for (j = 2; j <= i__3; ++j) {
  2004. work[*n + j] = work[*n + j + *ka];
  2005. work[j] = work[j + *ka];
  2006. /* L950: */
  2007. }
  2008. }
  2009. }
  2010. goto L490;
  2011. /* End of DSBGST */
  2012. } /* dsbgst_ */