function rs=reactr(ipr,ipp,imr,icr,cpr,spp,in)
% reactr: calculates reaction rates for competing reactions (use with react)
% rs=reactr(ipr,ipp,imr,icr,cpr,spp,in)
%  Argument  Gives
%  ipr      index of primary reactant, 
%  ipp      index of primary product,
%  imr      index of main reaction,
%  icr      index of competing reaction,
%  cpr      conversion of primary reactant,
%  spp      selectivity to primary product,
%  in       index of inlet stream,
% reactr returns the reaction rates to be used in REACT for rs.
% For additional help and picture, see PICREACTR
% Example: >> rv=reactr(4,1,1,2,0.25,0.8,1);
%          >> react(rv,1,2)
% OKB, TYLC

global ns stoic
sstoic=size(stoic);
r=zeros(1,sstoic(1));
st=[stoic(imr,ipr),stoic(icr,ipr);stoic(imr,ipp),stoic(icr,ipp)];
d1=st(1,1)*st(2,2);
d2=st(2,1)*st(1,2);
den=d1-d2;
r(imr)=(d1-(spp*d2))/(den*st(1,1));
r(icr)=st(2,1)*(spp-1)/den;
rs=(-cpr)*(ns(in,ipr))*r;
