1*> \brief \b CSPT03
2*
3*  =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6*            http://www.netlib.org/lapack/explore-html/
7*
8*  Definition:
9*  ===========
10*
11*       SUBROUTINE CSPT03( UPLO, N, A, AINV, WORK, LDW, RWORK, RCOND,
12*                          RESID )
13*
14*       .. Scalar Arguments ..
15*       CHARACTER          UPLO
16*       INTEGER            LDW, N
17*       REAL               RCOND, RESID
18*       ..
19*       .. Array Arguments ..
20*       REAL               RWORK( * )
21*       COMPLEX            A( * ), AINV( * ), WORK( LDW, * )
22*       ..
23*
24*
25*> \par Purpose:
26*  =============
27*>
28*> \verbatim
29*>
30*> CSPT03 computes the residual for a complex symmetric packed matrix
31*> times its inverse:
32*>    norm( I - A*AINV ) / ( N * norm(A) * norm(AINV) * EPS ),
33*> where EPS is the machine epsilon.
34*> \endverbatim
35*
36*  Arguments:
37*  ==========
38*
39*> \param[in] UPLO
40*> \verbatim
41*>          UPLO is CHARACTER*1
42*>          Specifies whether the upper or lower triangular part of the
43*>          complex symmetric matrix A is stored:
44*>          = 'U':  Upper triangular
45*>          = 'L':  Lower triangular
46*> \endverbatim
47*>
48*> \param[in] N
49*> \verbatim
50*>          N is INTEGER
51*>          The number of rows and columns of the matrix A.  N >= 0.
52*> \endverbatim
53*>
54*> \param[in] A
55*> \verbatim
56*>          A is COMPLEX array, dimension (N*(N+1)/2)
57*>          The original complex symmetric matrix A, stored as a packed
58*>          triangular matrix.
59*> \endverbatim
60*>
61*> \param[in] AINV
62*> \verbatim
63*>          AINV is COMPLEX array, dimension (N*(N+1)/2)
64*>          The (symmetric) inverse of the matrix A, stored as a packed
65*>          triangular matrix.
66*> \endverbatim
67*>
68*> \param[out] WORK
69*> \verbatim
70*>          WORK is COMPLEX array, dimension (LDW,N)
71*> \endverbatim
72*>
73*> \param[in] LDW
74*> \verbatim
75*>          LDW is INTEGER
76*>          The leading dimension of the array WORK.  LDW >= max(1,N).
77*> \endverbatim
78*>
79*> \param[out] RWORK
80*> \verbatim
81*>          RWORK is REAL array, dimension (N)
82*> \endverbatim
83*>
84*> \param[out] RCOND
85*> \verbatim
86*>          RCOND is REAL
87*>          The reciprocal of the condition number of A, computed as
88*>          ( 1/norm(A) ) / norm(AINV).
89*> \endverbatim
90*>
91*> \param[out] RESID
92*> \verbatim
93*>          RESID is REAL
94*>          norm(I - A*AINV) / ( N * norm(A) * norm(AINV) * EPS )
95*> \endverbatim
96*
97*  Authors:
98*  ========
99*
100*> \author Univ. of Tennessee
101*> \author Univ. of California Berkeley
102*> \author Univ. of Colorado Denver
103*> \author NAG Ltd.
104*
105*> \ingroup complex_lin
106*
107*  =====================================================================
108      SUBROUTINE CSPT03( UPLO, N, A, AINV, WORK, LDW, RWORK, RCOND,
109     $                   RESID )
110*
111*  -- LAPACK test routine --
112*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
113*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
114*
115*     .. Scalar Arguments ..
116      CHARACTER          UPLO
117      INTEGER            LDW, N
118      REAL               RCOND, RESID
119*     ..
120*     .. Array Arguments ..
121      REAL               RWORK( * )
122      COMPLEX            A( * ), AINV( * ), WORK( LDW, * )
123*     ..
124*
125*  =====================================================================
126*
127*     .. Parameters ..
128      REAL               ZERO, ONE
129      PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
130*     ..
131*     .. Local Scalars ..
132      INTEGER            I, ICOL, J, JCOL, K, KCOL, NALL
133      REAL               AINVNM, ANORM, EPS
134      COMPLEX            T
135*     ..
136*     .. External Functions ..
137      LOGICAL            LSAME
138      REAL               CLANGE, CLANSP, SLAMCH
139      COMPLEX            CDOTU
140      EXTERNAL           LSAME, CLANGE, CLANSP, SLAMCH, CDOTU
141*     ..
142*     .. Intrinsic Functions ..
143      INTRINSIC          REAL
144*     ..
145*     .. Executable Statements ..
146*
147*     Quick exit if N = 0.
148*
149      IF( N.LE.0 ) THEN
150         RCOND = ONE
151         RESID = ZERO
152         RETURN
153      END IF
154*
155*     Exit with RESID = 1/EPS if ANORM = 0 or AINVNM = 0.
156*
157      EPS = SLAMCH( 'Epsilon' )
158      ANORM = CLANSP( '1', UPLO, N, A, RWORK )
159      AINVNM = CLANSP( '1', UPLO, N, AINV, RWORK )
160      IF( ANORM.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN
161         RCOND = ZERO
162         RESID = ONE / EPS
163         RETURN
164      END IF
165      RCOND = ( ONE/ANORM ) / AINVNM
166*
167*     Case where both A and AINV are upper triangular:
168*     Each element of - A * AINV is computed by taking the dot product
169*     of a row of A with a column of AINV.
170*
171      IF( LSAME( UPLO, 'U' ) ) THEN
172         DO 70 I = 1, N
173            ICOL = ( ( I-1 )*I ) / 2 + 1
174*
175*           Code when J <= I
176*
177            DO 30 J = 1, I
178               JCOL = ( ( J-1 )*J ) / 2 + 1
179               T = CDOTU( J, A( ICOL ), 1, AINV( JCOL ), 1 )
180               JCOL = JCOL + 2*J - 1
181               KCOL = ICOL - 1
182               DO 10 K = J + 1, I
183                  T = T + A( KCOL+K )*AINV( JCOL )
184                  JCOL = JCOL + K
185   10          CONTINUE
186               KCOL = KCOL + 2*I
187               DO 20 K = I + 1, N
188                  T = T + A( KCOL )*AINV( JCOL )
189                  KCOL = KCOL + K
190                  JCOL = JCOL + K
191   20          CONTINUE
192               WORK( I, J ) = -T
193   30       CONTINUE
194*
195*           Code when J > I
196*
197            DO 60 J = I + 1, N
198               JCOL = ( ( J-1 )*J ) / 2 + 1
199               T = CDOTU( I, A( ICOL ), 1, AINV( JCOL ), 1 )
200               JCOL = JCOL - 1
201               KCOL = ICOL + 2*I - 1
202               DO 40 K = I + 1, J
203                  T = T + A( KCOL )*AINV( JCOL+K )
204                  KCOL = KCOL + K
205   40          CONTINUE
206               JCOL = JCOL + 2*J
207               DO 50 K = J + 1, N
208                  T = T + A( KCOL )*AINV( JCOL )
209                  KCOL = KCOL + K
210                  JCOL = JCOL + K
211   50          CONTINUE
212               WORK( I, J ) = -T
213   60       CONTINUE
214   70    CONTINUE
215      ELSE
216*
217*        Case where both A and AINV are lower triangular
218*
219         NALL = ( N*( N+1 ) ) / 2
220         DO 140 I = 1, N
221*
222*           Code when J <= I
223*
224            ICOL = NALL - ( ( N-I+1 )*( N-I+2 ) ) / 2 + 1
225            DO 100 J = 1, I
226               JCOL = NALL - ( ( N-J )*( N-J+1 ) ) / 2 - ( N-I )
227               T = CDOTU( N-I+1, A( ICOL ), 1, AINV( JCOL ), 1 )
228               KCOL = I
229               JCOL = J
230               DO 80 K = 1, J - 1
231                  T = T + A( KCOL )*AINV( JCOL )
232                  JCOL = JCOL + N - K
233                  KCOL = KCOL + N - K
234   80          CONTINUE
235               JCOL = JCOL - J
236               DO 90 K = J, I - 1
237                  T = T + A( KCOL )*AINV( JCOL+K )
238                  KCOL = KCOL + N - K
239   90          CONTINUE
240               WORK( I, J ) = -T
241  100       CONTINUE
242*
243*           Code when J > I
244*
245            ICOL = NALL - ( ( N-I )*( N-I+1 ) ) / 2
246            DO 130 J = I + 1, N
247               JCOL = NALL - ( ( N-J+1 )*( N-J+2 ) ) / 2 + 1
248               T = CDOTU( N-J+1, A( ICOL-N+J ), 1, AINV( JCOL ), 1 )
249               KCOL = I
250               JCOL = J
251               DO 110 K = 1, I - 1
252                  T = T + A( KCOL )*AINV( JCOL )
253                  JCOL = JCOL + N - K
254                  KCOL = KCOL + N - K
255  110          CONTINUE
256               KCOL = KCOL - I
257               DO 120 K = I, J - 1
258                  T = T + A( KCOL+K )*AINV( JCOL )
259                  JCOL = JCOL + N - K
260  120          CONTINUE
261               WORK( I, J ) = -T
262  130       CONTINUE
263  140    CONTINUE
264      END IF
265*
266*     Add the identity matrix to WORK .
267*
268      DO 150 I = 1, N
269         WORK( I, I ) = WORK( I, I ) + ONE
270  150 CONTINUE
271*
272*     Compute norm(I - A*AINV) / (N * norm(A) * norm(AINV) * EPS)
273*
274      RESID = CLANGE( '1', N, N, WORK, LDW, RWORK )
275*
276      RESID = ( ( RESID*RCOND )/EPS ) / REAL( N )
277*
278      RETURN
279*
280*     End of CSPT03
281*
282      END
283