PageRenderTime 70ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 2ms

/R-2.15.1/src/modules/lapack/dlapack1.f

#
FORTRAN Legacy | 13729 lines | 5545 code | 1 blank | 8183 comment | 0 complexity | 2debfe568d485e45100b760897a8738e MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, CC-BY-SA-4.0, BSD-3-Clause, AGPL-3.0, GPL-2.0, GPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. SUBROUTINE DGBSV( N, KL, KU, NRHS, AB, LDAB, IPIV, B, LDB, INFO )
  2. *
  3. * -- LAPACK driver routine (version 3.1) --
  4. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  5. * November 2006
  6. *
  7. * .. Scalar Arguments ..
  8. INTEGER INFO, KL, KU, LDAB, LDB, N, NRHS
  9. * ..
  10. * .. Array Arguments ..
  11. INTEGER IPIV( * )
  12. DOUBLE PRECISION AB( LDAB, * ), B( LDB, * )
  13. * ..
  14. *
  15. * Purpose
  16. * =======
  17. *
  18. * DGBSV computes the solution to a real system of linear equations
  19. * A * X = B, where A is a band matrix of order N with KL subdiagonals
  20. * and KU superdiagonals, and X and B are N-by-NRHS matrices.
  21. *
  22. * The LU decomposition with partial pivoting and row interchanges is
  23. * used to factor A as A = L * U, where L is a product of permutation
  24. * and unit lower triangular matrices with KL subdiagonals, and U is
  25. * upper triangular with KL+KU superdiagonals. The factored form of A
  26. * is then used to solve the system of equations A * X = B.
  27. *
  28. * Arguments
  29. * =========
  30. *
  31. * N (input) INTEGER
  32. * The number of linear equations, i.e., the order of the
  33. * matrix A. N >= 0.
  34. *
  35. * KL (input) INTEGER
  36. * The number of subdiagonals within the band of A. KL >= 0.
  37. *
  38. * KU (input) INTEGER
  39. * The number of superdiagonals within the band of A. KU >= 0.
  40. *
  41. * NRHS (input) INTEGER
  42. * The number of right hand sides, i.e., the number of columns
  43. * of the matrix B. NRHS >= 0.
  44. *
  45. * AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N)
  46. * On entry, the matrix A in band storage, in rows KL+1 to
  47. * 2*KL+KU+1; rows 1 to KL of the array need not be set.
  48. * The j-th column of A is stored in the j-th column of the
  49. * array AB as follows:
  50. * AB(KL+KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+KL)
  51. * On exit, details of the factorization: U is stored as an
  52. * upper triangular band matrix with KL+KU superdiagonals in
  53. * rows 1 to KL+KU+1, and the multipliers used during the
  54. * factorization are stored in rows KL+KU+2 to 2*KL+KU+1.
  55. * See below for further details.
  56. *
  57. * LDAB (input) INTEGER
  58. * The leading dimension of the array AB. LDAB >= 2*KL+KU+1.
  59. *
  60. * IPIV (output) INTEGER array, dimension (N)
  61. * The pivot indices that define the permutation matrix P;
  62. * row i of the matrix was interchanged with row IPIV(i).
  63. *
  64. * B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
  65. * On entry, the N-by-NRHS right hand side matrix B.
  66. * On exit, if INFO = 0, the N-by-NRHS solution matrix X.
  67. *
  68. * LDB (input) INTEGER
  69. * The leading dimension of the array B. LDB >= max(1,N).
  70. *
  71. * INFO (output) INTEGER
  72. * = 0: successful exit
  73. * < 0: if INFO = -i, the i-th argument had an illegal value
  74. * > 0: if INFO = i, U(i,i) is exactly zero. The factorization
  75. * has been completed, but the factor U is exactly
  76. * singular, and the solution has not been computed.
  77. *
  78. * Further Details
  79. * ===============
  80. *
  81. * The band storage scheme is illustrated by the following example, when
  82. * M = N = 6, KL = 2, KU = 1:
  83. *
  84. * On entry: On exit:
  85. *
  86. * * * * + + + * * * u14 u25 u36
  87. * * * + + + + * * u13 u24 u35 u46
  88. * * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56
  89. * a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66
  90. * a21 a32 a43 a54 a65 * m21 m32 m43 m54 m65 *
  91. * a31 a42 a53 a64 * * m31 m42 m53 m64 * *
  92. *
  93. * Array elements marked * are not used by the routine; elements marked
  94. * + need not be set on entry, but are required by the routine to store
  95. * elements of U because of fill-in resulting from the row interchanges.
  96. *
  97. * =====================================================================
  98. *
  99. * .. External Subroutines ..
  100. EXTERNAL DGBTRF, DGBTRS, XERBLA
  101. * ..
  102. * .. Intrinsic Functions ..
  103. INTRINSIC MAX
  104. * ..
  105. * .. Executable Statements ..
  106. *
  107. * Test the input parameters.
  108. *
  109. INFO = 0
  110. IF( N.LT.0 ) THEN
  111. INFO = -1
  112. ELSE IF( KL.LT.0 ) THEN
  113. INFO = -2
  114. ELSE IF( KU.LT.0 ) THEN
  115. INFO = -3
  116. ELSE IF( NRHS.LT.0 ) THEN
  117. INFO = -4
  118. ELSE IF( LDAB.LT.2*KL+KU+1 ) THEN
  119. INFO = -6
  120. ELSE IF( LDB.LT.MAX( N, 1 ) ) THEN
  121. INFO = -9
  122. END IF
  123. IF( INFO.NE.0 ) THEN
  124. CALL XERBLA( 'DGBSV ', -INFO )
  125. RETURN
  126. END IF
  127. *
  128. * Compute the LU factorization of the band matrix A.
  129. *
  130. CALL DGBTRF( N, N, KL, KU, AB, LDAB, IPIV, INFO )
  131. IF( INFO.EQ.0 ) THEN
  132. *
  133. * Solve the system A*X = B, overwriting B with X.
  134. *
  135. CALL DGBTRS( 'No transpose', N, KL, KU, NRHS, AB, LDAB, IPIV,
  136. $ B, LDB, INFO )
  137. END IF
  138. RETURN
  139. *
  140. * End of DGBSV
  141. *
  142. END
  143. SUBROUTINE DGBSVX( FACT, TRANS, N, KL, KU, NRHS, AB, LDAB, AFB,
  144. $ LDAFB, IPIV, EQUED, R, C, B, LDB, X, LDX,
  145. $ RCOND, FERR, BERR, WORK, IWORK, INFO )
  146. *
  147. * -- LAPACK driver routine (version 3.1) --
  148. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  149. * November 2006
  150. *
  151. * .. Scalar Arguments ..
  152. CHARACTER EQUED, FACT, TRANS
  153. INTEGER INFO, KL, KU, LDAB, LDAFB, LDB, LDX, N, NRHS
  154. DOUBLE PRECISION RCOND
  155. * ..
  156. * .. Array Arguments ..
  157. INTEGER IPIV( * ), IWORK( * )
  158. DOUBLE PRECISION AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
  159. $ BERR( * ), C( * ), FERR( * ), R( * ),
  160. $ WORK( * ), X( LDX, * )
  161. * ..
  162. *
  163. * Purpose
  164. * =======
  165. *
  166. * DGBSVX uses the LU factorization to compute the solution to a real
  167. * system of linear equations A * X = B, A**T * X = B, or A**H * X = B,
  168. * where A is a band matrix of order N with KL subdiagonals and KU
  169. * superdiagonals, and X and B are N-by-NRHS matrices.
  170. *
  171. * Error bounds on the solution and a condition estimate are also
  172. * provided.
  173. *
  174. * Description
  175. * ===========
  176. *
  177. * The following steps are performed by this subroutine:
  178. *
  179. * 1. If FACT = 'E', real scaling factors are computed to equilibrate
  180. * the system:
  181. * TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B
  182. * TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B
  183. * TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B
  184. * Whether or not the system will be equilibrated depends on the
  185. * scaling of the matrix A, but if equilibration is used, A is
  186. * overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N')
  187. * or diag(C)*B (if TRANS = 'T' or 'C').
  188. *
  189. * 2. If FACT = 'N' or 'E', the LU decomposition is used to factor the
  190. * matrix A (after equilibration if FACT = 'E') as
  191. * A = L * U,
  192. * where L is a product of permutation and unit lower triangular
  193. * matrices with KL subdiagonals, and U is upper triangular with
  194. * KL+KU superdiagonals.
  195. *
  196. * 3. If some U(i,i)=0, so that U is exactly singular, then the routine
  197. * returns with INFO = i. Otherwise, the factored form of A is used
  198. * to estimate the condition number of the matrix A. If the
  199. * reciprocal of the condition number is less than machine precision,
  200. * INFO = N+1 is returned as a warning, but the routine still goes on
  201. * to solve for X and compute error bounds as described below.
  202. *
  203. * 4. The system of equations is solved for X using the factored form
  204. * of A.
  205. *
  206. * 5. Iterative refinement is applied to improve the computed solution
  207. * matrix and calculate error bounds and backward error estimates
  208. * for it.
  209. *
  210. * 6. If equilibration was used, the matrix X is premultiplied by
  211. * diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so
  212. * that it solves the original system before equilibration.
  213. *
  214. * Arguments
  215. * =========
  216. *
  217. * FACT (input) CHARACTER*1
  218. * Specifies whether or not the factored form of the matrix A is
  219. * supplied on entry, and if not, whether the matrix A should be
  220. * equilibrated before it is factored.
  221. * = 'F': On entry, AFB and IPIV contain the factored form of
  222. * A. If EQUED is not 'N', the matrix A has been
  223. * equilibrated with scaling factors given by R and C.
  224. * AB, AFB, and IPIV are not modified.
  225. * = 'N': The matrix A will be copied to AFB and factored.
  226. * = 'E': The matrix A will be equilibrated if necessary, then
  227. * copied to AFB and factored.
  228. *
  229. * TRANS (input) CHARACTER*1
  230. * Specifies the form of the system of equations.
  231. * = 'N': A * X = B (No transpose)
  232. * = 'T': A**T * X = B (Transpose)
  233. * = 'C': A**H * X = B (Transpose)
  234. *
  235. * N (input) INTEGER
  236. * The number of linear equations, i.e., the order of the
  237. * matrix A. N >= 0.
  238. *
  239. * KL (input) INTEGER
  240. * The number of subdiagonals within the band of A. KL >= 0.
  241. *
  242. * KU (input) INTEGER
  243. * The number of superdiagonals within the band of A. KU >= 0.
  244. *
  245. * NRHS (input) INTEGER
  246. * The number of right hand sides, i.e., the number of columns
  247. * of the matrices B and X. NRHS >= 0.
  248. *
  249. * AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N)
  250. * On entry, the matrix A in band storage, in rows 1 to KL+KU+1.
  251. * The j-th column of A is stored in the j-th column of the
  252. * array AB as follows:
  253. * AB(KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+kl)
  254. *
  255. * If FACT = 'F' and EQUED is not 'N', then A must have been
  256. * equilibrated by the scaling factors in R and/or C. AB is not
  257. * modified if FACT = 'F' or 'N', or if FACT = 'E' and
  258. * EQUED = 'N' on exit.
  259. *
  260. * On exit, if EQUED .ne. 'N', A is scaled as follows:
  261. * EQUED = 'R': A := diag(R) * A
  262. * EQUED = 'C': A := A * diag(C)
  263. * EQUED = 'B': A := diag(R) * A * diag(C).
  264. *
  265. * LDAB (input) INTEGER
  266. * The leading dimension of the array AB. LDAB >= KL+KU+1.
  267. *
  268. * AFB (input or output) DOUBLE PRECISION array, dimension (LDAFB,N)
  269. * If FACT = 'F', then AFB is an input argument and on entry
  270. * contains details of the LU factorization of the band matrix
  271. * A, as computed by DGBTRF. U is stored as an upper triangular
  272. * band matrix with KL+KU superdiagonals in rows 1 to KL+KU+1,
  273. * and the multipliers used during the factorization are stored
  274. * in rows KL+KU+2 to 2*KL+KU+1. If EQUED .ne. 'N', then AFB is
  275. * the factored form of the equilibrated matrix A.
  276. *
  277. * If FACT = 'N', then AFB is an output argument and on exit
  278. * returns details of the LU factorization of A.
  279. *
  280. * If FACT = 'E', then AFB is an output argument and on exit
  281. * returns details of the LU factorization of the equilibrated
  282. * matrix A (see the description of AB for the form of the
  283. * equilibrated matrix).
  284. *
  285. * LDAFB (input) INTEGER
  286. * The leading dimension of the array AFB. LDAFB >= 2*KL+KU+1.
  287. *
  288. * IPIV (input or output) INTEGER array, dimension (N)
  289. * If FACT = 'F', then IPIV is an input argument and on entry
  290. * contains the pivot indices from the factorization A = L*U
  291. * as computed by DGBTRF; row i of the matrix was interchanged
  292. * with row IPIV(i).
  293. *
  294. * If FACT = 'N', then IPIV is an output argument and on exit
  295. * contains the pivot indices from the factorization A = L*U
  296. * of the original matrix A.
  297. *
  298. * If FACT = 'E', then IPIV is an output argument and on exit
  299. * contains the pivot indices from the factorization A = L*U
  300. * of the equilibrated matrix A.
  301. *
  302. * EQUED (input or output) CHARACTER*1
  303. * Specifies the form of equilibration that was done.
  304. * = 'N': No equilibration (always true if FACT = 'N').
  305. * = 'R': Row equilibration, i.e., A has been premultiplied by
  306. * diag(R).
  307. * = 'C': Column equilibration, i.e., A has been postmultiplied
  308. * by diag(C).
  309. * = 'B': Both row and column equilibration, i.e., A has been
  310. * replaced by diag(R) * A * diag(C).
  311. * EQUED is an input argument if FACT = 'F'; otherwise, it is an
  312. * output argument.
  313. *
  314. * R (input or output) DOUBLE PRECISION array, dimension (N)
  315. * The row scale factors for A. If EQUED = 'R' or 'B', A is
  316. * multiplied on the left by diag(R); if EQUED = 'N' or 'C', R
  317. * is not accessed. R is an input argument if FACT = 'F';
  318. * otherwise, R is an output argument. If FACT = 'F' and
  319. * EQUED = 'R' or 'B', each element of R must be positive.
  320. *
  321. * C (input or output) DOUBLE PRECISION array, dimension (N)
  322. * The column scale factors for A. If EQUED = 'C' or 'B', A is
  323. * multiplied on the right by diag(C); if EQUED = 'N' or 'R', C
  324. * is not accessed. C is an input argument if FACT = 'F';
  325. * otherwise, C is an output argument. If FACT = 'F' and
  326. * EQUED = 'C' or 'B', each element of C must be positive.
  327. *
  328. * B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
  329. * On entry, the right hand side matrix B.
  330. * On exit,
  331. * if EQUED = 'N', B is not modified;
  332. * if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by
  333. * diag(R)*B;
  334. * if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is
  335. * overwritten by diag(C)*B.
  336. *
  337. * LDB (input) INTEGER
  338. * The leading dimension of the array B. LDB >= max(1,N).
  339. *
  340. * X (output) DOUBLE PRECISION array, dimension (LDX,NRHS)
  341. * If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X
  342. * to the original system of equations. Note that A and B are
  343. * modified on exit if EQUED .ne. 'N', and the solution to the
  344. * equilibrated system is inv(diag(C))*X if TRANS = 'N' and
  345. * EQUED = 'C' or 'B', or inv(diag(R))*X if TRANS = 'T' or 'C'
  346. * and EQUED = 'R' or 'B'.
  347. *
  348. * LDX (input) INTEGER
  349. * The leading dimension of the array X. LDX >= max(1,N).
  350. *
  351. * RCOND (output) DOUBLE PRECISION
  352. * The estimate of the reciprocal condition number of the matrix
  353. * A after equilibration (if done). If RCOND is less than the
  354. * machine precision (in particular, if RCOND = 0), the matrix
  355. * is singular to working precision. This condition is
  356. * indicated by a return code of INFO > 0.
  357. *
  358. * FERR (output) DOUBLE PRECISION array, dimension (NRHS)
  359. * The estimated forward error bound for each solution vector
  360. * X(j) (the j-th column of the solution matrix X).
  361. * If XTRUE is the true solution corresponding to X(j), FERR(j)
  362. * is an estimated upper bound for the magnitude of the largest
  363. * element in (X(j) - XTRUE) divided by the magnitude of the
  364. * largest element in X(j). The estimate is as reliable as
  365. * the estimate for RCOND, and is almost always a slight
  366. * overestimate of the true error.
  367. *
  368. * BERR (output) DOUBLE PRECISION array, dimension (NRHS)
  369. * The componentwise relative backward error of each solution
  370. * vector X(j) (i.e., the smallest relative change in
  371. * any element of A or B that makes X(j) an exact solution).
  372. *
  373. * WORK (workspace/output) DOUBLE PRECISION array, dimension (3*N)
  374. * On exit, WORK(1) contains the reciprocal pivot growth
  375. * factor norm(A)/norm(U). The "max absolute element" norm is
  376. * used. If WORK(1) is much less than 1, then the stability
  377. * of the LU factorization of the (equilibrated) matrix A
  378. * could be poor. This also means that the solution X, condition
  379. * estimator RCOND, and forward error bound FERR could be
  380. * unreliable. If factorization fails with 0<INFO<=N, then
  381. * WORK(1) contains the reciprocal pivot growth factor for the
  382. * leading INFO columns of A.
  383. *
  384. * IWORK (workspace) INTEGER array, dimension (N)
  385. *
  386. * INFO (output) INTEGER
  387. * = 0: successful exit
  388. * < 0: if INFO = -i, the i-th argument had an illegal value
  389. * > 0: if INFO = i, and i is
  390. * <= N: U(i,i) is exactly zero. The factorization
  391. * has been completed, but the factor U is exactly
  392. * singular, so the solution and error bounds
  393. * could not be computed. RCOND = 0 is returned.
  394. * = N+1: U is nonsingular, but RCOND is less than machine
  395. * precision, meaning that the matrix is singular
  396. * to working precision. Nevertheless, the
  397. * solution and error bounds are computed because
  398. * there are a number of situations where the
  399. * computed solution can be more accurate than the
  400. * value of RCOND would suggest.
  401. *
  402. * =====================================================================
  403. *
  404. * .. Parameters ..
  405. DOUBLE PRECISION ZERO, ONE
  406. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  407. * ..
  408. * .. Local Scalars ..
  409. LOGICAL COLEQU, EQUIL, NOFACT, NOTRAN, ROWEQU
  410. CHARACTER NORM
  411. INTEGER I, INFEQU, J, J1, J2
  412. DOUBLE PRECISION AMAX, ANORM, BIGNUM, COLCND, RCMAX, RCMIN,
  413. $ ROWCND, RPVGRW, SMLNUM
  414. * ..
  415. * .. External Functions ..
  416. LOGICAL LSAME
  417. DOUBLE PRECISION DLAMCH, DLANGB, DLANTB
  418. EXTERNAL LSAME, DLAMCH, DLANGB, DLANTB
  419. * ..
  420. * .. External Subroutines ..
  421. EXTERNAL DCOPY, DGBCON, DGBEQU, DGBRFS, DGBTRF, DGBTRS,
  422. $ DLACPY, DLAQGB, XERBLA
  423. * ..
  424. * .. Intrinsic Functions ..
  425. INTRINSIC ABS, MAX, MIN
  426. * ..
  427. * .. Executable Statements ..
  428. *
  429. INFO = 0
  430. NOFACT = LSAME( FACT, 'N' )
  431. EQUIL = LSAME( FACT, 'E' )
  432. NOTRAN = LSAME( TRANS, 'N' )
  433. IF( NOFACT .OR. EQUIL ) THEN
  434. EQUED = 'N'
  435. ROWEQU = .FALSE.
  436. COLEQU = .FALSE.
  437. ELSE
  438. ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
  439. COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
  440. SMLNUM = DLAMCH( 'Safe minimum' )
  441. BIGNUM = ONE / SMLNUM
  442. END IF
  443. *
  444. * Test the input parameters.
  445. *
  446. IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) )
  447. $ THEN
  448. INFO = -1
  449. ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
  450. $ LSAME( TRANS, 'C' ) ) THEN
  451. INFO = -2
  452. ELSE IF( N.LT.0 ) THEN
  453. INFO = -3
  454. ELSE IF( KL.LT.0 ) THEN
  455. INFO = -4
  456. ELSE IF( KU.LT.0 ) THEN
  457. INFO = -5
  458. ELSE IF( NRHS.LT.0 ) THEN
  459. INFO = -6
  460. ELSE IF( LDAB.LT.KL+KU+1 ) THEN
  461. INFO = -8
  462. ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN
  463. INFO = -10
  464. ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT.
  465. $ ( ROWEQU .OR. COLEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN
  466. INFO = -12
  467. ELSE
  468. IF( ROWEQU ) THEN
  469. RCMIN = BIGNUM
  470. RCMAX = ZERO
  471. DO 10 J = 1, N
  472. RCMIN = MIN( RCMIN, R( J ) )
  473. RCMAX = MAX( RCMAX, R( J ) )
  474. 10 CONTINUE
  475. IF( RCMIN.LE.ZERO ) THEN
  476. INFO = -13
  477. ELSE IF( N.GT.0 ) THEN
  478. ROWCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
  479. ELSE
  480. ROWCND = ONE
  481. END IF
  482. END IF
  483. IF( COLEQU .AND. INFO.EQ.0 ) THEN
  484. RCMIN = BIGNUM
  485. RCMAX = ZERO
  486. DO 20 J = 1, N
  487. RCMIN = MIN( RCMIN, C( J ) )
  488. RCMAX = MAX( RCMAX, C( J ) )
  489. 20 CONTINUE
  490. IF( RCMIN.LE.ZERO ) THEN
  491. INFO = -14
  492. ELSE IF( N.GT.0 ) THEN
  493. COLCND = MAX( RCMIN, SMLNUM ) / MIN( RCMAX, BIGNUM )
  494. ELSE
  495. COLCND = ONE
  496. END IF
  497. END IF
  498. IF( INFO.EQ.0 ) THEN
  499. IF( LDB.LT.MAX( 1, N ) ) THEN
  500. INFO = -16
  501. ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
  502. INFO = -18
  503. END IF
  504. END IF
  505. END IF
  506. *
  507. IF( INFO.NE.0 ) THEN
  508. CALL XERBLA( 'DGBSVX', -INFO )
  509. RETURN
  510. END IF
  511. *
  512. IF( EQUIL ) THEN
  513. *
  514. * Compute row and column scalings to equilibrate the matrix A.
  515. *
  516. CALL DGBEQU( N, N, KL, KU, AB, LDAB, R, C, ROWCND, COLCND,
  517. $ AMAX, INFEQU )
  518. IF( INFEQU.EQ.0 ) THEN
  519. *
  520. * Equilibrate the matrix.
  521. *
  522. CALL DLAQGB( N, N, KL, KU, AB, LDAB, R, C, ROWCND, COLCND,
  523. $ AMAX, EQUED )
  524. ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
  525. COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
  526. END IF
  527. END IF
  528. *
  529. * Scale the right hand side.
  530. *
  531. IF( NOTRAN ) THEN
  532. IF( ROWEQU ) THEN
  533. DO 40 J = 1, NRHS
  534. DO 30 I = 1, N
  535. B( I, J ) = R( I )*B( I, J )
  536. 30 CONTINUE
  537. 40 CONTINUE
  538. END IF
  539. ELSE IF( COLEQU ) THEN
  540. DO 60 J = 1, NRHS
  541. DO 50 I = 1, N
  542. B( I, J ) = C( I )*B( I, J )
  543. 50 CONTINUE
  544. 60 CONTINUE
  545. END IF
  546. *
  547. IF( NOFACT .OR. EQUIL ) THEN
  548. *
  549. * Compute the LU factorization of the band matrix A.
  550. *
  551. DO 70 J = 1, N
  552. J1 = MAX( J-KU, 1 )
  553. J2 = MIN( J+KL, N )
  554. CALL DCOPY( J2-J1+1, AB( KU+1-J+J1, J ), 1,
  555. $ AFB( KL+KU+1-J+J1, J ), 1 )
  556. 70 CONTINUE
  557. *
  558. CALL DGBTRF( N, N, KL, KU, AFB, LDAFB, IPIV, INFO )
  559. *
  560. * Return if INFO is non-zero.
  561. *
  562. IF( INFO.GT.0 ) THEN
  563. *
  564. * Compute the reciprocal pivot growth factor of the
  565. * leading rank-deficient INFO columns of A.
  566. *
  567. ANORM = ZERO
  568. DO 90 J = 1, INFO
  569. DO 80 I = MAX( KU+2-J, 1 ), MIN( N+KU+1-J, KL+KU+1 )
  570. ANORM = MAX( ANORM, ABS( AB( I, J ) ) )
  571. 80 CONTINUE
  572. 90 CONTINUE
  573. RPVGRW = DLANTB( 'M', 'U', 'N', INFO, MIN( INFO-1, KL+KU ),
  574. $ AFB( MAX( 1, KL+KU+2-INFO ), 1 ), LDAFB,
  575. $ WORK )
  576. IF( RPVGRW.EQ.ZERO ) THEN
  577. RPVGRW = ONE
  578. ELSE
  579. RPVGRW = ANORM / RPVGRW
  580. END IF
  581. WORK( 1 ) = RPVGRW
  582. RCOND = ZERO
  583. RETURN
  584. END IF
  585. END IF
  586. *
  587. * Compute the norm of the matrix A and the
  588. * reciprocal pivot growth factor RPVGRW.
  589. *
  590. IF( NOTRAN ) THEN
  591. NORM = '1'
  592. ELSE
  593. NORM = 'I'
  594. END IF
  595. ANORM = DLANGB( NORM, N, KL, KU, AB, LDAB, WORK )
  596. RPVGRW = DLANTB( 'M', 'U', 'N', N, KL+KU, AFB, LDAFB, WORK )
  597. IF( RPVGRW.EQ.ZERO ) THEN
  598. RPVGRW = ONE
  599. ELSE
  600. RPVGRW = DLANGB( 'M', N, KL, KU, AB, LDAB, WORK ) / RPVGRW
  601. END IF
  602. *
  603. * Compute the reciprocal of the condition number of A.
  604. *
  605. CALL DGBCON( NORM, N, KL, KU, AFB, LDAFB, IPIV, ANORM, RCOND,
  606. $ WORK, IWORK, INFO )
  607. *
  608. * Compute the solution matrix X.
  609. *
  610. CALL DLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
  611. CALL DGBTRS( TRANS, N, KL, KU, NRHS, AFB, LDAFB, IPIV, X, LDX,
  612. $ INFO )
  613. *
  614. * Use iterative refinement to improve the computed solution and
  615. * compute error bounds and backward error estimates for it.
  616. *
  617. CALL DGBRFS( TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, LDAFB, IPIV,
  618. $ B, LDB, X, LDX, FERR, BERR, WORK, IWORK, INFO )
  619. *
  620. * Transform the solution matrix X to a solution of the original
  621. * system.
  622. *
  623. IF( NOTRAN ) THEN
  624. IF( COLEQU ) THEN
  625. DO 110 J = 1, NRHS
  626. DO 100 I = 1, N
  627. X( I, J ) = C( I )*X( I, J )
  628. 100 CONTINUE
  629. 110 CONTINUE
  630. DO 120 J = 1, NRHS
  631. FERR( J ) = FERR( J ) / COLCND
  632. 120 CONTINUE
  633. END IF
  634. ELSE IF( ROWEQU ) THEN
  635. DO 140 J = 1, NRHS
  636. DO 130 I = 1, N
  637. X( I, J ) = R( I )*X( I, J )
  638. 130 CONTINUE
  639. 140 CONTINUE
  640. DO 150 J = 1, NRHS
  641. FERR( J ) = FERR( J ) / ROWCND
  642. 150 CONTINUE
  643. END IF
  644. *
  645. * Set INFO = N+1 if the matrix is singular to working precision.
  646. *
  647. IF( RCOND.LT.DLAMCH( 'Epsilon' ) )
  648. $ INFO = N + 1
  649. *
  650. WORK( 1 ) = RPVGRW
  651. RETURN
  652. *
  653. * End of DGBSVX
  654. *
  655. END
  656. SUBROUTINE DGEES( JOBVS, SORT, SELECT, N, A, LDA, SDIM, WR, WI,
  657. $ VS, LDVS, WORK, LWORK, BWORK, INFO )
  658. *
  659. * -- LAPACK driver routine (version 3.1) --
  660. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  661. * November 2006
  662. *
  663. * .. Scalar Arguments ..
  664. CHARACTER JOBVS, SORT
  665. INTEGER INFO, LDA, LDVS, LWORK, N, SDIM
  666. * ..
  667. * .. Array Arguments ..
  668. LOGICAL BWORK( * )
  669. DOUBLE PRECISION A( LDA, * ), VS( LDVS, * ), WI( * ), WORK( * ),
  670. $ WR( * )
  671. * ..
  672. * .. Function Arguments ..
  673. LOGICAL SELECT
  674. EXTERNAL SELECT
  675. * ..
  676. *
  677. * Purpose
  678. * =======
  679. *
  680. * DGEES computes for an N-by-N real nonsymmetric matrix A, the
  681. * eigenvalues, the real Schur form T, and, optionally, the matrix of
  682. * Schur vectors Z. This gives the Schur factorization A = Z*T*(Z**T).
  683. *
  684. * Optionally, it also orders the eigenvalues on the diagonal of the
  685. * real Schur form so that selected eigenvalues are at the top left.
  686. * The leading columns of Z then form an orthonormal basis for the
  687. * invariant subspace corresponding to the selected eigenvalues.
  688. *
  689. * A matrix is in real Schur form if it is upper quasi-triangular with
  690. * 1-by-1 and 2-by-2 blocks. 2-by-2 blocks will be standardized in the
  691. * form
  692. * [ a b ]
  693. * [ c a ]
  694. *
  695. * where b*c < 0. The eigenvalues of such a block are a +- sqrt(bc).
  696. *
  697. * Arguments
  698. * =========
  699. *
  700. * JOBVS (input) CHARACTER*1
  701. * = 'N': Schur vectors are not computed;
  702. * = 'V': Schur vectors are computed.
  703. *
  704. * SORT (input) CHARACTER*1
  705. * Specifies whether or not to order the eigenvalues on the
  706. * diagonal of the Schur form.
  707. * = 'N': Eigenvalues are not ordered;
  708. * = 'S': Eigenvalues are ordered (see SELECT).
  709. *
  710. * SELECT (external procedure) LOGICAL FUNCTION of two DOUBLE PRECISION arguments
  711. * SELECT must be declared EXTERNAL in the calling subroutine.
  712. * If SORT = 'S', SELECT is used to select eigenvalues to sort
  713. * to the top left of the Schur form.
  714. * If SORT = 'N', SELECT is not referenced.
  715. * An eigenvalue WR(j)+sqrt(-1)*WI(j) is selected if
  716. * SELECT(WR(j),WI(j)) is true; i.e., if either one of a complex
  717. * conjugate pair of eigenvalues is selected, then both complex
  718. * eigenvalues are selected.
  719. * Note that a selected complex eigenvalue may no longer
  720. * satisfy SELECT(WR(j),WI(j)) = .TRUE. after ordering, since
  721. * ordering may change the value of complex eigenvalues
  722. * (especially if the eigenvalue is ill-conditioned); in this
  723. * case INFO is set to N+2 (see INFO below).
  724. *
  725. * N (input) INTEGER
  726. * The order of the matrix A. N >= 0.
  727. *
  728. * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
  729. * On entry, the N-by-N matrix A.
  730. * On exit, A has been overwritten by its real Schur form T.
  731. *
  732. * LDA (input) INTEGER
  733. * The leading dimension of the array A. LDA >= max(1,N).
  734. *
  735. * SDIM (output) INTEGER
  736. * If SORT = 'N', SDIM = 0.
  737. * If SORT = 'S', SDIM = number of eigenvalues (after sorting)
  738. * for which SELECT is true. (Complex conjugate
  739. * pairs for which SELECT is true for either
  740. * eigenvalue count as 2.)
  741. *
  742. * WR (output) DOUBLE PRECISION array, dimension (N)
  743. * WI (output) DOUBLE PRECISION array, dimension (N)
  744. * WR and WI contain the real and imaginary parts,
  745. * respectively, of the computed eigenvalues in the same order
  746. * that they appear on the diagonal of the output Schur form T.
  747. * Complex conjugate pairs of eigenvalues will appear
  748. * consecutively with the eigenvalue having the positive
  749. * imaginary part first.
  750. *
  751. * VS (output) DOUBLE PRECISION array, dimension (LDVS,N)
  752. * If JOBVS = 'V', VS contains the orthogonal matrix Z of Schur
  753. * vectors.
  754. * If JOBVS = 'N', VS is not referenced.
  755. *
  756. * LDVS (input) INTEGER
  757. * The leading dimension of the array VS. LDVS >= 1; if
  758. * JOBVS = 'V', LDVS >= N.
  759. *
  760. * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
  761. * On exit, if INFO = 0, WORK(1) contains the optimal LWORK.
  762. *
  763. * LWORK (input) INTEGER
  764. * The dimension of the array WORK. LWORK >= max(1,3*N).
  765. * For good performance, LWORK must generally be larger.
  766. *
  767. * If LWORK = -1, then a workspace query is assumed; the routine
  768. * only calculates the optimal size of the WORK array, returns
  769. * this value as the first entry of the WORK array, and no error
  770. * message related to LWORK is issued by XERBLA.
  771. *
  772. * BWORK (workspace) LOGICAL array, dimension (N)
  773. * Not referenced if SORT = 'N'.
  774. *
  775. * INFO (output) INTEGER
  776. * = 0: successful exit
  777. * < 0: if INFO = -i, the i-th argument had an illegal value.
  778. * > 0: if INFO = i, and i is
  779. * <= N: the QR algorithm failed to compute all the
  780. * eigenvalues; elements 1:ILO-1 and i+1:N of WR and WI
  781. * contain those eigenvalues which have converged; if
  782. * JOBVS = 'V', VS contains the matrix which reduces A
  783. * to its partially converged Schur form.
  784. * = N+1: the eigenvalues could not be reordered because some
  785. * eigenvalues were too close to separate (the problem
  786. * is very ill-conditioned);
  787. * = N+2: after reordering, roundoff changed values of some
  788. * complex eigenvalues so that leading eigenvalues in
  789. * the Schur form no longer satisfy SELECT=.TRUE. This
  790. * could also be caused by underflow due to scaling.
  791. *
  792. * =====================================================================
  793. *
  794. * .. Parameters ..
  795. DOUBLE PRECISION ZERO, ONE
  796. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
  797. * ..
  798. * .. Local Scalars ..
  799. LOGICAL CURSL, LASTSL, LQUERY, LST2SL, SCALEA, WANTST,
  800. $ WANTVS
  801. INTEGER HSWORK, I, I1, I2, IBAL, ICOND, IERR, IEVAL,
  802. $ IHI, ILO, INXT, IP, ITAU, IWRK, MAXWRK, MINWRK
  803. DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, S, SEP, SMLNUM
  804. * ..
  805. * .. Local Arrays ..
  806. INTEGER IDUM( 1 )
  807. DOUBLE PRECISION DUM( 1 )
  808. * ..
  809. * .. External Subroutines ..
  810. EXTERNAL DCOPY, DGEBAK, DGEBAL, DGEHRD, DHSEQR, DLACPY,
  811. $ DLABAD, DLASCL, DORGHR, DSWAP, DTRSEN, XERBLA
  812. * ..
  813. * .. External Functions ..
  814. LOGICAL LSAME
  815. INTEGER ILAENV
  816. DOUBLE PRECISION DLAMCH, DLANGE
  817. EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE
  818. * ..
  819. * .. Intrinsic Functions ..
  820. INTRINSIC MAX, SQRT
  821. * ..
  822. * .. Executable Statements ..
  823. *
  824. * Test the input arguments
  825. *
  826. INFO = 0
  827. LQUERY = ( LWORK.EQ.-1 )
  828. WANTVS = LSAME( JOBVS, 'V' )
  829. WANTST = LSAME( SORT, 'S' )
  830. IF( ( .NOT.WANTVS ) .AND. ( .NOT.LSAME( JOBVS, 'N' ) ) ) THEN
  831. INFO = -1
  832. ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN
  833. INFO = -2
  834. ELSE IF( N.LT.0 ) THEN
  835. INFO = -4
  836. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  837. INFO = -6
  838. ELSE IF( LDVS.LT.1 .OR. ( WANTVS .AND. LDVS.LT.N ) ) THEN
  839. INFO = -11
  840. END IF
  841. *
  842. * Compute workspace
  843. * (Note: Comments in the code beginning "Workspace:" describe the
  844. * minimal amount of workspace needed at that point in the code,
  845. * as well as the preferred amount for good performance.
  846. * NB refers to the optimal block size for the immediately
  847. * following subroutine, as returned by ILAENV.
  848. * HSWORK refers to the workspace preferred by DHSEQR, as
  849. * calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
  850. * the worst case.)
  851. *
  852. IF( INFO.EQ.0 ) THEN
  853. IF( N.EQ.0 ) THEN
  854. MINWRK = 1
  855. MAXWRK = 1
  856. ELSE
  857. MAXWRK = 2*N + N*ILAENV( 1, 'DGEHRD', ' ', N, 1, N, 0 )
  858. MINWRK = 3*N
  859. *
  860. CALL DHSEQR( 'S', JOBVS, N, 1, N, A, LDA, WR, WI, VS, LDVS,
  861. $ WORK, -1, IEVAL )
  862. HSWORK = WORK( 1 )
  863. *
  864. IF( .NOT.WANTVS ) THEN
  865. MAXWRK = MAX( MAXWRK, N + HSWORK )
  866. ELSE
  867. MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,
  868. $ 'DORGHR', ' ', N, 1, N, -1 ) )
  869. MAXWRK = MAX( MAXWRK, N + HSWORK )
  870. END IF
  871. END IF
  872. WORK( 1 ) = MAXWRK
  873. *
  874. IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
  875. INFO = -13
  876. END IF
  877. END IF
  878. *
  879. IF( INFO.NE.0 ) THEN
  880. CALL XERBLA( 'DGEES ', -INFO )
  881. RETURN
  882. ELSE IF( LQUERY ) THEN
  883. RETURN
  884. END IF
  885. *
  886. * Quick return if possible
  887. *
  888. IF( N.EQ.0 ) THEN
  889. SDIM = 0
  890. RETURN
  891. END IF
  892. *
  893. * Get machine constants
  894. *
  895. EPS = DLAMCH( 'P' )
  896. SMLNUM = DLAMCH( 'S' )
  897. BIGNUM = ONE / SMLNUM
  898. CALL DLABAD( SMLNUM, BIGNUM )
  899. SMLNUM = SQRT( SMLNUM ) / EPS
  900. BIGNUM = ONE / SMLNUM
  901. *
  902. * Scale A if max element outside range [SMLNUM,BIGNUM]
  903. *
  904. ANRM = DLANGE( 'M', N, N, A, LDA, DUM )
  905. SCALEA = .FALSE.
  906. IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
  907. SCALEA = .TRUE.
  908. CSCALE = SMLNUM
  909. ELSE IF( ANRM.GT.BIGNUM ) THEN
  910. SCALEA = .TRUE.
  911. CSCALE = BIGNUM
  912. END IF
  913. IF( SCALEA )
  914. $ CALL DLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
  915. *
  916. * Permute the matrix to make it more nearly triangular
  917. * (Workspace: need N)
  918. *
  919. IBAL = 1
  920. CALL DGEBAL( 'P', N, A, LDA, ILO, IHI, WORK( IBAL ), IERR )
  921. *
  922. * Reduce to upper Hessenberg form
  923. * (Workspace: need 3*N, prefer 2*N+N*NB)
  924. *
  925. ITAU = N + IBAL
  926. IWRK = N + ITAU
  927. CALL DGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
  928. $ LWORK-IWRK+1, IERR )
  929. *
  930. IF( WANTVS ) THEN
  931. *
  932. * Copy Householder vectors to VS
  933. *
  934. CALL DLACPY( 'L', N, N, A, LDA, VS, LDVS )
  935. *
  936. * Generate orthogonal matrix in VS
  937. * (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)
  938. *
  939. CALL DORGHR( N, ILO, IHI, VS, LDVS, WORK( ITAU ), WORK( IWRK ),
  940. $ LWORK-IWRK+1, IERR )
  941. END IF
  942. *
  943. SDIM = 0
  944. *
  945. * Perform QR iteration, accumulating Schur vectors in VS if desired
  946. * (Workspace: need N+1, prefer N+HSWORK (see comments) )
  947. *
  948. IWRK = ITAU
  949. CALL DHSEQR( 'S', JOBVS, N, ILO, IHI, A, LDA, WR, WI, VS, LDVS,
  950. $ WORK( IWRK ), LWORK-IWRK+1, IEVAL )
  951. IF( IEVAL.GT.0 )
  952. $ INFO = IEVAL
  953. *
  954. * Sort eigenvalues if desired
  955. *
  956. IF( WANTST .AND. INFO.EQ.0 ) THEN
  957. IF( SCALEA ) THEN
  958. CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N, 1, WR, N, IERR )
  959. CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N, 1, WI, N, IERR )
  960. END IF
  961. DO 10 I = 1, N
  962. BWORK( I ) = SELECT( WR( I ), WI( I ) )
  963. 10 CONTINUE
  964. *
  965. * Reorder eigenvalues and transform Schur vectors
  966. * (Workspace: none needed)
  967. *
  968. CALL DTRSEN( 'N', JOBVS, BWORK, N, A, LDA, VS, LDVS, WR, WI,
  969. $ SDIM, S, SEP, WORK( IWRK ), LWORK-IWRK+1, IDUM, 1,
  970. $ ICOND )
  971. IF( ICOND.GT.0 )
  972. $ INFO = N + ICOND
  973. END IF
  974. *
  975. IF( WANTVS ) THEN
  976. *
  977. * Undo balancing
  978. * (Workspace: need N)
  979. *
  980. CALL DGEBAK( 'P', 'R', N, ILO, IHI, WORK( IBAL ), N, VS, LDVS,
  981. $ IERR )
  982. END IF
  983. *
  984. IF( SCALEA ) THEN
  985. *
  986. * Undo scaling for the Schur form of A
  987. *
  988. CALL DLASCL( 'H', 0, 0, CSCALE, ANRM, N, N, A, LDA, IERR )
  989. CALL DCOPY( N, A, LDA+1, WR, 1 )
  990. IF( CSCALE.EQ.SMLNUM ) THEN
  991. *
  992. * If scaling back towards underflow, adjust WI if an
  993. * offdiagonal element of a 2-by-2 block in the Schur form
  994. * underflows.
  995. *
  996. IF( IEVAL.GT.0 ) THEN
  997. I1 = IEVAL + 1
  998. I2 = IHI - 1
  999. CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WI,
  1000. $ MAX( ILO-1, 1 ), IERR )
  1001. ELSE IF( WANTST ) THEN
  1002. I1 = 1
  1003. I2 = N - 1
  1004. ELSE
  1005. I1 = ILO
  1006. I2 = IHI - 1
  1007. END IF
  1008. INXT = I1 - 1
  1009. DO 20 I = I1, I2
  1010. IF( I.LT.INXT )
  1011. $ GO TO 20
  1012. IF( WI( I ).EQ.ZERO ) THEN
  1013. INXT = I + 1
  1014. ELSE
  1015. IF( A( I+1, I ).EQ.ZERO ) THEN
  1016. WI( I ) = ZERO
  1017. WI( I+1 ) = ZERO
  1018. ELSE IF( A( I+1, I ).NE.ZERO .AND. A( I, I+1 ).EQ.
  1019. $ ZERO ) THEN
  1020. WI( I ) = ZERO
  1021. WI( I+1 ) = ZERO
  1022. IF( I.GT.1 )
  1023. $ CALL DSWAP( I-1, A( 1, I ), 1, A( 1, I+1 ), 1 )
  1024. IF( N.GT.I+1 )
  1025. $ CALL DSWAP( N-I-1, A( I, I+2 ), LDA,
  1026. $ A( I+1, I+2 ), LDA )
  1027. IF( WANTVS ) THEN
  1028. CALL DSWAP( N, VS( 1, I ), 1, VS( 1, I+1 ), 1 )
  1029. END IF
  1030. A( I, I+1 ) = A( I+1, I )
  1031. A( I+1, I ) = ZERO
  1032. END IF
  1033. INXT = I + 2
  1034. END IF
  1035. 20 CONTINUE
  1036. END IF
  1037. *
  1038. * Undo scaling for the imaginary part of the eigenvalues
  1039. *
  1040. CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N-IEVAL, 1,
  1041. $ WI( IEVAL+1 ), MAX( N-IEVAL, 1 ), IERR )
  1042. END IF
  1043. *
  1044. IF( WANTST .AND. INFO.EQ.0 ) THEN
  1045. *
  1046. * Check if reordering successful
  1047. *
  1048. LASTSL = .TRUE.
  1049. LST2SL = .TRUE.
  1050. SDIM = 0
  1051. IP = 0
  1052. DO 30 I = 1, N
  1053. CURSL = SELECT( WR( I ), WI( I ) )
  1054. IF( WI( I ).EQ.ZERO ) THEN
  1055. IF( CURSL )
  1056. $ SDIM = SDIM + 1
  1057. IP = 0
  1058. IF( CURSL .AND. .NOT.LASTSL )
  1059. $ INFO = N + 2
  1060. ELSE
  1061. IF( IP.EQ.1 ) THEN
  1062. *
  1063. * Last eigenvalue of conjugate pair
  1064. *
  1065. CURSL = CURSL .OR. LASTSL
  1066. LASTSL = CURSL
  1067. IF( CURSL )
  1068. $ SDIM = SDIM + 2
  1069. IP = -1
  1070. IF( CURSL .AND. .NOT.LST2SL )
  1071. $ INFO = N + 2
  1072. ELSE
  1073. *
  1074. * First eigenvalue of conjugate pair
  1075. *
  1076. IP = 1
  1077. END IF
  1078. END IF
  1079. LST2SL = LASTSL
  1080. LASTSL = CURSL
  1081. 30 CONTINUE
  1082. END IF
  1083. *
  1084. WORK( 1 ) = MAXWRK
  1085. RETURN
  1086. *
  1087. * End of DGEES
  1088. *
  1089. END
  1090. SUBROUTINE DGEESX( JOBVS, SORT, SELECT, SENSE, N, A, LDA, SDIM,
  1091. $ WR, WI, VS, LDVS, RCONDE, RCONDV, WORK, LWORK,
  1092. $ IWORK, LIWORK, BWORK, INFO )
  1093. *
  1094. * -- LAPACK driver routine (version 3.1) --
  1095. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  1096. * November 2006
  1097. *
  1098. * .. Scalar Arguments ..
  1099. CHARACTER JOBVS, SENSE, SORT
  1100. INTEGER INFO, LDA, LDVS, LIWORK, LWORK, N, SDIM
  1101. DOUBLE PRECISION RCONDE, RCONDV
  1102. * ..
  1103. * .. Array Arguments ..
  1104. LOGICAL BWORK( * )
  1105. INTEGER IWORK( * )
  1106. DOUBLE PRECISION A( LDA, * ), VS( LDVS, * ), WI( * ), WORK( * ),
  1107. $ WR( * )
  1108. * ..
  1109. * .. Function Arguments ..
  1110. LOGICAL SELECT
  1111. EXTERNAL SELECT
  1112. * ..
  1113. *
  1114. * Purpose
  1115. * =======
  1116. *
  1117. * DGEESX computes for an N-by-N real nonsymmetric matrix A, the
  1118. * eigenvalues, the real Schur form T, and, optionally, the matrix of
  1119. * Schur vectors Z. This gives the Schur factorization A = Z*T*(Z**T).
  1120. *
  1121. * Optionally, it also orders the eigenvalues on the diagonal of the
  1122. * real Schur form so that selected eigenvalues are at the top left;
  1123. * computes a reciprocal condition number for the average of the
  1124. * selected eigenvalues (RCONDE); and computes a reciprocal condition
  1125. * number for the right invariant subspace corresponding to the
  1126. * selected eigenvalues (RCONDV). The leading columns of Z form an
  1127. * orthonormal basis for this invariant subspace.
  1128. *
  1129. * For further explanation of the reciprocal condition numbers RCONDE
  1130. * and RCONDV, see Section 4.10 of the LAPACK Users' Guide (where
  1131. * these quantities are called s and sep respectively).
  1132. *
  1133. * A real matrix is in real Schur form if it is upper quasi-triangular
  1134. * with 1-by-1 and 2-by-2 blocks. 2-by-2 blocks will be standardized in
  1135. * the form
  1136. * [ a b ]
  1137. * [ c a ]
  1138. *
  1139. * where b*c < 0. The eigenvalues of such a block are a +- sqrt(bc).
  1140. *
  1141. * Arguments
  1142. * =========
  1143. *
  1144. * JOBVS (input) CHARACTER*1
  1145. * = 'N': Schur vectors are not computed;
  1146. * = 'V': Schur vectors are computed.
  1147. *
  1148. * SORT (input) CHARACTER*1
  1149. * Specifies whether or not to order the eigenvalues on the
  1150. * diagonal of the Schur form.
  1151. * = 'N': Eigenvalues are not ordered;
  1152. * = 'S': Eigenvalues are ordered (see SELECT).
  1153. *
  1154. * SELECT (external procedure) LOGICAL FUNCTION of two DOUBLE PRECISION arguments
  1155. * SELECT must be declared EXTERNAL in the calling subroutine.
  1156. * If SORT = 'S', SELECT is used to select eigenvalues to sort
  1157. * to the top left of the Schur form.
  1158. * If SORT = 'N', SELECT is not referenced.
  1159. * An eigenvalue WR(j)+sqrt(-1)*WI(j) is selected if
  1160. * SELECT(WR(j),WI(j)) is true; i.e., if either one of a
  1161. * complex conjugate pair of eigenvalues is selected, then both
  1162. * are. Note that a selected complex eigenvalue may no longer
  1163. * satisfy SELECT(WR(j),WI(j)) = .TRUE. after ordering, since
  1164. * ordering may change the value of complex eigenvalues
  1165. * (especially if the eigenvalue is ill-conditioned); in this
  1166. * case INFO may be set to N+3 (see INFO below).
  1167. *
  1168. * SENSE (input) CHARACTER*1
  1169. * Determines which reciprocal condition numbers are computed.
  1170. * = 'N': None are computed;
  1171. * = 'E': Computed for average of selected eigenvalues only;
  1172. * = 'V': Computed for selected right invariant subspace only;
  1173. * = 'B': Computed for both.
  1174. * If SENSE = 'E', 'V' or 'B', SORT must equal 'S'.
  1175. *
  1176. * N (input) INTEGER
  1177. * The order of the matrix A. N >= 0.
  1178. *
  1179. * A (input/output) DOUBLE PRECISION array, dimension (LDA, N)
  1180. * On entry, the N-by-N matrix A.
  1181. * On exit, A is overwritten by its real Schur form T.
  1182. *
  1183. * LDA (input) INTEGER
  1184. * The leading dimension of the array A. LDA >= max(1,N).
  1185. *
  1186. * SDIM (output) INTEGER
  1187. * If SORT = 'N', SDIM = 0.
  1188. * If SORT = 'S', SDIM = number of eigenvalues (after sorting)
  1189. * for which SELECT is true. (Complex conjugate
  1190. * pairs for which SELECT is true for either
  1191. * eigenvalue count as 2.)
  1192. *
  1193. * WR (output) DOUBLE PRECISION array, dimension (N)
  1194. * WI (output) DOUBLE PRECISION array, dimension (N)
  1195. * WR and WI contain the real and imaginary parts, respectively,
  1196. * of the computed eigenvalues, in the same order that they
  1197. * appear on the diagonal of the output Schur form T. Complex
  1198. * conjugate pairs of eigenvalues appear consecutively with the
  1199. * eigenvalue having the positive imaginary part first.
  1200. *
  1201. * VS (output) DOUBLE PRECISION array, dimension (LDVS,N)
  1202. * If JOBVS = 'V', VS contains the orthogonal matrix Z of Schur
  1203. * vectors.
  1204. * If JOBVS = 'N', VS is not referenced.
  1205. *
  1206. * LDVS (input) INTEGER
  1207. * The leading dimension of the array VS. LDVS >= 1, and if
  1208. * JOBVS = 'V', LDVS >= N.
  1209. *
  1210. * RCONDE (output) DOUBLE PRECISION
  1211. * If SENSE = 'E' or 'B', RCONDE contains the reciprocal
  1212. * condition number for the average of the selected eigenvalues.
  1213. * Not referenced if SENSE = 'N' or 'V'.
  1214. *
  1215. * RCONDV (output) DOUBLE PRECISION
  1216. * If SENSE = 'V' or 'B', RCONDV contains the reciprocal
  1217. * condition number for the selected right invariant subspace.
  1218. * Not referenced if SENSE = 'N' or 'E'.
  1219. *
  1220. * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
  1221. * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  1222. *
  1223. * LWORK (input) INTEGER
  1224. * The dimension of the array WORK. LWORK >= max(1,3*N).
  1225. * Also, if SENSE = 'E' or 'V' or 'B',
  1226. * LWORK >= N+2*SDIM*(N-SDIM), where SDIM is the number of
  1227. * selected eigenvalues computed by this routine. Note that
  1228. * N+2*SDIM*(N-SDIM) <= N+N*N/2. Note also that an error is only
  1229. * returned if LWORK < max(1,3*N), but if SENSE = 'E' or 'V' or
  1230. * 'B' this may not be large enough.
  1231. * For good performance, LWORK must generally be larger.
  1232. *
  1233. * If LWORK = -1, then a workspace query is assumed; the routine
  1234. * only calculates upper bounds on the optimal sizes of the
  1235. * arrays WORK and IWORK, returns these values as the first
  1236. * entries of the WORK and IWORK arrays, and no error messages
  1237. * related to LWORK or LIWORK are issued by XERBLA.
  1238. *
  1239. * IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
  1240. * On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
  1241. *
  1242. * LIWORK (input) INTEGER
  1243. * The dimension of the array IWORK.
  1244. * LIWORK >= 1; if SENSE = 'V' or 'B', LIWORK >= SDIM*(N-SDIM).
  1245. * Note that SDIM*(N-SDIM) <= N*N/4. Note also that an error is
  1246. * only returned if LIWORK < 1, but if SENSE = 'V' or 'B' this
  1247. * may not be large enough.
  1248. *
  1249. * If LIWORK = -1, then a workspace query is assumed; the
  1250. * routine only calculates upper bounds on the optimal sizes of
  1251. * the arrays WORK and IWORK, returns these values as the first
  1252. * entries of the WORK and IWORK arrays, and no error messages
  1253. * related to LWORK or LIWORK are issued by XERBLA.
  1254. *
  1255. * BWORK (workspace) LOGICAL array, dimension (N)
  1256. * Not referenced if SORT = 'N'.
  1257. *
  1258. * INFO (output) INTEGER
  1259. * = 0: successful exit
  1260. * < 0: if INFO = -i, the i-th argument had an illegal value.
  1261. * > 0: if INFO = i, and i is
  1262. * <= N: the QR algorithm failed to compute all the
  1263. * eigenvalues; elements 1:ILO-1 and i+1:N of WR and WI
  1264. * contain those eigenvalues which have converged; if
  1265. * JOBVS = 'V', VS contains the transformation which
  1266. * reduces A to its partially converged Schur form.
  1267. * = N+1: the eigenvalues could not be reordered because some
  1268. * eigenvalues were too close to separate (the problem
  1269. * is very ill-conditioned);
  1270. * = N+2: after reordering, roundoff changed values of some
  1271. * complex eigenvalues so that leading eigenvalues in
  1272. * the Schur form no longer satisfy SELECT=.TRUE. This
  1273. * could also be caused by underflow due to scaling.
  1274. *
  1275. * =====================================================================
  1276. *
  1277. * .. Parameters ..
  1278. DOUBLE PRECISION ZERO, ONE
  1279. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
  1280. * ..
  1281. * .. Local Scalars ..
  1282. LOGICAL CURSL, LASTSL, LQUERY, LST2SL, SCALEA, WANTSB,
  1283. $ WANTSE, WANTSN, WANTST, WANTSV, WANTVS
  1284. INTEGER HSWORK, I, I1, I2, IBAL, ICOND, IERR, IEVAL,
  1285. $ IHI, ILO, INXT, IP, ITAU, IWRK, LIWRK, LWRK,
  1286. $ MAXWRK, MINWRK
  1287. DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, SMLNUM
  1288. * ..
  1289. * .. Local Arrays ..
  1290. DOUBLE PRECISION DUM( 1 )
  1291. * ..
  1292. * .. External Subroutines ..
  1293. EXTERNAL DCOPY, DGEBAK, DGEBAL, DGEHRD, DHSEQR, DLACPY,
  1294. $ DLASCL, DORGHR, DSWAP, DTRSEN, XERBLA
  1295. * ..
  1296. * .. External Functions ..
  1297. LOGICAL LSAME
  1298. INTEGER ILAENV
  1299. DOUBLE PRECISION DLAMCH, DLANGE
  1300. EXTERNAL LSAME, ILAENV, DLABAD, DLAMCH, DLANGE
  1301. * ..
  1302. * .. Intrinsic Functions ..
  1303. INTRINSIC MAX, SQRT
  1304. * ..
  1305. * .. Executable Statements ..
  1306. *
  1307. * Test the input arguments
  1308. *
  1309. INFO = 0
  1310. WANTVS = LSAME( JOBVS, 'V' )
  1311. WANTST = LSAME( SORT, 'S' )
  1312. WANTSN = LSAME( SENSE, 'N' )
  1313. WANTSE = LSAME( SENSE, 'E' )
  1314. WANTSV = LSAME( SENSE, 'V' )
  1315. WANTSB = LSAME( SENSE, 'B' )
  1316. LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
  1317. IF( ( .NOT.WANTVS ) .AND. ( .NOT.LSAME( JOBVS, 'N' ) ) ) THEN
  1318. INFO = -1
  1319. ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN
  1320. INFO = -2
  1321. ELSE IF( .NOT.( WANTSN .OR. WANTSE .OR. WANTSV .OR. WANTSB ) .OR.
  1322. $ ( .NOT.WANTST .AND. .NOT.WANTSN )

Large files files are truncated, but you can click here to view the full file