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