Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pycbal.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pycbal.f
1 
2 C*********************************************************************
3 
4 C...PYCBAL
5 C...Auxiliary to PYEICG
6 C
7 C THIS SUBROUTINE IS A TRANSLATION OF THE ALGOL PROCEDURE
8 C CBALANCE, WHICH IS A COMPLEX VERSION OF BALANCE,
9 C NUM. MATH. 13, 293-304(1969) BY PARLETT AND REINSCH.
10 C HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 315-326(1971).
11 C
12 C THIS SUBROUTINE BALANCES A COMPLEX MATRIX AND ISOLATES
13 C EIGENVALUES WHENEVER POSSIBLE.
14 C
15 C ON INPUT
16 C
17 C NM MUST BE SET TO THE ROW DIMENSION OF TWO-DIMENSIONAL
18 C ARRAY PARAMETERS AS DECLARED IN THE CALLING PROGRAM
19 C DIMENSION STATEMENT.
20 C
21 C N IS THE ORDER OF THE MATRIX.
22 C
23 C AR AND AI CONTAIN THE REAL AND IMAGINARY PARTS,
24 C RESPECTIVELY, OF THE COMPLEX MATRIX TO BE BALANCED.
25 C
26 C ON OUTPUT
27 C
28 C AR AND AI CONTAIN THE REAL AND IMAGINARY PARTS,
29 C RESPECTIVELY, OF THE BALANCED MATRIX.
30 C
31 C LOW AND IGH ARE TWO INTEGERS SUCH THAT AR(I,J) AND AI(I,J)
32 C ARE EQUAL TO ZERO IF
33 C (1) I IS GREATER THAN J AND
34 C (2) J=1,...,LOW-1 OR I=IGH+1,...,N.
35 C
36 C SCALE CONTAINS INFORMATION DETERMINING THE
37 C PERMUTATIONS AND SCALING FACTORS USED.
38 C
39 C SUPPOSE THAT THE PRINCIPAL SUBMATRIX IN ROWS LOW THROUGH IGH
40 C HAS BEEN BALANCED, THAT P(J) DENOTES THE INDEX INTERCHANGED
41 C WITH J DURING THE PERMUTATION STEP, AND THAT THE ELEMENTS
42 C OF THE DIAGONAL MATRIX USED ARE DENOTED BY D(I,J). THEN
43 C SCALE(J) = P(J), FOR J = 1,...,LOW-1
44 C = D(J,J) J = LOW,...,IGH
45 C = P(J) J = IGH+1,...,N.
46 C THE ORDER IN WHICH THE INTERCHANGES ARE MADE IS N TO IGH+1,
47 C THEN 1 TO LOW-1.
48 C
49 C NOTE THAT 1 IS RETURNED FOR IGH IF IGH IS ZERO FORMALLY.
50 C
51 C THE ALGOL PROCEDURE EXC CONTAINED IN CBALANCE APPEARS IN
52 C CBAL IN LINE. (NOTE THAT THE ALGOL ROLES OF IDENTIFIERS
53 C K,L HAVE BEEN REVERSED.)
54 C
55 C ARITHMETIC IS REAL THROUGHOUT.
56 C
57 C QUESTIONS AND COMMENTS SHOULD BE DIRECTED TO BURTON S. GARBOW,
58 C MATHEMATICS AND COMPUTER SCIENCE DIV, ARGONNE NATIONAL LABORATORY
59 C
60 C THIS VERSION DATED AUGUST 1983.
61 C
62 
63  SUBROUTINE pycbal(NM,N,AR,AI,LOW,IGH,SCALE)
64 
65  INTEGER i,j,k,l,m,n,jj,nm,igh,low,iexc
66  DOUBLE PRECISION ar(4,4),ai(4,4),scale(4)
67  DOUBLE PRECISION c,f,g,r,s,b2,radix
68  LOGICAL noconv
69 
70  radix = 16.0d0
71 C
72  b2 = radix * radix
73  k = 1
74  l = n
75  goto 150
76 C .......... IN-LINE PROCEDURE FOR ROW AND
77 C COLUMN EXCHANGE ..........
78  100 scale(m) = j
79  IF (j .EQ. m) goto 130
80 C
81  DO 110 i = 1, l
82  f = ar(i,j)
83  ar(i,j) = ar(i,m)
84  ar(i,m) = f
85  f = ai(i,j)
86  ai(i,j) = ai(i,m)
87  ai(i,m) = f
88  110 CONTINUE
89 C
90  DO 120 i = k, n
91  f = ar(j,i)
92  ar(j,i) = ar(m,i)
93  ar(m,i) = f
94  f = ai(j,i)
95  ai(j,i) = ai(m,i)
96  ai(m,i) = f
97  120 CONTINUE
98 C
99  130 IF(iexc.EQ.1) goto 140
100  IF(iexc.EQ.2) goto 180
101 C .......... SEARCH FOR ROWS ISOLATING AN EIGENVALUE
102 C AND PUSH THEM DOWN ..........
103  140 IF (l .EQ. 1) goto 320
104  l = l - 1
105 C .......... FOR J=L STEP -1 UNTIL 1 DO -- ..........
106  150 DO 170 jj = 1, l
107  j = l + 1 - jj
108 C
109  DO 160 i = 1, l
110  IF (i .EQ. j) goto 160
111  IF (ar(j,i) .NE. 0.0d0 .OR. ai(j,i) .NE. 0.0d0) goto 170
112  160 CONTINUE
113 C
114  m = l
115  iexc = 1
116  goto 100
117  170 CONTINUE
118 C
119  goto 190
120 C .......... SEARCH FOR COLUMNS ISOLATING AN EIGENVALUE
121 C AND PUSH THEM LEFT ..........
122  180 k = k + 1
123 C
124  190 DO 210 j = k, l
125 C
126  DO 200 i = k, l
127  IF (i .EQ. j) goto 200
128  IF (ar(i,j) .NE. 0.0d0 .OR. ai(i,j) .NE. 0.0d0) goto 210
129  200 CONTINUE
130 C
131  m = k
132  iexc = 2
133  goto 100
134  210 CONTINUE
135 C .......... NOW BALANCE THE SUBMATRIX IN ROWS K TO L ..........
136  DO 220 i = k, l
137  220 scale(i) = 1.0d0
138 C .......... ITERATIVE LOOP FOR NORM REDUCTION ..........
139  230 noconv = .false.
140 C
141  DO 310 i = k, l
142  c = 0.0d0
143  r = 0.0d0
144 C
145  DO 240 j = k, l
146  IF (j .EQ. i) goto 240
147  c = c + dabs(ar(j,i)) + dabs(ai(j,i))
148  r = r + dabs(ar(i,j)) + dabs(ai(i,j))
149  240 CONTINUE
150 C .......... GUARD AGAINST ZERO C OR R DUE TO UNDERFLOW ..........
151  IF (c .EQ. 0.0d0 .OR. r .EQ. 0.0d0) goto 310
152  g = r / radix
153  f = 1.0d0
154  s = c + r
155  250 IF (c .GE. g) goto 260
156  f = f * radix
157  c = c * b2
158  goto 250
159  260 g = r * radix
160  270 IF (c .LT. g) goto 280
161  f = f / radix
162  c = c / b2
163  goto 270
164 C .......... NOW BALANCE ..........
165  280 IF ((c + r) / f .GE. 0.95d0 * s) goto 310
166  g = 1.0d0 / f
167  scale(i) = scale(i) * f
168  noconv = .true.
169 C
170  DO 290 j = k, n
171  ar(i,j) = ar(i,j) * g
172  ai(i,j) = ai(i,j) * g
173  290 CONTINUE
174 C
175  DO 300 j = 1, l
176  ar(j,i) = ar(j,i) * f
177  ai(j,i) = ai(j,i) * f
178  300 CONTINUE
179 C
180  310 CONTINUE
181 C
182  IF (noconv) goto 230
183 C
184  320 low = k
185  igh = l
186  RETURN
187  END