Project 1 - Parsing NASA thermodynamic data
AIM:-To write a program in matlab to parse the NASA thermodynamic data file and then calculate the thermodynamic properties of various gas species.
OBJECTIVE:-
. To write of function that extracts the 14co-efficiebt and calculates the enthalpy,entropy and specific heats for all species in the data file.
. Calculating the molecular weight of each species and displaying it in command window .
. Plotting cp,enthalpy and entropy for local temperature range specific for each species.
. Save the plot as images with appropriate names and dump them in separate folders for each species with suitable name.
EQUATIONS:-
The equatiion that we are going to use in the functions to calculate CP,H,S are
Where
CP = Specific heat
R = molar gas constant
T = Temperature
S = Entropy
H = Enthalpy
A = Coefficients
MAIN CODE OF THE FUNCTION:-
clear all
close all
clc
% open the dat file and read
f = fopen("THERMO.dat","r");
% skiping the 1 st 5 lines
for o=1:5
fgetl(f);
end
% parcing of all the species from the file
for i=1:53
% frist line of the frist species "o"
a=fgetl(f)
% splitting the string
b=strsplit(a," ");
speciesname=b{1};
% position of low ,high and mid temp
Z = length(b);
% extracting the local temp
low_temp=str2double(b{Z-3});
high_temp=str2double(b{Z-2});
mid_temp=str2double(b{Z-1});
% extracting the coefficinet
%line 1
co_line1=fgetl(f);
% finding the positions of E in line 1
pos_e1=strfind(co_line1,"E");
% ALL COEFFICIENTS OF LINE 1
a1=str2double(co_line1(1:pos_e1(1)+3));
a2=str2double(co_line1(pos_e1(1)+4:pos_e1(2)+3));
a3=str2double(co_line1(pos_e1(2)+4:pos_e1(3)+3));
a4=str2double(co_line1(pos_e1(3)+4:pos_e1(4)+3));
a5=str2double(co_line1(pos_e1(4)+4:pos_e1(5)+3));
% line 2
co_line2=fgetl(f);
% finding the position of E in line 2
pos_e2=strfind(co_line2,"E")
% ALL COEFFICIENTS OF LINE 2
a6=str2double(co_line2(1:pos_e2(1)+3));
a7=str2double(co_line2(pos_e2(1)+4:pos_e2(2)+3));
a8=str2double(co_line2(pos_e2(2)+4:pos_e2(3)+3));
a9=str2double(co_line2(pos_e2(3)+4:pos_e2(4)+3));
a10=str2double(co_line2(pos_e2(4)+4:pos_e2(5)+3));
% line 3
co_line3=fgetl(f);
% finding the positions of E in line 3
pos_e3=strfind(co_line3,"E");
% ALL COEFFICIENTS OF LINE 3
a11=str2double(co_line3(1:pos_e3(1)+3));
a12=str2double(co_line3(pos_e3(1)+4:pos_e3(2)+3));
a13=str2double(co_line3(pos_e3(2)+4:pos_e3(3)+3));
a14=str2double(co_line3(pos_e3(3)+4:pos_e3(4)+3));
% save the species in the folder
mkdir(['C:\Users\akbar\OneDrive\Documents\MATLAB\species\',speciesname]);
% universal gas constant(R)
R= 8.3145;
% calculating specific heat ,entropy and enthalpy
% a1-a7 high temp co_effi , a8-a14 low temp co_effi
T=linspace(low_temp,high_temp,1000);
for k = 1:length(T);
if T(k)>mid_temp
% high temp co_effi
Cp(k)=(a1+a2*T(k)+a3*T(k)^2+a4*T(k)^3+a5*T(k)^4)*R;
H(k)=(a1+(a2*T(k))/2+(a3*T(k)^2)/33+(a4*T(k)^3)/4+(a5*T(k)^4)/5+a6/T(k))*R*T(k);
S(k)=(a1*log(T(k))+a2*T(k)+(a13*T(k)^2)/2+(a4*T(k)^3)/3+(a5*T(k)^4)/4+a7)*R;
else
% low temp coeffi
Cp(k)=(a8+a9*T(k)+a10*T(k)^2+a11*T(k)^3+a12*T(k)^4)*R;
H(k)=(a8+(a9*T(k))/2+(a10*T(k)^2)/3+(a11*T(k)^3)/4+(a12*T(k)^4)/5+a13/T(k))*R*T(k);
S(k)=(a8*log(T(k))+a9*T(k)+(a10*T(k)^2)/2+(a11*T(k)^3)/3+(a12*T(k)^4)/4+a14)*R;
end
end
% saving the file in the folder
cd(['C:\Users\akbar\OneDrive\Documents\MATLAB\species\',speciesname]);
% plotting
figure(1);
plot(T,Cp,"Linewidth",3,"Color","g");
xlabel("temperature");
ylabel("specific heat");
title("species name ,speciesname");
legend("Temperature vs specific heat");
grid on
saveas(1,"specific heat","jpg");
figure(2);
plot(T,H,"Linewidth",3,"Color","g");
xlabel("temperature");
ylabel("Entropy");
title("species name ",speciesname);
legend("Temperature vs entropy");
grid on ;
saveas(2,"Entropy","jpg");
figure(3);
plot(T,S,"Linewidth",3,"Color","g");
xlabel("temperature");
ylabel("Enthalpy");
title("species name ",speciesname);
legend("Temperature vs Enthalpy");
grid on;
saveas(3,"Enthalpy","jpg");
% calulating the moleculer weigth
elements = ['H','C','N','O','A'];
atomic_weight =[1.0079,12.0107,14.0067,15.999,39.948];
mol_mass=0;
for l=1:length(speciesname)
for m=1:length(atomic_weight)
if strcmp(speciesname(l),elements(m))
mol_mass=mol_mass+atomic_weight(m);
position=m
end
end
n=str2double(speciesname(l));
if n>1
mol_mass=mol_mass+atomic_weight(position)*(n-1);
end
end
sprintf('molecular weight of %s is %f',speciesname,mol_mass)
end
fclose(f)
OUTPUT IN WORKSPACE:-

OUTPUT:-
plot for oxygen(O2):-



OUTPUT:-
plot for Nitrogen (N2):-


OUTPUT:-
Plot for Carbon Dioxide (CO2):-



OUTPUT FILES FOR 53 SPECIE'S:-



OUTPUT IN COMMAND WINDOW:-
a =
'O L 1/90O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
Warning: Directory already exists.
> In file_parsing_2 (line 90)
position =
4
ans =
'molecular weight of O is 15.999000'
a =
'O2 TPIS89O 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
4
ans =
'molecular weight of O2 is 31.998000'
a =
'H L 7/88H 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
ans =
'molecular weight of H is 1.007900'
a =
'H2 TPIS78H 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
ans =
'molecular weight of H2 is 2.015800'
a =
'OH RUS 78O 1H 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
4
position =
1
ans =
'molecular weight of OH is 17.006900'
a =
'H2O L 8/89H 2O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
4
ans =
'molecular weight of H2O is 18.014800'
a =
'HO2 L 5/89H 1O 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
4
ans =
'molecular weight of HO2 is 33.005900'
a =
'H2O2 L 7/88H 2O 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
4
ans =
'molecular weight of H2O2 is 34.013800'
a =
'C L11/88C 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
ans =
'molecular weight of C is 12.010700'
a =
'CH TPIS79C 1H 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of CH is 13.018600'
a =
'CH2 L S/93C 1H 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of CH2 is 14.026500'
a =
'CH2(S) L S/93C 1H 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of CH2(S) is 14.026500'
a =
'CH3 L11/89C 1H 3 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of CH3 is 15.034400'
a =
'CH4 L 8/88C 1H 4 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of CH4 is 16.042300'
a =
'CO TPIS79C 1O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
4
ans =
'molecular weight of CO is 28.009700'
a =
'CO2 L 7/88C 1O 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
4
ans =
'molecular weight of CO2 is 44.008700'
a =
'HCO L12/89H 1C 1O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
2
position =
4
ans =
'molecular weight of HCO is 29.017600'
a =
'CH2O L 8/88H 2C 1O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
position =
4
ans =
'molecular weight of CH2O is 30.025500'
a =
'CH2OH GUNL93C 1H 3O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
position =
4
position =
1
ans =
'molecular weight of CH2OH is 31.033400'
a =
'CH3O 121686C 1H 3O 1 G 300.00 3000.00 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
position =
4
ans =
'molecular weight of CH3O is 31.033400'
a =
'CH3OH L 8/88C 1H 4O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
position =
4
position =
1
ans =
'molecular weight of CH3OH is 32.041300'
a =
'C2H L 1/91C 2H 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C2H is 25.029300'
a =
'C2H2 L 1/91C 2H 2 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C2H2 is 26.037200'
a =
'C2H3 L 2/92C 2H 3 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C2H3 is 27.045100'
a =
'C2H4 L 1/91C 2H 4 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C2H4 is 28.053000'
a =
'C2H5 L12/92C 2H 5 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C2H5 is 29.060900'
a =
'C2H6 L 8/88C 2H 6 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C2H6 is 30.068800'
a =
'CH2CO L 5/90C 2H 2O 1 G 200.000 3500.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
position =
2
position =
4
ans =
'molecular weight of CH2CO is 42.036200'
a =
'HCCO SRIC91H 1C 2O 1 G 300.00 4000.00 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
2
position =
2
position =
4
ans =
'molecular weight of HCCO is 41.028300'
a =
'HCCOH SRI91C 2O 1H 2 G 300.000 5000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
2
position =
2
position =
4
position =
1
ans =
'molecular weight of HCCOH is 42.036200'
a =
'H2CN 41687H 2C 1N 1 G 300.00 4000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
2
position =
3
ans =
'molecular weight of H2CN is 28.033200'
a =
'HCN GRI/98H 1C 1N 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
2
position =
3
ans =
'molecular weight of HCN is 27.025300'
a =
'HNO And93 H 1N 1O 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
3
position =
4
ans =
'molecular weight of HNO is 31.013600'
a =
'N L 6/88N 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
ans =
'molecular weight of N is 14.006700'
a =
'NNH T07/93N 2H 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
3
position =
1
ans =
'molecular weight of NNH is 29.021300'
a =
'N2O L 7/88N 2O 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
4
ans =
'molecular weight of N2O is 44.012400'
a =
'NH And94 N 1H 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
1
ans =
'molecular weight of NH is 15.014600'
a =
'NH2 And89 N 1H 2 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
1
ans =
'molecular weight of NH2 is 16.022500'
a =
'NH3 J 6/77N 1H 3 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
1
ans =
'molecular weight of NH3 is 17.030400'
a =
'NO RUS 78N 1O 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
4
ans =
'molecular weight of NO is 30.005700'
a =
'NO2 L 7/88N 1O 2 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
4
ans =
'molecular weight of NO2 is 46.004700'
a =
'HCNO BDEA94H 1N 1C 1O 1G 300.000 5000.000 1382.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
2
position =
3
position =
4
ans =
'molecular weight of HCNO is 43.024300'
a =
'HOCN BDEA94H 1N 1C 1O 1G 300.000 5000.000 1368.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
4
position =
2
position =
3
ans =
'molecular weight of HOCN is 43.024300'
a =
'HNCO BDEA94H 1N 1C 1O 1G 300.000 5000.000 1478.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
3
position =
2
position =
4
ans =
'molecular weight of HNCO is 43.024300'
a =
'NCO EA 93 N 1C 1O 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
position =
2
position =
4
ans =
'molecular weight of NCO is 42.016400'
a =
'CN HBH92 C 1N 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
3
ans =
'molecular weight of CN is 26.017400'
a =
'HCNN SRI/94C 1N 2H 1 G 300.000 5000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
1
position =
2
position =
3
position =
3
ans =
'molecular weight of HCNN is 41.032000'
a =
'N2 121286N 2 G 300.000 5000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
3
ans =
'molecular weight of N2 is 28.013400'
a =
'AR 120186AR 1 G 300.000 5000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
5
ans =
'molecular weight of AR is 39.948000'
a =
'C3H8 L 4/85C 3H 8 G 300.000 5000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C3H8 is 44.095300'
a =
'C3H7 L 9/84C 3H 7 G 300.000 5000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
ans =
'molecular weight of C3H7 is 43.087400'
a =
'CH3CHO L 8/88C 2H 4O 1 G 200.000 6000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
position =
2
position =
1
position =
4
ans =
'molecular weight of CH3CHO is 44.052000'
a =
'CH2CHO SAND86O 1H 3C 2 G 300.000 5000.000 1000.000 1'
pos_e2 =
12 27 42 57 72
position =
2
position =
1
position =
2
position =
1
position =
4
ans =
'molecular weight of CH2CHO is 43.044100'
ans =
0
>>