Challenge

Project 1 - Parsing NASA thermodynamic data

A function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file:

f1=fopen('THERMO.dat');

for i=1:5
c=fgetl(f1);
end
c1=fgetl(f1);

t=strfind(c1,'.');
low_local_temp_string=c1(t(1)-3:t(1)+3);
Mid_local_temp_string=c1(t(3)-4:t(3)+3);
high_local_temp_string= c1(t(2)-4:t(2)+3);

low_local_temp=str2double(low_local_temp_string);
Mid_local_temp=str2double(Mid_local_temp_string);
high_local_temp=str2double(high_local_temp_string);

coefficient a1 to a5


c6=fgetl(f1);
a=strfind(c6,'E');
A1=c6(1:a(1)+3);
A2=c6(a(1)+4:a(2)+3);
A3=c6(a(2)+4:a(3)+3);
A4=c6(a(3)+4:a(4)+3);
A5=c6(a(4)+4:a(5)+3);

a1=str2double(A1);
a2=str2double(A2);
a3=str2double(A3);
a4=str2double(A4);
a5=str2double(A5);

coefficient a6 to a10


c7=fgetl(f1);
aa=strfind(c7,'E');
A6=c7(1:aa(1)+3);
A7=c7(aa(1)+4:a(2)+3);
A8=c7(aa(2)+4:a(3)+3);
A9=c7(aa(3)+4:a(4)+3);
A10=c7(aa(4)+4:a(5)+3);

a6=str2double(A6);
a7=str2double(A7);
a8=str2double(A8);
a9=str2double(A9);
a10=str2double(A10);

coefficient a11 to a12


c8=fgetl(f1);
aaa=strfind(c8,'E');
A11=c8(1:aaa(1)+3);
A12=c8(aaa(1)+4:aaa(2)+3);
A13=c8(aaa(2)+4:aaa(3)+3);
A14=c8(aaa(3)+4:aaa(4)+3);

a11=str2double(A11);
a12=str2double(A12);
a13=str2double(A13);
a14=str2double(A14);


T=linspace(low_local_temp,high_local_temp,100);

Universal Gas constant=R
R=8.3144;


if T> Mid_local_temp
Cp= (a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4)*R;
H=(a1.*T+a2.*T.^2/2+a3.*T.^3/3+a4.*T.^4/4+a5.*T.^5/5+a6.*T)*R;
S=(a1.*log(T)+a2.*T+a3.*T.^2/2+a4.*T.^3/3+a5.*T.^4/4+a7)*R;
else
Cp= (a8+a9.*T+a10.*T.^2+a11.*T.^3+a12.*T.^4)*R;
H=(a8.*T+a9.*T.^2/2+a10.*T.^3/3+a11.*T.^4/4+a12.*T.^5/5+a13.*T)*R;
S=(a8.*log(T)+a9.*T+a10.*T.^2/2+a11.*T.^3/3+a12.*T.^4/4+a14)*R;
end

Calculation the molecular weight of each species and display it in the command window

species=input('enter the species name:','s');
Atom=['O','H','C','S','N','R'];
AW=[16,1,12,32,14,40];
MW=0;
for i=1:length(species)

for j=1:length(Atom)
if strcmpi(species(i),Atom(j))
MW=MW+AW(j);
p=j;
end
end
n=str2num(species(i));
if n>1
MW=MW+AW(p)*(n-1)
end
end

NOTE: file attached with name "Moleculer weight"

Plot the Cp, Enthalpy and Entropy:

t=sprintf('%s',species);
mkdir(t)
cd(t)

figure(1)
plot(T,Cp);
xlabel('Temperature');
ylabel('specific heats');
grid on
title(species)
saveas(1,'Cp.jpg')

figure(2)
plot(T,H);
xlabel('Temperature');
ylabel('enthalpy');
grid on
title(species)
saveas(2,'H.jpg')

figure(3)
plot(T,S);
xlabel('Temperature');
ylabel('entropy');
grid on
title(species)
saveas(2,'S.jpg')

cd ..

Note: Screenshot of folder is attached with name "folder"

Plots for o2, N2 and Co2 species:

file attached with name CP,H,S

explanation

a)fopen=used to read the file.

b)fgetl=used to scan line or row wise.

c)for loop used to scan the command line from i=1:5.

d)strfind=used to read local temperature of all species.

e)str2double=used to convert the string to number.

f)a1 to a14 coefficient is get using strfine & str2double.

g)if loop is used to calculate the CP,H,S value for high to mid (a1 to a7) & low to mid temperature(a8 to a14).

h)"input('enter the species name:','s');"=command used to get the input of species from user in string formate.

i)strcmpi=used to compare string being case insensitive.

j)mkdrt(species)=to make a directory of species name.

k)cd(species)=to go into species folder save the file / figure in that directory or to change the directory.

l)saveas(1,'Cp.jpg')=used to save the figure (1=figure number) in "species" directory.

m)cd..=used to get out of "species" directory and come to the directory where the program is saved.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.