001:       DOUBLE PRECISION FUNCTION DLANSP( NORM, UPLO, N, AP, 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            N
010: *     ..
011: *     .. Array Arguments ..
012:       DOUBLE PRECISION   AP( * ), WORK( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  DLANSP  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,  supplied in packed form.
021: *
022: *  Description
023: *  ===========
024: *
025: *  DLANSP returns the value
026: *
027: *     DLANSP = ( 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 DLANSP 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 supplied.
050: *          = 'U':  Upper triangular part of A is supplied
051: *          = 'L':  Lower triangular part of A is supplied
052: *
053: *  N       (input) INTEGER
054: *          The order of the matrix A.  N >= 0.  When N = 0, DLANSP is
055: *          set to zero.
056: *
057: *  AP      (input) DOUBLE PRECISION array, dimension (N*(N+1)/2)
058: *          The upper or lower triangle of the symmetric matrix A, packed
059: *          columnwise in a linear array.  The j-th column of A is stored
060: *          in the array AP as follows:
061: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
062: *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
063: *
064: *  WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
065: *          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
066: *          WORK is not referenced.
067: *
068: * =====================================================================
069: *
070: *     .. Parameters ..
071:       DOUBLE PRECISION   ONE, ZERO
072:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
073: *     ..
074: *     .. Local Scalars ..
075:       INTEGER            I, J, K
076:       DOUBLE PRECISION   ABSA, SCALE, SUM, VALUE
077: *     ..
078: *     .. External Subroutines ..
079:       EXTERNAL           DLASSQ
080: *     ..
081: *     .. External Functions ..
082:       LOGICAL            LSAME
083:       EXTERNAL           LSAME
084: *     ..
085: *     .. Intrinsic Functions ..
086:       INTRINSIC          ABS, MAX, SQRT
087: *     ..
088: *     .. Executable Statements ..
089: *
090:       IF( N.EQ.0 ) THEN
091:          VALUE = ZERO
092:       ELSE IF( LSAME( NORM, 'M' ) ) THEN
093: *
094: *        Find max(abs(A(i,j))).
095: *
096:          VALUE = ZERO
097:          IF( LSAME( UPLO, 'U' ) ) THEN
098:             K = 1
099:             DO 20 J = 1, N
100:                DO 10 I = K, K + J - 1
101:                   VALUE = MAX( VALUE, ABS( AP( I ) ) )
102:    10          CONTINUE
103:                K = K + J
104:    20       CONTINUE
105:          ELSE
106:             K = 1
107:             DO 40 J = 1, N
108:                DO 30 I = K, K + N - J
109:                   VALUE = MAX( VALUE, ABS( AP( I ) ) )
110:    30          CONTINUE
111:                K = K + N - J + 1
112:    40       CONTINUE
113:          END IF
114:       ELSE IF( ( LSAME( NORM, 'I' ) ) .OR. ( LSAME( NORM, 'O' ) ) .OR.
115:      $         ( NORM.EQ.'1' ) ) THEN
116: *
117: *        Find normI(A) ( = norm1(A), since A is symmetric).
118: *
119:          VALUE = ZERO
120:          K = 1
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( AP( K ) )
126:                   SUM = SUM + ABSA
127:                   WORK( I ) = WORK( I ) + ABSA
128:                   K = K + 1
129:    50          CONTINUE
130:                WORK( J ) = SUM + ABS( AP( K ) )
131:                K = K + 1
132:    60       CONTINUE
133:             DO 70 I = 1, N
134:                VALUE = MAX( VALUE, WORK( I ) )
135:    70       CONTINUE
136:          ELSE
137:             DO 80 I = 1, N
138:                WORK( I ) = ZERO
139:    80       CONTINUE
140:             DO 100 J = 1, N
141:                SUM = WORK( J ) + ABS( AP( K ) )
142:                K = K + 1
143:                DO 90 I = J + 1, N
144:                   ABSA = ABS( AP( K ) )
145:                   SUM = SUM + ABSA
146:                   WORK( I ) = WORK( I ) + ABSA
147:                   K = K + 1
148:    90          CONTINUE
149:                VALUE = MAX( VALUE, SUM )
150:   100       CONTINUE
151:          END IF
152:       ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
153: *
154: *        Find normF(A).
155: *
156:          SCALE = ZERO
157:          SUM = ONE
158:          K = 2
159:          IF( LSAME( UPLO, 'U' ) ) THEN
160:             DO 110 J = 2, N
161:                CALL DLASSQ( J-1, AP( K ), 1, SCALE, SUM )
162:                K = K + J
163:   110       CONTINUE
164:          ELSE
165:             DO 120 J = 1, N - 1
166:                CALL DLASSQ( N-J, AP( K ), 1, SCALE, SUM )
167:                K = K + N - J + 1
168:   120       CONTINUE
169:          END IF
170:          SUM = 2*SUM
171:          K = 1
172:          DO 130 I = 1, N
173:             IF( AP( K ).NE.ZERO ) THEN
174:                ABSA = ABS( AP( K ) )
175:                IF( SCALE.LT.ABSA ) THEN
176:                   SUM = ONE + SUM*( SCALE / ABSA )**2
177:                   SCALE = ABSA
178:                ELSE
179:                   SUM = SUM + ( ABSA / SCALE )**2
180:                END IF
181:             END IF
182:             IF( LSAME( UPLO, 'U' ) ) THEN
183:                K = K + I + 1
184:             ELSE
185:                K = K + N - I + 1
186:             END IF
187:   130    CONTINUE
188:          VALUE = SCALE*SQRT( SUM )
189:       END IF
190: *
191:       DLANSP = VALUE
192:       RETURN
193: *
194: *     End of DLANSP
195: *
196:       END
197: