001:       DOUBLE PRECISION FUNCTION DLANSY( NORM, UPLO, N, A, LDA, WORK )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       CHARACTER          NORM, UPLO
009:       INTEGER            LDA, N
010: *     ..
011: *     .. Array Arguments ..
012:       DOUBLE PRECISION   A( LDA, * ), WORK( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  DLANSY  returns the value of the one norm,  or the Frobenius norm, or
019: *  the  infinity norm,  or the  element of  largest absolute value  of a
020: *  real symmetric matrix A.
021: *
022: *  Description
023: *  ===========
024: *
025: *  DLANSY returns the value
026: *
027: *     DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'
028: *              (
029: *              ( norm1(A),         NORM = '1', 'O' or 'o'
030: *              (
031: *              ( normI(A),         NORM = 'I' or 'i'
032: *              (
033: *              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
034: *
035: *  where  norm1  denotes the  one norm of a matrix (maximum column sum),
036: *  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
037: *  normF  denotes the  Frobenius norm of a matrix (square root of sum of
038: *  squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
039: *
040: *  Arguments
041: *  =========
042: *
043: *  NORM    (input) CHARACTER*1
044: *          Specifies the value to be returned in DLANSY as described
045: *          above.
046: *
047: *  UPLO    (input) CHARACTER*1
048: *          Specifies whether the upper or lower triangular part of the
049: *          symmetric matrix A is to be referenced.
050: *          = 'U':  Upper triangular part of A is referenced
051: *          = 'L':  Lower triangular part of A is referenced
052: *
053: *  N       (input) INTEGER
054: *          The order of the matrix A.  N >= 0.  When N = 0, DLANSY is
055: *          set to zero.
056: *
057: *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
058: *          The symmetric matrix A.  If UPLO = 'U', the leading n by n
059: *          upper triangular part of A contains the upper triangular part
060: *          of the matrix A, and the strictly lower triangular part of A
061: *          is not referenced.  If UPLO = 'L', the leading n by n lower
062: *          triangular part of A contains the lower triangular part of
063: *          the matrix A, and the strictly upper triangular part of A is
064: *          not referenced.
065: *
066: *  LDA     (input) INTEGER
067: *          The leading dimension of the array A.  LDA >= max(N,1).
068: *
069: *  WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
070: *          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
071: *          WORK is not referenced.
072: *
073: * =====================================================================
074: *
075: *     .. Parameters ..
076:       DOUBLE PRECISION   ONE, ZERO
077:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
078: *     ..
079: *     .. Local Scalars ..
080:       INTEGER            I, J
081:       DOUBLE PRECISION   ABSA, SCALE, SUM, VALUE
082: *     ..
083: *     .. External Subroutines ..
084:       EXTERNAL           DLASSQ
085: *     ..
086: *     .. External Functions ..
087:       LOGICAL            LSAME
088:       EXTERNAL           LSAME
089: *     ..
090: *     .. Intrinsic Functions ..
091:       INTRINSIC          ABS, MAX, SQRT
092: *     ..
093: *     .. Executable Statements ..
094: *
095:       IF( N.EQ.0 ) THEN
096:          VALUE = ZERO
097:       ELSE IF( LSAME( NORM, 'M' ) ) THEN
098: *
099: *        Find max(abs(A(i,j))).
100: *
101:          VALUE = ZERO
102:          IF( LSAME( UPLO, 'U' ) ) THEN
103:             DO 20 J = 1, N
104:                DO 10 I = 1, J
105:                   VALUE = MAX( VALUE, ABS( A( I, J ) ) )
106:    10          CONTINUE
107:    20       CONTINUE
108:          ELSE
109:             DO 40 J = 1, N
110:                DO 30 I = J, N
111:                   VALUE = MAX( VALUE, ABS( A( I, J ) ) )
112:    30          CONTINUE
113:    40       CONTINUE
114:          END IF
115:       ELSE IF( ( LSAME( NORM, 'I' ) ) .OR. ( LSAME( NORM, 'O' ) ) .OR.
116:      $         ( NORM.EQ.'1' ) ) THEN
117: *
118: *        Find normI(A) ( = norm1(A), since A is symmetric).
119: *
120:          VALUE = ZERO
121:          IF( LSAME( UPLO, 'U' ) ) THEN
122:             DO 60 J = 1, N
123:                SUM = ZERO
124:                DO 50 I = 1, J - 1
125:                   ABSA = ABS( A( I, J ) )
126:                   SUM = SUM + ABSA
127:                   WORK( I ) = WORK( I ) + ABSA
128:    50          CONTINUE
129:                WORK( J ) = SUM + ABS( A( J, J ) )
130:    60       CONTINUE
131:             DO 70 I = 1, N
132:                VALUE = MAX( VALUE, WORK( I ) )
133:    70       CONTINUE
134:          ELSE
135:             DO 80 I = 1, N
136:                WORK( I ) = ZERO
137:    80       CONTINUE
138:             DO 100 J = 1, N
139:                SUM = WORK( J ) + ABS( A( J, J ) )
140:                DO 90 I = J + 1, N
141:                   ABSA = ABS( A( I, J ) )
142:                   SUM = SUM + ABSA
143:                   WORK( I ) = WORK( I ) + ABSA
144:    90          CONTINUE
145:                VALUE = MAX( VALUE, SUM )
146:   100       CONTINUE
147:          END IF
148:       ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
149: *
150: *        Find normF(A).
151: *
152:          SCALE = ZERO
153:          SUM = ONE
154:          IF( LSAME( UPLO, 'U' ) ) THEN
155:             DO 110 J = 2, N
156:                CALL DLASSQ( J-1, A( 1, J ), 1, SCALE, SUM )
157:   110       CONTINUE
158:          ELSE
159:             DO 120 J = 1, N - 1
160:                CALL DLASSQ( N-J, A( J+1, J ), 1, SCALE, SUM )
161:   120       CONTINUE
162:          END IF
163:          SUM = 2*SUM
164:          CALL DLASSQ( N, A, LDA+1, SCALE, SUM )
165:          VALUE = SCALE*SQRT( SUM )
166:       END IF
167: *
168:       DLANSY = VALUE
169:       RETURN
170: *
171: *     End of DLANSY
172: *
173:       END
174: