001:       SUBROUTINE ZPTEQR( COMPZ, N, D, E, Z, LDZ, WORK, 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          COMPZ
009:       INTEGER            INFO, LDZ, N
010: *     ..
011: *     .. Array Arguments ..
012:       DOUBLE PRECISION   D( * ), E( * ), WORK( * )
013:       COMPLEX*16         Z( LDZ, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  ZPTEQR computes all eigenvalues and, optionally, eigenvectors of a
020: *  symmetric positive definite tridiagonal matrix by first factoring the
021: *  matrix using DPTTRF and then calling ZBDSQR to compute the singular
022: *  values of the bidiagonal factor.
023: *
024: *  This routine computes the eigenvalues of the positive definite
025: *  tridiagonal matrix to high relative accuracy.  This means that if the
026: *  eigenvalues range over many orders of magnitude in size, then the
027: *  small eigenvalues and corresponding eigenvectors will be computed
028: *  more accurately than, for example, with the standard QR method.
029: *
030: *  The eigenvectors of a full or band positive definite Hermitian matrix
031: *  can also be found if ZHETRD, ZHPTRD, or ZHBTRD has been used to
032: *  reduce this matrix to tridiagonal form.  (The reduction to
033: *  tridiagonal form, however, may preclude the possibility of obtaining
034: *  high relative accuracy in the small eigenvalues of the original
035: *  matrix, if these eigenvalues range over many orders of magnitude.)
036: *
037: *  Arguments
038: *  =========
039: *
040: *  COMPZ   (input) CHARACTER*1
041: *          = 'N':  Compute eigenvalues only.
042: *          = 'V':  Compute eigenvectors of original Hermitian
043: *                  matrix also.  Array Z contains the unitary matrix
044: *                  used to reduce the original matrix to tridiagonal
045: *                  form.
046: *          = 'I':  Compute eigenvectors of tridiagonal matrix also.
047: *
048: *  N       (input) INTEGER
049: *          The order of the matrix.  N >= 0.
050: *
051: *  D       (input/output) DOUBLE PRECISION array, dimension (N)
052: *          On entry, the n diagonal elements of the tridiagonal matrix.
053: *          On normal exit, D contains the eigenvalues, in descending
054: *          order.
055: *
056: *  E       (input/output) DOUBLE PRECISION array, dimension (N-1)
057: *          On entry, the (n-1) subdiagonal elements of the tridiagonal
058: *          matrix.
059: *          On exit, E has been destroyed.
060: *
061: *  Z       (input/output) COMPLEX*16 array, dimension (LDZ, N)
062: *          On entry, if COMPZ = 'V', the unitary matrix used in the
063: *          reduction to tridiagonal form.
064: *          On exit, if COMPZ = 'V', the orthonormal eigenvectors of the
065: *          original Hermitian matrix;
066: *          if COMPZ = 'I', the orthonormal eigenvectors of the
067: *          tridiagonal matrix.
068: *          If INFO > 0 on exit, Z contains the eigenvectors associated
069: *          with only the stored eigenvalues.
070: *          If  COMPZ = 'N', then Z is not referenced.
071: *
072: *  LDZ     (input) INTEGER
073: *          The leading dimension of the array Z.  LDZ >= 1, and if
074: *          COMPZ = 'V' or 'I', LDZ >= max(1,N).
075: *
076: *  WORK    (workspace) DOUBLE PRECISION array, dimension (4*N)
077: *
078: *  INFO    (output) INTEGER
079: *          = 0:  successful exit.
080: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
081: *          > 0:  if INFO = i, and i is:
082: *                <= N  the Cholesky factorization of the matrix could
083: *                      not be performed because the i-th principal minor
084: *                      was not positive definite.
085: *                > N   the SVD algorithm failed to converge;
086: *                      if INFO = N+i, i off-diagonal elements of the
087: *                      bidiagonal factor did not converge to zero.
088: *
089: *  ====================================================================
090: *
091: *     .. Parameters ..
092:       COMPLEX*16         CZERO, CONE
093:       PARAMETER          ( CZERO = ( 0.0D+0, 0.0D+0 ),
094:      $                   CONE = ( 1.0D+0, 0.0D+0 ) )
095: *     ..
096: *     .. External Functions ..
097:       LOGICAL            LSAME
098:       EXTERNAL           LSAME
099: *     ..
100: *     .. External Subroutines ..
101:       EXTERNAL           DPTTRF, XERBLA, ZBDSQR, ZLASET
102: *     ..
103: *     .. Local Arrays ..
104:       COMPLEX*16         C( 1, 1 ), VT( 1, 1 )
105: *     ..
106: *     .. Local Scalars ..
107:       INTEGER            I, ICOMPZ, NRU
108: *     ..
109: *     .. Intrinsic Functions ..
110:       INTRINSIC          MAX, SQRT
111: *     ..
112: *     .. Executable Statements ..
113: *
114: *     Test the input parameters.
115: *
116:       INFO = 0
117: *
118:       IF( LSAME( COMPZ, 'N' ) ) THEN
119:          ICOMPZ = 0
120:       ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
121:          ICOMPZ = 1
122:       ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
123:          ICOMPZ = 2
124:       ELSE
125:          ICOMPZ = -1
126:       END IF
127:       IF( ICOMPZ.LT.0 ) THEN
128:          INFO = -1
129:       ELSE IF( N.LT.0 ) THEN
130:          INFO = -2
131:       ELSE IF( ( LDZ.LT.1 ) .OR. ( ICOMPZ.GT.0 .AND. LDZ.LT.MAX( 1,
132:      $         N ) ) ) THEN
133:          INFO = -6
134:       END IF
135:       IF( INFO.NE.0 ) THEN
136:          CALL XERBLA( 'ZPTEQR', -INFO )
137:          RETURN
138:       END IF
139: *
140: *     Quick return if possible
141: *
142:       IF( N.EQ.0 )
143:      $   RETURN
144: *
145:       IF( N.EQ.1 ) THEN
146:          IF( ICOMPZ.GT.0 )
147:      $      Z( 1, 1 ) = CONE
148:          RETURN
149:       END IF
150:       IF( ICOMPZ.EQ.2 )
151:      $   CALL ZLASET( 'Full', N, N, CZERO, CONE, Z, LDZ )
152: *
153: *     Call DPTTRF to factor the matrix.
154: *
155:       CALL DPTTRF( N, D, E, INFO )
156:       IF( INFO.NE.0 )
157:      $   RETURN
158:       DO 10 I = 1, N
159:          D( I ) = SQRT( D( I ) )
160:    10 CONTINUE
161:       DO 20 I = 1, N - 1
162:          E( I ) = E( I )*D( I )
163:    20 CONTINUE
164: *
165: *     Call ZBDSQR to compute the singular values/vectors of the
166: *     bidiagonal factor.
167: *
168:       IF( ICOMPZ.GT.0 ) THEN
169:          NRU = N
170:       ELSE
171:          NRU = 0
172:       END IF
173:       CALL ZBDSQR( 'Lower', N, 0, NRU, 0, D, E, VT, 1, Z, LDZ, C, 1,
174:      $             WORK, INFO )
175: *
176: *     Square the singular values.
177: *
178:       IF( INFO.EQ.0 ) THEN
179:          DO 30 I = 1, N
180:             D( I ) = D( I )*D( I )
181:    30    CONTINUE
182:       ELSE
183:          INFO = N + INFO
184:       END IF
185: *
186:       RETURN
187: *
188: *     End of ZPTEQR
189: *
190:       END
191: