function c=dsplaye(in,out,s,d)
% dsplaye	- Used in showe; displaying stream info in energy balance
%
% dsplaye(in,out,s,d)
% Arguments:
%     in     the inlet stream numbers and
%     out    the exit stream numbers
%     s      the number of spaces for each flow.
%            (NOTE: if s is less than 7 this probably won't work.)
%     d      the number of decimals to display flows.
%
% Example: cmix=dsplaye(1:2,3,10,3)
%
% OKB; help revised by MAH

global ns cnms ne Tdeg

if d<3
   de=d;
else
   de=d-2;
end

lin=length(in);
lout=length(out);
totl='   Total';

if s<8
   totl=totl(9-s:8);
else
   totl=cext(totl,s);
end

if length(in)==1
   min=ns(in,:)';
   tin=charmx(in,s,0);
   sin=floor((s-5)/2);
else
   min=ns(in,:);
   min=[min;sum(min)]';
   tin=[charmx(in,s,0),totl];
   sin=floor((((lin+1)*s)-5)/2);
end

if length(out)==1
   mout=ns(out,:)';
   tout=charmx(out,s,0);
   sout=floor((s-6)/2);
else
   mout=ns(out,:);
   mout=[mout;sum(mout)]';
   tout=[charmx(out,s,0),totl];
   sout=floor((((lout+1)*s)-6)/2);
end

tempin=charmx((ne(in,1))',s,2);

statein='';
for i=1:lin

   if ne(in(i),2)==1
      newstate=[cext(' ',(s-7)),'liquid '];
   elseif ne(in(i),2)==2
      newstate=[cext(' ',(s-6)),'vapor '];
   else
      newstate=[cext(' ',(s-6)),'solid '];
   end

   statein=[statein newstate(1:s)];
end

enthin=charmx((ne(in,3))',s,de);
tempout=charmx((ne(out,1))',s,2);

stateout='';
for i=1:lout
   if ne(out(i),2)==1
      newstate=[cext(' ',(s-7)),'liquid '];
   elseif ne(out(i),2)==2
      newstate=[cext(' ',(s-6)),'vapor '];
   else
      newstate=[cext(' ',(s-6)),'solid '];
   end

   stateout=[stateout newstate(1:s)];
end

enthout=charmx((ne(out,3))',s,de);

if lin~=1
   tempin=[tempin,cext(' ',s)];
   statein=[statein,cext(' ',s)];
   enthin=[enthin,charmx(sum(ne(in,3)),s,de)];
end

if lout~=1
   tempout=[tempout,cext(' ',s)];
   stateout=[stateout,cext(' ',s)];
   enthout=[enthout,charmx(sum(ne(out,3)),s,de)];
end

min=[min;csum(min)];
mout=[mout;csum(mout)];
inl=cext([cext(' ',sin),'Inlet'],length(tin));
inl=inl(1:length(tin));
cin=[inl;tin;tempin;statein;enthin];
cin=[cin;charmx(min,s,d)];
ino=cext([cext(' ',sout),'Outlet'],length(tout));
ino=ino(1:length(tout));
cout=[ino;tout;tempout;stateout;enthout];
cout=[cout;charmx(mout,s,d)];
[nr,nc]=size(cnms);

if nc<8
   bl=blank(nr,8-nc);
   cnms=addcol(cnms,bl);
   nc=8;
end

bl=cext(' ',nc-6);
lft=[cext('       ',nc);[bl,'Stream'];cext(['  Tmp ',Tdeg],nc)];
lft=[lft;cext('  State',nc);cext('  Entlpy',nc);cnms;cext('Total',nc)];
mid=[nchar(' ',nr+3);nchar('|',nr+3)]';
mid=[' |';' |';' |';mid];
c=addcol(lft,cin,mid,cout);
v=[1 2];
[nri,nc1]=size(min);
[nro,nco]=size(mout);

for k=1:nr
   if (abs(min(k,nc1))>eps)|(abs(mout(k,nco))>eps)
       v=[v,k+2];
   end
end

v=v+3;
c=c([1:3,v,nr+6],:);
[nr,nc]=size(c);
candsf=cext('Compound    Stream Flows',nc);
c=[c(1:5,:)
   candsf(1:nc)
   c(6:nr,:)];
   

