function er = reactee(s,tmp,in,out,rsx,jv,P)
% reactee: energy-balance equilibrium reactor module
% function er = reactee(s,tmp,in,out,rsx,jv,P)
% Argument List:
% Argument    Gives
%    s      the state of the exit stream:  'v'
%   tmp     the temperature of the exit stream in Tdeg.
%   in      the index(ices) of the inlet streams.
%   out     the index of the exit stream.
%   rsx     guess for reaction rates
%    jv     indices of reactions that will be at equilibrium
%     P     pressure of the exit stream
%  reactee returns the error  between the keq(thermo)
%  and the product of partial pressures from kvalp.m
%  Ex. cs = ssec2([0 .95],'reactee(''v'',1393,1,2,x,1,1)')
%     would give the equilibrium extent of reaction in vapor
%     stream 2 with temperature 1393Tdeg and 1(unit pressure)
%     for reaction 1 and inlet stream 1
% LDM
nj=length(jv);
keq=kequil(tmp,jv);
for ji=1:nj
    j=jv(ji);
    if  j > length(keq)
        disp('Index of reaction is too large')
        return
    end
    if keq(j) == 0
        disp('Equilibrium constant has not been calculated for this reaction')
        return
    end
    reacte(s,tmp,in,out,rsx);
    er(j) = keq(j) - Kvalp(j,out,P);
end
