lapack_agmg_win.f90
上传用户:qi_qi_qi_
上传日期:2021-11-15
资源大小:35k
文件大小:142k
源码类别:

网格计算

开发平台:

Windows_Unix

  1.       SUBROUTINE DGETF2( M, N, A, LDA, IPIV, INFO ) 
  2.         use MSIMSL
  3. !                                                                       
  4. !  -- LAPACK routine (version 3.1) --                                   
  5. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  6. !     November 2006                                                     
  7. !                                                                       
  8. !     .. Scalar Arguments ..                                            
  9.       INTEGER            INFO, LDA, M, N 
  10. !     ..                                                                
  11. !     .. Array Arguments ..                                             
  12.       INTEGER            IPIV( * ) 
  13.       DOUBLE PRECISION   A( LDA, * ) 
  14. !     ..                                                                
  15. !                                                                       
  16. !  Purpose                                                              
  17. !  =======                                                              
  18. !                                                                       
  19. !  DGETF2 computes an LU factorization of a general m-by-n matrix A     
  20. !  using partial pivoting with row interchanges.                        
  21. !                                                                       
  22. !  The factorization has the form                                       
  23. !     A = P * L * U                                                     
  24. !  where P is a permutation matrix, L is lower triangular with unit     
  25. !  diagonal elements (lower trapezoidal if m > n), and U is upper       
  26. !  triangular (upper trapezoidal if m < n).                             
  27. !                                                                       
  28. !  This is the right-looking Level 2 BLAS version of the algorithm.     
  29. !                                                                       
  30. !  Arguments                                                            
  31. !  =========                                                            
  32. !                                                                       
  33. !  M       (input) INTEGER                                              
  34. !          The number of rows of the matrix A.  M >= 0.                 
  35. !                                                                       
  36. !  N       (input) INTEGER                                              
  37. !          The number of columns of the matrix A.  N >= 0.              
  38. !                                                                       
  39. !  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)     
  40. !          On entry, the m by n matrix to be factored.                  
  41. !          On exit, the factors L and U from the factorization          
  42. !          A = P*L*U; the unit diagonal elements of L are not stored.   
  43. !                                                                       
  44. !  LDA     (input) INTEGER                                              
  45. !          The leading dimension of the array A.  LDA >= max(1,M).      
  46. !                                                                       
  47. !  IPIV    (output) INTEGER array, dimension (min(M,N))                 
  48. !          The pivot indices; for 1 <= i <= min(M,N), row i of the      
  49. !          matrix was interchanged with row IPIV(i).                    
  50. !                                                                       
  51. !  INFO    (output) INTEGER                                             
  52. !          = 0: successful exit                                         
  53. !          < 0: if INFO = -k, the k-th argument had an illegal value    
  54. !          > 0: if INFO = k, U(k,k) is exactly zero. The factorization  
  55. !               has been completed, but the factor U is exactly         
  56. !               singular, and division by zero will occur if it is used 
  57. !               to solve a system of equations.                         
  58. !                                                                       
  59. !  =====================================================================
  60. !                                                                       
  61. !     .. Parameters ..                                                  
  62.       DOUBLE PRECISION   ONE, ZERO 
  63.       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 ) 
  64. !     ..                                                                
  65. !     .. Local Scalars ..                                               
  66.       DOUBLE PRECISION   SFMIN 
  67.       INTEGER            I, J, JP 
  68. !     ..                                                                
  69. !     .. External Functions ..                                          
  70.       DOUBLE PRECISION   DLAMCH 
  71. !msimslINTEGER            IDAMAX 
  72.       EXTERNAL           DLAMCH!msimsl, IDAMAX 
  73. !     ..                                                                
  74. !     .. External Subroutines ..                                        
  75. !msimslEXTERNAL           DGER, DSCAL, DSWAP, XERBLA 
  76. EXTERNAL  XERBLA 
  77. !     ..                                                                
  78. !     .. Intrinsic Functions ..                                         
  79.       INTRINSIC          MAX, MIN 
  80. !     ..                                                                
  81. !     .. Executable Statements ..                                       
  82. !                                                                       
  83. !     Test the input parameters.                                        
  84. !                                                                       
  85.       INFO = 0 
  86.       IF( M.LT.0 ) THEN 
  87.          INFO = -1 
  88.       ELSE IF( N.LT.0 ) THEN 
  89.          INFO = -2 
  90.       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN 
  91.          INFO = -4 
  92.       END IF 
  93.       IF( INFO.NE.0 ) THEN 
  94.          CALL XERBLA( 'DGETF2', -INFO ) 
  95.          RETURN 
  96.       END IF 
  97. !                                                                       
  98. !     Quick return if possible                                          
  99. !                                                                       
  100.       IF( M.EQ.0 .OR. N.EQ.0 )                                          &
  101.      &   RETURN                                                         
  102. !                                                                       
  103. !     Compute machine safe minimum                                      
  104. !                                                                       
  105.       SFMIN = DLAMCH('S') 
  106. !                                                                       
  107.       DO 10 J = 1, MIN( M, N ) 
  108. !                                                                       
  109. !        Find pivot and test for singularity.                           
  110. !                                                                       
  111.          JP = J - 1 + IDAMAX( M-J+1, A( J, J ), 1 ) 
  112.          IPIV( J ) = JP 
  113.          IF( A( JP, J ).NE.ZERO ) THEN 
  114. !                                                                       
  115. !           Apply the interchange to columns 1:N.                       
  116. !                                                                       
  117.             IF( JP.NE.J )                                               &
  118.      &         CALL DSWAP( N, A( J, 1 ), LDA, A( JP, 1 ), LDA )         
  119. !                                                                       
  120. !           Compute elements J+1:M of J-th column.                      
  121. !                                                                       
  122.             IF( J.LT.M ) THEN 
  123.                IF( ABS(A( J, J )) .GE. SFMIN ) THEN 
  124.                   CALL DSCAL( M-J, ONE / A( J, J ), A( J+1, J ), 1 ) 
  125.                ELSE 
  126.                  DO 20 I = 1, M-J 
  127.                     A( J+I, J ) = A( J+I, J ) / A( J, J ) 
  128.    20            CONTINUE 
  129.                END IF 
  130.             END IF 
  131. !                                                                       
  132.          ELSE IF( INFO.EQ.0 ) THEN 
  133. !                                                                       
  134.             INFO = J 
  135.          END IF 
  136. !                                                                       
  137.          IF( J.LT.MIN( M, N ) ) THEN 
  138. !                                                                       
  139. !           Update trailing submatrix.                                  
  140. !                                                                       
  141.             CALL DGER( M-J, N-J, -ONE, A( J+1, J ), 1, A( J, J+1 ), LDA,&
  142.      &                 A( J+1, J+1 ), LDA )                             
  143.          END IF 
  144.    10 END DO 
  145.       RETURN 
  146. !                                                                       
  147. !     End of DGETF2                                                     
  148. !                                                                       
  149.       END                                           
  150.       SUBROUTINE DGETRF( M, N, A, LDA, IPIV, INFO ) 
  151.         use MSIMSL
  152. !                                                                       
  153. !  -- LAPACK routine (version 3.1) --                                   
  154. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  155. !     November 2006                                                     
  156. !                                                                       
  157. !     .. Scalar Arguments ..                                            
  158.       INTEGER            INFO, LDA, M, N 
  159. !     ..                                                                
  160. !     .. Array Arguments ..                                             
  161.       INTEGER            IPIV( * ) 
  162.       DOUBLE PRECISION   A( LDA, * ) 
  163. !     ..                                                                
  164. !                                                                       
  165. !  Purpose                                                              
  166. !  =======                                                              
  167. !                                                                       
  168. !  DGETRF computes an LU factorization of a general M-by-N matrix A     
  169. !  using partial pivoting with row interchanges.                        
  170. !                                                                       
  171. !  The factorization has the form                                       
  172. !     A = P * L * U                                                     
  173. !  where P is a permutation matrix, L is lower triangular with unit     
  174. !  diagonal elements (lower trapezoidal if m > n), and U is upper       
  175. !  triangular (upper trapezoidal if m < n).                             
  176. !                                                                       
  177. !  This is the right-looking Level 3 BLAS version of the algorithm.     
  178. !                                                                       
  179. !  Arguments                                                            
  180. !  =========                                                            
  181. !                                                                       
  182. !  M       (input) INTEGER                                              
  183. !          The number of rows of the matrix A.  M >= 0.                 
  184. !                                                                       
  185. !  N       (input) INTEGER                                              
  186. !          The number of columns of the matrix A.  N >= 0.              
  187. !                                                                       
  188. !  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)     
  189. !          On entry, the M-by-N matrix to be factored.                  
  190. !          On exit, the factors L and U from the factorization          
  191. !          A = P*L*U; the unit diagonal elements of L are not stored.   
  192. !                                                                       
  193. !  LDA     (input) INTEGER                                              
  194. !          The leading dimension of the array A.  LDA >= max(1,M).      
  195. !                                                                       
  196. !  IPIV    (output) INTEGER array, dimension (min(M,N))                 
  197. !          The pivot indices; for 1 <= i <= min(M,N), row i of the      
  198. !          matrix was interchanged with row IPIV(i).                    
  199. !                                                                       
  200. !  INFO    (output) INTEGER                                             
  201. !          = 0:  successful exit                                        
  202. !          < 0:  if INFO = -i, the i-th argument had an illegal value   
  203. !          > 0:  if INFO = i, U(i,i) is exactly zero. The factorization 
  204. !                has been completed, but the factor U is exactly        
  205. !                singular, and division by zero will occur if it is used
  206. !                to solve a system of equations.                        
  207. !                                                                       
  208. !  =====================================================================
  209. !                                                                       
  210. !     .. Parameters ..                                                  
  211.       DOUBLE PRECISION   ONE 
  212.       PARAMETER          ( ONE = 1.0D+0 ) 
  213. !     ..                                                                
  214. !     .. Local Scalars ..                                               
  215.       INTEGER            I, IINFO, J, JB, NB 
  216. !     ..                                                                
  217. !     .. External Subroutines ..                                        
  218. !msimslEXTERNAL           DGEMM,  DTRSM, 
  219. EXTERNAL DGETF2, DLASWP, XERBLA
  220. !     ..                                                                
  221. !     .. External Functions ..                                          
  222.       INTEGER            ILAENV 
  223.       EXTERNAL           ILAENV 
  224. !     ..                                                                
  225. !     .. Intrinsic Functions ..                                         
  226.       INTRINSIC          MAX, MIN 
  227. !     ..                                                                
  228. !     .. Executable Statements ..                                       
  229. !                                                                       
  230. !     Test the input parameters.                                        
  231. !                                                                       
  232.       INFO = 0 
  233.       IF( M.LT.0 ) THEN 
  234.          INFO = -1 
  235.       ELSE IF( N.LT.0 ) THEN 
  236.          INFO = -2 
  237.       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN 
  238.          INFO = -4 
  239.       END IF 
  240.       IF( INFO.NE.0 ) THEN 
  241.          CALL XERBLA( 'DGETRF', -INFO ) 
  242.          RETURN 
  243.       END IF 
  244. !                                                                       
  245. !     Quick return if possible                                          
  246. !                                                                       
  247.       IF( M.EQ.0 .OR. N.EQ.0 )                                          &
  248.      &   RETURN                                                         
  249. !                                                                       
  250. !     Determine the block size for this environment.                    
  251. !                                                                       
  252.       NB = ILAENV( 1, 'DGETRF', ' ', M, N, -1, -1 ) 
  253.       IF( NB.LE.1 .OR. NB.GE.MIN( M, N ) ) THEN 
  254. !                                                                       
  255. !        Use unblocked code.                                            
  256. !                                                                       
  257.          CALL DGETF2( M, N, A, LDA, IPIV, INFO ) 
  258.       ELSE 
  259. !                                                                       
  260. !        Use blocked code.                                              
  261. !                                                                       
  262.          DO 20 J = 1, MIN( M, N ), NB 
  263.             JB = MIN( MIN( M, N )-J+1, NB ) 
  264. !                                                                       
  265. !           Factor diagonal and subdiagonal blocks and test for exact   
  266. !           singularity.                                                
  267. !                                                                       
  268.             CALL DGETF2( M-J+1, JB, A( J, J ), LDA, IPIV( J ), IINFO ) 
  269. !                                                                       
  270. !           Adjust INFO and the pivot indices.                          
  271. !                                                                       
  272.             IF( INFO.EQ.0 .AND. IINFO.GT.0 )                            &
  273.      &         INFO = IINFO + J - 1                                     
  274.             DO 10 I = J, MIN( M, J+JB-1 ) 
  275.                IPIV( I ) = J - 1 + IPIV( I ) 
  276.    10       CONTINUE 
  277. !                                                                       
  278. !           Apply interchanges to columns 1:J-1.                        
  279. !                                                                       
  280.             CALL DLASWP( J-1, A, LDA, J, J+JB-1, IPIV, 1 ) 
  281. !                                                                       
  282.             IF( J+JB.LE.N ) THEN 
  283. !                                                                       
  284. !              Apply interchanges to columns J+JB:N.                    
  285. !                                                                       
  286.                CALL DLASWP( N-J-JB+1, A( 1, J+JB ), LDA, J, J+JB-1,     &
  287.      &                      IPIV, 1 )                                   
  288. !                                                                       
  289. !              Compute block row of U.                                  
  290. !                                                                       
  291.                CALL DTRSM( 'Left', 'Lower', 'No transpose', 'Unit', JB, &
  292.      &                     N-J-JB+1, ONE, A( J, J ), LDA, A( J, J+JB ), &
  293.      &                     LDA )                                        
  294.                IF( J+JB.LE.M ) THEN 
  295. !                                                                       
  296. !                 Update trailing submatrix.                            
  297. !                                                                       
  298.                   CALL DGEMM( 'No transpose', 'No transpose', M-J-JB+1, &
  299.      &                        N-J-JB+1, JB, -ONE, A( J+JB, J ), LDA,    &
  300.      &                        A( J, J+JB ), LDA, ONE, A( J+JB, J+JB ),  &
  301.      &                        LDA )                                     
  302.                END IF 
  303.             END IF 
  304.    20    CONTINUE 
  305.       END IF 
  306.       RETURN 
  307. !                                                                       
  308. !     End of DGETRF                                                     
  309. !                                                                       
  310.       END                                           
  311.       SUBROUTINE DGETRS( TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO ) 
  312.         use MSIMSL
  313. !                                                                       
  314. !  -- LAPACK routine (version 3.1) --                                   
  315. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  316. !     November 2006                                                     
  317. !                                                                       
  318. !     .. Scalar Arguments ..                                            
  319.       CHARACTER          TRANS 
  320.       INTEGER            INFO, LDA, LDB, N, NRHS 
  321. !     ..                                                                
  322. !     .. Array Arguments ..                                             
  323.       INTEGER            IPIV( * ) 
  324.       DOUBLE PRECISION   A( LDA, * ), B( LDB, * ) 
  325. !     ..                                                                
  326. !                                                                       
  327. !  Purpose                                                              
  328. !  =======                                                              
  329. !                                                                       
  330. !  DGETRS solves a system of linear equations                           
  331. !     A * X = B  or  A' * X = B                                         
  332. !  with a general N-by-N matrix A using the LU factorization computed   
  333. !  by DGETRF.                                                           
  334. !                                                                       
  335. !  Arguments                                                            
  336. !  =========                                                            
  337. !                                                                       
  338. !  TRANS   (input) CHARACTER*1                                          
  339. !          Specifies the form of the system of equations:               
  340. !          = 'N':  A * X = B  (No transpose)                            
  341. !          = 'T':  A'* X = B  (Transpose)                               
  342. !          = 'C':  A'* X = B  (Conjugate transpose = Transpose)         
  343. !                                                                       
  344. !  N       (input) INTEGER                                              
  345. !          The order of the matrix A.  N >= 0.                          
  346. !                                                                       
  347. !  NRHS    (input) INTEGER                                              
  348. !          The number of right hand sides, i.e., the number of columns  
  349. !          of the matrix B.  NRHS >= 0.                                 
  350. !                                                                       
  351. !  A       (input) DOUBLE PRECISION array, dimension (LDA,N)            
  352. !          The factors L and U from the factorization A = P*L*U         
  353. !          as computed by DGETRF.                                       
  354. !                                                                       
  355. !  LDA     (input) INTEGER                                              
  356. !          The leading dimension of the array A.  LDA >= max(1,N).      
  357. !                                                                       
  358. !  IPIV    (input) INTEGER array, dimension (N)                         
  359. !          The pivot indices from DGETRF; for 1<=i<=N, row i of the     
  360. !          matrix was interchanged with row IPIV(i).                    
  361. !                                                                       
  362. !  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)  
  363. !          On entry, the right hand side matrix B.                      
  364. !          On exit, the solution matrix X.                              
  365. !                                                                       
  366. !  LDB     (input) INTEGER                                              
  367. !          The leading dimension of the array B.  LDB >= max(1,N).      
  368. !                                                                       
  369. !  INFO    (output) INTEGER                                             
  370. !          = 0:  successful exit                                        
  371. !          < 0:  if INFO = -i, the i-th argument had an illegal value   
  372. !                                                                       
  373. !  =====================================================================
  374. !                                                                       
  375. !     .. Parameters ..                                                  
  376.       DOUBLE PRECISION   ONE 
  377.       PARAMETER          ( ONE = 1.0D+0 ) 
  378. !     ..                                                                
  379. !     .. Local Scalars ..                                               
  380.       LOGICAL            NOTRAN 
  381. !     ..                                                                
  382. !     .. External Functions ..                                          
  383.       LOGICAL            LSAME 
  384.       EXTERNAL           LSAME 
  385. !     ..                                                                
  386. !     .. External Subroutines ..                                        
  387. !msimslEXTERNAL        , DTRSM,   
  388. EXTERNAL DLASWP, XERBLA 
  389. !     ..                                                                
  390. !     .. Intrinsic Functions ..                                         
  391.       INTRINSIC          MAX 
  392. !     ..                                                                
  393. !     .. Executable Statements ..                                       
  394. !                                                                       
  395. !     Test the input parameters.                                        
  396. !                                                                       
  397.       INFO = 0 
  398.       NOTRAN = LSAME( TRANS, 'N' ) 
  399.       IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.        &
  400.      &    LSAME( TRANS, 'C' ) ) THEN                                    
  401.          INFO = -1 
  402.       ELSE IF( N.LT.0 ) THEN 
  403.          INFO = -2 
  404.       ELSE IF( NRHS.LT.0 ) THEN 
  405.          INFO = -3 
  406.       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN 
  407.          INFO = -5 
  408.       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 
  409.          INFO = -8 
  410.       END IF 
  411.       IF( INFO.NE.0 ) THEN 
  412.          CALL XERBLA( 'DGETRS', -INFO ) 
  413.          RETURN 
  414.       END IF 
  415. !                                                                       
  416. !     Quick return if possible                                          
  417. !                                                                       
  418.       IF( N.EQ.0 .OR. NRHS.EQ.0 )                                       &
  419.      &   RETURN                                                         
  420. !                                                                       
  421.       IF( NOTRAN ) THEN 
  422. !                                                                       
  423. !        Solve A * X = B.                                               
  424. !                                                                       
  425. !        Apply row interchanges to the right hand sides.                
  426. !                                                                       
  427.          CALL DLASWP( NRHS, B, LDB, 1, N, IPIV, 1 ) 
  428. !                                                                       
  429. !        Solve L*X = B, overwriting B with X.                           
  430. !                                                                       
  431.          CALL DTRSM( 'Left', 'Lower', 'No transpose', 'Unit', N, NRHS,  &
  432.      &               ONE, A, LDA, B, LDB )                              
  433. !                                                                       
  434. !        Solve U*X = B, overwriting B with X.                           
  435. !                                                                       
  436.          CALL DTRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', N,    &
  437.      &               NRHS, ONE, A, LDA, B, LDB )                        
  438.       ELSE 
  439. !                                                                       
  440. !        Solve A' * X = B.                                              
  441. !                                                                       
  442. !        Solve U'*X = B, overwriting B with X.                          
  443. !                                                                       
  444.          CALL DTRSM( 'Left', 'Upper', 'Transpose', 'Non-unit', N, NRHS, &
  445.      &               ONE, A, LDA, B, LDB )                              
  446. !                                                                       
  447. !        Solve L'*X = B, overwriting B with X.                          
  448. !                                                                       
  449.          CALL DTRSM( 'Left', 'Lower', 'Transpose', 'Unit', N, NRHS, ONE,&
  450.      &               A, LDA, B, LDB )                                   
  451. !                                                                       
  452. !        Apply row interchanges to the solution vectors.                
  453. !                                                                       
  454.          CALL DLASWP( NRHS, B, LDB, 1, N, IPIV, -1 ) 
  455.       END IF 
  456. !                                                                       
  457.       RETURN 
  458. !                                                                       
  459. !     End of DGETRS                                                     
  460. !                                                                       
  461.       END                                           
  462.       SUBROUTINE DLASWP( N, A, LDA, K1, K2, IPIV, INCX ) 
  463. !                                                                       
  464. !  -- LAPACK auxiliary routine (version 3.1) --                         
  465. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  466. !     November 2006                                                     
  467. !                                                                       
  468. !     .. Scalar Arguments ..                                            
  469.       INTEGER            INCX, K1, K2, LDA, N 
  470. !     ..                                                                
  471. !     .. Array Arguments ..                                             
  472.       INTEGER            IPIV( * ) 
  473.       DOUBLE PRECISION   A( LDA, * ) 
  474. !     ..                                                                
  475. !                                                                       
  476. !  Purpose                                                              
  477. !  =======                                                              
  478. !                                                                       
  479. !  DLASWP performs a series of row interchanges on the matrix A.        
  480. !  One row interchange is initiated for each of rows K1 through K2 of A.
  481. !                                                                       
  482. !  Arguments                                                            
  483. !  =========                                                            
  484. !                                                                       
  485. !  N       (input) INTEGER                                              
  486. !          The number of columns of the matrix A.                       
  487. !                                                                       
  488. !  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)     
  489. !          On entry, the matrix of column dimension N to which the row  
  490. !          interchanges will be applied.                                
  491. !          On exit, the permuted matrix.                                
  492. !                                                                       
  493. !  LDA     (input) INTEGER                                              
  494. !          The leading dimension of the array A.                        
  495. !                                                                       
  496. !  K1      (input) INTEGER                                              
  497. !          The first element of IPIV for which a row interchange will   
  498. !          be done.                                                     
  499. !                                                                       
  500. !  K2      (input) INTEGER                                              
  501. !          The last element of IPIV for which a row interchange will    
  502. !          be done.                                                     
  503. !                                                                       
  504. !  IPIV    (input) INTEGER array, dimension (K2*abs(INCX))              
  505. !          The vector of pivot indices.  Only the elements in positions 
  506. !          K1 through K2 of IPIV are accessed.                          
  507. !          IPIV(K) = L implies rows K and L are to be interchanged.     
  508. !                                                                       
  509. !  INCX    (input) INTEGER                                              
  510. !          The increment between successive values of IPIV.  If IPIV    
  511. !          is negative, the pivots are applied in reverse order.        
  512. !                                                                       
  513. !  Further Details                                                      
  514. !  ===============                                                      
  515. !                                                                       
  516. !  Modified by                                                          
  517. !   R. C. Whaley, Computer Science Dept., Univ. of Tenn., Knoxville, USA
  518. !                                                                       
  519. ! ===================================================================== 
  520. !                                                                       
  521. !     .. Local Scalars ..                                               
  522.       INTEGER            I, I1, I2, INC, IP, IX, IX0, J, K, N32 
  523.       DOUBLE PRECISION   TEMP 
  524. !     ..                                                                
  525. !     .. Executable Statements ..                                       
  526. !                                                                       
  527. !     Interchange row I with row IPIV(I) for each of rows K1 through K2.
  528. !                                                                       
  529.       IF( INCX.GT.0 ) THEN 
  530.          IX0 = K1 
  531.          I1 = K1 
  532.          I2 = K2 
  533.          INC = 1 
  534.       ELSE IF( INCX.LT.0 ) THEN 
  535.          IX0 = 1 + ( 1-K2 )*INCX 
  536.          I1 = K2 
  537.          I2 = K1 
  538.          INC = -1 
  539.       ELSE 
  540.          RETURN 
  541.       END IF 
  542. !                                                                       
  543.       N32 = ( N / 32 )*32 
  544.       IF( N32.NE.0 ) THEN 
  545.          DO 30 J = 1, N32, 32 
  546.             IX = IX0 
  547.             DO 20 I = I1, I2, INC 
  548.                IP = IPIV( IX ) 
  549.                IF( IP.NE.I ) THEN 
  550.                   DO 10 K = J, J + 31 
  551.                      TEMP = A( I, K ) 
  552.                      A( I, K ) = A( IP, K ) 
  553.                      A( IP, K ) = TEMP 
  554.    10             CONTINUE 
  555.                END IF 
  556.                IX = IX + INCX 
  557.    20       CONTINUE 
  558.    30    CONTINUE 
  559.       END IF 
  560.       IF( N32.NE.N ) THEN 
  561.          N32 = N32 + 1 
  562.          IX = IX0 
  563.          DO 50 I = I1, I2, INC 
  564.             IP = IPIV( IX ) 
  565.             IF( IP.NE.I ) THEN 
  566.                DO 40 K = N32, N 
  567.                   TEMP = A( I, K ) 
  568.                   A( I, K ) = A( IP, K ) 
  569.                   A( IP, K ) = TEMP 
  570.    40          CONTINUE 
  571.             END IF 
  572.             IX = IX + INCX 
  573.    50    CONTINUE 
  574.       END IF 
  575. !                                                                       
  576.       RETURN 
  577. !                                                                       
  578. !     End of DLASWP                                                     
  579. !                                                                       
  580.       END                                           
  581.       SUBROUTINE DTPTRS( UPLO, TRANS, DIAG, N, NRHS, AP, B, LDB, INFO ) 
  582.         use MSIMSL
  583. !                                                                       
  584. !  -- LAPACK routine (version 3.1) --                                   
  585. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  586. !     November 2006                                                     
  587. !                                                                       
  588. !     .. Scalar Arguments ..                                            
  589.       CHARACTER          DIAG, TRANS, UPLO 
  590.       INTEGER            INFO, LDB, N, NRHS 
  591. !     ..                                                                
  592. !     .. Array Arguments ..                                             
  593.       DOUBLE PRECISION   AP( * ), B( LDB, * ) 
  594. !     ..                                                                
  595. !                                                                       
  596. !  Purpose                                                              
  597. !  =======                                                              
  598. !                                                                       
  599. !  DTPTRS solves a triangular system of the form                        
  600. !                                                                       
  601. !     A * X = B  or  A**T * X = B,                                      
  602. !                                                                       
  603. !  where A is a triangular matrix of order N stored in packed format,   
  604. !  and B is an N-by-NRHS matrix.  A check is made to verify that A is   
  605. !  nonsingular.                                                         
  606. !                                                                       
  607. !  Arguments                                                            
  608. !  =========                                                            
  609. !                                                                       
  610. !  UPLO    (input) CHARACTER*1                                          
  611. !          = 'U':  A is upper triangular;                               
  612. !          = 'L':  A is lower triangular.                               
  613. !                                                                       
  614. !  TRANS   (input) CHARACTER*1                                          
  615. !          Specifies the form of the system of equations:               
  616. !          = 'N':  A * X = B  (No transpose)                            
  617. !          = 'T':  A**T * X = B  (Transpose)                            
  618. !          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)      
  619. !                                                                       
  620. !  DIAG    (input) CHARACTER*1                                          
  621. !          = 'N':  A is non-unit triangular;                            
  622. !          = 'U':  A is unit triangular.                                
  623. !                                                                       
  624. !  N       (input) INTEGER                                              
  625. !          The order of the matrix A.  N >= 0.                          
  626. !                                                                       
  627. !  NRHS    (input) INTEGER                                              
  628. !          The number of right hand sides, i.e., the number of columns  
  629. !          of the matrix B.  NRHS >= 0.                                 
  630. !                                                                       
  631. !  AP      (input) DOUBLE PRECISION array, dimension (N*(N+1)/2)        
  632. !          The upper or lower triangular matrix A, packed columnwise in 
  633. !          a linear array.  The j-th column of A is stored in the array 
  634. !          AP as follows:                                               
  635. !          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;       
  636. !          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. 
  637. !                                                                       
  638. !  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)  
  639. !          On entry, the right hand side matrix B.                      
  640. !          On exit, if INFO = 0, the solution matrix X.                 
  641. !                                                                       
  642. !  LDB     (input) INTEGER                                              
  643. !          The leading dimension of the array B.  LDB >= max(1,N).      
  644. !                                                                       
  645. !  INFO    (output) INTEGER                                             
  646. !          = 0:  successful exit                                        
  647. !          < 0:  if INFO = -i, the i-th argument had an illegal value   
  648. !          > 0:  if INFO = i, the i-th diagonal element of A is zero,   
  649. !                indicating that the matrix is singular and the         
  650. !                solutions X have not been computed.                    
  651. !                                                                       
  652. !  =====================================================================
  653. !                                                                       
  654. !     .. Parameters ..                                                  
  655.       DOUBLE PRECISION   ZERO 
  656.       PARAMETER          ( ZERO = 0.0D+0 ) 
  657. !     ..                                                                
  658. !     .. Local Scalars ..                                               
  659.       LOGICAL            NOUNIT, UPPER 
  660.       INTEGER            J, JC 
  661. !     ..                                                                
  662. !     .. External Functions ..                                          
  663.       LOGICAL            LSAME 
  664.       EXTERNAL           LSAME 
  665. !     ..                                                                
  666. !     .. External Subroutines ..                                        
  667.       EXTERNAL           DTPSV, XERBLA 
  668. !     ..                                                                
  669. !     .. Intrinsic Functions ..                                         
  670.       INTRINSIC          MAX 
  671. !     ..                                                                
  672. !     .. Executable Statements ..                                       
  673. !                                                                       
  674. !     Test the input parameters.                                        
  675. !                                                                       
  676.       INFO = 0 
  677.       UPPER = LSAME( UPLO, 'U' ) 
  678.       NOUNIT = LSAME( DIAG, 'N' ) 
  679.       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 
  680.          INFO = -1 
  681.       ELSE IF( .NOT.LSAME( TRANS, 'N' ) .AND. .NOT.                     &
  682.      &         LSAME( TRANS, 'T' ) .AND. .NOT.LSAME( TRANS, 'C' ) ) THEN
  683.          INFO = -2 
  684.       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN 
  685.          INFO = -3 
  686.       ELSE IF( N.LT.0 ) THEN 
  687.          INFO = -4 
  688.       ELSE IF( NRHS.LT.0 ) THEN 
  689.          INFO = -5 
  690.       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 
  691.          INFO = -8 
  692.       END IF 
  693.       IF( INFO.NE.0 ) THEN 
  694.          CALL XERBLA( 'DTPTRS', -INFO ) 
  695.          RETURN 
  696.       END IF 
  697. !                                                                       
  698. !     Quick return if possible                                          
  699. !                                                                       
  700.       IF( N.EQ.0 )                                                      &
  701.      &   RETURN                                                         
  702. !                                                                       
  703. !     Check for singularity.                                            
  704. !                                                                       
  705.       IF( NOUNIT ) THEN 
  706.          IF( UPPER ) THEN 
  707.             JC = 1 
  708.             DO 10 INFO = 1, N 
  709.                IF( AP( JC+INFO-1 ).EQ.ZERO )                            &
  710.      &            RETURN                                                
  711.                JC = JC + INFO 
  712.    10       CONTINUE 
  713.          ELSE 
  714.             JC = 1 
  715.             DO 20 INFO = 1, N 
  716.                IF( AP( JC ).EQ.ZERO )                                   &
  717.      &            RETURN                                                
  718.                JC = JC + N - INFO + 1 
  719.    20       CONTINUE 
  720.          END IF 
  721.       END IF 
  722.       INFO = 0 
  723. !                                                                       
  724. !     Solve A * x = b  or  A' * x = b.                                  
  725. !                                                                       
  726.       DO 30 J = 1, NRHS 
  727.          CALL DTPSV( UPLO, TRANS, DIAG, N, AP, B( 1, J ), 1 ) 
  728.    30 END DO 
  729. !                                                                       
  730.       RETURN 
  731. !                                                                       
  732. !     End of DTPTRS                                                     
  733. !                                                                       
  734.       END                                           
  735.       DOUBLE PRECISION FUNCTION DLAMCH( CMACH ) 
  736. !                                                                       
  737. !  -- LAPACK auxiliary routine (version 3.1) --                         
  738. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  739. !     November 2006                                                     
  740. !                                                                       
  741. !     .. Scalar Arguments ..                                            
  742.       CHARACTER          CMACH 
  743. !     ..                                                                
  744. !                                                                       
  745. !  Purpose                                                              
  746. !  =======                                                              
  747. !                                                                       
  748. !  DLAMCH determines double precision machine parameters.               
  749. !                                                                       
  750. !  Arguments                                                            
  751. !  =========                                                            
  752. !                                                                       
  753. !  CMACH   (input) CHARACTER*1                                          
  754. !          Specifies the value to be returned by DLAMCH:                
  755. !          = 'E' or 'e',   DLAMCH := eps                                
  756. !          = 'S' or 's ,   DLAMCH := sfmin                              
  757. !          = 'B' or 'b',   DLAMCH := base                               
  758. !          = 'P' or 'p',   DLAMCH := eps*base                           
  759. !          = 'N' or 'n',   DLAMCH := t                                  
  760. !          = 'R' or 'r',   DLAMCH := rnd                                
  761. !          = 'M' or 'm',   DLAMCH := emin                               
  762. !          = 'U' or 'u',   DLAMCH := rmin                               
  763. !          = 'L' or 'l',   DLAMCH := emax                               
  764. !          = 'O' or 'o',   DLAMCH := rmax                               
  765. !                                                                       
  766. !          where                                                        
  767. !                                                                       
  768. !          eps   = relative machine precision                           
  769. !          sfmin = safe minimum, such that 1/sfmin does not overflow    
  770. !          base  = base of the machine                                  
  771. !          prec  = eps*base                                             
  772. !          t     = number of (base) digits in the mantissa              
  773. !          rnd   = 1.0 when rounding occurs in addition, 0.0 otherwise  
  774. !          emin  = minimum exponent before (gradual) underflow          
  775. !          rmin  = underflow threshold - base**(emin-1)                 
  776. !          emax  = largest exponent before overflow                     
  777. !          rmax  = overflow threshold  - (base**emax)*(1-eps)           
  778. !                                                                       
  779. ! ===================================================================== 
  780. !                                                                       
  781. !     .. Parameters ..                                                  
  782.       DOUBLE PRECISION   ONE, ZERO 
  783.       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 ) 
  784. !     ..                                                                
  785. !     .. Local Scalars ..                                               
  786.       LOGICAL            FIRST, LRND 
  787.       INTEGER            BETA, IMAX, IMIN, IT 
  788.       DOUBLE PRECISION   BASE, EMAX, EMIN, EPS, PREC, RMACH, RMAX, RMIN,&
  789.      &                   RND, SFMIN, SMALL, T                           
  790. !     ..                                                                
  791. !     .. External Functions ..                                          
  792.       LOGICAL            LSAME 
  793.       EXTERNAL           LSAME 
  794. !     ..                                                                
  795. !     .. External Subroutines ..                                        
  796.       EXTERNAL           DLAMC2 
  797. !     ..                                                                
  798. !     .. Save statement ..                                              
  799.       SAVE               FIRST, EPS, SFMIN, BASE, T, RND, EMIN, RMIN,   &
  800.      &                   EMAX, RMAX, PREC                               
  801. !     ..                                                                
  802. !     .. Data statements ..                                             
  803.       DATA               FIRST / .TRUE. / 
  804. !     ..                                                                
  805. !     .. Executable Statements ..                                       
  806. !                                                                       
  807.       IF( FIRST ) THEN 
  808.          CALL DLAMC2( BETA, IT, LRND, EPS, IMIN, RMIN, IMAX, RMAX ) 
  809.          BASE = BETA 
  810.          T = IT 
  811.          IF( LRND ) THEN 
  812.             RND = ONE 
  813.             EPS = ( BASE**( 1-IT ) ) / 2 
  814.          ELSE 
  815.             RND = ZERO 
  816.             EPS = BASE**( 1-IT ) 
  817.          END IF 
  818.          PREC = EPS*BASE 
  819.          EMIN = IMIN 
  820.          EMAX = IMAX 
  821.          SFMIN = RMIN 
  822.          SMALL = ONE / RMAX 
  823.          IF( SMALL.GE.SFMIN ) THEN 
  824. !                                                                       
  825. !           Use SMALL plus a bit, to avoid the possibility of rounding  
  826. !           causing overflow when computing  1/sfmin.                   
  827. !                                                                       
  828.             SFMIN = SMALL*( ONE+EPS ) 
  829.          END IF 
  830.       END IF 
  831. !                                                                       
  832.       IF( LSAME( CMACH, 'E' ) ) THEN 
  833.          RMACH = EPS 
  834.       ELSE IF( LSAME( CMACH, 'S' ) ) THEN 
  835.          RMACH = SFMIN 
  836.       ELSE IF( LSAME( CMACH, 'B' ) ) THEN 
  837.          RMACH = BASE 
  838.       ELSE IF( LSAME( CMACH, 'P' ) ) THEN 
  839.          RMACH = PREC 
  840.       ELSE IF( LSAME( CMACH, 'N' ) ) THEN 
  841.          RMACH = T 
  842.       ELSE IF( LSAME( CMACH, 'R' ) ) THEN 
  843.          RMACH = RND 
  844.       ELSE IF( LSAME( CMACH, 'M' ) ) THEN 
  845.          RMACH = EMIN 
  846.       ELSE IF( LSAME( CMACH, 'U' ) ) THEN 
  847.          RMACH = RMIN 
  848.       ELSE IF( LSAME( CMACH, 'L' ) ) THEN 
  849.          RMACH = EMAX 
  850.       ELSE IF( LSAME( CMACH, 'O' ) ) THEN 
  851.          RMACH = RMAX 
  852.       END IF 
  853. !                                                                       
  854.       DLAMCH = RMACH 
  855.       FIRST  = .FALSE. 
  856.       RETURN 
  857. !                                                                       
  858. !     End of DLAMCH                                                     
  859. !                                                                       
  860.       END                                           
  861. !                                                                       
  862. !***********************************************************************
  863. !                                                                       
  864.       SUBROUTINE DLAMC1( BETA, T, RND, IEEE1 ) 
  865. !                                                                       
  866. !  -- LAPACK auxiliary routine (version 3.1) --                         
  867. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  868. !     November 2006                                                     
  869. !                                                                       
  870. !     .. Scalar Arguments ..                                            
  871.       LOGICAL            IEEE1, RND 
  872.       INTEGER            BETA, T 
  873. !     ..                                                                
  874. !                                                                       
  875. !  Purpose                                                              
  876. !  =======                                                              
  877. !                                                                       
  878. !  DLAMC1 determines the machine parameters given by BETA, T, RND, and  
  879. !  IEEE1.                                                               
  880. !                                                                       
  881. !  Arguments                                                            
  882. !  =========                                                            
  883. !                                                                       
  884. !  BETA    (output) INTEGER                                             
  885. !          The base of the machine.                                     
  886. !                                                                       
  887. !  T       (output) INTEGER                                             
  888. !          The number of ( BETA ) digits in the mantissa.               
  889. !                                                                       
  890. !  RND     (output) LOGICAL                                             
  891. !          Specifies whether proper rounding  ( RND = .TRUE. )  or      
  892. !          chopping  ( RND = .FALSE. )  occurs in addition. This may not
  893. !          be a reliable guide to the way in which the machine performs 
  894. !          its arithmetic.                                              
  895. !                                                                       
  896. !  IEEE1   (output) LOGICAL                                             
  897. !          Specifies whether rounding appears to be done in the IEEE    
  898. !          'round to nearest' style.                                    
  899. !                                                                       
  900. !  Further Details                                                      
  901. !  ===============                                                      
  902. !                                                                       
  903. !  The routine is based on the routine  ENVRON  by Malcolm and          
  904. !  incorporates suggestions by Gentleman and Marovich. See              
  905. !                                                                       
  906. !     Malcolm M. A. (1972) Algorithms to reveal properties of           
  907. !        floating-point arithmetic. Comms. of the ACM, 15, 949-951.     
  908. !                                                                       
  909. !     Gentleman W. M. and Marovich S. B. (1974) More on algorithms      
  910. !        that reveal properties of floating point arithmetic units.     
  911. !        Comms. of the ACM, 17, 276-277.                                
  912. !                                                                       
  913. ! ===================================================================== 
  914. !                                                                       
  915. !     .. Local Scalars ..                                               
  916.       LOGICAL            FIRST, LIEEE1, LRND 
  917.       INTEGER            LBETA, LT 
  918.       DOUBLE PRECISION   A, B, C, F, ONE, QTR, SAVEC, T1, T2 
  919. !     ..                                                                
  920. !     .. External Functions ..                                          
  921.       DOUBLE PRECISION   DLAMC3 
  922.       EXTERNAL           DLAMC3 
  923. !     ..                                                                
  924. !     .. Save statement ..                                              
  925.       SAVE               FIRST, LIEEE1, LBETA, LRND, LT 
  926. !     ..                                                                
  927. !     .. Data statements ..                                             
  928.       DATA               FIRST / .TRUE. / 
  929. !     ..                                                                
  930. !     .. Executable Statements ..                                       
  931. !                                                                       
  932.       IF( FIRST ) THEN 
  933.          ONE = 1 
  934. !                                                                       
  935. !        LBETA,  LIEEE1,  LT and  LRND  are the  local values  of  BETA,
  936. !        IEEE1, T and RND.                                              
  937. !                                                                       
  938. !        Throughout this routine  we use the function  DLAMC3  to ensure
  939. !        that relevant values are  stored and not held in registers,  or
  940. !        are not affected by optimizers.                                
  941. !                                                                       
  942. !        Compute  a = 2.0**m  with the  smallest positive integer m such
  943. !        that                                                           
  944. !                                                                       
  945. !           fl( a + 1.0 ) = a.                                          
  946. !                                                                       
  947.          A = 1 
  948.          C = 1 
  949. !                                                                       
  950. !+       WHILE( C.EQ.ONE )LOOP                                          
  951.    10    CONTINUE 
  952.          IF( C.EQ.ONE ) THEN 
  953.             A = 2*A 
  954.             C = DLAMC3( A, ONE ) 
  955.             C = DLAMC3( C, -A ) 
  956.             GO TO 10 
  957.          END IF 
  958. !+       END WHILE                                                      
  959. !                                                                       
  960. !        Now compute  b = 2.0**m  with the smallest positive integer m  
  961. !        such that                                                      
  962. !                                                                       
  963. !           fl( a + b ) .gt. a.                                         
  964. !                                                                       
  965.          B = 1 
  966.          C = DLAMC3( A, B ) 
  967. !                                                                       
  968. !+       WHILE( C.EQ.A )LOOP                                            
  969.    20    CONTINUE 
  970.          IF( C.EQ.A ) THEN 
  971.             B = 2*B 
  972.             C = DLAMC3( A, B ) 
  973.             GO TO 20 
  974.          END IF 
  975. !+       END WHILE                                                      
  976. !                                                                       
  977. !        Now compute the base.  a and c  are neighbouring floating point
  978. !        numbers  in the  interval  ( beta**t, beta**( t + 1 ) )  and so
  979. !        their difference is beta. Adding 0.25 to c is to ensure that it
  980. !        is truncated to beta and not ( beta - 1 ).                     
  981. !                                                                       
  982.          QTR = ONE / 4 
  983.          SAVEC = C 
  984.          C = DLAMC3( C, -A ) 
  985.          LBETA = C + QTR 
  986. !                                                                       
  987. !        Now determine whether rounding or chopping occurs,  by adding a
  988. !        bit  less  than  beta/2  and a  bit  more  than  beta/2  to  a.
  989. !                                                                       
  990.          B = LBETA 
  991.          F = DLAMC3( B / 2, -B / 100 ) 
  992.          C = DLAMC3( F, A ) 
  993.          IF( C.EQ.A ) THEN 
  994.             LRND = .TRUE. 
  995.          ELSE 
  996.             LRND = .FALSE. 
  997.          END IF 
  998.          F = DLAMC3( B / 2, B / 100 ) 
  999.          C = DLAMC3( F, A ) 
  1000.          IF( ( LRND ) .AND. ( C.EQ.A ) )                                &
  1001.      &      LRND = .FALSE.                                              
  1002. !                                                                       
  1003. !        Try and decide whether rounding is done in the  IEEE  'round to
  1004. !        nearest' style. B/2 is half a unit in the last place of the two
  1005. !        numbers A and SAVEC. Furthermore, A is even, i.e. has last  bit
  1006. !        zero, and SAVEC is odd. Thus adding B/2 to A should not  change
  1007. !        A, but adding B/2 to SAVEC should change SAVEC.                
  1008. !                                                                       
  1009.          T1 = DLAMC3( B / 2, A ) 
  1010.          T2 = DLAMC3( B / 2, SAVEC ) 
  1011.          LIEEE1 = ( T1.EQ.A ) .AND. ( T2.GT.SAVEC ) .AND. LRND 
  1012. !                                                                       
  1013. !        Now find  the  mantissa, t.  It should  be the  integer part of
  1014. !        log to the base beta of a,  however it is safer to determine  t
  1015. !        by powering.  So we find t as the smallest positive integer for
  1016. !        which                                                          
  1017. !                                                                       
  1018. !           fl( beta**t + 1.0 ) = 1.0.                                  
  1019. !                                                                       
  1020.          LT = 0 
  1021.          A = 1 
  1022.          C = 1 
  1023. !                                                                       
  1024. !+       WHILE( C.EQ.ONE )LOOP                                          
  1025.    30    CONTINUE 
  1026.          IF( C.EQ.ONE ) THEN 
  1027.             LT = LT + 1 
  1028.             A = A*LBETA 
  1029.             C = DLAMC3( A, ONE ) 
  1030.             C = DLAMC3( C, -A ) 
  1031.             GO TO 30 
  1032.          END IF 
  1033. !+       END WHILE                                                      
  1034. !                                                                       
  1035.       END IF 
  1036. !                                                                       
  1037.       BETA = LBETA 
  1038.       T = LT 
  1039.       RND = LRND 
  1040.       IEEE1 = LIEEE1 
  1041.       FIRST = .FALSE. 
  1042.       RETURN 
  1043. !                                                                       
  1044. !     End of DLAMC1                                                     
  1045. !                                                                       
  1046.       END                                           
  1047. !                                                                       
  1048. !***********************************************************************
  1049. !                                                                       
  1050.       SUBROUTINE DLAMC2( BETA, T, RND, EPS, EMIN, RMIN, EMAX, RMAX ) 
  1051. !                                                                       
  1052. !  -- LAPACK auxiliary routine (version 3.1) --                         
  1053. !     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..    
  1054. !     November 2006                                                     
  1055. !                                                                       
  1056. !     .. Scalar Arguments ..                                            
  1057.       LOGICAL            RND 
  1058.       INTEGER            BETA, EMAX, EMIN, T 
  1059.       DOUBLE PRECISION   EPS, RMAX, RMIN 
  1060. !     ..                                                                
  1061. !                                                                       
  1062. !  Purpose                                                              
  1063. !  =======                                                              
  1064. !                                                                       
  1065. !  DLAMC2 determines the machine parameters specified in its argument   
  1066. !  list.                                                                
  1067. !                                                                       
  1068. !  Arguments                                                            
  1069. !  =========                                                            
  1070. !                                                                       
  1071. !  BETA    (output) INTEGER                                             
  1072. !          The base of the machine.                                     
  1073. !                                                                       
  1074. !  T       (output) INTEGER                                             
  1075. !          The number of ( BETA ) digits in the mantissa.               
  1076. !                                                                       
  1077. !  RND     (output) LOGICAL                                             
  1078. !          Specifies whether proper rounding  ( RND = .TRUE. )  or      
  1079. !          chopping  ( RND = .FALSE. )  occurs in addition. This may not
  1080. !          be a reliable guide to the way in which the machine performs 
  1081. !          its arithmetic.                                              
  1082. !                                                                       
  1083. !  EPS     (output) DOUBLE PRECISION                                    
  1084. !          The smallest positive number such that                       
  1085. !                                                                       
  1086. !             fl( 1.0 - EPS ) .LT. 1.0,                                 
  1087. !                                                                       
  1088. !          where fl denotes the computed value.                         
  1089. !                                                                       
  1090. !  EMIN    (output) INTEGER                                             
  1091. !          The minimum exponent before (gradual) underflow occurs.      
  1092. !                                                                       
  1093. !  RMIN    (output) DOUBLE PRECISION                                    
  1094. !          The smallest normalized number for the machine, given by     
  1095. !          BASE**( EMIN - 1 ), where  BASE  is the floating point value 
  1096. !          of BETA.                                                     
  1097. !                                                                       
  1098. !  EMAX    (output) INTEGER                                             
  1099. !          The maximum exponent before overflow occurs.                 
  1100. !                                                                       
  1101. !  RMAX    (output) DOUBLE PRECISION                                    
  1102. !          The largest positive number for the machine, given by        
  1103. !          BASE**EMAX * ( 1 - EPS ), where  BASE  is the floating point 
  1104. !          value of BETA.                                               
  1105. !                                                                       
  1106. !  Further Details                                                      
  1107. !  ===============                                                      
  1108. !                                                                       
  1109. !  The computation of  EPS  is based on a routine PARANOIA by           
  1110. !  W. Kahan of the University of California at Berkeley.                
  1111. !                                                                       
  1112. ! ===================================================================== 
  1113. !                                                                       
  1114. !     .. Local Scalars ..                                               
  1115.       LOGICAL            FIRST, IEEE, IWARN, LIEEE1, LRND 
  1116.       INTEGER            GNMIN, GPMIN, I, LBETA, LEMAX, LEMIN, LT,      &
  1117.      &                   NGNMIN, NGPMIN                                 
  1118.       DOUBLE PRECISION   A, B, C, HALF, LEPS, LRMAX, LRMIN, ONE, RBASE, &
  1119.      &                   SIXTH, SMALL, THIRD, TWO, ZERO                 
  1120. !     ..                                                                
  1121. !     .. External Functions ..                                          
  1122.       DOUBLE PRECISION   DLAMC3 
  1123.       EXTERNAL           DLAMC3 
  1124. !     ..                                                                
  1125. !     .. External Subroutines ..                                        
  1126.       EXTERNAL           DLAMC1, DLAMC4, DLAMC5 
  1127. !     ..                                                                
  1128. !     .. Intrinsic Functions ..                                         
  1129.       INTRINSIC          ABS, MAX, MIN 
  1130. !     ..                                                                
  1131. !     .. Save statement ..                                              
  1132.       SAVE               FIRST, IWARN, LBETA, LEMAX, LEMIN, LEPS, LRMAX,&
  1133.      &                   LRMIN, LT                                      
  1134. !     ..                                                                
  1135. !     .. Data statements ..                                             
  1136.       DATA               FIRST / .TRUE. / , IWARN / .FALSE. / 
  1137. !     ..                                                                
  1138. !     .. Executable Statements ..                                       
  1139. !                                                                       
  1140.       IF( FIRST ) THEN 
  1141.          ZERO = 0 
  1142.          ONE = 1 
  1143.          TWO = 2 
  1144. !                                                                       
  1145. !        LBETA, LT, LRND, LEPS, LEMIN and LRMIN  are the local values of
  1146. !        BETA, T, RND, EPS, EMIN and RMIN.                              
  1147. !                                                                       
  1148. !        Throughout this routine  we use the function  DLAMC3  to ensure
  1149. !        that relevant values are stored  and not held in registers,  or
  1150. !        are not affected by optimizers.                                
  1151. !                                                                       
  1152. !        DLAMC1 returns the parameters  LBETA, LT, LRND and LIEEE1.     
  1153. !                                                                       
  1154.          CALL DLAMC1( LBETA, LT, LRND, LIEEE1 ) 
  1155. !                                                                       
  1156. !        Start to find EPS.                                             
  1157. !                                                                       
  1158.          B = LBETA 
  1159.          A = B**( -LT ) 
  1160.          LEPS = A 
  1161. !                                                                       
  1162. !        Try some tricks to see whether or not this is the correct  EPS.
  1163. !                                                                       
  1164.          B = TWO / 3 
  1165.          HALF = ONE / 2 
  1166.          SIXTH = DLAMC3( B, -HALF ) 
  1167.          THIRD = DLAMC3( SIXTH, SIXTH ) 
  1168.          B = DLAMC3( THIRD, -HALF ) 
  1169.          B = DLAMC3( B, SIXTH ) 
  1170.          B = ABS( B ) 
  1171.          IF( B.LT.LEPS )                                                &
  1172.      &      B = LEPS                                                    
  1173. !                                                                       
  1174.          LEPS = 1 
  1175. !                                                                       
  1176. !+       WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP                   
  1177.    10    CONTINUE 
  1178.          IF( ( LEPS.GT.B ) .AND. ( B.GT.ZERO ) ) THEN 
  1179.             LEPS = B 
  1180.             C = DLAMC3( HALF*LEPS, ( TWO**5 )*( LEPS**2 ) ) 
  1181.             C = DLAMC3( HALF, -C ) 
  1182.             B = DLAMC3( HALF, C ) 
  1183.             C = DLAMC3( HALF, -B ) 
  1184.             B = DLAMC3( HALF, C ) 
  1185.             GO TO 10 
  1186.          END IF 
  1187. !+       END WHILE                                                      
  1188. !                                                                       
  1189.          IF( A.LT.LEPS )                                                &
  1190.      &      LEPS = A                                                    
  1191. !                                                                       
  1192. !        Computation of EPS complete.                                   
  1193. !                                                                       
  1194. !        Now find  EMIN.  Let A = + or - 1, and + or - (1 + BASE**(-3)).
  1195. !        Keep dividing  A by BETA until (gradual) underflow occurs. This
  1196. !        is detected when we cannot recover the previous A.             
  1197. !                                                                       
  1198.          RBASE = ONE / LBETA 
  1199.          SMALL = ONE 
  1200.          DO 20 I = 1, 3 
  1201.             SMALL = DLAMC3( SMALL*RBASE, ZERO ) 
  1202.    20    CONTINUE 
  1203.          A = DLAMC3( ONE, SMALL ) 
  1204.          CALL DLAMC4( NGPMIN, ONE, LBETA ) 
  1205.          CALL DLAMC4( NGNMIN, -ONE, LBETA ) 
  1206.          CALL DLAMC4( GPMIN, A, LBETA ) 
  1207.          CALL DLAMC4( GNMIN, -A, LBETA ) 
  1208.          IEEE = .FALSE. 
  1209. !                                                                       
  1210.          IF( ( NGPMIN.EQ.NGNMIN ) .AND. ( GPMIN.EQ.GNMIN ) ) THEN 
  1211.             IF( NGPMIN.EQ.GPMIN ) THEN 
  1212.                LEMIN = NGPMIN 
  1213. !            ( Non twos-complement machines, no gradual underflow;      
  1214. !              e.g.,  VAX )                                             
  1215.             ELSE IF( ( GPMIN-NGPMIN ).EQ.3 ) THEN 
  1216.                LEMIN = NGPMIN - 1 + LT 
  1217.                IEEE = .TRUE. 
  1218. !            ( Non twos-complement machines, with gradual underflow;    
  1219. !              e.g., IEEE standard followers )                          
  1220.             ELSE 
  1221.                LEMIN = MIN( NGPMIN, GPMIN ) 
  1222. !            ( A guess; no known machine )                              
  1223.                IWARN = .TRUE. 
  1224.             END IF 
  1225. !                                                                       
  1226.          ELSE IF( ( NGPMIN.EQ.GPMIN ) .AND. ( NGNMIN.EQ.GNMIN ) ) THEN 
  1227.             IF( ABS( NGPMIN-NGNMIN ).EQ.1 ) THEN 
  1228.                LEMIN = MAX( NGPMIN, NGNMIN ) 
  1229. !            ( Twos-complement machines, no gradual underflow;          
  1230. !              e.g., CYBER 205 )                                        
  1231.             ELSE 
  1232.                LEMIN = MIN( NGPMIN, NGNMIN ) 
  1233. !            ( A guess; no known machine )                              
  1234.                IWARN = .TRUE. 
  1235.             END IF 
  1236. !                                                                       
  1237.          ELSE IF( ( ABS( NGPMIN-NGNMIN ).EQ.1 ) .AND.                   &
  1238.      &            ( GPMIN.EQ.GNMIN ) ) THEN                             
  1239.             IF( ( GPMIN-MIN( NGPMIN, NGNMIN ) ).EQ.3 ) THEN 
  1240.                LEMIN = MAX( NGPMIN, NGNMIN ) - 1 + LT 
  1241. !            ( Twos-complement machines with gradual underflow;         
  1242. !              no known machine )                                       
  1243.             ELSE 
  1244.                LEMIN = MIN( NGPMIN, NGNMIN ) 
  1245. !            ( A guess; no known machine )                              
  1246.                IWARN = .TRUE. 
  1247.             END IF 
  1248. !                                                                       
  1249.          ELSE 
  1250.             LEMIN = MIN( NGPMIN, NGNMIN, GPMIN, GNMIN ) 
  1251. !         ( A guess; no known machine )                                 
  1252.             IWARN = .TRUE. 
  1253.          END IF 
  1254.          FIRST = .FALSE. 
  1255. !**                                                                     
  1256. ! Comment out this if block if EMIN is ok                               
  1257.          IF( IWARN ) THEN 
  1258.             FIRST = .TRUE. 
  1259.             WRITE( 6, FMT = 9999 )LEMIN 
  1260.          END IF 
  1261. !**                                                                     
  1262. !                                                                       
  1263. !        Assume IEEE arithmetic if we found denormalised  numbers above,
  1264. !        or if arithmetic seems to round in the  IEEE style,  determined
  1265. !        in routine DLAMC1. A true IEEE machine should have both  things
  1266. !        true; however, faulty machines may have one or the other.      
  1267. !                                                                       
  1268.          IEEE = IEEE .OR. LIEEE1 
  1269. !                                                                       
  1270. !        Compute  RMIN by successive division by  BETA. We could compute