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.

zlatbs.c 49 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__1 = 1;
  485. static doublereal c_b36 = .5;
  486. /* > \brief \b ZLATBS solves a triangular banded system of equations. */
  487. /* =========== DOCUMENTATION =========== */
  488. /* Online html documentation available at */
  489. /* http://www.netlib.org/lapack/explore-html/ */
  490. /* > \htmlonly */
  491. /* > Download ZLATBS + dependencies */
  492. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlatbs.
  493. f"> */
  494. /* > [TGZ]</a> */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlatbs.
  496. f"> */
  497. /* > [ZIP]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlatbs.
  499. f"> */
  500. /* > [TXT]</a> */
  501. /* > \endhtmlonly */
  502. /* Definition: */
  503. /* =========== */
  504. /* SUBROUTINE ZLATBS( UPLO, TRANS, DIAG, NORMIN, N, KD, AB, LDAB, X, */
  505. /* SCALE, CNORM, INFO ) */
  506. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  507. /* INTEGER INFO, KD, LDAB, N */
  508. /* DOUBLE PRECISION SCALE */
  509. /* DOUBLE PRECISION CNORM( * ) */
  510. /* COMPLEX*16 AB( LDAB, * ), X( * ) */
  511. /* > \par Purpose: */
  512. /* ============= */
  513. /* > */
  514. /* > \verbatim */
  515. /* > */
  516. /* > ZLATBS solves one of the triangular systems */
  517. /* > */
  518. /* > A * x = s*b, A**T * x = s*b, or A**H * x = s*b, */
  519. /* > */
  520. /* > with scaling to prevent overflow, where A is an upper or lower */
  521. /* > triangular band matrix. Here A**T denotes the transpose of A, x and b */
  522. /* > are n-element vectors, and s is a scaling factor, usually less than */
  523. /* > or equal to 1, chosen so that the components of x will be less than */
  524. /* > the overflow threshold. If the unscaled problem will not cause */
  525. /* > overflow, the Level 2 BLAS routine ZTBSV is called. If the matrix A */
  526. /* > is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
  527. /* > non-trivial solution to A*x = 0 is returned. */
  528. /* > \endverbatim */
  529. /* Arguments: */
  530. /* ========== */
  531. /* > \param[in] UPLO */
  532. /* > \verbatim */
  533. /* > UPLO is CHARACTER*1 */
  534. /* > Specifies whether the matrix A is upper or lower triangular. */
  535. /* > = 'U': Upper triangular */
  536. /* > = 'L': Lower triangular */
  537. /* > \endverbatim */
  538. /* > */
  539. /* > \param[in] TRANS */
  540. /* > \verbatim */
  541. /* > TRANS is CHARACTER*1 */
  542. /* > Specifies the operation applied to A. */
  543. /* > = 'N': Solve A * x = s*b (No transpose) */
  544. /* > = 'T': Solve A**T * x = s*b (Transpose) */
  545. /* > = 'C': Solve A**H * x = s*b (Conjugate transpose) */
  546. /* > \endverbatim */
  547. /* > */
  548. /* > \param[in] DIAG */
  549. /* > \verbatim */
  550. /* > DIAG is CHARACTER*1 */
  551. /* > Specifies whether or not the matrix A is unit triangular. */
  552. /* > = 'N': Non-unit triangular */
  553. /* > = 'U': Unit triangular */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] NORMIN */
  557. /* > \verbatim */
  558. /* > NORMIN is CHARACTER*1 */
  559. /* > Specifies whether CNORM has been set or not. */
  560. /* > = 'Y': CNORM contains the column norms on entry */
  561. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  562. /* > be computed and stored in CNORM. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] N */
  566. /* > \verbatim */
  567. /* > N is INTEGER */
  568. /* > The order of the matrix A. N >= 0. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] KD */
  572. /* > \verbatim */
  573. /* > KD is INTEGER */
  574. /* > The number of subdiagonals or superdiagonals in the */
  575. /* > triangular matrix A. KD >= 0. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[in] AB */
  579. /* > \verbatim */
  580. /* > AB is COMPLEX*16 array, dimension (LDAB,N) */
  581. /* > The upper or lower triangular band matrix A, stored in the */
  582. /* > first KD+1 rows of the array. The j-th column of A is stored */
  583. /* > in the j-th column of the array AB as follows: */
  584. /* > if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for f2cmax(1,j-kd)<=i<=j; */
  585. /* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(n,j+kd). */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] LDAB */
  589. /* > \verbatim */
  590. /* > LDAB is INTEGER */
  591. /* > The leading dimension of the array AB. LDAB >= KD+1. */
  592. /* > \endverbatim */
  593. /* > */
  594. /* > \param[in,out] X */
  595. /* > \verbatim */
  596. /* > X is COMPLEX*16 array, dimension (N) */
  597. /* > On entry, the right hand side b of the triangular system. */
  598. /* > On exit, X is overwritten by the solution vector x. */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[out] SCALE */
  602. /* > \verbatim */
  603. /* > SCALE is DOUBLE PRECISION */
  604. /* > The scaling factor s for the triangular system */
  605. /* > A * x = s*b, A**T * x = s*b, or A**H * x = s*b. */
  606. /* > If SCALE = 0, the matrix A is singular or badly scaled, and */
  607. /* > the vector x is an exact or approximate solution to A*x = 0. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in,out] CNORM */
  611. /* > \verbatim */
  612. /* > CNORM is DOUBLE PRECISION array, dimension (N) */
  613. /* > */
  614. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  615. /* > contains the norm of the off-diagonal part of the j-th column */
  616. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  617. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  618. /* > must be greater than or equal to the 1-norm. */
  619. /* > */
  620. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  621. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  622. /* > of A. */
  623. /* > \endverbatim */
  624. /* > */
  625. /* > \param[out] INFO */
  626. /* > \verbatim */
  627. /* > INFO is INTEGER */
  628. /* > = 0: successful exit */
  629. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  630. /* > \endverbatim */
  631. /* Authors: */
  632. /* ======== */
  633. /* > \author Univ. of Tennessee */
  634. /* > \author Univ. of California Berkeley */
  635. /* > \author Univ. of Colorado Denver */
  636. /* > \author NAG Ltd. */
  637. /* > \date November 2017 */
  638. /* > \ingroup complex16OTHERauxiliary */
  639. /* > \par Further Details: */
  640. /* ===================== */
  641. /* > */
  642. /* > \verbatim */
  643. /* > */
  644. /* > A rough bound on x is computed; if that is less than overflow, ZTBSV */
  645. /* > is called, otherwise, specific code is used which checks for possible */
  646. /* > overflow or divide-by-zero at every operation. */
  647. /* > */
  648. /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */
  649. /* > if A is lower triangular is */
  650. /* > */
  651. /* > x[1:n] := b[1:n] */
  652. /* > for j = 1, ..., n */
  653. /* > x(j) := x(j) / A(j,j) */
  654. /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
  655. /* > end */
  656. /* > */
  657. /* > Define bounds on the components of x after j iterations of the loop: */
  658. /* > M(j) = bound on x[1:j] */
  659. /* > G(j) = bound on x[j+1:n] */
  660. /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
  661. /* > */
  662. /* > Then for iteration j+1 we have */
  663. /* > M(j+1) <= G(j) / | A(j+1,j+1) | */
  664. /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
  665. /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
  666. /* > */
  667. /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */
  668. /* > column j+1 of A, not counting the diagonal. Hence */
  669. /* > */
  670. /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
  671. /* > 1<=i<=j */
  672. /* > and */
  673. /* > */
  674. /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
  675. /* > 1<=i< j */
  676. /* > */
  677. /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine ZTBSV if the */
  678. /* > reciprocal of the largest M(j), j=1,..,n, is larger than */
  679. /* > f2cmax(underflow, 1/overflow). */
  680. /* > */
  681. /* > The bound on x(j) is also used to determine when a step in the */
  682. /* > columnwise method can be performed without fear of overflow. If */
  683. /* > the computed bound is greater than a large constant, x is scaled to */
  684. /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
  685. /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
  686. /* > */
  687. /* > Similarly, a row-wise scheme is used to solve A**T *x = b or */
  688. /* > A**H *x = b. The basic algorithm for A upper triangular is */
  689. /* > */
  690. /* > for j = 1, ..., n */
  691. /* > x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
  692. /* > end */
  693. /* > */
  694. /* > We simultaneously compute two bounds */
  695. /* > G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
  696. /* > M(j) = bound on x(i), 1<=i<=j */
  697. /* > */
  698. /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
  699. /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
  700. /* > Then the bound on x(j) is */
  701. /* > */
  702. /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
  703. /* > */
  704. /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
  705. /* > 1<=i<=j */
  706. /* > */
  707. /* > and we can safely call ZTBSV if 1/M(n) and 1/G(n) are both greater */
  708. /* > than f2cmax(underflow, 1/overflow). */
  709. /* > \endverbatim */
  710. /* > */
  711. /* ===================================================================== */
  712. /* Subroutine */ void zlatbs_(char *uplo, char *trans, char *diag, char *
  713. normin, integer *n, integer *kd, doublecomplex *ab, integer *ldab,
  714. doublecomplex *x, doublereal *scale, doublereal *cnorm, integer *info)
  715. {
  716. /* System generated locals */
  717. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4, i__5;
  718. doublereal d__1, d__2, d__3, d__4;
  719. doublecomplex z__1, z__2, z__3, z__4;
  720. /* Local variables */
  721. integer jinc, jlen;
  722. doublereal xbnd;
  723. integer imax;
  724. doublereal tmax;
  725. doublecomplex tjjs;
  726. doublereal xmax, grow;
  727. integer i__, j;
  728. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  729. integer *);
  730. integer maind;
  731. extern logical lsame_(char *, char *);
  732. doublereal tscal;
  733. doublecomplex uscal;
  734. integer jlast;
  735. doublecomplex csumj;
  736. extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
  737. doublecomplex *, integer *, doublecomplex *, integer *);
  738. logical upper;
  739. extern /* Double Complex */ VOID zdotu_(doublecomplex *, integer *,
  740. doublecomplex *, integer *, doublecomplex *, integer *);
  741. extern /* Subroutine */ void ztbsv_(char *, char *, char *, integer *,
  742. integer *, doublecomplex *, integer *, doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *,
  743. doublecomplex *, integer *, doublecomplex *, integer *), dlabad_(
  744. doublereal *, doublereal *);
  745. extern doublereal dlamch_(char *);
  746. doublereal xj;
  747. extern integer idamax_(integer *, doublereal *, integer *);
  748. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  749. extern void zdscal_(
  750. integer *, doublereal *, doublecomplex *, integer *);
  751. doublereal bignum;
  752. extern integer izamax_(integer *, doublecomplex *, integer *);
  753. extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
  754. doublecomplex *);
  755. logical notran;
  756. integer jfirst;
  757. extern doublereal dzasum_(integer *, doublecomplex *, integer *);
  758. doublereal smlnum;
  759. logical nounit;
  760. doublereal rec, tjj;
  761. /* -- LAPACK auxiliary routine (version 3.8.0) -- */
  762. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  763. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  764. /* November 2017 */
  765. /* ===================================================================== */
  766. /* Parameter adjustments */
  767. ab_dim1 = *ldab;
  768. ab_offset = 1 + ab_dim1 * 1;
  769. ab -= ab_offset;
  770. --x;
  771. --cnorm;
  772. /* Function Body */
  773. *info = 0;
  774. upper = lsame_(uplo, "U");
  775. notran = lsame_(trans, "N");
  776. nounit = lsame_(diag, "N");
  777. /* Test the input parameters. */
  778. if (! upper && ! lsame_(uplo, "L")) {
  779. *info = -1;
  780. } else if (! notran && ! lsame_(trans, "T") && !
  781. lsame_(trans, "C")) {
  782. *info = -2;
  783. } else if (! nounit && ! lsame_(diag, "U")) {
  784. *info = -3;
  785. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  786. "N")) {
  787. *info = -4;
  788. } else if (*n < 0) {
  789. *info = -5;
  790. } else if (*kd < 0) {
  791. *info = -6;
  792. } else if (*ldab < *kd + 1) {
  793. *info = -8;
  794. }
  795. if (*info != 0) {
  796. i__1 = -(*info);
  797. xerbla_("ZLATBS", &i__1, (ftnlen)6);
  798. return;
  799. }
  800. /* Quick return if possible */
  801. if (*n == 0) {
  802. return;
  803. }
  804. /* Determine machine dependent parameters to control overflow. */
  805. smlnum = dlamch_("Safe minimum");
  806. bignum = 1. / smlnum;
  807. dlabad_(&smlnum, &bignum);
  808. smlnum /= dlamch_("Precision");
  809. bignum = 1. / smlnum;
  810. *scale = 1.;
  811. if (lsame_(normin, "N")) {
  812. /* Compute the 1-norm of each column, not including the diagonal. */
  813. if (upper) {
  814. /* A is upper triangular. */
  815. i__1 = *n;
  816. for (j = 1; j <= i__1; ++j) {
  817. /* Computing MIN */
  818. i__2 = *kd, i__3 = j - 1;
  819. jlen = f2cmin(i__2,i__3);
  820. cnorm[j] = dzasum_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1], &
  821. c__1);
  822. /* L10: */
  823. }
  824. } else {
  825. /* A is lower triangular. */
  826. i__1 = *n;
  827. for (j = 1; j <= i__1; ++j) {
  828. /* Computing MIN */
  829. i__2 = *kd, i__3 = *n - j;
  830. jlen = f2cmin(i__2,i__3);
  831. if (jlen > 0) {
  832. cnorm[j] = dzasum_(&jlen, &ab[j * ab_dim1 + 2], &c__1);
  833. } else {
  834. cnorm[j] = 0.;
  835. }
  836. /* L20: */
  837. }
  838. }
  839. }
  840. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  841. /* greater than BIGNUM/2. */
  842. imax = idamax_(n, &cnorm[1], &c__1);
  843. tmax = cnorm[imax];
  844. if (tmax <= bignum * .5) {
  845. tscal = 1.;
  846. } else {
  847. tscal = .5 / (smlnum * tmax);
  848. dscal_(n, &tscal, &cnorm[1], &c__1);
  849. }
  850. /* Compute a bound on the computed solution vector to see if the */
  851. /* Level 2 BLAS routine ZTBSV can be used. */
  852. xmax = 0.;
  853. i__1 = *n;
  854. for (j = 1; j <= i__1; ++j) {
  855. /* Computing MAX */
  856. i__2 = j;
  857. d__3 = xmax, d__4 = (d__1 = x[i__2].r / 2., abs(d__1)) + (d__2 =
  858. d_imag(&x[j]) / 2., abs(d__2));
  859. xmax = f2cmax(d__3,d__4);
  860. /* L30: */
  861. }
  862. xbnd = xmax;
  863. if (notran) {
  864. /* Compute the growth in A * x = b. */
  865. if (upper) {
  866. jfirst = *n;
  867. jlast = 1;
  868. jinc = -1;
  869. maind = *kd + 1;
  870. } else {
  871. jfirst = 1;
  872. jlast = *n;
  873. jinc = 1;
  874. maind = 1;
  875. }
  876. if (tscal != 1.) {
  877. grow = 0.;
  878. goto L60;
  879. }
  880. if (nounit) {
  881. /* A is non-unit triangular. */
  882. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  883. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  884. grow = .5 / f2cmax(xbnd,smlnum);
  885. xbnd = grow;
  886. i__1 = jlast;
  887. i__2 = jinc;
  888. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  889. /* Exit the loop if the growth factor is too small. */
  890. if (grow <= smlnum) {
  891. goto L60;
  892. }
  893. i__3 = maind + j * ab_dim1;
  894. tjjs.r = ab[i__3].r, tjjs.i = ab[i__3].i;
  895. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
  896. d__2));
  897. if (tjj >= smlnum) {
  898. /* M(j) = G(j-1) / abs(A(j,j)) */
  899. /* Computing MIN */
  900. d__1 = xbnd, d__2 = f2cmin(1.,tjj) * grow;
  901. xbnd = f2cmin(d__1,d__2);
  902. } else {
  903. /* M(j) could overflow, set XBND to 0. */
  904. xbnd = 0.;
  905. }
  906. if (tjj + cnorm[j] >= smlnum) {
  907. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  908. grow *= tjj / (tjj + cnorm[j]);
  909. } else {
  910. /* G(j) could overflow, set GROW to 0. */
  911. grow = 0.;
  912. }
  913. /* L40: */
  914. }
  915. grow = xbnd;
  916. } else {
  917. /* A is unit triangular. */
  918. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  919. /* Computing MIN */
  920. d__1 = 1., d__2 = .5 / f2cmax(xbnd,smlnum);
  921. grow = f2cmin(d__1,d__2);
  922. i__2 = jlast;
  923. i__1 = jinc;
  924. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  925. /* Exit the loop if the growth factor is too small. */
  926. if (grow <= smlnum) {
  927. goto L60;
  928. }
  929. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  930. grow *= 1. / (cnorm[j] + 1.);
  931. /* L50: */
  932. }
  933. }
  934. L60:
  935. ;
  936. } else {
  937. /* Compute the growth in A**T * x = b or A**H * x = b. */
  938. if (upper) {
  939. jfirst = 1;
  940. jlast = *n;
  941. jinc = 1;
  942. maind = *kd + 1;
  943. } else {
  944. jfirst = *n;
  945. jlast = 1;
  946. jinc = -1;
  947. maind = 1;
  948. }
  949. if (tscal != 1.) {
  950. grow = 0.;
  951. goto L90;
  952. }
  953. if (nounit) {
  954. /* A is non-unit triangular. */
  955. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  956. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  957. grow = .5 / f2cmax(xbnd,smlnum);
  958. xbnd = grow;
  959. i__1 = jlast;
  960. i__2 = jinc;
  961. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  962. /* Exit the loop if the growth factor is too small. */
  963. if (grow <= smlnum) {
  964. goto L90;
  965. }
  966. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  967. xj = cnorm[j] + 1.;
  968. /* Computing MIN */
  969. d__1 = grow, d__2 = xbnd / xj;
  970. grow = f2cmin(d__1,d__2);
  971. i__3 = maind + j * ab_dim1;
  972. tjjs.r = ab[i__3].r, tjjs.i = ab[i__3].i;
  973. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
  974. d__2));
  975. if (tjj >= smlnum) {
  976. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  977. if (xj > tjj) {
  978. xbnd *= tjj / xj;
  979. }
  980. } else {
  981. /* M(j) could overflow, set XBND to 0. */
  982. xbnd = 0.;
  983. }
  984. /* L70: */
  985. }
  986. grow = f2cmin(grow,xbnd);
  987. } else {
  988. /* A is unit triangular. */
  989. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  990. /* Computing MIN */
  991. d__1 = 1., d__2 = .5 / f2cmax(xbnd,smlnum);
  992. grow = f2cmin(d__1,d__2);
  993. i__2 = jlast;
  994. i__1 = jinc;
  995. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  996. /* Exit the loop if the growth factor is too small. */
  997. if (grow <= smlnum) {
  998. goto L90;
  999. }
  1000. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  1001. xj = cnorm[j] + 1.;
  1002. grow /= xj;
  1003. /* L80: */
  1004. }
  1005. }
  1006. L90:
  1007. ;
  1008. }
  1009. if (grow * tscal > smlnum) {
  1010. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  1011. /* elements of X is not too small. */
  1012. ztbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1);
  1013. } else {
  1014. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  1015. if (xmax > bignum * .5) {
  1016. /* Scale X so that its components are less than or equal to */
  1017. /* BIGNUM in absolute value. */
  1018. *scale = bignum * .5 / xmax;
  1019. zdscal_(n, scale, &x[1], &c__1);
  1020. xmax = bignum;
  1021. } else {
  1022. xmax *= 2.;
  1023. }
  1024. if (notran) {
  1025. /* Solve A * x = b */
  1026. i__1 = jlast;
  1027. i__2 = jinc;
  1028. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1029. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  1030. i__3 = j;
  1031. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
  1032. abs(d__2));
  1033. if (nounit) {
  1034. i__3 = maind + j * ab_dim1;
  1035. z__1.r = tscal * ab[i__3].r, z__1.i = tscal * ab[i__3].i;
  1036. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1037. } else {
  1038. tjjs.r = tscal, tjjs.i = 0.;
  1039. if (tscal == 1.) {
  1040. goto L110;
  1041. }
  1042. }
  1043. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
  1044. d__2));
  1045. if (tjj > smlnum) {
  1046. /* abs(A(j,j)) > SMLNUM: */
  1047. if (tjj < 1.) {
  1048. if (xj > tjj * bignum) {
  1049. /* Scale x by 1/b(j). */
  1050. rec = 1. / xj;
  1051. zdscal_(n, &rec, &x[1], &c__1);
  1052. *scale *= rec;
  1053. xmax *= rec;
  1054. }
  1055. }
  1056. i__3 = j;
  1057. zladiv_(&z__1, &x[j], &tjjs);
  1058. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1059. i__3 = j;
  1060. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1061. , abs(d__2));
  1062. } else if (tjj > 0.) {
  1063. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1064. if (xj > tjj * bignum) {
  1065. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  1066. /* to avoid overflow when dividing by A(j,j). */
  1067. rec = tjj * bignum / xj;
  1068. if (cnorm[j] > 1.) {
  1069. /* Scale by 1/CNORM(j) to avoid overflow when */
  1070. /* multiplying x(j) times column j. */
  1071. rec /= cnorm[j];
  1072. }
  1073. zdscal_(n, &rec, &x[1], &c__1);
  1074. *scale *= rec;
  1075. xmax *= rec;
  1076. }
  1077. i__3 = j;
  1078. zladiv_(&z__1, &x[j], &tjjs);
  1079. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1080. i__3 = j;
  1081. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1082. , abs(d__2));
  1083. } else {
  1084. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1085. /* scale = 0, and compute a solution to A*x = 0. */
  1086. i__3 = *n;
  1087. for (i__ = 1; i__ <= i__3; ++i__) {
  1088. i__4 = i__;
  1089. x[i__4].r = 0., x[i__4].i = 0.;
  1090. /* L100: */
  1091. }
  1092. i__3 = j;
  1093. x[i__3].r = 1., x[i__3].i = 0.;
  1094. xj = 1.;
  1095. *scale = 0.;
  1096. xmax = 0.;
  1097. }
  1098. L110:
  1099. /* Scale x if necessary to avoid overflow when adding a */
  1100. /* multiple of column j of A. */
  1101. if (xj > 1.) {
  1102. rec = 1. / xj;
  1103. if (cnorm[j] > (bignum - xmax) * rec) {
  1104. /* Scale x by 1/(2*abs(x(j))). */
  1105. rec *= .5;
  1106. zdscal_(n, &rec, &x[1], &c__1);
  1107. *scale *= rec;
  1108. }
  1109. } else if (xj * cnorm[j] > bignum - xmax) {
  1110. /* Scale x by 1/2. */
  1111. zdscal_(n, &c_b36, &x[1], &c__1);
  1112. *scale *= .5;
  1113. }
  1114. if (upper) {
  1115. if (j > 1) {
  1116. /* Compute the update */
  1117. /* x(f2cmax(1,j-kd):j-1) := x(f2cmax(1,j-kd):j-1) - */
  1118. /* x(j)* A(f2cmax(1,j-kd):j-1,j) */
  1119. /* Computing MIN */
  1120. i__3 = *kd, i__4 = j - 1;
  1121. jlen = f2cmin(i__3,i__4);
  1122. i__3 = j;
  1123. z__2.r = -x[i__3].r, z__2.i = -x[i__3].i;
  1124. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1125. zaxpy_(&jlen, &z__1, &ab[*kd + 1 - jlen + j * ab_dim1]
  1126. , &c__1, &x[j - jlen], &c__1);
  1127. i__3 = j - 1;
  1128. i__ = izamax_(&i__3, &x[1], &c__1);
  1129. i__3 = i__;
  1130. xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
  1131. &x[i__]), abs(d__2));
  1132. }
  1133. } else if (j < *n) {
  1134. /* Compute the update */
  1135. /* x(j+1:f2cmin(j+kd,n)) := x(j+1:f2cmin(j+kd,n)) - */
  1136. /* x(j) * A(j+1:f2cmin(j+kd,n),j) */
  1137. /* Computing MIN */
  1138. i__3 = *kd, i__4 = *n - j;
  1139. jlen = f2cmin(i__3,i__4);
  1140. if (jlen > 0) {
  1141. i__3 = j;
  1142. z__2.r = -x[i__3].r, z__2.i = -x[i__3].i;
  1143. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1144. zaxpy_(&jlen, &z__1, &ab[j * ab_dim1 + 2], &c__1, &x[
  1145. j + 1], &c__1);
  1146. }
  1147. i__3 = *n - j;
  1148. i__ = j + izamax_(&i__3, &x[j + 1], &c__1);
  1149. i__3 = i__;
  1150. xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[
  1151. i__]), abs(d__2));
  1152. }
  1153. /* L120: */
  1154. }
  1155. } else if (lsame_(trans, "T")) {
  1156. /* Solve A**T * x = b */
  1157. i__2 = jlast;
  1158. i__1 = jinc;
  1159. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  1160. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  1161. /* k<>j */
  1162. i__3 = j;
  1163. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
  1164. abs(d__2));
  1165. uscal.r = tscal, uscal.i = 0.;
  1166. rec = 1. / f2cmax(xmax,1.);
  1167. if (cnorm[j] > (bignum - xj) * rec) {
  1168. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  1169. rec *= .5;
  1170. if (nounit) {
  1171. i__3 = maind + j * ab_dim1;
  1172. z__1.r = tscal * ab[i__3].r, z__1.i = tscal * ab[i__3]
  1173. .i;
  1174. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1175. } else {
  1176. tjjs.r = tscal, tjjs.i = 0.;
  1177. }
  1178. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1179. abs(d__2));
  1180. if (tjj > 1.) {
  1181. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1182. /* Computing MIN */
  1183. d__1 = 1., d__2 = rec * tjj;
  1184. rec = f2cmin(d__1,d__2);
  1185. zladiv_(&z__1, &uscal, &tjjs);
  1186. uscal.r = z__1.r, uscal.i = z__1.i;
  1187. }
  1188. if (rec < 1.) {
  1189. zdscal_(n, &rec, &x[1], &c__1);
  1190. *scale *= rec;
  1191. xmax *= rec;
  1192. }
  1193. }
  1194. csumj.r = 0., csumj.i = 0.;
  1195. if (uscal.r == 1. && uscal.i == 0.) {
  1196. /* If the scaling needed for A in the dot product is 1, */
  1197. /* call ZDOTU to perform the dot product. */
  1198. if (upper) {
  1199. /* Computing MIN */
  1200. i__3 = *kd, i__4 = j - 1;
  1201. jlen = f2cmin(i__3,i__4);
  1202. zdotu_(&z__1, &jlen, &ab[*kd + 1 - jlen + j * ab_dim1]
  1203. , &c__1, &x[j - jlen], &c__1);
  1204. csumj.r = z__1.r, csumj.i = z__1.i;
  1205. } else {
  1206. /* Computing MIN */
  1207. i__3 = *kd, i__4 = *n - j;
  1208. jlen = f2cmin(i__3,i__4);
  1209. if (jlen > 1) {
  1210. zdotu_(&z__1, &jlen, &ab[j * ab_dim1 + 2], &c__1,
  1211. &x[j + 1], &c__1);
  1212. csumj.r = z__1.r, csumj.i = z__1.i;
  1213. }
  1214. }
  1215. } else {
  1216. /* Otherwise, use in-line code for the dot product. */
  1217. if (upper) {
  1218. /* Computing MIN */
  1219. i__3 = *kd, i__4 = j - 1;
  1220. jlen = f2cmin(i__3,i__4);
  1221. i__3 = jlen;
  1222. for (i__ = 1; i__ <= i__3; ++i__) {
  1223. i__4 = *kd + i__ - jlen + j * ab_dim1;
  1224. z__3.r = ab[i__4].r * uscal.r - ab[i__4].i *
  1225. uscal.i, z__3.i = ab[i__4].r * uscal.i +
  1226. ab[i__4].i * uscal.r;
  1227. i__5 = j - jlen - 1 + i__;
  1228. z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i,
  1229. z__2.i = z__3.r * x[i__5].i + z__3.i * x[
  1230. i__5].r;
  1231. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1232. z__2.i;
  1233. csumj.r = z__1.r, csumj.i = z__1.i;
  1234. /* L130: */
  1235. }
  1236. } else {
  1237. /* Computing MIN */
  1238. i__3 = *kd, i__4 = *n - j;
  1239. jlen = f2cmin(i__3,i__4);
  1240. i__3 = jlen;
  1241. for (i__ = 1; i__ <= i__3; ++i__) {
  1242. i__4 = i__ + 1 + j * ab_dim1;
  1243. z__3.r = ab[i__4].r * uscal.r - ab[i__4].i *
  1244. uscal.i, z__3.i = ab[i__4].r * uscal.i +
  1245. ab[i__4].i * uscal.r;
  1246. i__5 = j + i__;
  1247. z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i,
  1248. z__2.i = z__3.r * x[i__5].i + z__3.i * x[
  1249. i__5].r;
  1250. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1251. z__2.i;
  1252. csumj.r = z__1.r, csumj.i = z__1.i;
  1253. /* L140: */
  1254. }
  1255. }
  1256. }
  1257. z__1.r = tscal, z__1.i = 0.;
  1258. if (uscal.r == z__1.r && uscal.i == z__1.i) {
  1259. /* Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
  1260. /* was not used to scale the dotproduct. */
  1261. i__3 = j;
  1262. i__4 = j;
  1263. z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i -
  1264. csumj.i;
  1265. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1266. i__3 = j;
  1267. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1268. , abs(d__2));
  1269. if (nounit) {
  1270. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1271. i__3 = maind + j * ab_dim1;
  1272. z__1.r = tscal * ab[i__3].r, z__1.i = tscal * ab[i__3]
  1273. .i;
  1274. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1275. } else {
  1276. tjjs.r = tscal, tjjs.i = 0.;
  1277. if (tscal == 1.) {
  1278. goto L160;
  1279. }
  1280. }
  1281. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1282. abs(d__2));
  1283. if (tjj > smlnum) {
  1284. /* abs(A(j,j)) > SMLNUM: */
  1285. if (tjj < 1.) {
  1286. if (xj > tjj * bignum) {
  1287. /* Scale X by 1/abs(x(j)). */
  1288. rec = 1. / xj;
  1289. zdscal_(n, &rec, &x[1], &c__1);
  1290. *scale *= rec;
  1291. xmax *= rec;
  1292. }
  1293. }
  1294. i__3 = j;
  1295. zladiv_(&z__1, &x[j], &tjjs);
  1296. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1297. } else if (tjj > 0.) {
  1298. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1299. if (xj > tjj * bignum) {
  1300. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1301. rec = tjj * bignum / xj;
  1302. zdscal_(n, &rec, &x[1], &c__1);
  1303. *scale *= rec;
  1304. xmax *= rec;
  1305. }
  1306. i__3 = j;
  1307. zladiv_(&z__1, &x[j], &tjjs);
  1308. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1309. } else {
  1310. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1311. /* scale = 0 and compute a solution to A**T *x = 0. */
  1312. i__3 = *n;
  1313. for (i__ = 1; i__ <= i__3; ++i__) {
  1314. i__4 = i__;
  1315. x[i__4].r = 0., x[i__4].i = 0.;
  1316. /* L150: */
  1317. }
  1318. i__3 = j;
  1319. x[i__3].r = 1., x[i__3].i = 0.;
  1320. *scale = 0.;
  1321. xmax = 0.;
  1322. }
  1323. L160:
  1324. ;
  1325. } else {
  1326. /* Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
  1327. /* product has already been divided by 1/A(j,j). */
  1328. i__3 = j;
  1329. zladiv_(&z__2, &x[j], &tjjs);
  1330. z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
  1331. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1332. }
  1333. /* Computing MAX */
  1334. i__3 = j;
  1335. d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 =
  1336. d_imag(&x[j]), abs(d__2));
  1337. xmax = f2cmax(d__3,d__4);
  1338. /* L170: */
  1339. }
  1340. } else {
  1341. /* Solve A**H * x = b */
  1342. i__1 = jlast;
  1343. i__2 = jinc;
  1344. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1345. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  1346. /* k<>j */
  1347. i__3 = j;
  1348. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
  1349. abs(d__2));
  1350. uscal.r = tscal, uscal.i = 0.;
  1351. rec = 1. / f2cmax(xmax,1.);
  1352. if (cnorm[j] > (bignum - xj) * rec) {
  1353. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  1354. rec *= .5;
  1355. if (nounit) {
  1356. d_cnjg(&z__2, &ab[maind + j * ab_dim1]);
  1357. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1358. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1359. } else {
  1360. tjjs.r = tscal, tjjs.i = 0.;
  1361. }
  1362. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1363. abs(d__2));
  1364. if (tjj > 1.) {
  1365. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1366. /* Computing MIN */
  1367. d__1 = 1., d__2 = rec * tjj;
  1368. rec = f2cmin(d__1,d__2);
  1369. zladiv_(&z__1, &uscal, &tjjs);
  1370. uscal.r = z__1.r, uscal.i = z__1.i;
  1371. }
  1372. if (rec < 1.) {
  1373. zdscal_(n, &rec, &x[1], &c__1);
  1374. *scale *= rec;
  1375. xmax *= rec;
  1376. }
  1377. }
  1378. csumj.r = 0., csumj.i = 0.;
  1379. if (uscal.r == 1. && uscal.i == 0.) {
  1380. /* If the scaling needed for A in the dot product is 1, */
  1381. /* call ZDOTC to perform the dot product. */
  1382. if (upper) {
  1383. /* Computing MIN */
  1384. i__3 = *kd, i__4 = j - 1;
  1385. jlen = f2cmin(i__3,i__4);
  1386. zdotc_(&z__1, &jlen, &ab[*kd + 1 - jlen + j * ab_dim1]
  1387. , &c__1, &x[j - jlen], &c__1);
  1388. csumj.r = z__1.r, csumj.i = z__1.i;
  1389. } else {
  1390. /* Computing MIN */
  1391. i__3 = *kd, i__4 = *n - j;
  1392. jlen = f2cmin(i__3,i__4);
  1393. if (jlen > 1) {
  1394. zdotc_(&z__1, &jlen, &ab[j * ab_dim1 + 2], &c__1,
  1395. &x[j + 1], &c__1);
  1396. csumj.r = z__1.r, csumj.i = z__1.i;
  1397. }
  1398. }
  1399. } else {
  1400. /* Otherwise, use in-line code for the dot product. */
  1401. if (upper) {
  1402. /* Computing MIN */
  1403. i__3 = *kd, i__4 = j - 1;
  1404. jlen = f2cmin(i__3,i__4);
  1405. i__3 = jlen;
  1406. for (i__ = 1; i__ <= i__3; ++i__) {
  1407. d_cnjg(&z__4, &ab[*kd + i__ - jlen + j * ab_dim1])
  1408. ;
  1409. z__3.r = z__4.r * uscal.r - z__4.i * uscal.i,
  1410. z__3.i = z__4.r * uscal.i + z__4.i *
  1411. uscal.r;
  1412. i__4 = j - jlen - 1 + i__;
  1413. z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i,
  1414. z__2.i = z__3.r * x[i__4].i + z__3.i * x[
  1415. i__4].r;
  1416. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1417. z__2.i;
  1418. csumj.r = z__1.r, csumj.i = z__1.i;
  1419. /* L180: */
  1420. }
  1421. } else {
  1422. /* Computing MIN */
  1423. i__3 = *kd, i__4 = *n - j;
  1424. jlen = f2cmin(i__3,i__4);
  1425. i__3 = jlen;
  1426. for (i__ = 1; i__ <= i__3; ++i__) {
  1427. d_cnjg(&z__4, &ab[i__ + 1 + j * ab_dim1]);
  1428. z__3.r = z__4.r * uscal.r - z__4.i * uscal.i,
  1429. z__3.i = z__4.r * uscal.i + z__4.i *
  1430. uscal.r;
  1431. i__4 = j + i__;
  1432. z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i,
  1433. z__2.i = z__3.r * x[i__4].i + z__3.i * x[
  1434. i__4].r;
  1435. z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
  1436. z__2.i;
  1437. csumj.r = z__1.r, csumj.i = z__1.i;
  1438. /* L190: */
  1439. }
  1440. }
  1441. }
  1442. z__1.r = tscal, z__1.i = 0.;
  1443. if (uscal.r == z__1.r && uscal.i == z__1.i) {
  1444. /* Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
  1445. /* was not used to scale the dotproduct. */
  1446. i__3 = j;
  1447. i__4 = j;
  1448. z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i -
  1449. csumj.i;
  1450. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1451. i__3 = j;
  1452. xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
  1453. , abs(d__2));
  1454. if (nounit) {
  1455. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1456. d_cnjg(&z__2, &ab[maind + j * ab_dim1]);
  1457. z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
  1458. tjjs.r = z__1.r, tjjs.i = z__1.i;
  1459. } else {
  1460. tjjs.r = tscal, tjjs.i = 0.;
  1461. if (tscal == 1.) {
  1462. goto L210;
  1463. }
  1464. }
  1465. tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
  1466. abs(d__2));
  1467. if (tjj > smlnum) {
  1468. /* abs(A(j,j)) > SMLNUM: */
  1469. if (tjj < 1.) {
  1470. if (xj > tjj * bignum) {
  1471. /* Scale X by 1/abs(x(j)). */
  1472. rec = 1. / xj;
  1473. zdscal_(n, &rec, &x[1], &c__1);
  1474. *scale *= rec;
  1475. xmax *= rec;
  1476. }
  1477. }
  1478. i__3 = j;
  1479. zladiv_(&z__1, &x[j], &tjjs);
  1480. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1481. } else if (tjj > 0.) {
  1482. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1483. if (xj > tjj * bignum) {
  1484. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1485. rec = tjj * bignum / xj;
  1486. zdscal_(n, &rec, &x[1], &c__1);
  1487. *scale *= rec;
  1488. xmax *= rec;
  1489. }
  1490. i__3 = j;
  1491. zladiv_(&z__1, &x[j], &tjjs);
  1492. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1493. } else {
  1494. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1495. /* scale = 0 and compute a solution to A**H *x = 0. */
  1496. i__3 = *n;
  1497. for (i__ = 1; i__ <= i__3; ++i__) {
  1498. i__4 = i__;
  1499. x[i__4].r = 0., x[i__4].i = 0.;
  1500. /* L200: */
  1501. }
  1502. i__3 = j;
  1503. x[i__3].r = 1., x[i__3].i = 0.;
  1504. *scale = 0.;
  1505. xmax = 0.;
  1506. }
  1507. L210:
  1508. ;
  1509. } else {
  1510. /* Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
  1511. /* product has already been divided by 1/A(j,j). */
  1512. i__3 = j;
  1513. zladiv_(&z__2, &x[j], &tjjs);
  1514. z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
  1515. x[i__3].r = z__1.r, x[i__3].i = z__1.i;
  1516. }
  1517. /* Computing MAX */
  1518. i__3 = j;
  1519. d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 =
  1520. d_imag(&x[j]), abs(d__2));
  1521. xmax = f2cmax(d__3,d__4);
  1522. /* L220: */
  1523. }
  1524. }
  1525. *scale /= tscal;
  1526. }
  1527. /* Scale the column norms by 1/TSCAL for return. */
  1528. if (tscal != 1.) {
  1529. d__1 = 1. / tscal;
  1530. dscal_(n, &d__1, &cnorm[1], &c__1);
  1531. }
  1532. return;
  1533. /* End of ZLATBS */
  1534. } /* zlatbs_ */