153
154
155
156
157
158
159 CHARACTER DIAG, TRANS, UPLO
160 INTEGER INFO, LDA, LDB, N, NRHS
161
162
163 INTEGER IPIV( * )
164 COMPLEX A( LDA, * ), B( LDB, * )
165
166
167
168
169
170 COMPLEX ONE
171 parameter( one = ( 1.0e+0, 0.0e+0 ) )
172
173
174 LOGICAL NOUNIT
175 INTEGER J, K, KP
176 COMPLEX D11, D12, D21, D22, T1, T2
177
178
179 LOGICAL LSAME
181
182
184
185
186 INTRINSIC abs, conjg, max
187
188
189
190
191
192 info = 0
193 IF( .NOT.
lsame( uplo,
'U' ) .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
194 info = -1
195 ELSE IF( .NOT.
lsame( trans,
'N' ) .AND. .NOT.
lsame( trans,
'C' ) )
196 $ THEN
197 info = -2
198 ELSE IF( .NOT.
lsame( diag,
'U' ) .AND. .NOT.
lsame( diag,
'N' ) )
199 $ THEN
200 info = -3
201 ELSE IF( n.LT.0 ) THEN
202 info = -4
203 ELSE IF( lda.LT.max( 1, n ) ) THEN
204 info = -6
205 ELSE IF( ldb.LT.max( 1, n ) ) THEN
206 info = -9
207 END IF
208 IF( info.NE.0 ) THEN
209 CALL xerbla(
'CLAVHE ', -info )
210 RETURN
211 END IF
212
213
214
215 IF( n.EQ.0 )
216 $ RETURN
217
218 nounit =
lsame( diag,
'N' )
219
220
221
222
223
224 IF(
lsame( trans,
'N' ) )
THEN
225
226
227
228
229 IF(
lsame( uplo,
'U' ) )
THEN
230
231
232
233 k = 1
234 10 CONTINUE
235 IF( k.GT.n )
236 $ GO TO 30
237 IF( ipiv( k ).GT.0 ) THEN
238
239
240
241
242
243 IF( nounit )
244 $
CALL cscal( nrhs, a( k, k ), b( k, 1 ), ldb )
245
246
247
248 IF( k.GT.1 ) THEN
249
250
251
252 CALL cgeru( k-1, nrhs, one, a( 1, k ), 1, b( k, 1 ),
253 $ ldb, b( 1, 1 ), ldb )
254
255
256
257 kp = ipiv( k )
258 IF( kp.NE.k )
259 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
260 END IF
261 k = k + 1
262 ELSE
263
264
265
266
267
268 IF( nounit ) THEN
269 d11 = a( k, k )
270 d22 = a( k+1, k+1 )
271 d12 = a( k, k+1 )
272 d21 = conjg( d12 )
273 DO 20 j = 1, nrhs
274 t1 = b( k, j )
275 t2 = b( k+1, j )
276 b( k, j ) = d11*t1 + d12*t2
277 b( k+1, j ) = d21*t1 + d22*t2
278 20 CONTINUE
279 END IF
280
281
282
283 IF( k.GT.1 ) THEN
284
285
286
287 CALL cgeru( k-1, nrhs, one, a( 1, k ), 1, b( k, 1 ),
288 $ ldb, b( 1, 1 ), ldb )
289 CALL cgeru( k-1, nrhs, one, a( 1, k+1 ), 1,
290 $ b( k+1, 1 ), ldb, b( 1, 1 ), ldb )
291
292
293
294 kp = abs( ipiv( k ) )
295 IF( kp.NE.k )
296 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
297 END IF
298 k = k + 2
299 END IF
300 GO TO 10
301 30 CONTINUE
302
303
304
305
306 ELSE
307
308
309
310 k = n
311 40 CONTINUE
312 IF( k.LT.1 )
313 $ GO TO 60
314
315
316
317
318 IF( ipiv( k ).GT.0 ) THEN
319
320
321
322
323
324 IF( nounit )
325 $
CALL cscal( nrhs, a( k, k ), b( k, 1 ), ldb )
326
327
328
329 IF( k.NE.n ) THEN
330 kp = ipiv( k )
331
332
333
334 CALL cgeru( n-k, nrhs, one, a( k+1, k ), 1,
335 $ b( k, 1 ), ldb, b( k+1, 1 ), ldb )
336
337
338
339
340 IF( kp.NE.k )
341 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
342 END IF
343 k = k - 1
344
345 ELSE
346
347
348
349
350
351 IF( nounit ) THEN
352 d11 = a( k-1, k-1 )
353 d22 = a( k, k )
354 d21 = a( k, k-1 )
355 d12 = conjg( d21 )
356 DO 50 j = 1, nrhs
357 t1 = b( k-1, j )
358 t2 = b( k, j )
359 b( k-1, j ) = d11*t1 + d12*t2
360 b( k, j ) = d21*t1 + d22*t2
361 50 CONTINUE
362 END IF
363
364
365
366 IF( k.NE.n ) THEN
367
368
369
370 CALL cgeru( n-k, nrhs, one, a( k+1, k ), 1,
371 $ b( k, 1 ), ldb, b( k+1, 1 ), ldb )
372 CALL cgeru( n-k, nrhs, one, a( k+1, k-1 ), 1,
373 $ b( k-1, 1 ), ldb, b( k+1, 1 ), ldb )
374
375
376
377
378 kp = abs( ipiv( k ) )
379 IF( kp.NE.k )
380 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
381 END IF
382 k = k - 2
383 END IF
384 GO TO 40
385 60 CONTINUE
386 END IF
387
388
389
390
391
392 ELSE
393
394
395
396
397
398 IF(
lsame( uplo,
'U' ) )
THEN
399
400
401
402 k = n
403 70 IF( k.LT.1 )
404 $ GO TO 90
405
406
407
408 IF( ipiv( k ).GT.0 ) THEN
409 IF( k.GT.1 ) THEN
410
411
412
413 kp = ipiv( k )
414 IF( kp.NE.k )
415 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
416
417
418
419
420
421 CALL clacgv( nrhs, b( k, 1 ), ldb )
422 CALL cgemv(
'Conjugate', k-1, nrhs, one, b, ldb,
423 $ a( 1, k ), 1, one, b( k, 1 ), ldb )
424 CALL clacgv( nrhs, b( k, 1 ), ldb )
425 END IF
426 IF( nounit )
427 $
CALL cscal( nrhs, a( k, k ), b( k, 1 ), ldb )
428 k = k - 1
429
430
431
432 ELSE
433 IF( k.GT.2 ) THEN
434
435
436
437 kp = abs( ipiv( k ) )
438 IF( kp.NE.k-1 )
439 $
CALL cswap( nrhs, b( k-1, 1 ), ldb, b( kp, 1 ),
440 $ ldb )
441
442
443
444
445
446
447 CALL clacgv( nrhs, b( k, 1 ), ldb )
448 CALL cgemv(
'Conjugate', k-2, nrhs, one, b, ldb,
449 $ a( 1, k ), 1, one, b( k, 1 ), ldb )
450 CALL clacgv( nrhs, b( k, 1 ), ldb )
451
452 CALL clacgv( nrhs, b( k-1, 1 ), ldb )
453 CALL cgemv(
'Conjugate', k-2, nrhs, one, b, ldb,
454 $ a( 1, k-1 ), 1, one, b( k-1, 1 ), ldb )
455 CALL clacgv( nrhs, b( k-1, 1 ), ldb )
456 END IF
457
458
459
460 IF( nounit ) THEN
461 d11 = a( k-1, k-1 )
462 d22 = a( k, k )
463 d12 = a( k-1, k )
464 d21 = conjg( d12 )
465 DO 80 j = 1, nrhs
466 t1 = b( k-1, j )
467 t2 = b( k, j )
468 b( k-1, j ) = d11*t1 + d12*t2
469 b( k, j ) = d21*t1 + d22*t2
470 80 CONTINUE
471 END IF
472 k = k - 2
473 END IF
474 GO TO 70
475 90 CONTINUE
476
477
478
479
480
481 ELSE
482
483
484
485 k = 1
486 100 CONTINUE
487 IF( k.GT.n )
488 $ GO TO 120
489
490
491
492 IF( ipiv( k ).GT.0 ) THEN
493 IF( k.LT.n ) THEN
494
495
496
497 kp = ipiv( k )
498 IF( kp.NE.k )
499 $
CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
500
501
502
503 CALL clacgv( nrhs, b( k, 1 ), ldb )
504 CALL cgemv(
'Conjugate', n-k, nrhs, one, b( k+1, 1 ),
505 $ ldb, a( k+1, k ), 1, one, b( k, 1 ), ldb )
506 CALL clacgv( nrhs, b( k, 1 ), ldb )
507 END IF
508 IF( nounit )
509 $
CALL cscal( nrhs, a( k, k ), b( k, 1 ), ldb )
510 k = k + 1
511
512
513
514 ELSE
515 IF( k.LT.n-1 ) THEN
516
517
518
519 kp = abs( ipiv( k ) )
520 IF( kp.NE.k+1 )
521 $
CALL cswap( nrhs, b( k+1, 1 ), ldb, b( kp, 1 ),
522 $ ldb )
523
524
525
526 CALL clacgv( nrhs, b( k+1, 1 ), ldb )
527 CALL cgemv(
'Conjugate', n-k-1, nrhs, one,
528 $ b( k+2, 1 ), ldb, a( k+2, k+1 ), 1, one,
529 $ b( k+1, 1 ), ldb )
530 CALL clacgv( nrhs, b( k+1, 1 ), ldb )
531
532 CALL clacgv( nrhs, b( k, 1 ), ldb )
533 CALL cgemv(
'Conjugate', n-k-1, nrhs, one,
534 $ b( k+2, 1 ), ldb, a( k+2, k ), 1, one,
535 $ b( k, 1 ), ldb )
536 CALL clacgv( nrhs, b( k, 1 ), ldb )
537 END IF
538
539
540
541 IF( nounit ) THEN
542 d11 = a( k, k )
543 d22 = a( k+1, k+1 )
544 d21 = a( k+1, k )
545 d12 = conjg( d21 )
546 DO 110 j = 1, nrhs
547 t1 = b( k, j )
548 t2 = b( k+1, j )
549 b( k, j ) = d11*t1 + d12*t2
550 b( k+1, j ) = d21*t1 + d22*t2
551 110 CONTINUE
552 END IF
553 k = k + 2
554 END IF
555 GO TO 100
556 120 CONTINUE
557 END IF
558
559 END IF
560 RETURN
561
562
563
subroutine xerbla(srname, info)
subroutine cgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
CGEMV
subroutine cgeru(m, n, alpha, x, incx, y, incy, a, lda)
CGERU
subroutine clacgv(n, x, incx)
CLACGV conjugates a complex vector.
logical function lsame(ca, cb)
LSAME
subroutine cscal(n, ca, cx, incx)
CSCAL
subroutine cswap(n, cx, incx, cy, incy)
CSWAP