function react(r,in,out)
% React: mass-balance module for simulating a reactor
% function react(r,in,out)
% Simulates the behavior of a reactor.
% Argument    Gives
%    r      the vector of reaction rates
%    in     the index of the inlet stream(s)
%    out    the index of the outlet stream
% The global variable: stoic is a matrix giving the
%   coefficient of the ith compound in the jth 
%   reaction as: stoic(i,j).
% For additional help and picture, see PICREACT
% OKB, TYLC
% Example: >> react(10,1,2)
%    would treat stream 1 as the inlet and stream 2
%    as the exit.  There must be only 1 reaction
%    and its rate is 10.

global ns stoic
cr=size(stoic);
if cr(1)~=length(r)
   disp('The reaction vector, r, and array, stoic, are inconsistent.')
   if length(r)==1
      disp('Your argument: r, says there is: 1 reaction.')
   else
      fprintf('Your argument: r, says there are: %2.0f',length(r))
      disp(' reactions.')
   end
   if cr(1)==1
      disp('The stoic array says there is 1 reaction')
   else
      fprintf('The stoic array says there are: %2.0f reactions\n',cr(1))
   end
   return
end
if length(in)>1
   ns(out,:)=sum(ns(in,:))+r*stoic;
else
   ns(out,:)=ns(in,:)+r*stoic;
end
