subroutine bandr(nm,n,mb,a,d,e,e2,matz,z) C REFORMULATED S2 IN LOOP 500 TO AVOID OVERFLOW. (9/29/89 BSG) c integer j,k,l,n,r,i1,i2,j1,j2,kr,mb,mr,m1,nm,n2,r1,ugl,maxl,maxr real a(nm,mb),d(n),e(n),e2(n),z(nm,n) real g,u,b1,b2,c2,f1,f2,s2,dmin,dminrt logical matz c c this subroutine is a translation of the algol procedure bandrd, c num. math. 12, 231-241(1968) by schwarz. c handbook for auto. comp., vol.ii-linear algebra, 273-283(1971). c c this subroutine reduces a real symmetric band matrix c to a symmetric tridiagonal matrix using and optionally c accumulating orthogonal similarity transformations. c c on input c c nm must be set to the row dimension of two-dimensional c array parameters as declared in the calling program c dimension statement. c c n is the order of the matrix. c c mb is the (half) band width of the matrix, defined as the c number of adjacent diagonals, including the principal c diagonal, required to specify the non-zero portion of the c lower triangle of the matrix. c c a contains the lower triangle of the symmetric band input c matrix stored as an n by mb array. its lowest subdiagonal c is stored in the last n+1-mb positions of the first column, c its next subdiagonal in the last n+2-mb positions of the c second column, further subdiagonals similarly, and finally c its principal diagonal in the n positions of the last column. c contents of storages not part of the matrix are arbitrary. c c matz should be set to .true. if the transformation matrix is c to be accumulated, and to .false. otherwise. c c on output c c a has been destroyed, except for its last two columns which c contain a copy of the tridiagonal matrix. c c d contains the diagonal elements of the tridiagonal matrix. c c e contains the subdiagonal elements of the tridiagonal c matrix in its last n-1 positions. e(1) is set to zero. c c e2 contains the squares of the corresponding elements of e. c e2 may coincide with e if the squares are not needed. c c z contains the orthogonal transformation matrix produced in c the reduction if matz has been set to .true. otherwise, z c is not referenced. c c questions and comments should be directed to burton s. garbow, c mathematics and computer science div, argonne national laboratory c c this version dated september 1989. c c ------------------------------------------------------------------ c dmin = 2.0e0**(-64) dminrt = 2.0e0**(-32) c .......... initialize diagonal scaling matrix .......... do 30 j = 1, n 30 d(j) = 1.0e0 c if (.not. matz) go to 60 c do 50 j = 1, n c do 40 k = 1, n 40 z(j,k) = 0.0e0 c z(j,j) = 1.0e0 50 continue c 60 m1 = mb - 1 if (m1 - 1) 900, 800, 70 70 n2 = n - 2 c do 700 k = 1, n2 maxr = min0(m1,n-k) c .......... for r=maxr step -1 until 2 do -- .......... do 600 r1 = 2, maxr r = maxr + 2 - r1 kr = k + r mr = mb - r g = a(kr,mr) a(kr-1,1) = a(kr-1,mr+1) ugl = k c do 500 j = kr, n, m1 j1 = j - 1 j2 = j1 - 1 if (g .eq. 0.0e0) go to 600 b1 = a(j1,1) / g b2 = b1 * d(j1) / d(j) IF (ABS(B1) .GT. 1.0E0) THEN U = 1.0E0 / B1 S2 = U / (U + B2) ELSE S2 = 1.0E0 / (1.0E0 + B1 * B2) ENDIF c if (s2 .ge. 0.5e0 ) go to 450 b1 = g / a(j1,1) b2 = b1 * d(j) / d(j1) c2 = 1.0e0 - s2 d(j1) = c2 * d(j1) d(j) = c2 * d(j) f1 = 2.0e0 * a(j,m1) f2 = b1 * a(j1,mb) a(j,m1) = -b2 * (b1 * a(j,m1) - a(j,mb)) - f2 + a(j,m1) a(j1,mb) = b2 * (b2 * a(j,mb) + f1) + a(j1,mb) a(j,mb) = b1 * (f2 - f1) + a(j,mb) c do 200 l = ugl, j2 i2 = mb - j + l u = a(j1,i2+1) + b2 * a(j,i2) a(j,i2) = -b1 * a(j1,i2+1) + a(j,i2) a(j1,i2+1) = u 200 continue c ugl = j a(j1,1) = a(j1,1) + b2 * g if (j .eq. n) go to 350 maxl = min0(m1,n-j1) c do 300 l = 2, maxl i1 = j1 + l i2 = mb - l u = a(i1,i2) + b2 * a(i1,i2+1) a(i1,i2+1) = -b1 * a(i1,i2) + a(i1,i2+1) a(i1,i2) = u 300 continue c i1 = j + m1 if (i1 .gt. n) go to 350 g = b2 * a(i1,1) 350 if (.not. matz) go to 500 c do 400 l = 1, n u = z(l,j1) + b2 * z(l,j) z(l,j) = -b1 * z(l,j1) + z(l,j) z(l,j1) = u 400 continue c go to 500 c 450 u = d(j1) d(j1) = s2 * d(j) d(j) = s2 * u f1 = 2.0e0 * a(j,m1) f2 = b1 * a(j,mb) u = b1 * (f2 - f1) + a(j1,mb) a(j,m1) = b2 * (b1 * a(j,m1) - a(j1,mb)) + f2 - a(j,m1) a(j1,mb) = b2 * (b2 * a(j1,mb) + f1) + a(j,mb) a(j,mb) = u c do 460 l = ugl, j2 i2 = mb - j + l u = b2 * a(j1,i2+1) + a(j,i2) a(j,i2) = -a(j1,i2+1) + b1 * a(j,i2) a(j1,i2+1) = u 460 continue c ugl = j a(j1,1) = b2 * a(j1,1) + g if (j .eq. n) go to 480 maxl = min0(m1,n-j1) c do 470 l = 2, maxl i1 = j1 + l i2 = mb - l u = b2 * a(i1,i2) + a(i1,i2+1) a(i1,i2+1) = -a(i1,i2) + b1 * a(i1,i2+1) a(i1,i2) = u 470 continue c i1 = j + m1 if (i1 .gt. n) go to 480 g = a(i1,1) a(i1,1) = b1 * a(i1,1) 480 if (.not. matz) go to 500 c do 490 l = 1, n u = b2 * z(l,j1) + z(l,j) z(l,j) = -z(l,j1) + b1 * z(l,j) z(l,j1) = u 490 continue c 500 continue c 600 continue c if (mod(k,64) .ne. 0) go to 700 c .......... rescale to avoid underflow or overflow .......... do 650 j = k, n if (d(j) .ge. dmin) go to 650 maxl = max0(1,mb+1-j) c do 610 l = maxl, m1 610 a(j,l) = dminrt * a(j,l) c if (j .eq. n) go to 630 maxl = min0(m1,n-j) c do 620 l = 1, maxl i1 = j + l i2 = mb - l a(i1,i2) = dminrt * a(i1,i2) 620 continue c 630 if (.not. matz) go to 645 c do 640 l = 1, n 640 z(l,j) = dminrt * z(l,j) c 645 a(j,mb) = dmin * a(j,mb) d(j) = d(j) / dmin 650 continue c 700 continue c .......... form square root of scaling matrix .......... 800 do 810 j = 2, n 810 e(j) = sqrt(d(j)) c if (.not. matz) go to 840 c do 830 j = 1, n c do 820 k = 2, n 820 z(j,k) = e(k) * z(j,k) c 830 continue c 840 u = 1.0e0 c do 850 j = 2, n a(j,m1) = u * e(j) * a(j,m1) u = e(j) e2(j) = a(j,m1) ** 2 a(j,mb) = d(j) * a(j,mb) d(j) = a(j,mb) e(j) = a(j,m1) 850 continue c d(1) = a(1,mb) e(1) = 0.0e0 e2(1) = 0.0e0 go to 1001 c 900 do 950 j = 1, n d(j) = a(j,mb) e(j) = 0.0e0 e2(j) = 0.0e0 950 continue c 1001 return end subroutine comlr2(nm,n,low,igh,int,hr,hi,wr,wi,zr,zi,ierr) C MESHED overflow control WITH vectors of isolated roots (10/19/89 BSG) C MESHED overflow control WITH triangular multiply (10/30/89 BSG) c integer i,j,k,l,m,n,en,ii,jj,ll,mm,nm,nn,igh,im1,ip1, x itn,its,low,mp1,enm1,iend,ierr real hr(nm,n),hi(nm,n),wr(n),wi(n),zr(nm,n),zi(nm,n) real si,sr,ti,tr,xi,xr,yi,yr,zzi,zzr,norm,tst1,tst2 integer int(igh) c c this subroutine is a translation of the algol procedure comlr2, c num. math. 16, 181-204(1970) by peters and wilkinson. c handbook for auto. comp., vol.ii-linear algebra, 372-395(1971). c c this subroutine finds the eigenvalues and eigenvectors c of a complex upper hessenberg matrix by the modified lr c method. the eigenvectors of a complex general matrix c can also be found if comhes has been used to reduce c this general matrix to hessenberg form. c c on input c c nm must be set to the row dimension of two-dimensional c array parameters as declared in the calling program c dimension statement. c c n is the order of the matrix. c c low and igh are integers determined by the balancing c subroutine cbal. if cbal has not been used, c set low=1, igh=n. c c int contains information on the rows and columns interchanged c in the reduction by comhes, if performed. only elements c low through igh are used. if the eigenvectors of the hessen- c berg matrix are desired, set int(j)=j for these elements. c c hr and hi contain the real and imaginary parts, c respectively, of the complex upper hessenberg matrix. c their lower triangles below the subdiagonal contain the c multipliers which were used in the reduction by comhes, c if performed. if the eigenvectors of the hessenberg c matrix are desired, these elements must be set to zero. c c on output c c the upper hessenberg portions of hr and hi have been c destroyed, but the location hr(1,1) contains the norm c of the triangularized matrix. c c wr and wi contain the real and imaginary parts, c respectively, of the eigenvalues. if an error c exit is made, the eigenvalues should be correct c for indices ierr+1,...,n. c c zr and zi contain the real and imaginary parts, c respectively, of the eigenvectors. the eigenvectors c are unnormalized. if an error exit is made, none of c the eigenvectors has been found. c c ierr is set to c zero for normal return, c j if the limit of 30*n iterations is exhausted c while the j-th eigenvalue is being sought. c c c calls cdiv for complex division. c calls csroot for complex square root. c c questions and comments should be directed to burton s. garbow, c mathematics and computer science div, argonne national laboratory c c this version dated october 1989. c c ------------------------------------------------------------------ c ierr = 0 c .......... initialize eigenvector matrix .......... do 100 i = 1, n c do 100 j = 1, n zr(i,j) = 0.0e0 zi(i,j) = 0.0e0 if (i .eq. j) zr(i,j) = 1.0e0 100 continue c .......... form the matrix of accumulated transformations c from the information left by comhes .......... iend = igh - low - 1 if (iend .le. 0) go to 180 c .......... for i=igh-1 step -1 until low+1 do -- .......... do 160 ii = 1, iend i = igh - ii ip1 = i + 1 c do 120 k = ip1, igh zr(k,i) = hr(k,i-1) zi(k,i) = hi(k,i-1) 120 continue c j = int(i) if (i .eq. j) go to 160 c do 140 k = i, igh zr(i,k) = zr(j,k) zi(i,k) = zi(j,k) zr(j,k) = 0.0e0 zi(j,k) = 0.0e0 140 continue c zr(j,i) = 1.0e0 160 continue c .......... store roots isolated by cbal .......... 180 do 200 i = 1, n if (i .ge. low .and. i .le. igh) go to 200 wr(i) = hr(i,i) wi(i) = hi(i,i) 200 continue c en = igh tr = 0.0e0 ti = 0.0e0 itn = 30*n c .......... search for next eigenvalue .......... 220 if (en .lt. low) go to 680 its = 0 enm1 = en - 1 c .......... look for single small sub-diagonal element c for l=en step -1 until low do -- .......... 240 do 260 ll = low, en l = en + low - ll if (l .eq. low) go to 300 tst1 = abs(hr(l-1,l-1)) + abs(hi(l-1,l-1)) x + abs(hr(l,l)) + abs(hi(l,l)) tst2 = tst1 + abs(hr(l,l-1)) + abs(hi(l,l-1)) if (tst2 .eq. tst1) go to 300 260 continue c .......... form shift .......... 300 if (l .eq. en) go to 660 if (itn .eq. 0) go to 1000 if (its .eq. 10 .or. its .eq. 20) go to 320 sr = hr(en,en) si = hi(en,en) xr = hr(enm1,en) * hr(en,enm1) - hi(enm1,en) * hi(en,enm1) xi = hr(enm1,en) * hi(en,enm1) + hi(enm1,en) * hr(en,enm1) if (xr .eq. 0.0e0 .and. xi .eq. 0.0e0) go to 340 yr = (hr(enm1,enm1) - sr) / 2.0e0 yi = (hi(enm1,enm1) - si) / 2.0e0 call csroot(yr**2-yi**2+xr,2.0e0*yr*yi+xi,zzr,zzi) if (yr * zzr + yi * zzi .ge. 0.0e0) go to 310 zzr = -zzr zzi = -zzi 310 call cdiv(xr,xi,yr+zzr,yi+zzi,xr,xi) sr = sr - xr si = si - xi go to 340 c .......... form exceptional shift .......... 320 sr = abs(hr(en,enm1)) + abs(hr(enm1,en-2)) si = abs(hi(en,enm1)) + abs(hi(enm1,en-2)) c 340 do 360 i = low, en hr(i,i) = hr(i,i) - sr hi(i,i) = hi(i,i) - si 360 continue c tr = tr + sr ti = ti + si its = its + 1 itn = itn - 1 c .......... look for two consecutive small c sub-diagonal elements .......... xr = abs(hr(enm1,enm1)) + abs(hi(enm1,enm1)) yr = abs(hr(en,enm1)) + abs(hi(en,enm1)) zzr = abs(hr(en,en)) + abs(hi(en,en)) c .......... for m=en-1 step -1 until l do -- .......... do 380 mm = l, enm1 m = enm1 + l - mm if (m .eq. l) go to 420 yi = yr yr = abs(hr(m,m-1)) + abs(hi(m,m-1)) xi = zzr zzr = xr xr = abs(hr(m-1,m-1)) + abs(hi(m-1,m-1)) tst1 = zzr / yi * (zzr + xr + xi) tst2 = tst1 + yr if (tst2 .eq. tst1) go to 420 380 continue c .......... triangular decomposition h=l*r .......... 420 mp1 = m + 1 c do 520 i = mp1, en im1 = i - 1 xr = hr(im1,im1) xi = hi(im1,im1) yr = hr(i,im1) yi = hi(i,im1) if (abs(xr) + abs(xi) .ge. abs(yr) + abs(yi)) go to 460 c .......... interchange rows of hr and hi .......... do 440 j = im1, n zzr = hr(im1,j) hr(im1,j) = hr(i,j) hr(i,j) = zzr zzi = hi(im1,j) hi(im1,j) = hi(i,j) hi(i,j) = zzi 440 continue c call cdiv(xr,xi,yr,yi,zzr,zzi) wr(i) = 1.0e0 go to 480 460 call cdiv(yr,yi,xr,xi,zzr,zzi) wr(i) = -1.0e0 480 hr(i,im1) = zzr hi(i,im1) = zzi c do 500 j = i, n hr(i,j) = hr(i,j) - zzr * hr(im1,j) + zzi * hi(im1,j) hi(i,j) = hi(i,j) - zzr * hi(im1,j) - zzi * hr(im1,j) 500 continue c 520 continue c .......... composition r*l=h .......... do 640 j = mp1, en xr = hr(j,j-1) xi = hi(j,j-1) hr(j,j-1) = 0.0e0 hi(j,j-1) = 0.0e0 c .......... interchange columns of hr, hi, zr, and zi, c if necessary .......... if (wr(j) .le. 0.0e0) go to 580 c do 540 i = 1, j zzr = hr(i,j-1) hr(i,j-1) = hr(i,j) hr(i,j) = zzr zzi = hi(i,j-1) hi(i,j-1) = hi(i,j) hi(i,j) = zzi 540 continue c do 560 i = low, igh zzr = zr(i,j-1) zr(i,j-1) = zr(i,j) zr(i,j) = zzr zzi = zi(i,j-1) zi(i,j-1) = zi(i,j) zi(i,j) = zzi 560 continue c 580 do 600 i = 1, j hr(i,j-1) = hr(i,j-1) + xr * hr(i,j) - xi * hi(i,j) hi(i,j-1) = hi(i,j-1) + xr * hi(i,j) + xi * hr(i,j) 600 continue c .......... accumulate transformations .......... do 620 i = low, igh zr(i,j-1) = zr(i,j-1) + xr * zr(i,j) - xi * zi(i,j) zi(i,j-1) = zi(i,j-1) + xr * zi(i,j) + xi * zr(i,j) 620 continue c 640 continue c go to 240 c .......... a root found .......... 660 hr(en,en) = hr(en,en) + tr wr(en) = hr(en,en) hi(en,en) = hi(en,en) + ti wi(en) = hi(en,en) en = enm1 go to 220 c .......... all roots found. backsubstitute to find c vectors of upper triangular form .......... 680 norm = 0.0e0 c do 720 i = 1, n c do 720 j = i, n tr = abs(hr(i,j)) + abs(hi(i,j)) if (tr .gt. norm) norm = tr 720 continue c hr(1,1) = norm if (n .eq. 1 .or. norm .eq. 0.0e0) go to 1001 c .......... for en=n step -1 until 2 do -- .......... do 800 nn = 2, n en = n + 2 - nn xr = wr(en) xi = wi(en) hr(en,en) = 1.0e0 hi(en,en) = 0.0e0 enm1 = en - 1 c .......... for i=en-1 step -1 until 1 do -- .......... do 780 ii = 1, enm1 i = en - ii zzr = 0.0e0 zzi = 0.0e0 ip1 = i + 1 c do 740 j = ip1, en zzr = zzr + hr(i,j) * hr(j,en) - hi(i,j) * hi(j,en) zzi = zzi + hr(i,j) * hi(j,en) + hi(i,j) * hr(j,en) 740 continue c yr = xr - wr(i) yi = xi - wi(i) if (yr .ne. 0.0e0 .or. yi .ne. 0.0e0) go to 765 tst1 = norm yr = tst1 760 yr = 0.01e0 * yr tst2 = norm + yr if (tst2 .gt. tst1) go to 760 765 continue call cdiv(zzr,zzi,yr,yi,hr(i,en),hi(i,en)) c .......... overflow control .......... tr = abs(hr(i,en)) + abs(hi(i,en)) if (tr .eq. 0.0e0) go to 780 tst1 = tr tst2 = tst1 + 1.0e0/tst1 if (tst2 .gt. tst1) go to 780 do 770 j = i, en hr(j,en) = hr(j,en)/tr hi(j,en) = hi(j,en)/tr 770 continue c 780 continue c 800 continue c .......... end backsubstitution .......... c .......... vectors of isolated roots .......... do 840 i = 1, N if (i .ge. low .and. i .le. igh) go to 840 c do 820 j = I, n zr(i,j) = hr(i,j) zi(i,j) = hi(i,j) 820 continue c 840 continue c .......... multiply by transformation matrix to give c vectors of original full matrix. c for j=n step -1 until low do -- .......... do 880 jj = low, N j = n + low - jj m = min0(j,igh) c do 880 i = low, igh zzr = 0.0e0 zzi = 0.0e0 c do 860 k = low, m zzr = zzr + zr(i,k) * hr(k,j) - zi(i,k) * hi(k,j) zzi = zzi + zr(i,k) * hi(k,j) + zi(i,k) * hr(k,j) 860 continue c zr(i,j) = zzr zi(i,j) = zzi 880 continue c go to 1001 c .......... set error -- all eigenvalues have not c converged after 30*n iterations .......... 1000 ierr = en 1001 return end subroutine comqr2(nm,n,low,igh,ortr,orti,hr,hi,wr,wi,zr,zi,ierr) C MESHED overflow control WITH vectors of isolated roots (10/19/89 BSG) C MESHED overflow control WITH triangular multiply (10/30/89 BSG) c integer i,j,k,l,m,n,en,ii,jj,ll,nm,nn,igh,ip1, x itn,its,low,lp1,enm1,iend,ierr real hr(nm,n),hi(nm,n),wr(n),wi(n),zr(nm,n),zi(nm,n), x ortr(igh),orti(igh) real si,sr,ti,tr,xi,xr,yi,yr,zzi,zzr,norm,tst1,tst2, x pythag c c this subroutine is a translation of a unitary analogue of the c algol procedure comlr2, num. math. 16, 181-204(1970) by peters c and wilkinson. c handbook for auto. comp., vol.ii-linear algebra, 372-395(1971). c the unitary analogue substitutes the qr algorithm of francis c (comp. jour. 4, 332-345(1962)) for the lr algorithm. c c this subroutine finds the eigenvalues and eigenvectors c of a complex upper hessenberg matrix by the qr c method. the eigenvectors of a complex general matrix c can also be found if corth has been used to reduce c this general matrix to hessenberg form. c c on input c c nm must be set to the row dimension of two-dimensional c array parameters as declared in the calling program c dimension statement. c c n is the order of the matrix. c c low and igh are integers determined by the balancing c subroutine cbal. if cbal has not been used, c set low=1, igh=n. c c ortr and orti contain information about the unitary trans- c formations used in the reduction by corth, if performed. c only elements low through igh are used. if the eigenvectors c of the hessenberg matrix are desired, set ortr(j) and c orti(j) to 0.0e0 for these elements. c c hr and hi contain the real and imaginary parts, c respectively, of the complex upper hessenberg matrix. c their lower triangles below the subdiagonal contain further c information about the transformations which were used in the c reduction by corth, if performed. if the eigenvectors of c the hessenberg matrix are desired, these elements may be c arbitrary. c c on output c c ortr, orti, and the upper hessenberg portions of hr and hi c have been destroyed. c c wr and wi contain the real and imaginary parts, c respectively, of the eigenvalues. if an error c exit is made, the eigenvalues should be correct c for indices ierr+1,...,n. c c zr and zi contain the real and imaginary parts, c respectively, of the eigenvectors. the eigenvectors c are unnormalized. if an error exit is made, none of c the eigenvectors has been found. c c ierr is set to c zero for normal return, c j if the limit of 30*n iterations is exhausted c while the j-th eigenvalue is being sought. c c calls cdiv for complex division. c calls csroot for complex square root. c calls pythag for sqrt(a*a + b*b) . c c questions and comments should be directed to burton s. garbow, c mathematics and computer science div, argonne national laboratory c c this version dated october 1989. c c ------------------------------------------------------------------ c ierr = 0 c .......... initialize eigenvector matrix .......... do 101 j = 1, n c do 100 i = 1, n zr(i,j) = 0.0e0 zi(i,j) = 0.0e0 100 continue zr(j,j) = 1.0e0 101 continue c .......... form the matrix of accumulated transformations c from the information left by corth .......... iend = igh - low - 1 if (iend) 180, 150, 105 c .......... for i=igh-1 step -1 until low+1 do -- .......... 105 do 140 ii = 1, iend i = igh - ii if (ortr(i) .eq. 0.0e0 .and. orti(i) .eq. 0.0e0) go to 140 if (hr(i,i-1) .eq. 0.0e0 .and. hi(i,i-1) .eq. 0.0e0) go to 140 c .......... norm below is negative of h formed in corth .......... norm = hr(i,i-1) * ortr(i) + hi(i,i-1) * orti(i) ip1 = i + 1 c do 110 k = ip1, igh ortr(k) = hr(k,i-1) orti(k) = hi(k,i-1) 110 continue c do 130 j = i, igh sr = 0.0e0 si = 0.0e0 c do 115 k = i, igh sr = sr + ortr(k) * zr(k,j) + orti(k) * zi(k,j) si = si + ortr(k) * zi(k,j) - orti(k) * zr(k,j) 115 continue c sr = sr / norm si = si / norm c do 120 k = i, igh zr(k,j) = zr(k,j) + sr * ortr(k) - si * orti(k) zi(k,j) = zi(k,j) + sr * orti(k) + si * ortr(k) 120 continue c 130 continue c 140 continue c .......... create real subdiagonal elements .......... 150 l = low + 1 c do 170 i = l, igh ll = min0(i+1,igh) if (hi(i,i-1) .eq. 0.0e0) go to 170 norm = pythag(hr(i,i-1),hi(i,i-1)) yr = hr(i,i-1) / norm yi = hi(i,i-1) / norm hr(i,i-1) = norm hi(i,i-1) = 0.0e0 c do 155 j = i, n si = yr * hi(i,j) - yi * hr(i,j) hr(i,j) = yr * hr(i,j) + yi * hi(i,j) hi(i,j) = si 155 continue c do 160 j = 1, ll si = yr * hi(j,i) + yi * hr(j,i) hr(j,i) = yr * hr(j,i) - yi * hi(j,i) hi(j,i) = si 160 continue c do 165 j = low, igh si = yr * zi(j,i) + yi * zr(j,i) zr(j,i) = yr * zr(j,i) - yi * zi(j,i) zi(j,i) = si 165 continue c 170 continue c .......... store roots isolated by cbal .......... 180 do 200 i = 1, n if (i .ge. low .and. i .le. igh) go to 200 wr(i) = hr(i,i) wi(i) = hi(i,i) 200 continue c en = igh tr = 0.0e0 ti = 0.0e0 itn = 30*n c .......... search for next eigenvalue .......... 220 if (en .lt. low) go to 680 its = 0 enm1 = en - 1 c .......... look for single small sub-diagonal element c for l=en step -1 until low do -- .......... 240 do 260 ll = low, en l = en + low - ll if (l .eq. low) go to 300 tst1 = abs(hr(l-1,l-1)) + abs(hi(l-1,l-1)) x + abs(hr(l,l)) + abs(hi(l,l)) tst2 = tst1 + abs(hr(l,l-1)) if (tst2 .eq. tst1) go to 300 260 continue c .......... form shift .......... 300 if (l .eq. en) go to 660 if (itn .eq. 0) go to 1000 if (its .eq. 10 .or. its .eq. 20) go to 320 sr = hr(en,en) si = hi(en,en) xr = hr(enm1,en) * hr(en,enm1) xi = hi(enm1,en) * hr(en,enm1) if (xr .eq. 0.0e0 .and. xi .eq. 0.0e0) go to 340 yr = (hr(enm1,enm1) - sr) / 2.0e0 yi = (hi(enm1,enm1) - si) / 2.0e0 call csroot(yr**2-yi**2+xr,2.0e0*yr*yi+xi,zzr,zzi) if (yr * zzr + yi * zzi .ge. 0.0e0) go to 310 zzr = -zzr zzi = -zzi 310 call cdiv(xr,xi,yr+zzr,yi+zzi,xr,xi) sr = sr - xr si = si - xi go to 340 c .......... form exceptional shift .......... 320 sr = abs(hr(en,enm1)) + abs(hr(enm1,en-2)) si = 0.0e0 c 340 do 360 i = low, en hr(i,i) = hr(i,i) - sr hi(i,i) = hi(i,i) - si 360 continue c tr = tr + sr ti = ti + si its = its + 1 itn = itn - 1 c .......... reduce to triangle (rows) .......... lp1 = l + 1 c do 500 i = lp1, en sr = hr(i,i-1) hr(i,i-1) = 0.0e0 norm = pythag(pythag(hr(i-1,i-1),hi(i-1,i-1)),sr) xr = hr(i-1,i-1) / norm wr(i-1) = xr xi = hi(i-1,i-1) / norm wi(i-1) = xi hr(i-1,i-1) = norm hi(i-1,i-1) = 0.0e0 hi(i,i-1) = sr / norm c do 490 j = i, n yr = hr(i-1,j) yi = hi(i-1,j) zzr = hr(i,j) zzi = hi(i,j) hr(i-1,j) = xr * yr + xi * yi + hi(i,i-1) * zzr hi(i-1,j) = xr * yi - xi * yr + hi(i,i-1) * zzi hr(i,j) = xr * zzr - xi * zzi - hi(i,i-1) * yr hi(i,j) = xr * zzi + xi * zzr - hi(i,i-1) * yi 490 continue c 500 continue c si = hi(en,en) if (si .eq. 0.0e0) go to 540 norm = pythag(hr(en,en),si) sr = hr(en,en) / norm si = si / norm hr(en,en) = norm hi(en,en) = 0.0e0 if (en .eq. n) go to 540 ip1 = en + 1 c do 520 j = ip1, n yr = hr(en,j) yi = hi(en,j) hr(en,j) = sr * yr + si * yi hi(en,j) = sr * yi - si * yr 520 continue c .......... inverse operation (columns) .......... 540 do 600 j = lp1, en xr = wr(j-1) xi = wi(j-1) c do 580 i = 1, j yr = hr(i,j-1) yi = 0.0e0 zzr = hr(i,j) zzi = hi(i,j) if (i .eq. j) go to 560 yi = hi(i,j-1) hi(i,j-1) = xr * yi + xi * yr + hi(j,j-1) * zzi 560 hr(i,j-1) = xr * yr - xi * yi + hi(j,j-1) * zzr hr(i,j) = xr * zzr + xi * zzi - hi(j,j-1) * yr hi(i,j) = xr * zzi - xi * zzr - hi(j,j-1) * yi 580 continue c do 590 i = low, igh yr = zr(i,j-1) yi = zi(i,j-1) zzr = zr(i,j) zzi = zi(i,j) zr(i,j-1) = xr * yr - xi * yi + hi(j,j-1) * zzr zi(i,j-1) = xr * yi + xi * yr + hi(j,j-1) * zzi zr(i,j) = xr * zzr + xi * zzi - hi(j,j-1) * yr zi(i,j) = xr * zzi - xi * zzr - hi(j,j-1) * yi 590 continue c 600 continue c if (si .eq. 0.0e0) go to 240 c do 630 i = 1, en yr = hr(i,en) yi = hi(i,en) hr(i,en) = sr * yr - si * yi hi(i,en) = sr * yi + si * yr 630 continue c do 640 i = low, igh yr = zr(i,en) yi = zi(i,en) zr(i,en) = sr * yr - si * yi zi(i,en) = sr * yi + si * yr 640 continue c go to 240 c .......... a root found .......... 660 hr(en,en) = hr(en,en) + tr wr(en) = hr(en,en) hi(en,en) = hi(en,en) + ti wi(en) = hi(en,en) en = enm1 go to 220 c .......... all roots found. backsubstitute to find c vectors of upper triangular form .......... 680 norm = 0.0e0 c do 720 i = 1, n c do 720 j = i, n tr = abs(hr(i,j)) + abs(hi(i,j)) if (tr .gt. norm) norm = tr 720 continue c if (n .eq. 1 .or. norm .eq. 0.0e0) go to 1001 c .......... for en=n step -1 until 2 do -- .......... do 800 nn = 2, n en = n + 2 - nn xr = wr(en) xi = wi(en) hr(en,en) = 1.0e0 hi(en,en) = 0.0e0 enm1 = en - 1 c .......... for i=en-1 step -1 until 1 do -- .......... do 780 ii = 1, enm1 i = en - ii zzr = 0.0e0 zzi = 0.0e0 ip1 = i + 1 c do 740 j = ip1, en zzr = zzr + hr(i,j) * hr(j,en) - hi(i,j) * hi(j,en) zzi = zzi + hr(i,j) * hi(j,en) + hi(i,j) * hr(j,en) 740 continue c yr = xr - wr(i) yi = xi - wi(i) if (yr .ne. 0.0e0 .or. yi .ne. 0.0e0) go to 765 tst1 = norm yr = tst1 760 yr = 0.01e0 * yr tst2 = norm + yr if (tst2 .gt. tst1) go to 760 765 continue call cdiv(zzr,zzi,yr,yi,hr(i,en),hi(i,en)) c .......... overflow control .......... tr = abs(hr(i,en)) + abs(hi(i,en)) if (tr .eq. 0.0e0) go to 780 tst1 = tr tst2 = tst1 + 1.0e0/tst1 if (tst2 .gt. tst1) go to 780 do 770 j = i, en hr(j,en) = hr(j,en)/tr hi(j,en) = hi(j,en)/tr 770 continue c 780 continue c 800 continue c .......... end backsubstitution .......... c .......... vectors of isolated roots .......... do 840 i = 1, N if (i .ge. low .and. i .le. igh) go to 840 c do 820 j = I, n zr(i,j) = hr(i,j) zi(i,j) = hi(i,j) 820 continue c 840 continue c .......... multiply by transformation matrix to give c vectors of original full matrix. c for j=n step -1 until low do -- .......... do 880 jj = low, N j = n + low - jj m = min0(j,igh) c do 880 i = low, igh zzr = 0.0e0 zzi = 0.0e0 c do 860 k = low, m zzr = zzr + zr(i,k) * hr(k,j) - zi(i,k) * hi(k,j) zzi = zzi + zr(i,k) * hi(k,j) + zi(i,k) * hr(k,j) 860 continue c zr(i,j) = zzr zi(i,j) = zzi 880 continue c go to 1001 c .......... set error -- all eigenvalues have not c converged after 30*n iterations .......... 1000 ierr = en 1001 return end subroutine hqr(nm,n,low,igh,h,wr,wi,ierr) C RESTORED CORRECT INDICES OF LOOPS (200,210,230,240). (9/29/89 BSG) c integer i,j,k,l,m,n,en,ll,mm,na,nm,igh,itn,its,low,mp2,enm2,ierr real h(nm,n),wr(n),wi(n) real p,q,r,s,t,w,x,y,zz,norm,tst1,tst2 logical notlas c c this subroutine is a translation of the algol procedure hqr, c num. math. 14, 219-231(1970) by martin, peters, and wilkinson. c handbook for auto. comp., vol.ii-linear algebra, 359-371(1971). c c this subroutine finds the eigenvalues of a real c upper hessenberg matrix by the qr method. c c on input c c nm must be set to the row dimension of two-dimensional c array parameters as declared in the calling program c dimension statement. c c n is the order of the matrix. c c low and igh are integers determined by the balancing c subroutine balanc. if balanc has not been used, c set low=1, igh=n. c c h contains the upper hessenberg matrix. information about c the transformations used in the reduction to hessenberg c form by elmhes or orthes, if performed, is stored c in the remaining triangle under the hessenberg matrix. c c on output c c h has been destroyed. therefore, it must be saved c before calling hqr if subsequent calculation and c back transformation of eigenvectors is to be performed. c c wr and wi contain the real and imaginary parts, c respectively, of the eigenvalues. the eigenvalues c are unordered except that complex conjugate pairs c of values appear consecutively with the eigenvalue c having the positive imaginary part first. if an c error exit is made, the eigenvalues should be correct c for indices ierr+1,...,n. c c ierr is set to c zero for normal return, c j if the limit of 30*n iterations is exhausted c while the j-th eigenvalue is being sought. c c questions and comments should be directed to burton s. garbow, c mathematics and computer science div, argonne national laboratory c c this version dated september 1989. c c ------------------------------------------------------------------ c ierr = 0 norm = 0.0e0 k = 1 c .......... store roots isolated by balanc c and compute matrix norm .......... do 50 i = 1, n c do 40 j = k, n 40 norm = norm + abs(h(i,j)) c k = i if (i .ge. low .and. i .le. igh) go to 50 wr(i) = h(i,i) wi(i) = 0.0e0 50 continue c en = igh t = 0.0e0 itn = 30*n c .......... search for next eigenvalues .......... 60 if (en .lt. low) go to 1001 its = 0 na = en - 1 enm2 = na - 1 c .......... look for single small sub-diagonal element c for l=en step -1 until low do -- .......... 70 do 80 ll = low, en l = en + low - ll if (l .eq. low) go to 100 s = abs(h(l-1,l-1)) + abs(h(l,l)) if (s .eq. 0.0e0) s = norm tst1 = s tst2 = tst1 + abs(h(l,l-1)) if (tst2 .eq. tst1) go to 100 80 continue c .......... form shift .......... 100 x = h(en,en) if (l .eq. en) go to 270 y = h(na,na) w = h(en,na) * h(na,en) if (l .eq. na) go to 280 if (itn .eq. 0) go to 1000 if (its .ne. 10 .and. its .ne. 20) go to 130 c .......... form exceptional shift .......... t = t + x c do 120 i = low, en 120 h(i,i) = h(i,i) - x c s = abs(h(en,na)) + abs(h(na,enm2)) x = 0.75e0 * s y = x w = -0.4375e0 * s * s 130 its = its + 1 itn = itn - 1 c .......... look for two consecutive small c sub-diagonal elements. c for m=en-2 step -1 until l do -- .......... do 140 mm = l, enm2 m = enm2 + l - mm zz = h(m,m) r = x - zz s = y - zz p = (r * s - w) / h(m+1,m) + h(m,m+1) q = h(m+1,m+1) - zz - r - s r = h(m+2,m+1) s = abs(p) + abs(q) + abs(r) p = p / s q = q / s r = r / s if (m .eq. l) go to 150 tst1 = abs(p)*(abs(h(m-1,m-1)) + abs(zz) + abs(h(m+1,m+1))) tst2 = tst1 + abs(h(m,m-1))*(abs(q) + abs(r)) if (tst2 .eq. tst1) go to 150 140 continue c 150 mp2 = m + 2 c do 160 i = mp2, en h(i,i-2) = 0.0e0 if (i .eq. mp2) go to 160 h(i,i-3) = 0.0e0 160 continue c .......... double qr step involving rows l to en and c columns m to en .......... do 260 k = m, na notlas = k .ne. na if (k .eq. m) go to 170 p = h(k,k-1) q = h(k+1,k-1) r = 0.0e0 if (notlas) r = h(k+2,k-1) x = abs(p) + abs(q) + abs(r) if (x .eq. 0.0e0) go to 260 p = p / x q = q / x r = r / x 170 s = sign(sqrt(p*p+q*q+r*r),p) if (k .eq. m) go to 180 h(k,k-1) = -s * x go to 190 180 if (l .ne. m) h(k,k-1) = -h(k,k-1) 190 p = p + s x = p / s y = q / s zz = r / s q = q / p r = r / p if (notlas) go to 225 c .......... row modification .......... do 200 j = k, EN p = h(k,j) + q * h(k+1,j) h(k,j) = h(k,j) - p * x h(k+1,j) = h(k+1,j) - p * y 200 continue c j = min0(en,k+3) c .......... column modification .......... do 210 i = L, j p = x * h(i,k) + y * h(i,k+1) h(i,k) = h(i,k) - p h(i,k+1) = h(i,k+1) - p * q 210 continue go to 255 225 continue c .......... row modification .......... do 230 j = k, EN p = h(k,j) + q * h(k+1,j) + r * h(k+2,j) h(k,j) = h(k,j) - p * x h(k+1,j) = h(k+1,j) - p * y h(k+2,j) = h(k+2,j) - p * zz 230 continue c j = min0(en,k+3) c .......... column modification .......... do 240 i = L, j p = x * h(i,k) + y * h(i,k+1) + zz * h(i,k+2) h(i,k) = h(i,k) - p h(i,k+1) = h(i,k+1) - p * q h(i,k+2) = h(i,k+2) - p * r 240 continue 255 continue c 260 continue c go to 70 c .......... one root found .......... 270 wr(en) = x + t wi(en) = 0.0e0 en = na go to 60 c .......... two roots found .......... 280 p = (y - x) / 2.0e0 q = p * p + w zz = sqrt(abs(q)) x = x + t if (q .lt. 0.0e0) go to 320 c .......... real pair .......... zz = p + sign(zz,p) wr(na) = x + zz wr(en) = wr(na) if (zz .ne. 0.0e0) wr(en) = x - w / zz wi(na) = 0.0e0 wi(en) = 0.0e0 go to 330 c .......... complex pair .......... 320 wr(na) = x + p wr(en) = x + p wi(na) = zz wi(en) = -zz 330 en = enm2 go to 60 c .......... set error -- all eigenvalues have not c converged after 30*n iterations .......... 1000 ierr = en 1001 return end