function [ x, y,VF, hl, hv  ] = flashTPeo(t,P, x0,y0,z,VF0,Zl0,Zg0)
% % Recursive routine for TPFlash calculation. 
% Extracts liquid composition, vapor composition, vapour
% fraction, molar enthalpy for liquid and for vapor phase, given Temperature and Pressure. 
%Definition of global variables for recoursive routine 
global T p zf
T=t; p=P; zf=z; 
% zf % Specified feed composition 
% p % Specified pressure [N/m2]
% T % Specified temperature [K]

%Inital estimates for solver
w0= [x0, y0, VF0,Zl0,Zg0];    
%x0 initial estimate for liquid composition
%y0 initial estimate for vapor composition
%vf0 initial estimate for vapor fraction
%Zl0 initial estimate for liquid compressibility
%Zg0 initial estimate for vapor compressibility
NC=5; 

%Boundary constrains. 
UB(1:2*NC+1)=1; UB(2*NC+1)=3;
LB(1:2*NC+1)=0;

%Solution subject to the equilibrium and solving the EOS. For further
%details check flashTPsrk.m
w=fmincon('1',w0,[],[],[],[],LB,UB,@flashTPsrkeo);

% %Data extraction

%Compositions for each phase (Final component calculated)
x =[w(1:NC-1) 1-sum(w(1:NC-1))];
y =[w(NC:2*NC-2) 1-sum(w(NC:2*NC-2))];
VF=w(2*NC-1);

%Compresibility, fugacity, enthalpy and volume calculations
%For the purpose of this project, only enthalpy is needed. 
[Zv,phiv,hv,Vv]= srks(y,T,p,2);
[Zl,phil,hl,Vl]= srks(x,T,p,1);

end

