function prtmtx(nm,name)
%PRTMTX - Print numeric matrix with optional label
% nm - numeric matrix
% name - string label
%
% Philip D. Loewen
% 2 June 1997
% Adjusted 30 Dec 97

[m,n]=size(nm);

if nargin<2,
  label=[];
else    % Build nicely rectangular string matrix with label in top row.
  label=[name ' = '; setstr(ones(m-1,length(name)+3)*' ')];
end

% DEBUG HELPERS
%disp(label)


sm=[];
for ll = 1:n,
  thiscol = [];
  for kk=1:m,
    %disp(['kk=',int2str(kk),'; ll=',int2str(ll)])
    nextstring = sprintf('%8.2e ',nm(kk,ll));
    %% Next line pads leading blank on nonnegative numbers.  30 Dec 97.
    if nm(kk,ll)>=0, nextstring = setstr([' ',nextstring]); end;
    if kk>1,
      if length(nextstring)<size(thiscol,2),
        nextstring = [' '*ones(1,size(thiscol,2)-length(nextstring)), nextstring];
      elseif length(nextstring)>size(thiscol,2),
        thiscol = [' '*ones(size(thiscol,1),length(nextstring)-size(thiscol,2)), thiscol];
      end
    end
    thiscol = [thiscol; nextstring];
  end
  sm = [sm thiscol];
end
      
disp([label,sm])

return
