% REBOILER.M %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Reboiler model

function [sys,dm,temp,dT] = reboiler(t,x,u,flag)

temp = x(4);
holdup = x(5);
x = x(1:3);

if (flag == 1)
    
    
L_in = u(1);
x_in = u(2:4);
V_out = u(5);

    % Derivatives
    B = u(6);
    
    dm = L_in - V_out - B;
    [y,dT] = termo(x',temp,3);

    dx = (L_in * (x_in - x) - V_out * (y' - x)) / holdup;
    sys = dx;
elseif (flag == 3)
    % Measurements
    [y,dT] = termo(x',temp,3);
    sys = y;
end