function er=phaseg(iw,ioil,isol,dis,in,out,x)
% Phaseg: Calculates solute distribution in 2-phase separation using modules.
% function er=phaseg(iw,ioil,isol,dis,in,out,x)
% Argument   Gives
%   iw     index of the water in cnms.
%   ioil   index of oil in cnms.
%   isol   index of the solute in cnms.
%   dis    distribution coefficient
%   in     index of the inlet stream
%   out    indices of the exit streams
%    x     fraction of solute going into
%          the top phase
%  er returns the difference between dis and the
%     ratio actually set for the solute in the exit streams.
% For additional help and picture see PICPHASEG
% See also PHASE
% Example: >> ssec2([.1 .9],'phaseg(1,2,3,3.0,3,4:5,x)')
% revised help by TYLC

global ns
v([iw ioil isol])=[0 1 x];
sep(v,in,out)
temp=sum(ns(out,:)');
xs=ns(out,isol)./temp';
er=dis-xs(1)/xs(2);
