Engineering thermodynamics/Steam tables/Saturated temperature (small)/Generating code


The Excel spreadsheet Satpar.xlsx, as well as two Matlab files (XSteam.m, studentsaturated.m) must be placed in a folder. Run TableGraphmaker.m to generate the table and figures. The first row of Satpar.xlsx contains the temperatures (Celsius), and the second row contains the pressures (bars). At the moment, the code demands that the number of temperatures must equal the number of pressures.

Satpar.xlsx edit

1 3 10 30 100 200 225 250 275 300 325 350 355 360 365 373
1 3 10 20 30 40 50 75 100 125 150 175 200 210 215 220

studentsaturated edit

click to view/hide
clear all; close all;clc;
linewidth=1.2;  markersize = 3;
%Rwater=461.526/100000;  %Tcritical = 374; %Pcritical = 220.6395 %bar
Satpar=xlsread('Satpar.xlsx'); %Reads an excel file
T = Satpar(1,:); NT = size(T,2); % formally: p = Satpar(2,:); Np = size(p,2);
fout=fopen('StudentSaturateVersusT.txt', 'w+');% % formally: fout=fopen('saturatedpressures.txt', 'w+');%
sigfigs = '%10.2E'; %Significant figures
sigfigsT= '%10.1f'; %change to '%10.0f' ?

%Bug:  If T is out of range, the header will read the wrong values but the
%code might nevertheless run by removing out-of-range temperatures.
string1='====For T = ';  string2=' Celsius to T = ';  string3='Celsius====';
low=T(1);    high=T(NT);
stringlow = num2str(low,sigfigsT);
stringhigh=num2str(high,sigfigsT); %formally with stringplow and stringphigh
% formally:
% string1='====For P = ';  string2=' bars to P = ';  string3='bars====';
% plow=p(1);    phigh=p(Np);
% stringplow = num2str(plow,'%10.2E');
% stringphigh=num2str(phigh,'%10.2E');

fprintf(fout,'%s\n',[string1,stringlow,string2,stringhigh,string3]);%formally:fprintf(fout,'%s\n',[string1,stringplow,string2,stringphigh,string3]);
%alternative format: fprintf(fout,'%s\n','{| class="wikitable" style="text-align:center;  width:600px;" ');

fprintf(fout,'%s\n','{| class="wikitable" style="text-align:center;');
fprintf(fout,'%s\n','|-');
string = '| ||   ||||' ;
string = [string,' fluid || gas'];
string = [string,' |||| fluid || gas'];
string = [string,' |||| fluid || gas'];
string = [string,' |||| fluid || gas'];
fprintf(fout,'%s\n',string);
fprintf(fout,'%s\n','|-');

string = '| Pressure || Temp. ||||' ;% formally: string = '| Temp || Pressure ||||' ;
string = [string,' volume ||volume'];
string = [string,' |||| energy || energy'];
string = [string,' |||| enthalpy || enthalpy'];
string = [string,' |||| entropy || entropy'];
fprintf(fout,'%s\n',string);
fprintf(fout,'%s\n','|-');

string = '! T(C(  !!P(bars) !!!!' ; % formally: string = '! P (bars)  !!T<sub>sat</sub> (&deg;C) !!!!' ;
string = [string,' v<sub>f</sub> &nbsp; (m<sup>3</sup>/kg) !! v<sub>g</sub> &nbsp; (m<sup>3</sup>/kg)'];
string = [string,' !!!! u<sub>f</sub> &nbsp; (kJ/kg) !! u<sub>g</sub> &nbsp; (kJ/kg)'];
string = [string,' !!!! h<sub>f</sub> &nbsp; (kJ/kg) !! h<sub>g</sub> &nbsp; (kJ/kg)'];
string = [string,' !!!! s<sub>f</sub> &nbsp; (kJ/kg) !! s<sub>g</sub> &nbsp; (kJ/kg)'];
fprintf(fout,'%s\n',string);
fprintf(fout,'%s\n','|-');

