function [sys,sys2,x0]=reboiler(T,x,u,flag,alphas,M0,hydraulics,Tc)
%
%Generalized reboiler model
%assumptions	- no liquid or vapour dynamics, constant relative volatility, 
%total condenser
%Input:
%		T				- time
%		X				- state vector containing composition vector 
%		u(1)			- Liquid feed to reboiler
% 		u(2:nc)		- Compositions for components 1 - (nc-1) in liq. feed
%		u(nc+1)		- reboiler demand
%		Tc				- time constant from boilup demand to actual boilup flow
% 		alphas		- relative volatilities for the nc components relateted to heaviest comp.
%		M0				- Tray holdup
global coldata
x0=[];
nc=length(alphas);
xc=x(1:nc-1);
holdup=x(nc);

if (flag==1)					%state derivatives xdot=f(x,u)
   %Splitting the input u
   Lin=u(1);
   xin=u(2:nc);
   V=u(nc+1);
   B=u(nc+2);
   mdot=Lin-V-B;
   yc=equilib(xc',alphas)';
   xdot=((Lin*(xin-xc)-V*(yc-xc))/holdup);
   sys=xdot;
   sys2=mdot;
elseif (flag==3)				%measurements y=f(x,u)
   V=u(nc+1);
   L=u(1);
   B=L-V;
   yc=equilib(xc',alphas)';
   sys=[B;xc;V;yc;holdup];
end