function[sys,x0]=reakrt(t,x,u,flag)
q=.015;qc=0.004;
ro=1020;roc=998;
cp=4.02;cpc=4.182;
v=.23;vc=.21;
a=1.51;k=42.8;
cva=4.22;cvb=0;cvc=0;tv=328;tcv=298;
k10=1.55e11;k20=4.55e25;
e1lr=9850;e2lr=22019;
dr1h=8.6e4;dr2h=1.82e4;
cas=0.4919;cbs=2.0081;ccs=1.7199;ts=363.6011;tcs=350.1340;
if flag==0,
x0(1)=cas;
x0(2)=cbs;
x0(3)=ccs;
x0(4)=ts;
x0(5)=tcs;
sys=[5,0,1,1,0,0];
elseif flag==1,
   if t>=100
      tcv=328;
   end
   if t>=200
      tcv=293;
   end
k1=k10*exp(-e1lr/x(4));
k2=k20*exp(-e2lr/x(4));
hr=(dr1h*k1+dr2h*k2)*x(1);
dx(1)=q/v*(cva-x(1))-(k1+k2)*x(1);
dx(2)=q/v*(cvb-x(2))+k1*x(1);
dx(3)=q/v*(cvc-x(3))+k2*x(1);
dx(4)=hr/ro/cp+q/v*(tv-x(4))-a*k/v/ro/cp*(x(4)-x(5));
dx(5)=u(1)/vc*(tcv-x(5))+a*k/vc/roc/cpc*(x(4)-x(5));
sys=dx;
elseif flag==3,
   sys(1)=x(4);%+.1*(rand-.5);   
else 
sys=[];
end