```001:       SUBROUTINE ZTRTRI( UPLO, DIAG, N, A, LDA, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       CHARACTER          DIAG, UPLO
009:       INTEGER            INFO, LDA, N
010: *     ..
011: *     .. Array Arguments ..
012:       COMPLEX*16         A( LDA, * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  ZTRTRI computes the inverse of a complex upper or lower triangular
019: *  matrix A.
020: *
021: *  This is the Level 3 BLAS version of the algorithm.
022: *
023: *  Arguments
024: *  =========
025: *
026: *  UPLO    (input) CHARACTER*1
027: *          = 'U':  A is upper triangular;
028: *          = 'L':  A is lower triangular.
029: *
030: *  DIAG    (input) CHARACTER*1
031: *          = 'N':  A is non-unit triangular;
032: *          = 'U':  A is unit triangular.
033: *
034: *  N       (input) INTEGER
035: *          The order of the matrix A.  N >= 0.
036: *
037: *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
038: *          On entry, the triangular matrix A.  If UPLO = 'U', the
039: *          leading N-by-N upper triangular part of the array A contains
040: *          the upper triangular matrix, and the strictly lower
041: *          triangular part of A is not referenced.  If UPLO = 'L', the
042: *          leading N-by-N lower triangular part of the array A contains
043: *          the lower triangular matrix, and the strictly upper
044: *          triangular part of A is not referenced.  If DIAG = 'U', the
045: *          diagonal elements of A are also not referenced and are
046: *          assumed to be 1.
047: *          On exit, the (triangular) inverse of the original matrix, in
048: *          the same storage format.
049: *
050: *  LDA     (input) INTEGER
051: *          The leading dimension of the array A.  LDA >= max(1,N).
052: *
053: *  INFO    (output) INTEGER
054: *          = 0: successful exit
055: *          < 0: if INFO = -i, the i-th argument had an illegal value
056: *          > 0: if INFO = i, A(i,i) is exactly zero.  The triangular
057: *               matrix is singular and its inverse can not be computed.
058: *
059: *  =====================================================================
060: *
061: *     .. Parameters ..
062:       COMPLEX*16         ONE, ZERO
063:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ),
064:      \$                   ZERO = ( 0.0D+0, 0.0D+0 ) )
065: *     ..
066: *     .. Local Scalars ..
067:       LOGICAL            NOUNIT, UPPER
068:       INTEGER            J, JB, NB, NN
069: *     ..
070: *     .. External Functions ..
071:       LOGICAL            LSAME
072:       INTEGER            ILAENV
073:       EXTERNAL           LSAME, ILAENV
074: *     ..
075: *     .. External Subroutines ..
076:       EXTERNAL           XERBLA, ZTRMM, ZTRSM, ZTRTI2
077: *     ..
078: *     .. Intrinsic Functions ..
079:       INTRINSIC          MAX, MIN
080: *     ..
081: *     .. Executable Statements ..
082: *
083: *     Test the input parameters.
084: *
085:       INFO = 0
086:       UPPER = LSAME( UPLO, 'U' )
087:       NOUNIT = LSAME( DIAG, 'N' )
088:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
089:          INFO = -1
090:       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
091:          INFO = -2
092:       ELSE IF( N.LT.0 ) THEN
093:          INFO = -3
094:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
095:          INFO = -5
096:       END IF
097:       IF( INFO.NE.0 ) THEN
098:          CALL XERBLA( 'ZTRTRI', -INFO )
099:          RETURN
100:       END IF
101: *
102: *     Quick return if possible
103: *
104:       IF( N.EQ.0 )
105:      \$   RETURN
106: *
107: *     Check for singularity if non-unit.
108: *
109:       IF( NOUNIT ) THEN
110:          DO 10 INFO = 1, N
111:             IF( A( INFO, INFO ).EQ.ZERO )
112:      \$         RETURN
113:    10    CONTINUE
114:          INFO = 0
115:       END IF
116: *
117: *     Determine the block size for this environment.
118: *
119:       NB = ILAENV( 1, 'ZTRTRI', UPLO // DIAG, N, -1, -1, -1 )
120:       IF( NB.LE.1 .OR. NB.GE.N ) THEN
121: *
122: *        Use unblocked code
123: *
124:          CALL ZTRTI2( UPLO, DIAG, N, A, LDA, INFO )
125:       ELSE
126: *
127: *        Use blocked code
128: *
129:          IF( UPPER ) THEN
130: *
131: *           Compute inverse of upper triangular matrix
132: *
133:             DO 20 J = 1, N, NB
134:                JB = MIN( NB, N-J+1 )
135: *
136: *              Compute rows 1:j-1 of current block column
137: *
138:                CALL ZTRMM( 'Left', 'Upper', 'No transpose', DIAG, J-1,
139:      \$                     JB, ONE, A, LDA, A( 1, J ), LDA )
140:                CALL ZTRSM( 'Right', 'Upper', 'No transpose', DIAG, J-1,
141:      \$                     JB, -ONE, A( J, J ), LDA, A( 1, J ), LDA )
142: *
143: *              Compute inverse of current diagonal block
144: *
145:                CALL ZTRTI2( 'Upper', DIAG, JB, A( J, J ), LDA, INFO )
146:    20       CONTINUE
147:          ELSE
148: *
149: *           Compute inverse of lower triangular matrix
150: *
151:             NN = ( ( N-1 ) / NB )*NB + 1
152:             DO 30 J = NN, 1, -NB
153:                JB = MIN( NB, N-J+1 )
154:                IF( J+JB.LE.N ) THEN
155: *
156: *                 Compute rows j+jb:n of current block column
157: *
158:                   CALL ZTRMM( 'Left', 'Lower', 'No transpose', DIAG,
159:      \$                        N-J-JB+1, JB, ONE, A( J+JB, J+JB ), LDA,
160:      \$                        A( J+JB, J ), LDA )
161:                   CALL ZTRSM( 'Right', 'Lower', 'No transpose', DIAG,
162:      \$                        N-J-JB+1, JB, -ONE, A( J, J ), LDA,
163:      \$                        A( J+JB, J ), LDA )
164:                END IF
165: *
166: *              Compute inverse of current diagonal block
167: *
168:                CALL ZTRTI2( 'Lower', DIAG, JB, A( J, J ), LDA, INFO )
169:    30       CONTINUE
170:          END IF
171:       END IF
172: *
173:       RETURN
174: *
175: *     End of ZTRTRI
176: *
177:       END
178: ```