-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathcyclic_reduction.f90
2269 lines (1991 loc) · 51.5 KB
/
cyclic_reduction.f90
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
subroutine c83_cr_fa ( n, a, a_cr )
!*****************************************************************************80
!
!! C83_CR_FA decomposes a C83 matrix using cyclic reduction.
!
! Discussion:
!
! The D83 storage format is used for a real tridiagonal matrix.
! The superdiagonal is stored in entries (1,2:N), the diagonal in
! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the
! original matrix is "collapsed" vertically into the array.
!
! Once C83_CR_FA has decomposed a matrix A, then C83_CR_SL may be used
! to solve linear systems A * x = b.
!
! C83_CR_FA does not employ pivoting. Hence, the results can be more
! sensitive to ill-conditioning than standard Gauss elimination. In
! particular, C83_CR_FA will fail if any diagonal element of the matrix
! is zero. Other matrices may also cause C83_CR_FA to fail.
!
! C83_CR_FA can be guaranteed to work properly if the matrix is strictly
! diagonally dominant, that is, if the absolute value of the diagonal
! element is strictly greater than the sum of the absolute values of
! the offdiagonal elements, for each equation.
!
! The algorithm may be illustrated by the following figures:
!
! The initial matrix is given by:
!
! D1 U1
! L1 D2 U2
! L2 D3 U3
! L3 D4 U4
! L4 D5 U5
! L5 D6
!
! Rows and columns are permuted in an odd/even way to yield:
!
! D1 U1
! D3 L2 U3
! D5 L4 U5
! L1 U2 D2
! L3 U4 D4
! L5 D6
!
! A block LU decomposition is performed to yield:
!
! D1 |U1
! D3 |L2 U3
! D5| L4 U5
! --------+--------
! |D2'F3
! |F1 D4'F4
! | F2 D6'
!
! For large systems, this reduction is repeated on the lower right hand
! tridiagonal subsystem until a completely upper triangular system
! is obtained. The system has now been factored into the product of a
! lower triangular system and an upper triangular one, and the information
! defining this factorization may be used by C83_CR_SL to solve linear
! systems.
!
! Example:
!
! Here is how a C83 matrix of order 5 would be stored:
!
! * A12 A23 A34 A45
! A11 A22 A33 A44 A55
! A21 A32 A43 A54 *
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 30 May 2009
!
! Author:
!
! FORTRAN90 version by John Burkardt
!
! Reference:
!
! Roger Hockney,
! A fast direct solution of Poisson's equation using Fourier Analysis,
! Journal of the ACM,
! Volume 12, Number 1, pages 95-113, January 1965.
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the order of the matrix.
! N must be positive.
!
! Input, complex ( kind = 8 ) A(3,N), the matrix.
!
! Output, complex ( kind = 8 ) A_CR(3,0:2*N), factorization information
! needed by C83_CR_SL.
!
implicit none
integer ( kind = 4 ) n
complex ( kind = 8 ) a(3,n)
complex ( kind = 8 ) a_cr(3,0:2*n)
integer ( kind = 4 ) iful
integer ( kind = 4 ) ifulp
integer ( kind = 4 ) ihaf
integer ( kind = 4 ) il
integer ( kind = 4 ) ilp
integer ( kind = 4 ) inc
integer ( kind = 4 ) incr
integer ( kind = 4 ) ipnt
integer ( kind = 4 ) ipntp
if ( n <= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'C83_CR_FA - Fatal error!'
write ( *, '(a,i8)' ) ' Nonpositive N = ', n
stop
end if
if ( n == 1 ) then
a_cr(1,0:2) = 0.0D+00
a_cr(2,0) = 0.0D+00
a_cr(2,1) = 1.0D+00 / a(2,1)
a_cr(2,2) = 0.0D+00
a_cr(3,0:2) = 0.0D+00
return
end if
!
! Zero out the workspace entries.
!
a_cr(1,0) = 0.0D+00
a_cr(1,1:n-1) = a(1,2:n)
a_cr(1,n:2*n) = 0.0D+00
a_cr(2,0) = 0.0D+00
a_cr(2,1:n) = a(2,1:n)
a_cr(2,n+1:2*n) = 0.0D+00
a_cr(3,0) = 0.0D+00
a_cr(3,1:n-1) = a(3,1:n-1)
a_cr(3,n:2*n) = 0.0D+00
il = n
ipntp = 0
do while ( 1 < il )
ipnt = ipntp
ipntp = ipntp + il
if ( mod ( il, 2 ) == 1 ) then
inc = il + 1
else
inc = il
end if
incr = inc / 2
il = il / 2
ihaf = ipntp + incr + 1
ifulp = ipnt + inc + 2
!dir$ ivdep
do ilp = incr, 1, -1
ifulp = ifulp - 2
iful = ifulp - 1
ihaf = ihaf - 1
a_cr(2,iful) = 1.0D+00 / a_cr(2,iful)
a_cr(3,iful) = a_cr(3,iful) * a_cr(2,iful)
a_cr(1,ifulp) = a_cr(1,ifulp) * a_cr(2,ifulp+1)
a_cr(2,ihaf) = a_cr(2,ifulp) - a_cr(1,iful) * a_cr(3,iful) &
- a_cr(1,ifulp) * a_cr(3,ifulp)
a_cr(3,ihaf) = -a_cr(3,ifulp) * a_cr(3,ifulp+1)
a_cr(1,ihaf) = -a_cr(1,ifulp) * a_cr(1,ifulp+1)
end do
end do
a_cr(2,ipntp+1) = 1.0D+00 / a_cr(2,ipntp+1)
return
end
subroutine c83_cr_sl ( n, a_cr, b, x )
!*****************************************************************************80
!
!! C83_CR_SL solves a linear system factored by C83_CR_FA.
!
! Discussion:
!
! The matrix A must be tridiagonal. C83_CR_FA is called to compute the
! LU factors of A. It does so using a form of cyclic reduction. If
! the factors computed by C83_CR_FA are passed to C83_CR_SL, then a
! linear system involving the matrix A may be solved.
!
! Note that C83_CR_FA does not perform pivoting, and so the solution
! produced by C83_CR_SL may be less accurate than a solution produced
! by a standard Gauss algorithm. However, such problems can be
! guaranteed not to occur if the matrix A is strictly diagonally
! dominant, that is, if the absolute value of the diagonal coefficient
! is greater than the sum of the absolute values of the two off diagonal
! coefficients, for each row of the matrix.
!
! Example:
!
! Here is how a C83 matrix of order 5 would be stored:
!
! * A12 A23 A34 A45
! A11 A22 A33 A44 A55
! A21 A32 A43 A54 *
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 06 May 2010
!
! Author:
!
! John Burkardt
!
! Reference:
!
! Roger Hockney,
! A fast direct solution of Poisson's equation using Fourier Analysis,
! Journal of the ACM,
! Volume 12, Number 1, pages 95-113, January 1965.
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the order of the matrix.
! N must be positive.
!
! Input, complex ( kind = 8 ) A_CR(3,0:2*N), factorization information
! computed by C83_CR_FA.
!
! Input, real ( kind = 8 ) B(N), the right hand sides.
!
! Output, real ( kind = 8 ) X(N), the solutions of the linear systems.
!
implicit none
integer ( kind = 4 ) n
complex ( kind = 8 ) a_cr(3,0:2*n)
complex ( kind = 8 ) b(n)
integer ( kind = 4 ) iful
integer ( kind = 4 ) ifulm
integer ( kind = 4 ) ihaf
integer ( kind = 4 ) il
integer ( kind = 4 ) ipnt
integer ( kind = 4 ) ipntp
integer ( kind = 4 ) ndiv
complex ( kind = 8 ) rhs(0:2*n)
complex ( kind = 8 ) x(n)
if ( n <= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'C83_CR_SL - Fatal error!'
write ( *, '(a,i8)' ) ' Nonpositive N = ', n
stop
end if
if ( n == 1 ) then
x(1) = a_cr(2,1) * b(1)
return
end if
!
! Set up RHS.
!
rhs(0) = 0.0D+00
rhs(1:n) = b(1:n)
rhs(n+1:2*n) = 0.0D+00
il = n
ndiv = 1
ipntp = 0
do while ( 1 < il )
ipnt = ipntp
ipntp = ipntp + il
il = il / 2
ndiv = ndiv * 2
ihaf = ipntp
!dir$ ivdep
do iful = ipnt + 2, ipntp, 2
ihaf = ihaf + 1
rhs(ihaf) = rhs(iful) &
- a_cr(3,iful-1) * rhs(iful-1) &
- a_cr(1,iful) * rhs(iful+1)
end do
end do
rhs(ihaf) = rhs(ihaf) * a_cr(2,ihaf)
ipnt = ipntp
do while ( 0 < ipnt )
ipntp = ipnt
ndiv = ndiv / 2
il = n / ndiv
ipnt = ipnt - il
ihaf = ipntp
!dir$ ivdep
do ifulm = ipnt + 1, ipntp, 2
iful = ifulm + 1
ihaf = ihaf + 1
rhs(iful) = rhs(ihaf)
rhs(ifulm) = a_cr(2,ifulm) &
* ( rhs(ifulm) &
- a_cr(3,ifulm-1) * rhs(ifulm-1) &
- a_cr(1,ifulm) * rhs(iful) )
end do
end do
x(1:n) = rhs(1:n)
return
end
subroutine c83_cr_sls ( n, a_cr, nb, b, x )
!*****************************************************************************80
!
!! C83_CR_SLS solves several linear systems factored by C83_CR_FA.
!
! Discussion:
!
! The matrix A must be tridiagonal. C83_CR_FA is called to compute the
! LU factors of A. It does so using a form of cyclic reduction. If
! the factors computed by C83_CR_FA are passed to C83_CR_SLS, then one or
! many linear systems involving the matrix A may be solved.
!
! Note that C83_CR_FA does not perform pivoting, and so the solution
! produced by C83_CR_SLS may be less accurate than a solution produced
! by a standard Gauss algorithm. However, such problems can be
! guaranteed not to occur if the matrix A is strictly diagonally
! dominant, that is, if the absolute value of the diagonal coefficient
! is greater than the sum of the absolute values of the two off diagonal
! coefficients, for each row of the matrix.
!
! Example:
!
! Here is how a C83 matrix of order 5 would be stored:
!
! * A12 A23 A34 A45
! A11 A22 A33 A44 A55
! A21 A32 A43 A54 *
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 30 May 2009
!
! Author:
!
! John Burkardt
!
! Reference:
!
! Roger Hockney,
! A fast direct solution of Poisson's equation using Fourier Analysis,
! Journal of the ACM,
! Volume 12, Number 1, pages 95-113, January 1965.
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the order of the matrix.
! N must be positive.
!
! Input, complex ( kind = 8 ) A_CR(3,0:2*N), factorization information
! computed by C83_CR_FA.
!
! Input, integer ( kind = 4 ) NB, the number of right hand sides.
!
! Input, real ( kind = 8 ) B(N,NB), the right hand sides.
!
! Output, real ( kind = 8 ) X(N,NB), the solutions of the linear systems.
!
implicit none
integer ( kind = 4 ) n
integer ( kind = 4 ) nb
complex ( kind = 8 ) a_cr(3,0:2*n)
complex ( kind = 8 ) b(n,nb)
integer ( kind = 4 ) iful
integer ( kind = 4 ) ifulm
integer ( kind = 4 ) ihaf
integer ( kind = 4 ) il
integer ( kind = 4 ) ipnt
integer ( kind = 4 ) ipntp
integer ( kind = 4 ) ndiv
complex ( kind = 8 ) rhs(0:2*n,nb)
complex ( kind = 8 ) x(n,nb)
if ( n <= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'C83_CR_SLS - Fatal error!'
write ( *, '(a,i8)' ) ' Nonpositive N = ', n
stop
end if
if ( n == 1 ) then
x(1,1:nb) = a_cr(2,1) * b(1,1:nb)
return
end if
!
! Set up RHS.
!
rhs(0,1:nb) = 0.0D+00
rhs(1:n,1:nb) = b(1:n,1:nb)
rhs(n+1:2*n,1:nb) = 0.0D+00
il = n
ndiv = 1
ipntp = 0
do while ( 1 < il )
ipnt = ipntp
ipntp = ipntp + il
il = il / 2
ndiv = ndiv * 2
ihaf = ipntp
!dir$ ivdep
do iful = ipnt + 2, ipntp, 2
ihaf = ihaf + 1
rhs(ihaf,1:nb) = rhs(iful,1:nb) &
- a_cr(3,iful-1) * rhs(iful-1,1:nb) &
- a_cr(1,iful) * rhs(iful+1,1:nb)
end do
end do
rhs(ihaf,1:nb) = rhs(ihaf,1:nb) * a_cr(2,ihaf)
ipnt = ipntp
do while ( 0 < ipnt )
ipntp = ipnt
ndiv = ndiv / 2
il = n / ndiv
ipnt = ipnt - il
ihaf = ipntp
!dir$ ivdep
do ifulm = ipnt + 1, ipntp, 2
iful = ifulm + 1
ihaf = ihaf + 1
rhs(iful,1:nb) = rhs(ihaf,1:nb)
rhs(ifulm,1:nb) = a_cr(2,ifulm) &
* ( rhs(ifulm,1:nb) &
- a_cr(3,ifulm-1) * rhs(ifulm-1,1:nb) &
- a_cr(1,ifulm) * rhs(iful,1:nb) )
end do
end do
x(1:n,1:nb) = rhs(1:n,1:nb)
return
end
subroutine c83_indicator ( n, a )
!*****************************************************************************80
!
!! C83_INDICATOR sets up a C83 indicator matrix.
!
! Discussion:
!
! The C83 storage format is used for a tridiagonal matrix.
! The superdiagonal is stored in entries (1,2:N), the diagonal in
! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the
! original matrix is "collapsed" vertically into the array.
!
! Example:
!
! Here is how a C83 matrix of order 5 would be stored:
!
! * A12 A23 A34 A45
! A11 A22 A33 A44 A55
! A21 A32 A43 A54 *
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 30 May 2009
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the order of the matrix.
! N must be at least 2.
!
! Output, complex ( kind = 8 ) A(3,N), the indicator matrix.
!
implicit none
integer ( kind = 4 ) n
complex ( kind = 8 ) a(3,n)
integer ( kind = 4 ) i
integer ( kind = 4 ) j
a(1,1) = 0.0D+00
do j = 2, n
i = j - 1
a(1,j) = cmplx ( i, j, kind = 8 )
end do
do j = 1, n
i = j
a(2,j) = cmplx ( i, j, kind = 8 )
end do
do j = 1, n - 1
i = j + 1
a(3,j) = cmplx ( i, j, kind = 8 )
end do
a(3,n) = 0.0D+00
return
end
subroutine c83_mxv ( n, a, x, b )
!*****************************************************************************80
!
!! C83_MXV multiplies a C83 matrix times a C8VEC.
!
! Discussion:
!
! The C83 storage format is used for a tridiagonal matrix.
! The superdiagonal is stored in entries (1,2:N), the diagonal in
! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the
! original matrix is "collapsed" vertically into the array.
!
! Example:
!
! Here is how a C83 matrix of order 5 would be stored:
!
! * A12 A23 A34 A45
! A11 A22 A33 A44 A55
! A21 A32 A43 A54 *
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 30 May 2009
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the order of the linear system.
!
! Input, complex ( kind = 8 ) A(3,N), the matrix.
!
! Input, complex ( kind = 8 ) X(N), the vector to be multiplied by A.
!
! Output, complex ( kind = 8 ) B(N), the product A * x.
!
implicit none
integer ( kind = 4 ) n
complex ( kind = 8 ) a(3,n)
complex ( kind = 8 ) b(n)
complex ( kind = 8 ) x(n)
b(1:n) = a(2,1:n) * x(1:n)
b(1:n-1) = b(1:n-1) + a(1,2:n) * x(2:n)
b(2:n) = b(2:n) + a(3,1:n-1) * x(1:n-1)
return
end
subroutine c83_print ( n, a, title )
!*****************************************************************************80
!
!! C83_PRINT prints a C83 matrix.
!
! Discussion:
!
! The C83 storage format is used for a complex tridiagonal matrix.
! The superdiagonal is stored in entries (1,2:N), the diagonal in
! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the
! original matrix is "collapsed" vertically into the array.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 30 May 2009
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the order of the matrix.
! N must be positive.
!
! Input, complex ( kind = 8 ) A(3,N), the C83 matrix.
!
! Input, character ( len = * ) TITLE, a title.
!
implicit none
integer ( kind = 4 ) n
complex ( kind = 8 ) a(3,n)
character ( len = * ) title
call c83_print_some ( n, a, 1, 1, n, n, title )
return
end
subroutine c83_print_some ( n, a, ilo, jlo, ihi, jhi, title )
!*****************************************************************************80
!
!! C83_PRINT_SOME prints some of a C83 matrix.
!
! Discussion:
!
! The C83 storage format is used for a complex tridiagonal matrix.
! The superdiagonal is stored in entries (1,2:N), the diagonal in
! entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the
! original matrix is "collapsed" vertically into the array.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 30 May 2009
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the order of the matrix.
! N must be positive.
!
! Input, complex ( kind = 8 ) A(3,N), the C83 matrix.
!
! Input, integer ( kind = 4 ) ILO, JLO, IHI, JHI, the first row and
! column, and the last row and column, to be printed.
!
! Input, character ( len = * ) TITLE, a title.
!
implicit none
integer ( kind = 4 ), parameter :: incx = 3
integer ( kind = 4 ) n
complex ( kind = 8 ) a(3,n)
character ( len = 12 ) citemp(incx)
character ( len = 12 ) crtemp(incx)
integer ( kind = 4 ) i
integer ( kind = 4 ) i2hi
integer ( kind = 4 ) i2lo
integer ( kind = 4 ) ihi
integer ( kind = 4 ) ilo
integer ( kind = 4 ) inc
integer ( kind = 4 ) j
integer ( kind = 4 ) j2
integer ( kind = 4 ) j2hi
integer ( kind = 4 ) j2lo
integer ( kind = 4 ) jhi
integer ( kind = 4 ) jlo
real ( kind = 8 ) xi
real ( kind = 8 ) xr
character ( len = * ) title
write ( *, '(a)' ) ' '
write ( *, '(a)' ) trim ( title )
!
! Print the columns of the matrix, in strips of 5.
!
do j2lo = jlo, jhi, incx
j2hi = j2lo + incx - 1
j2hi = min ( j2hi, n )
j2hi = min ( j2hi, jhi )
inc = j2hi + 1 - j2lo
write ( *, '(a)' ) ' '
do j = j2lo, j2hi
j2 = j + 1 - j2lo
write ( crtemp(j2), '(i8,6x)' ) j
write ( citemp(j2), '(i8,6x)' ) j
end do
write ( *, '('' Col: '',6a12)' ) ( crtemp(j2), citemp(j2), j2 = 1, inc )
write ( *, '(a)' ) ' Row'
write ( *, '(a)' ) ' ---'
!
! Determine the range of the rows in this strip.
!
i2lo = max ( ilo, 1 )
i2lo = max ( i2lo, j2lo - 1 )
i2hi = min ( ihi, n )
i2hi = min ( i2hi, j2hi + 1 )
do i = i2lo, i2hi
!
! Print out (up to) INCX entries in row I, that lie in the current strip.
!
do j2 = 1, inc
j = j2lo - 1 + j2
if ( 1 < i - j .or. 1 < j - i ) then
crtemp(j2) = ' '
citemp(j2) = ' '
else
if ( j == i - 1 ) then
xr = real ( a(1,i), kind = 8 )
xi = imag ( a(1,i) )
else if ( j == i ) then
xr = real ( a(2,i), kind = 8 )
xi = imag ( a(2,i) )
else if ( j == i + 1 ) then
xr = real ( a(3,i), kind = 8 )
xi = imag ( a(3,i) )
end if
if ( xr == 0.0D+00 .and. xi == 0.0D+00 ) then
crtemp(j2) = ' 0.0'
citemp(j2) = ' '
else if ( xr == 0.0D+00 .and. xi /= 0.0D+00 ) then
crtemp(j2) = ' '
write ( citemp(j2), '(g12.5)' ) xi
else if ( xr /= 0.0D+00 .and. xi == 0.0D+00 ) then
write ( crtemp(j2), '(g12.5)' ) xr
citemp(j2) = ' '
else
write ( crtemp(j2), '(g12.5)' ) xr
write ( citemp(j2), '(g12.5)' ) xi
end if
end if
end do
write ( *, '(i5,a,6a12)' ) i, ':', ( crtemp(j2), citemp(j2), j2 = 1, inc )
end do
end do
return
end
subroutine c8mat_print ( m, n, a, title )
!*****************************************************************************80
!
!! C8MAT_PRINT prints a C8MAT.
!
! Discussion:
!
! A C8MAT is a matrix of C8's.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 23 March 2005
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) M, N, the number of rows and columns
! in the matrix.
!
! Input, complex ( kind = 8 ) A(M,N), the matrix.
!
! Input, character ( len = * ) TITLE, a title.
!
implicit none
integer ( kind = 4 ) m
integer ( kind = 4 ) n
complex ( kind = 8 ) a(m,n)
character ( len = * ) title
call c8mat_print_some ( m, n, a, 1, 1, m, n, title )
return
end
subroutine c8mat_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )
!*****************************************************************************80
!
!! C8MAT_PRINT_SOME prints some of a C8MAT.
!
! Discussion:
!
! A C8MAT is a matrix of C8's.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 23 March 2005
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) M, N, the number of rows and columns
! in the matrix.
!
! Input, complex ( kind = 8 ) A(M,N), the matrix.
!
! Input, integer ( kind = 4 ) ILO, JLO, IHI, JHI, the first row and
! column, and the last row and column to be printed.
!
! Input, character ( len = * ) TITLE, a title.
!
implicit none
integer ( kind = 4 ), parameter :: incx = 4
integer ( kind = 4 ) m
integer ( kind = 4 ) n
complex ( kind = 8 ) a(m,n)
character ( len = 20 ) ctemp(incx)
integer ( kind = 4 ) i
integer ( kind = 4 ) i2hi
integer ( kind = 4 ) i2lo
integer ( kind = 4 ) ihi
integer ( kind = 4 ) ilo
integer ( kind = 4 ) inc
integer ( kind = 4 ) j
integer ( kind = 4 ) j2
integer ( kind = 4 ) j2hi
integer ( kind = 4 ) j2lo
integer ( kind = 4 ) jhi
integer ( kind = 4 ) jlo
character ( len = * ) title
complex ( kind = 8 ) zero
zero = cmplx ( 0.0D+00, 0.0D+00, kind = 8 )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) trim ( title )
!
! Print the columns of the matrix, in strips of INCX.
!
do j2lo = jlo, jhi, incx
j2hi = j2lo + incx - 1
j2hi = min ( j2hi, n )
j2hi = min ( j2hi, jhi )
inc = j2hi + 1 - j2lo
write ( *, '(a)' ) ' '
do j = j2lo, j2hi
j2 = j + 1 - j2lo
write ( ctemp(j2), '(i10,10x)' ) j
end do
write ( *, '(a,4a20)' ) ' Col: ', ( ctemp(j2), j2 = 1, inc )
write ( *, '(a)' ) ' Row'
write ( *, '(a)' ) ' ---'
!
! Determine the range of the rows in this strip.
!
i2lo = max ( ilo, 1 )
i2hi = min ( ihi, m )
do i = i2lo, i2hi
!
! Print out (up to) INCX entries in row I, that lie in the current strip.
!
do j2 = 1, inc
j = j2lo - 1 + j2
if ( a(i,j) == zero ) then
ctemp(j2) = ' 0.0 '
else if ( imag ( a(i,j) ) == 0.0D+00 ) then
write ( ctemp(j2), '(g10.3,10x)' ) real ( a(i,j), kind = 8 )
else
write ( ctemp(j2), '(2g10.3)' ) a(i,j)
end if
end do
write ( *, '(i5,a,4a20)' ) i, ':', ( ctemp(j2), j2 = 1, inc )
end do
end do
return
end
subroutine c8vec_indicator ( n, a )
!*****************************************************************************80
!
!! C8VEC_INDICATOR sets a C8VEC to an "indicator" vector.
!
! Discussion:
!
! X(1:N) = ( 1-1i, 2-2i, 3-3i, 4-4i, ... )
!
! Modified:
!
! 04 January 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) N, the number of elements of A.
!
! Output, complex ( kind = 8 ) A(N), the array to be initialized.
!
implicit none
integer ( kind = 4 ) n
complex ( kind = 8 ) a(n)
integer ( kind = 4 ) i
do i = 1, n
a(i) = cmplx ( i, - i, kind = 8 )
end do
return
end
subroutine c8vec_print ( n, a, title )
!*****************************************************************************80
!
!! C8VEC_PRINT prints a C8VEC, with an optional title.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 08 March 2001
!
! Author:
!
! John Burkardt