1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
|
*> \brief \b STRSYL
*
* =========== DOCUMENTATION ===========
*
* Online html documentation available at
* http://www.netlib.org/lapack/explore-html/
*
*> \htmlonly
*> Download STRSYL + dependencies
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/strsyl.f">
*> [TGZ]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/strsyl.f">
*> [ZIP]</a>
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/strsyl.f">
*> [TXT]</a>
*> \endhtmlonly
*
* Definition:
* ===========
*
* SUBROUTINE STRSYL( TRANA, TRANB, ISGN, M, N, A, LDA, B, LDB, C,
* LDC, SCALE, INFO )
*
* .. Scalar Arguments ..
* CHARACTER TRANA, TRANB
* INTEGER INFO, ISGN, LDA, LDB, LDC, M, N
* REAL SCALE
* ..
* .. Array Arguments ..
* REAL A( LDA, * ), B( LDB, * ), C( LDC, * )
* ..
*
*
*> \par Purpose:
* =============
*>
*> \verbatim
*>
*> STRSYL solves the real Sylvester matrix equation:
*>
*> op(A)*X + X*op(B) = scale*C or
*> op(A)*X - X*op(B) = scale*C,
*>
*> where op(A) = A or A**T, and A and B are both upper quasi-
*> triangular. A is M-by-M and B is N-by-N; the right hand side C and
*> the solution X are M-by-N; and scale is an output scale factor, set
*> <= 1 to avoid overflow in X.
*>
*> A and B must be in Schur canonical form (as returned by SHSEQR), that
*> is, block upper triangular with 1-by-1 and 2-by-2 diagonal blocks;
*> each 2-by-2 diagonal block has its diagonal elements equal and its
*> off-diagonal elements of opposite sign.
*> \endverbatim
*
* Arguments:
* ==========
*
*> \param[in] TRANA
*> \verbatim
*> TRANA is CHARACTER*1
*> Specifies the option op(A):
*> = 'N': op(A) = A (No transpose)
*> = 'T': op(A) = A**T (Transpose)
*> = 'C': op(A) = A**H (Conjugate transpose = Transpose)
*> \endverbatim
*>
*> \param[in] TRANB
*> \verbatim
*> TRANB is CHARACTER*1
*> Specifies the option op(B):
*> = 'N': op(B) = B (No transpose)
*> = 'T': op(B) = B**T (Transpose)
*> = 'C': op(B) = B**H (Conjugate transpose = Transpose)
*> \endverbatim
*>
*> \param[in] ISGN
*> \verbatim
*> ISGN is INTEGER
*> Specifies the sign in the equation:
*> = +1: solve op(A)*X + X*op(B) = scale*C
*> = -1: solve op(A)*X - X*op(B) = scale*C
*> \endverbatim
*>
*> \param[in] M
*> \verbatim
*> M is INTEGER
*> The order of the matrix A, and the number of rows in the
*> matrices X and C. M >= 0.
*> \endverbatim
*>
*> \param[in] N
*> \verbatim
*> N is INTEGER
*> The order of the matrix B, and the number of columns in the
*> matrices X and C. N >= 0.
*> \endverbatim
*>
*> \param[in] A
*> \verbatim
*> A is REAL array, dimension (LDA,M)
*> The upper quasi-triangular matrix A, in Schur canonical form.
*> \endverbatim
*>
*> \param[in] LDA
*> \verbatim
*> LDA is INTEGER
*> The leading dimension of the array A. LDA >= max(1,M).
*> \endverbatim
*>
*> \param[in] B
*> \verbatim
*> B is REAL array, dimension (LDB,N)
*> The upper quasi-triangular matrix B, in Schur canonical form.
*> \endverbatim
*>
*> \param[in] LDB
*> \verbatim
*> LDB is INTEGER
*> The leading dimension of the array B. LDB >= max(1,N).
*> \endverbatim
*>
*> \param[in,out] C
*> \verbatim
*> C is REAL array, dimension (LDC,N)
*> On entry, the M-by-N right hand side matrix C.
*> On exit, C is overwritten by the solution matrix X.
*> \endverbatim
*>
*> \param[in] LDC
*> \verbatim
*> LDC is INTEGER
*> The leading dimension of the array C. LDC >= max(1,M)
*> \endverbatim
*>
*> \param[out] SCALE
*> \verbatim
*> SCALE is REAL
*> The scale factor, scale, set <= 1 to avoid overflow in X.
*> \endverbatim
*>
*> \param[out] INFO
*> \verbatim
*> INFO is INTEGER
*> = 0: successful exit
*> < 0: if INFO = -i, the i-th argument had an illegal value
*> = 1: A and B have common or very close eigenvalues; perturbed
*> values were used to solve the equation (but the matrices
*> A and B are unchanged).
*> \endverbatim
*
* Authors:
* ========
*
*> \author Univ. of Tennessee
*> \author Univ. of California Berkeley
*> \author Univ. of Colorado Denver
*> \author NAG Ltd.
*
*> \date November 2011
*
*> \ingroup realSYcomputational
*
* =====================================================================
SUBROUTINE STRSYL( TRANA, TRANB, ISGN, M, N, A, LDA, B, LDB, C,
$ LDC, SCALE, INFO )
*
* -- LAPACK computational routine (version 3.4.0) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2011
*
* .. Scalar Arguments ..
CHARACTER TRANA, TRANB
INTEGER INFO, ISGN, LDA, LDB, LDC, M, N
REAL SCALE
* ..
* .. Array Arguments ..
REAL A( LDA, * ), B( LDB, * ), C( LDC, * )
* ..
*
* =====================================================================
*
* .. Parameters ..
REAL ZERO, ONE
PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
* ..
* .. Local Scalars ..
LOGICAL NOTRNA, NOTRNB
INTEGER IERR, J, K, K1, K2, KNEXT, L, L1, L2, LNEXT
REAL A11, BIGNUM, DA11, DB, EPS, SCALOC, SGN, SMIN,
$ SMLNUM, SUML, SUMR, XNORM
* ..
* .. Local Arrays ..
REAL DUM( 1 ), VEC( 2, 2 ), X( 2, 2 )
* ..
* .. External Functions ..
LOGICAL LSAME
REAL SDOT, SLAMCH, SLANGE
EXTERNAL LSAME, SDOT, SLAMCH, SLANGE
* ..
* .. External Subroutines ..
EXTERNAL SLABAD, SLALN2, SLASY2, SSCAL, XERBLA
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, MAX, MIN, REAL
* ..
* .. Executable Statements ..
*
* Decode and Test input parameters
*
NOTRNA = LSAME( TRANA, 'N' )
NOTRNB = LSAME( TRANB, 'N' )
*
INFO = 0
IF( .NOT.NOTRNA .AND. .NOT.LSAME( TRANA, 'T' ) .AND. .NOT.
$ LSAME( TRANA, 'C' ) ) THEN
INFO = -1
ELSE IF( .NOT.NOTRNB .AND. .NOT.LSAME( TRANB, 'T' ) .AND. .NOT.
$ LSAME( TRANB, 'C' ) ) THEN
INFO = -2
ELSE IF( ISGN.NE.1 .AND. ISGN.NE.-1 ) THEN
INFO = -3
ELSE IF( M.LT.0 ) THEN
INFO = -4
ELSE IF( N.LT.0 ) THEN
INFO = -5
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
INFO = -7
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -9
ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
INFO = -11
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'STRSYL', -INFO )
RETURN
END IF
*
* Quick return if possible
*
SCALE = ONE
IF( M.EQ.0 .OR. N.EQ.0 )
$ RETURN
*
* Set constants to control overflow
*
EPS = SLAMCH( 'P' )
SMLNUM = SLAMCH( 'S' )
BIGNUM = ONE / SMLNUM
CALL SLABAD( SMLNUM, BIGNUM )
SMLNUM = SMLNUM*REAL( M*N ) / EPS
BIGNUM = ONE / SMLNUM
*
SMIN = MAX( SMLNUM, EPS*SLANGE( 'M', M, M, A, LDA, DUM ),
$ EPS*SLANGE( 'M', N, N, B, LDB, DUM ) )
*
SGN = ISGN
*
IF( NOTRNA .AND. NOTRNB ) THEN
*
* Solve A*X + ISGN*X*B = scale*C.
*
* The (K,L)th block of X is determined starting from
* bottom-left corner column by column by
*
* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L)
*
* Where
* M L-1
* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)].
* I=K+1 J=1
*
* Start column loop (index = L)
* L1 (L2) : column index of the first (first) row of X(K,L).
*
LNEXT = 1
DO 70 L = 1, N
IF( L.LT.LNEXT )
$ GO TO 70
IF( L.EQ.N ) THEN
L1 = L
L2 = L
ELSE
IF( B( L+1, L ).NE.ZERO ) THEN
L1 = L
L2 = L + 1
LNEXT = L + 2
ELSE
L1 = L
L2 = L
LNEXT = L + 1
END IF
END IF
*
* Start row loop (index = K)
* K1 (K2): row index of the first (last) row of X(K,L).
*
KNEXT = M
DO 60 K = M, 1, -1
IF( K.GT.KNEXT )
$ GO TO 60
IF( K.EQ.1 ) THEN
K1 = K
K2 = K
ELSE
IF( A( K, K-1 ).NE.ZERO ) THEN
K1 = K - 1
K2 = K
KNEXT = K - 2
ELSE
K1 = K
K2 = K
KNEXT = K - 1
END IF
END IF
*
IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
SUML = SDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
$ C( MIN( K1+1, M ), L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
SCALOC = ONE
*
A11 = A( K1, K1 ) + SGN*B( L1, L1 )
DA11 = ABS( A11 )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( VEC( 1, 1 ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
*
IF( SCALOC.NE.ONE ) THEN
DO 10 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
10 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
*
ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
CALL SLALN2( .FALSE., 2, 1, SMIN, ONE, A( K1, K1 ),
$ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 20 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
20 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K2, L1 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
*
SUML = SDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
$ C( MIN( K1+1, M ), L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
*
SUML = SDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
$ C( MIN( K1+1, M ), L2 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
*
CALL SLALN2( .TRUE., 2, 1, SMIN, ONE, B( L1, L1 ),
$ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 40 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
40 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L2 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L2 ), 1 )
SUMR = SDOT( L1-1, C( K2, 1 ), LDC, B( 1, L2 ), 1 )
VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
*
CALL SLASY2( .FALSE., .FALSE., ISGN, 2, 2,
$ A( K1, K1 ), LDA, B( L1, L1 ), LDB, VEC,
$ 2, SCALOC, X, 2, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 50 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
50 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 1, 2 )
C( K2, L1 ) = X( 2, 1 )
C( K2, L2 ) = X( 2, 2 )
END IF
*
60 CONTINUE
*
70 CONTINUE
*
ELSE IF( .NOT.NOTRNA .AND. NOTRNB ) THEN
*
* Solve A**T *X + ISGN*X*B = scale*C.
*
* The (K,L)th block of X is determined starting from
* upper-left corner column by column by
*
* A(K,K)**T*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L)
*
* Where
* K-1 L-1
* R(K,L) = SUM [A(I,K)**T*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)]
* I=1 J=1
*
* Start column loop (index = L)
* L1 (L2): column index of the first (last) row of X(K,L)
*
LNEXT = 1
DO 130 L = 1, N
IF( L.LT.LNEXT )
$ GO TO 130
IF( L.EQ.N ) THEN
L1 = L
L2 = L
ELSE
IF( B( L+1, L ).NE.ZERO ) THEN
L1 = L
L2 = L + 1
LNEXT = L + 2
ELSE
L1 = L
L2 = L
LNEXT = L + 1
END IF
END IF
*
* Start row loop (index = K)
* K1 (K2): row index of the first (last) row of X(K,L)
*
KNEXT = 1
DO 120 K = 1, M
IF( K.LT.KNEXT )
$ GO TO 120
IF( K.EQ.M ) THEN
K1 = K
K2 = K
ELSE
IF( A( K+1, K ).NE.ZERO ) THEN
K1 = K
K2 = K + 1
KNEXT = K + 2
ELSE
K1 = K
K2 = K
KNEXT = K + 1
END IF
END IF
*
IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
SCALOC = ONE
*
A11 = A( K1, K1 ) + SGN*B( L1, L1 )
DA11 = ABS( A11 )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( VEC( 1, 1 ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
*
IF( SCALOC.NE.ONE ) THEN
DO 80 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
80 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
*
ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
CALL SLALN2( .TRUE., 2, 1, SMIN, ONE, A( K1, K1 ),
$ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 90 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
90 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K2, L1 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
*
CALL SLALN2( .TRUE., 2, 1, SMIN, ONE, B( L1, L1 ),
$ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 100 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
100 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
SUMR = SDOT( L1-1, C( K1, 1 ), LDC, B( 1, L2 ), 1 )
VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( L1-1, C( K2, 1 ), LDC, B( 1, L1 ), 1 )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K2 ), 1, C( 1, L2 ), 1 )
SUMR = SDOT( L1-1, C( K2, 1 ), LDC, B( 1, L2 ), 1 )
VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
*
CALL SLASY2( .TRUE., .FALSE., ISGN, 2, 2, A( K1, K1 ),
$ LDA, B( L1, L1 ), LDB, VEC, 2, SCALOC, X,
$ 2, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 110 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
110 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 1, 2 )
C( K2, L1 ) = X( 2, 1 )
C( K2, L2 ) = X( 2, 2 )
END IF
*
120 CONTINUE
130 CONTINUE
*
ELSE IF( .NOT.NOTRNA .AND. .NOT.NOTRNB ) THEN
*
* Solve A**T*X + ISGN*X*B**T = scale*C.
*
* The (K,L)th block of X is determined starting from
* top-right corner column by column by
*
* A(K,K)**T*X(K,L) + ISGN*X(K,L)*B(L,L)**T = C(K,L) - R(K,L)
*
* Where
* K-1 N
* R(K,L) = SUM [A(I,K)**T*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**T].
* I=1 J=L+1
*
* Start column loop (index = L)
* L1 (L2): column index of the first (last) row of X(K,L)
*
LNEXT = N
DO 190 L = N, 1, -1
IF( L.GT.LNEXT )
$ GO TO 190
IF( L.EQ.1 ) THEN
L1 = L
L2 = L
ELSE
IF( B( L, L-1 ).NE.ZERO ) THEN
L1 = L - 1
L2 = L
LNEXT = L - 2
ELSE
L1 = L
L2 = L
LNEXT = L - 1
END IF
END IF
*
* Start row loop (index = K)
* K1 (K2): row index of the first (last) row of X(K,L)
*
KNEXT = 1
DO 180 K = 1, M
IF( K.LT.KNEXT )
$ GO TO 180
IF( K.EQ.M ) THEN
K1 = K
K2 = K
ELSE
IF( A( K+1, K ).NE.ZERO ) THEN
K1 = K
K2 = K + 1
KNEXT = K + 2
ELSE
K1 = K
K2 = K
KNEXT = K + 1
END IF
END IF
*
IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( N-L1, C( K1, MIN( L1+1, N ) ), LDC,
$ B( L1, MIN( L1+1, N ) ), LDB )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
SCALOC = ONE
*
A11 = A( K1, K1 ) + SGN*B( L1, L1 )
DA11 = ABS( A11 )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( VEC( 1, 1 ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
*
IF( SCALOC.NE.ONE ) THEN
DO 140 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
140 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
*
ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
CALL SLALN2( .TRUE., 2, 1, SMIN, ONE, A( K1, K1 ),
$ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 150 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
150 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K2, L1 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L2, MIN( L2+1, N ) ), LDB )
VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
*
CALL SLALN2( .FALSE., 2, 1, SMIN, ONE, B( L1, L1 ),
$ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 160 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
160 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K1 ), 1, C( 1, L2 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L2, MIN( L2+1, N ) ), LDB )
VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K2 ), 1, C( 1, L1 ), 1 )
SUMR = SDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( K1-1, A( 1, K2 ), 1, C( 1, L2 ), 1 )
SUMR = SDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
$ B( L2, MIN(L2+1, N ) ), LDB )
VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
*
CALL SLASY2( .TRUE., .TRUE., ISGN, 2, 2, A( K1, K1 ),
$ LDA, B( L1, L1 ), LDB, VEC, 2, SCALOC, X,
$ 2, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 170 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
170 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 1, 2 )
C( K2, L1 ) = X( 2, 1 )
C( K2, L2 ) = X( 2, 2 )
END IF
*
180 CONTINUE
190 CONTINUE
*
ELSE IF( NOTRNA .AND. .NOT.NOTRNB ) THEN
*
* Solve A*X + ISGN*X*B**T = scale*C.
*
* The (K,L)th block of X is determined starting from
* bottom-right corner column by column by
*
* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L)**T = C(K,L) - R(K,L)
*
* Where
* M N
* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**T].
* I=K+1 J=L+1
*
* Start column loop (index = L)
* L1 (L2): column index of the first (last) row of X(K,L)
*
LNEXT = N
DO 250 L = N, 1, -1
IF( L.GT.LNEXT )
$ GO TO 250
IF( L.EQ.1 ) THEN
L1 = L
L2 = L
ELSE
IF( B( L, L-1 ).NE.ZERO ) THEN
L1 = L - 1
L2 = L
LNEXT = L - 2
ELSE
L1 = L
L2 = L
LNEXT = L - 1
END IF
END IF
*
* Start row loop (index = K)
* K1 (K2): row index of the first (last) row of X(K,L)
*
KNEXT = M
DO 240 K = M, 1, -1
IF( K.GT.KNEXT )
$ GO TO 240
IF( K.EQ.1 ) THEN
K1 = K
K2 = K
ELSE
IF( A( K, K-1 ).NE.ZERO ) THEN
K1 = K - 1
K2 = K
KNEXT = K - 2
ELSE
K1 = K
K2 = K
KNEXT = K - 1
END IF
END IF
*
IF( L1.EQ.L2 .AND. K1.EQ.K2 ) THEN
SUML = SDOT( M-K1, A( K1, MIN(K1+1, M ) ), LDA,
$ C( MIN( K1+1, M ), L1 ), 1 )
SUMR = SDOT( N-L1, C( K1, MIN( L1+1, N ) ), LDC,
$ B( L1, MIN( L1+1, N ) ), LDB )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
SCALOC = ONE
*
A11 = A( K1, K1 ) + SGN*B( L1, L1 )
DA11 = ABS( A11 )
IF( DA11.LE.SMIN ) THEN
A11 = SMIN
DA11 = SMIN
INFO = 1
END IF
DB = ABS( VEC( 1, 1 ) )
IF( DA11.LT.ONE .AND. DB.GT.ONE ) THEN
IF( DB.GT.BIGNUM*DA11 )
$ SCALOC = ONE / DB
END IF
X( 1, 1 ) = ( VEC( 1, 1 )*SCALOC ) / A11
*
IF( SCALOC.NE.ONE ) THEN
DO 200 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
200 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
*
ELSE IF( L1.EQ.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
CALL SLALN2( .FALSE., 2, 1, SMIN, ONE, A( K1, K1 ),
$ LDA, ONE, ONE, VEC, 2, -SGN*B( L1, L1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 210 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
210 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K2, L1 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.EQ.K2 ) THEN
*
SUML = SDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
$ C( MIN( K1+1, M ), L1 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 1, 1 ) = SGN*( C( K1, L1 )-( SUML+SGN*SUMR ) )
*
SUML = SDOT( M-K1, A( K1, MIN( K1+1, M ) ), LDA,
$ C( MIN( K1+1, M ), L2 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L2, MIN( L2+1, N ) ), LDB )
VEC( 2, 1 ) = SGN*( C( K1, L2 )-( SUML+SGN*SUMR ) )
*
CALL SLALN2( .FALSE., 2, 1, SMIN, ONE, B( L1, L1 ),
$ LDB, ONE, ONE, VEC, 2, -SGN*A( K1, K1 ),
$ ZERO, X, 2, SCALOC, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 220 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
220 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 2, 1 )
*
ELSE IF( L1.NE.L2 .AND. K1.NE.K2 ) THEN
*
SUML = SDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 1, 1 ) = C( K1, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K1, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L2 ), 1 )
SUMR = SDOT( N-L2, C( K1, MIN( L2+1, N ) ), LDC,
$ B( L2, MIN( L2+1, N ) ), LDB )
VEC( 1, 2 ) = C( K1, L2 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L1 ), 1 )
SUMR = SDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
$ B( L1, MIN( L2+1, N ) ), LDB )
VEC( 2, 1 ) = C( K2, L1 ) - ( SUML+SGN*SUMR )
*
SUML = SDOT( M-K2, A( K2, MIN( K2+1, M ) ), LDA,
$ C( MIN( K2+1, M ), L2 ), 1 )
SUMR = SDOT( N-L2, C( K2, MIN( L2+1, N ) ), LDC,
$ B( L2, MIN( L2+1, N ) ), LDB )
VEC( 2, 2 ) = C( K2, L2 ) - ( SUML+SGN*SUMR )
*
CALL SLASY2( .FALSE., .TRUE., ISGN, 2, 2, A( K1, K1 ),
$ LDA, B( L1, L1 ), LDB, VEC, 2, SCALOC, X,
$ 2, XNORM, IERR )
IF( IERR.NE.0 )
$ INFO = 1
*
IF( SCALOC.NE.ONE ) THEN
DO 230 J = 1, N
CALL SSCAL( M, SCALOC, C( 1, J ), 1 )
230 CONTINUE
SCALE = SCALE*SCALOC
END IF
C( K1, L1 ) = X( 1, 1 )
C( K1, L2 ) = X( 1, 2 )
C( K2, L1 ) = X( 2, 1 )
C( K2, L2 ) = X( 2, 2 )
END IF
*
240 CONTINUE
250 CONTINUE
*
END IF
*
RETURN
*
* End of STRSYL
*
END
|