1*> \brief \b DSBT21
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 DSBT21( UPLO, N, KA, KS, A, LDA, D, E, U, LDU, WORK,
12*                          RESULT )
13*
14*       .. Scalar Arguments ..
15*       CHARACTER          UPLO
16*       INTEGER            KA, KS, LDA, LDU, N
17*       ..
18*       .. Array Arguments ..
19*       DOUBLE PRECISION   A( LDA, * ), D( * ), E( * ), RESULT( 2 ),
20*      $                   U( LDU, * ), WORK( * )
21*       ..
22*
23*
24*> \par Purpose:
25*  =============
26*>
27*> \verbatim
28*>
29*> DSBT21  generally checks a decomposition of the form
30*>
31*>         A = U S U'
32*>
33*> where ' means transpose, A is symmetric banded, U is
34*> orthogonal, and S is diagonal (if KS=0) or symmetric
35*> tridiagonal (if KS=1).
36*>
37*> Specifically:
38*>
39*>         RESULT(1) = | A - U S U' | / ( |A| n ulp ) *andC>         RESULT(2) = | I - UU' | / ( n ulp )
40*> \endverbatim
41*
42*  Arguments:
43*  ==========
44*
45*> \param[in] UPLO
46*> \verbatim
47*>          UPLO is CHARACTER
48*>          If UPLO='U', the upper triangle of A and V will be used and
49*>          the (strictly) lower triangle will not be referenced.
50*>          If UPLO='L', the lower triangle of A and V will be used and
51*>          the (strictly) upper triangle will not be referenced.
52*> \endverbatim
53*>
54*> \param[in] N
55*> \verbatim
56*>          N is INTEGER
57*>          The size of the matrix.  If it is zero, DSBT21 does nothing.
58*>          It must be at least zero.
59*> \endverbatim
60*>
61*> \param[in] KA
62*> \verbatim
63*>          KA is INTEGER
64*>          The bandwidth of the matrix A.  It must be at least zero.  If
65*>          it is larger than N-1, then max( 0, N-1 ) will be used.
66*> \endverbatim
67*>
68*> \param[in] KS
69*> \verbatim
70*>          KS is INTEGER
71*>          The bandwidth of the matrix S.  It may only be zero or one.
72*>          If zero, then S is diagonal, and E is not referenced.  If
73*>          one, then S is symmetric tri-diagonal.
74*> \endverbatim
75*>
76*> \param[in] A
77*> \verbatim
78*>          A is DOUBLE PRECISION array, dimension (LDA, N)
79*>          The original (unfactored) matrix.  It is assumed to be
80*>          symmetric, and only the upper (UPLO='U') or only the lower
81*>          (UPLO='L') will be referenced.
82*> \endverbatim
83*>
84*> \param[in] LDA
85*> \verbatim
86*>          LDA is INTEGER
87*>          The leading dimension of A.  It must be at least 1
88*>          and at least min( KA, N-1 ).
89*> \endverbatim
90*>
91*> \param[in] D
92*> \verbatim
93*>          D is DOUBLE PRECISION array, dimension (N)
94*>          The diagonal of the (symmetric tri-) diagonal matrix S.
95*> \endverbatim
96*>
97*> \param[in] E
98*> \verbatim
99*>          E is DOUBLE PRECISION array, dimension (N-1)
100*>          The off-diagonal of the (symmetric tri-) diagonal matrix S.
101*>          E(1) is the (1,2) and (2,1) element, E(2) is the (2,3) and
102*>          (3,2) element, etc.
103*>          Not referenced if KS=0.
104*> \endverbatim
105*>
106*> \param[in] U
107*> \verbatim
108*>          U is DOUBLE PRECISION array, dimension (LDU, N)
109*>          The orthogonal matrix in the decomposition, expressed as a
110*>          dense matrix (i.e., not as a product of Householder
111*>          transformations, Givens transformations, etc.)
112*> \endverbatim
113*>
114*> \param[in] LDU
115*> \verbatim
116*>          LDU is INTEGER
117*>          The leading dimension of U.  LDU must be at least N and
118*>          at least 1.
119*> \endverbatim
120*>
121*> \param[out] WORK
122*> \verbatim
123*>          WORK is DOUBLE PRECISION array, dimension (N**2+N)
124*> \endverbatim
125*>
126*> \param[out] RESULT
127*> \verbatim
128*>          RESULT is DOUBLE PRECISION array, dimension (2)
129*>          The values computed by the two tests described above.  The
130*>          values are currently limited to 1/ulp, to avoid overflow.
131*> \endverbatim
132*
133*  Authors:
134*  ========
135*
136*> \author Univ. of Tennessee
137*> \author Univ. of California Berkeley
138*> \author Univ. of Colorado Denver
139*> \author NAG Ltd.
140*
141*> \date November 2011
142*
143*> \ingroup double_eig
144*
145*  =====================================================================
146      SUBROUTINE DSBT21( UPLO, N, KA, KS, A, LDA, D, E, U, LDU, WORK,
147     $                   RESULT )
148*
149*  -- LAPACK test routine (version 3.4.0) --
150*  -- LAPACK is a software package provided by Univ. of Tennessee,    --
151*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
152*     November 2011
153*
154*     .. Scalar Arguments ..
155      CHARACTER          UPLO
156      INTEGER            KA, KS, LDA, LDU, N
157*     ..
158*     .. Array Arguments ..
159      DOUBLE PRECISION   A( LDA, * ), D( * ), E( * ), RESULT( 2 ),
160     $                   U( LDU, * ), WORK( * )
161*     ..
162*
163*  =====================================================================
164*
165*     .. Parameters ..
166      DOUBLE PRECISION   ZERO, ONE
167      PARAMETER          ( ZERO = 0.0D0, ONE = 1.0D0 )
168*     ..
169*     .. Local Scalars ..
170      LOGICAL            LOWER
171      CHARACTER          CUPLO
172      INTEGER            IKA, J, JC, JR, LW
173      DOUBLE PRECISION   ANORM, ULP, UNFL, WNORM
174*     ..
175*     .. External Functions ..
176      LOGICAL            LSAME
177      DOUBLE PRECISION   DLAMCH, DLANGE, DLANSB, DLANSP
178      EXTERNAL           LSAME, DLAMCH, DLANGE, DLANSB, DLANSP
179*     ..
180*     .. External Subroutines ..
181      EXTERNAL           DGEMM, DSPR, DSPR2
182*     ..
183*     .. Intrinsic Functions ..
184      INTRINSIC          DBLE, MAX, MIN
185*     ..
186*     .. Executable Statements ..
187*
188*     Constants
189*
190      RESULT( 1 ) = ZERO
191      RESULT( 2 ) = ZERO
192      IF( N.LE.0 )
193     $   RETURN
194*
195      IKA = MAX( 0, MIN( N-1, KA ) )
196      LW = ( N*( N+1 ) ) / 2
197*
198      IF( LSAME( UPLO, 'U' ) ) THEN
199         LOWER = .FALSE.
200         CUPLO = 'U'
201      ELSE
202         LOWER = .TRUE.
203         CUPLO = 'L'
204      END IF
205*
206      UNFL = DLAMCH( 'Safe minimum' )
207      ULP = DLAMCH( 'Epsilon' )*DLAMCH( 'Base' )
208*
209*     Some Error Checks
210*
211*     Do Test 1
212*
213*     Norm of A:
214*
215      ANORM = MAX( DLANSB( '1', CUPLO, N, IKA, A, LDA, WORK ), UNFL )
216*
217*     Compute error matrix:    Error = A - U S U'
218*
219*     Copy A from SB to SP storage format.
220*
221      J = 0
222      DO 50 JC = 1, N
223         IF( LOWER ) THEN
224            DO 10 JR = 1, MIN( IKA+1, N+1-JC )
225               J = J + 1
226               WORK( J ) = A( JR, JC )
227   10       CONTINUE
228            DO 20 JR = IKA + 2, N + 1 - JC
229               J = J + 1
230               WORK( J ) = ZERO
231   20       CONTINUE
232         ELSE
233            DO 30 JR = IKA + 2, JC
234               J = J + 1
235               WORK( J ) = ZERO
236   30       CONTINUE
237            DO 40 JR = MIN( IKA, JC-1 ), 0, -1
238               J = J + 1
239               WORK( J ) = A( IKA+1-JR, JC )
240   40       CONTINUE
241         END IF
242   50 CONTINUE
243*
244      DO 60 J = 1, N
245         CALL DSPR( CUPLO, N, -D( J ), U( 1, J ), 1, WORK )
246   60 CONTINUE
247*
248      IF( N.GT.1 .AND. KS.EQ.1 ) THEN
249         DO 70 J = 1, N - 1
250            CALL DSPR2( CUPLO, N, -E( J ), U( 1, J ), 1, U( 1, J+1 ), 1,
251     $                  WORK )
252   70    CONTINUE
253      END IF
254      WNORM = DLANSP( '1', CUPLO, N, WORK, WORK( LW+1 ) )
255*
256      IF( ANORM.GT.WNORM ) THEN
257         RESULT( 1 ) = ( WNORM / ANORM ) / ( N*ULP )
258      ELSE
259         IF( ANORM.LT.ONE ) THEN
260            RESULT( 1 ) = ( MIN( WNORM, N*ANORM ) / ANORM ) / ( N*ULP )
261         ELSE
262            RESULT( 1 ) = MIN( WNORM / ANORM, DBLE( N ) ) / ( N*ULP )
263         END IF
264      END IF
265*
266*     Do Test 2
267*
268*     Compute  UU' - I
269*
270      CALL DGEMM( 'N', 'C', N, N, N, ONE, U, LDU, U, LDU, ZERO, WORK,
271     $            N )
272*
273      DO 80 J = 1, N
274         WORK( ( N+1 )*( J-1 )+1 ) = WORK( ( N+1 )*( J-1 )+1 ) - ONE
275   80 CONTINUE
276*
277      RESULT( 2 ) = MIN( DLANGE( '1', N, N, WORK, N, WORK( N**2+1 ) ),
278     $              DBLE( N ) ) / ( N*ULP )
279*
280      RETURN
281*
282*     End of DSBT21
283*
284      END
285