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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332
  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 */ int 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 */ int 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 */ int 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 */ int dlar2v_(integer *, doublereal *, doublereal *,
  656. doublereal *, integer *, doublereal *, doublereal *, integer *);
  657. doublereal ra;
  658. integer nr, nx;
  659. extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
  660. doublereal *, doublereal *, doublereal *, integer *),
  661. dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  662. doublereal *), xerbla_(char *, integer *, ftnlen), dlargv_(
  663. integer *, doublereal *, integer *, doublereal *, integer *,
  664. doublereal *, integer *);
  665. logical update;
  666. extern /* Subroutine */ int 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 0;
  717. }
  718. /* Quick return if possible */
  719. if (*n == 0) {
  720. return 0;
  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 0;
  1415. }
  1416. goto L490;
  1417. }
  1418. } else {
  1419. i__ -= *ka;
  1420. if (i__ < 2) {
  1421. return 0;
  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_ */