function bt_y = BUBL_T(A, B, C, P,x)
% [T y] = BUBL_T(A, B, C, P,x)
% Bubble Temperature and Composition of Vapor
% Input: Antoine Constants (A,B,C), Total Pressure, x
% Output: Bubble Temperature & Composition of vapor

% Done on 09-Sep-2001, M.Subramanian
% msubbu@svce.ac.in

n = size(A,2); % No of components
T_init = sum(x.*sat_temp_antoine(A,B,C,P));
p_sat = sat_pr_antoine(A,B,C,T_init);
alpha = p_sat./p_sat(n);
p_sat(n) = P/sum(x.*alpha);
T = sat_temp_antoine(A(n),B(n),C(n),p_sat(n));

while abs(T-T_init) > 0.001
   T_init = T;
   p_sat = sat_pr_antoine(A,B,C,T_init);
   alpha = p_sat./p_sat(n);
	p_sat(n) = P/sum(x.*alpha);
   T = sat_temp_antoine(A(n),B(n),C(n),p_sat(n));
end
y = x.*p_sat/P;
bt_y = [T y];
% end

%A = [14.5463 14.2724 14.2043];
%B = [2940.46 2945.47 2972.64];
%C = [237.22 224 209];
%x = [0.3 0.45 0.25];
%P = 80;
%BUBL_T(A, B, C, x,P)
