function s=thermo_state(T,rho,f) s=r23.eos(T,rho,f);s.h_out=s.h_J_kg;s.vapor_quality=NaN; if T=f.saturation_domain(1) && T<=f.saturation_domain(2) v=interp1(f.saturation(:,1),f.saturation(:,2:8),T,'pchip'); rl=v(2);rv=v(3); if rhorv x=(1/rho-1/rl)/(1/rv-1/rl); s.p_Pa=v(1);s.u_J_kg=(1-x)*v(4)+x*v(5);s.h_J_kg=s.u_J_kg+s.p_Pa/rho; s.h_out=v(7);s.vapor_quality=x;s.phase='two_phase_equilibrium'; end end end