function [bw,az,beta,ec] = pwr_1(mat,nblk,blk,blkp,repp,fulp,bw)
%
%  performs one iteration of the power iteration
%    described in "A Power Method for the Structured
%    Singular Value," Andy Packard, Michael Fan, and
%    John Doyle, pg. 2137-2142, 1988 CDC proceedings,
%    Austin, TX.
%
%    Not to be called by user.
%
    [nr nc] = size(mat);
    ec = 0;
    z = zeros(nr,1);
    a = mat * bw(:,1);
    beta(1) = norm(a);
    if beta(1) < 1e-6
      ec = 1;
      return
    end
    a = (1.0/beta(1)) * a; 
    for j=1:length(repp)
      ww = bw(blkp(repp(j),1):blkp(repp(j)+1,1)-1,2);
      aa = a(blkp(repp(j),2):blkp(repp(j)+1,2)-1);
      wwaa = ww' * aa;
	den = abs(wwaa);
      if den < 10*eps
	wwaa = wwaa + (den < 10*eps);	% set phase=1 for zero elements
	den = abs(wwaa);
      end %if den
        z(blkp(repp(j),2):blkp(repp(j)+1,2)-1) = (wwaa/den) * ww;

    end %for
    for j=1:length(fulp)
      aa = a(blkp(fulp(j),2):blkp(fulp(j)+1,2)-1);
      na = norm(aa);
      if na < 10*eps
	   fix = 1;
	else
	   fix = norm(bw(blkp(fulp(j),1):blkp(fulp(j)+1,1)-1,2)) / na;
      end
      z(blkp(fulp(j),2):blkp(fulp(j)+1,2)-1) = fix * aa;
    end
    az = [a z];

    bw(:,2) = mat' * z; 
    beta(2) = norm(bw(:,2));
    if beta(2) < 1e-6
      ec = 1;
      return
    end
%   check zero and return
    bw(:,2) = (1.0/beta(2)) * bw(:,2);
    for j=1:length(repp)
      ww = bw(blkp(repp(j),1):blkp(repp(j)+1,1)-1,2);
      aa = a(blkp(repp(j),2):blkp(repp(j)+1,2)-1);
      aaww = aa' * ww;
	den = abs(aaww);
      if den < 10*eps
	aaww = aaww + (den < 10*eps);	% set phase=1 for zero elements
	den = abs(aaww);
      end %if den
	bw(blkp(repp(j),1):blkp(repp(j)+1,1)-1,1) =  (aaww/den)* aa;
    end
    for j=1:length(fulp)
      ww = bw(blkp(fulp(j),1):blkp(fulp(j)+1,1)-1,2);
      nw = norm(ww);
      if nw < 10*eps
	   fix = 1;
	else
	   fix = norm(a(blkp(fulp(j),2):blkp(fulp(j)+1,2)-1)) / nw ;
      end
%     check zero and return
      bw(blkp(fulp(j),1):blkp(fulp(j)+1,1)-1,1) = fix * ww;
    end

%
% Copyright MUSYN INC 1991,  All Rights Reserved
