function out = evaporator(x, aux)
% Steady state CO2 evaporator model
% Jørgen Bauck Jensen
% 10.01.2005
% Inputs:       x - States
%               u - Inputs
%               d - Data struct
% Outputs:      out.res - residual
u = aux.u;
d = aux.d;
sc = aux.sc;
x = x.*sc.x;

T = x(1);
Nl = x(2);
Nv = x(3);
Vl = x(4);
Q = x(5);
A = x(6);
P = x(end);
Vv = d.Vvap-Vl;

hin = u(1);
n = u(2);
Tair = u(end);
Pl = P_given_TVN([T; Vl; Nl]);
myl = my_given_TVN([T; Vl; Nl]);
Pv = P_given_TVN([T; Vv; Nv]);
myv = my_given_TVN([T; Vv; Nv]);
hout = h_given_TVN([T; Vv; Nv]);

out = [(hin-hout)*n+Q;                  % Energy balance
       Q-d.Uvap.*A.*(Tair-T); % Heat transfer
       Pv-P;
       Pl-P;
       myl-myv]./sc.res;                    