for nT = 1:NT %formally: for np = 1:Np
    stringT=num2str(T(nT),sigfigsT);% was:  stringp=num2str(p(np),sigfigs);
    p=XSteam('psat_T', T(nT)); stringp=num2str(p,sigfigs);   %formally: T =XSteam('Tsat_p',p(np));  stringT = num2str(T,sigfigs);
    vV = XSteam('vV_T',T(nT)); %vV_T	Saturated vapour volume    %formally: vV = XSteam('vV_p',p(np)); %vV_T	Saturated vapour volume
    vL = XSteam('vL_T',T(nT)); %vL_T	Saturated liquid volume    %formally: vL = XSteam('vL_p',p(np)); %vL_T	Saturated liquid volume
    stringvV=num2str(vV,sigfigs);  stringvL=num2str(vL,sigfigs);    %formally: stringvV=num2str(vV,sigfigs);  stringvL=num2str(vL,sigfigs);
    uV = XSteam('uV_T',T(nT)); %uV_T	Saturated vapour internal energy    %formally: uV = XSteam('uV_p',p(np)); %uV_T	Saturated vapour internal energy
    uL = XSteam('uL_T',T(nT)); %uL_T	Saturated liquid internal energy    %formally: uL = XSteam('uL_p',p(np)); %uL_T	Saturated liquid internal energy
    stringuV=num2str(uV,sigfigs);  stringuL=num2str(uL,sigfigs);
    hV = XSteam('hV_T',T(nT)); %hV_T	formally: hV = XSteam('hV_p',p(np)); %hV_T	Saturated vapour enthalpy
    hL = XSteam('hL_T',T(nT));     %formally:%hL_T	Saturated liquid enthalpy
    stringhV=num2str(hV,sigfigs);  stringhL=num2str(hL,sigfigs);
    sV = XSteam('sV_T',T(nT));     %formally: sV = XSteam('sV_p',p(np)); %sV_T	Saturated vapour entropy
    sL = XSteam('sL_T',T(nT));    %formally: sL = XSteam('sL_p',p(np)); %sL_T	Saturated liquid entropy
    stringsV=num2str(sV,sigfigs);  stringsL=num2str(sL,sigfigs);
    
    if T(nT)>=low && T(nT)<=high % formally if p(np)>=plow && p(np)<=phigh
        string = ['|' stringT ,  '||', stringp ];% formally string = ['|' stringp ,  '||', stringT ];
        string = [string, '||||', stringvL, '||', stringvV];
        string = [string, '||||', stringuL, '||', stringuV  ];
        string = [string, '||||', stringhL, '||', stringhV  ];
        string = [string, '||||', stringsL, '||', stringsV  ];
        fprintf(fout,'%s\n',string);
        fprintf(fout,'%s\n','|-');
        
        %Make plot variables   %start here after fixing bug in other code
        Pplot(nT)=p;% was: Tplot(np)=T;
        Tplot(nT)= T(nT);% was: Pplot(np)= p(np);
        vLplot(nT) = vL; % nT was np
        uLplot(nT) = uL;
        hLplot(nT) = hL;
        sLplot(nT) = sL;
        vVplot(nT) = vV;
        uVplot(nT)= uV;
        hVplot(nT) = hV;
        sVplot(nT) = sV;
        %
    end %if ... &&...
    
end %for np = 1:Np
fprintf(fout,'%s\n','');%next line
fprintf(fout,'%s\n','|}');

fclose(fout);

figure(1);
plot(Tplot,Pplot,'-o','LineWidth',linewidth,'MarkerSize',markersize); %was: plot(Pplot,Tplot);
title('P(bars) versus T(Celsius)')%was: title('T(^{ \circ}C) versus P(bars)')
savefig('student steam table saturation P(T)');%was T(P)

figure(2); 
subplot(8,2,1);
plot(Tplot, vLplot,'-o','LineWidth',linewidth,'MarkerSize',markersize); %was Pplot,...
title('v_f vs T'); %was ... vs P
subplot(8,2,2);
plot(Tplot, log10(vVplot),'-o','LineWidth',linewidth,'MarkerSize',markersize);%was Pplot,..
title(' log10(v_g) vs T');%was ... vs P
subplot(8,2,3);
plot(Tplot,uLplot,'-o','LineWidth',linewidth,'MarkerSize',markersize);%was Pplot,..
title('u_f vs T'); %was ... vs P
subplot(8,2,4);
plot(Tplot,uVplot,'-o','LineWidth',linewidth,'MarkerSize',markersize)%was Pplot,..
title('u_g vs T');
subplot(8,2,5);
plot(Tplot,hLplot,'-o','LineWidth',linewidth,'MarkerSize',markersize);%was Pplot,..
title('h_f vs T'); %was ... vs P
subplot(8,2,6);
plot(Tplot,hVplot,'-o','LineWidth',linewidth,'MarkerSize',markersize)%was Pplot,..
title('h_g vs T'); %was ... vs P
subplot(8,2,7);
plot(Tplot,sLplot,'-o','LineWidth',linewidth,'MarkerSize',markersize);%was Pplot,..
title('s_f vs T'); %was ... vs P
subplot(8,2,8);
plot(Tplot,sVplot,'-o','LineWidth',linewidth,'MarkerSize',markersize);%was Pplot,..
title('s_g vs T'); %was ... vs P
savefig('student steam table saturation v,u,h,s');

%The following plots in pairs but is awkard for Matlab to render into
%useable pngs.
% figure(1)
% plot(Tplot,Pplot); %was: plot(Pplot,Tplot);
% title('P(bars) versus T(Celsius)')%was: title('T(^{ \circ}C) versus P(bars)')
% savefig('student steam table saturation P(T)');%was T(P)
% 
% figure(2); subplot(2,2,1);
% plot(Tplot, vLplot); %was Pplot,...
% title('v_f vs T'); %was ... vs P
% subplot(2,2,2);
% plot(Tplot, log10(vVplot));%was Pplot,..
% title(' log10(v_g) vs T');%was ... vs P
% savefig('student steam table saturation v(T)');%was ... vs P
% 
% figure(3);subplot(2,2,1);
% plot(Tplot,uLplot);%was Pplot,..
% title('u_f vs T'); %was ... vs P
% subplot(2,2,2);
% plot(Tplot,uVplot)%was Pplot,..
% title('u_g vs T');
% savefig('student steam table saturation u(T)');%was ... vs P
% 
% figure(4);subplot(2,2,1)
% plot(Tplot,hLplot);%was Pplot,..
% title('h_f vs T'); %was ... vs P
% subplot(2,2,2);
% plot(Tplot,hVplot)%was Pplot,..
% title('h_g vs T'); %was ... vs P
% savefig('student steam table saturation h(T)');%was ... vs P
% 
% figure(5);subplot(2,2,1)
% plot(Tplot,sLplot);%was Pplot,..
% title('s_f vs T'); %was ... vs P
% subplot(2,2,2)
% plot(Tplot,sVplot);%was Pplot,..
% title('s_g vs T'); %was ... vs P
% savefig('student steam table saturation s(T)');%was ... vs P