STYLE: Remove trailing whitespace in Fortran files
[platform/upstream/lapack.git] / SRC / clanhb.f
1 *> \brief \b CLANHB returns the value of the 1-norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a Hermitian band matrix.
2 *
3 *  =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 *            http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download CLANHB + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clanhb.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clanhb.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clanhb.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 *  Definition:
19 *  ===========
20 *
21 *       REAL             FUNCTION CLANHB( NORM, UPLO, N, K, AB, LDAB,
22 *                        WORK )
23 *
24 *       .. Scalar Arguments ..
25 *       CHARACTER          NORM, UPLO
26 *       INTEGER            K, LDAB, N
27 *       ..
28 *       .. Array Arguments ..
29 *       REAL               WORK( * )
30 *       COMPLEX            AB( LDAB, * )
31 *       ..
32 *
33 *
34 *> \par Purpose:
35 *  =============
36 *>
37 *> \verbatim
38 *>
39 *> CLANHB  returns the value of the one norm,  or the Frobenius norm, or
40 *> the  infinity norm,  or the element of  largest absolute value  of an
41 *> n by n hermitian band matrix A,  with k super-diagonals.
42 *> \endverbatim
43 *>
44 *> \return CLANHB
45 *> \verbatim
46 *>
47 *>    CLANHB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
48 *>             (
49 *>             ( norm1(A),         NORM = '1', 'O' or 'o'
50 *>             (
51 *>             ( normI(A),         NORM = 'I' or 'i'
52 *>             (
53 *>             ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
54 *>
55 *> where  norm1  denotes the  one norm of a matrix (maximum column sum),
56 *> normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
57 *> normF  denotes the  Frobenius norm of a matrix (square root of sum of
58 *> squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
59 *> \endverbatim
60 *
61 *  Arguments:
62 *  ==========
63 *
64 *> \param[in] NORM
65 *> \verbatim
66 *>          NORM is CHARACTER*1
67 *>          Specifies the value to be returned in CLANHB as described
68 *>          above.
69 *> \endverbatim
70 *>
71 *> \param[in] UPLO
72 *> \verbatim
73 *>          UPLO is CHARACTER*1
74 *>          Specifies whether the upper or lower triangular part of the
75 *>          band matrix A is supplied.
76 *>          = 'U':  Upper triangular
77 *>          = 'L':  Lower triangular
78 *> \endverbatim
79 *>
80 *> \param[in] N
81 *> \verbatim
82 *>          N is INTEGER
83 *>          The order of the matrix A.  N >= 0.  When N = 0, CLANHB is
84 *>          set to zero.
85 *> \endverbatim
86 *>
87 *> \param[in] K
88 *> \verbatim
89 *>          K is INTEGER
90 *>          The number of super-diagonals or sub-diagonals of the
91 *>          band matrix A.  K >= 0.
92 *> \endverbatim
93 *>
94 *> \param[in] AB
95 *> \verbatim
96 *>          AB is COMPLEX array, dimension (LDAB,N)
97 *>          The upper or lower triangle of the hermitian band matrix A,
98 *>          stored in the first K+1 rows of AB.  The j-th column of A is
99 *>          stored in the j-th column of the array AB as follows:
100 *>          if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j;
101 *>          if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j<=i<=min(n,j+k).
102 *>          Note that the imaginary parts of the diagonal elements need
103 *>          not be set and are assumed to be zero.
104 *> \endverbatim
105 *>
106 *> \param[in] LDAB
107 *> \verbatim
108 *>          LDAB is INTEGER
109 *>          The leading dimension of the array AB.  LDAB >= K+1.
110 *> \endverbatim
111 *>
112 *> \param[out] WORK
113 *> \verbatim
114 *>          WORK is REAL array, dimension (MAX(1,LWORK)),
115 *>          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
116 *>          WORK is not referenced.
117 *> \endverbatim
118 *
119 *  Authors:
120 *  ========
121 *
122 *> \author Univ. of Tennessee
123 *> \author Univ. of California Berkeley
124 *> \author Univ. of Colorado Denver
125 *> \author NAG Ltd.
126 *
127 *> \date September 2012
128 *
129 *> \ingroup complexOTHERauxiliary
130 *
131 *  =====================================================================
132       REAL             FUNCTION CLANHB( NORM, UPLO, N, K, AB, LDAB,
133      $                 WORK )
134 *
135 *  -- LAPACK auxiliary routine (version 3.4.2) --
136 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
137 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
138 *     September 2012
139 *
140 *     .. Scalar Arguments ..
141       CHARACTER          NORM, UPLO
142       INTEGER            K, LDAB, N
143 *     ..
144 *     .. Array Arguments ..
145       REAL               WORK( * )
146       COMPLEX            AB( LDAB, * )
147 *     ..
148 *
149 * =====================================================================
150 *
151 *     .. Parameters ..
152       REAL               ONE, ZERO
153       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
154 *     ..
155 *     .. Local Scalars ..
156       INTEGER            I, J, L
157       REAL               ABSA, SCALE, SUM, VALUE
158 *     ..
159 *     .. External Functions ..
160       LOGICAL            LSAME, SISNAN
161       EXTERNAL           LSAME, SISNAN
162 *     ..
163 *     .. External Subroutines ..
164       EXTERNAL           CLASSQ
165 *     ..
166 *     .. Intrinsic Functions ..
167       INTRINSIC          ABS, MAX, MIN, REAL, SQRT
168 *     ..
169 *     .. Executable Statements ..
170 *
171       IF( N.EQ.0 ) THEN
172          VALUE = ZERO
173       ELSE IF( LSAME( NORM, 'M' ) ) THEN
174 *
175 *        Find max(abs(A(i,j))).
176 *
177          VALUE = ZERO
178          IF( LSAME( UPLO, 'U' ) ) THEN
179             DO 20 J = 1, N
180                DO 10 I = MAX( K+2-J, 1 ), K
181                   SUM = ABS( AB( I, J ) )
182                   IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
183    10          CONTINUE
184                SUM = ABS( REAL( AB( K+1, J ) ) )
185                IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
186    20       CONTINUE
187          ELSE
188             DO 40 J = 1, N
189                SUM = ABS( REAL( AB( 1, J ) ) )
190                IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
191                DO 30 I = 2, MIN( N+1-J, K+1 )
192                   SUM = ABS( AB( I, J ) )
193                   IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
194    30          CONTINUE
195    40       CONTINUE
196          END IF
197       ELSE IF( ( LSAME( NORM, 'I' ) ) .OR. ( LSAME( NORM, 'O' ) ) .OR.
198      $         ( NORM.EQ.'1' ) ) THEN
199 *
200 *        Find normI(A) ( = norm1(A), since A is hermitian).
201 *
202          VALUE = ZERO
203          IF( LSAME( UPLO, 'U' ) ) THEN
204             DO 60 J = 1, N
205                SUM = ZERO
206                L = K + 1 - J
207                DO 50 I = MAX( 1, J-K ), J - 1
208                   ABSA = ABS( AB( L+I, J ) )
209                   SUM = SUM + ABSA
210                   WORK( I ) = WORK( I ) + ABSA
211    50          CONTINUE
212                WORK( J ) = SUM + ABS( REAL( AB( K+1, J ) ) )
213    60       CONTINUE
214             DO 70 I = 1, N
215                SUM = WORK( I )
216                IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
217    70       CONTINUE
218          ELSE
219             DO 80 I = 1, N
220                WORK( I ) = ZERO
221    80       CONTINUE
222             DO 100 J = 1, N
223                SUM = WORK( J ) + ABS( REAL( AB( 1, J ) ) )
224                L = 1 - J
225                DO 90 I = J + 1, MIN( N, J+K )
226                   ABSA = ABS( AB( L+I, J ) )
227                   SUM = SUM + ABSA
228                   WORK( I ) = WORK( I ) + ABSA
229    90          CONTINUE
230                IF( VALUE .LT. SUM .OR. SISNAN( SUM ) ) VALUE = SUM
231   100       CONTINUE
232          END IF
233       ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN
234 *
235 *        Find normF(A).
236 *
237          SCALE = ZERO
238          SUM = ONE
239          IF( K.GT.0 ) THEN
240             IF( LSAME( UPLO, 'U' ) ) THEN
241                DO 110 J = 2, N
242                   CALL CLASSQ( MIN( J-1, K ), AB( MAX( K+2-J, 1 ), J ),
243      $                         1, SCALE, SUM )
244   110          CONTINUE
245                L = K + 1
246             ELSE
247                DO 120 J = 1, N - 1
248                   CALL CLASSQ( MIN( N-J, K ), AB( 2, J ), 1, SCALE,
249      $                         SUM )
250   120          CONTINUE
251                L = 1
252             END IF
253             SUM = 2*SUM
254          ELSE
255             L = 1
256          END IF
257          DO 130 J = 1, N
258             IF( REAL( AB( L, J ) ).NE.ZERO ) THEN
259                ABSA = ABS( REAL( AB( L, J ) ) )
260                IF( SCALE.LT.ABSA ) THEN
261                   SUM = ONE + SUM*( SCALE / ABSA )**2
262                   SCALE = ABSA
263                ELSE
264                   SUM = SUM + ( ABSA / SCALE )**2
265                END IF
266             END IF
267   130    CONTINUE
268          VALUE = SCALE*SQRT( SUM )
269       END IF
270 *
271       CLANHB = VALUE
272       RETURN
273 *
274 *     End of CLANHB
275 *
276       END