Parsing NASA thermodynamic data
Parsing NASA thermodynamic data
Aim -To parsing nasa thermodynamic data
Objective-
1) To write function that extarct the 14 coefficent and calculate the enthalpy ,entrophy and specific heats for all the species in the nasa thermodynamic data file 'Thermo.dat'
The NASA polynomial have the form shown below.

Where ,
R is the universal gas constant .
T is the temperature.
2) To calculate the molecule weight of each species and display it in the command window.
3) To plot the Cp ,enthalpy and entrophy for the local tempreture range specific for each species
4) To save the plot as images with approprite names and dump them in seprete folders for each species with suitable names automaticly.
File Parsing,
File parsing refers to how information can be read from a particular text file or any type of file and how that information can be used in a computer program.
Step 1- Define the function step
Step 2-Create an input parse objects
Step 3-Add input to the scheme.
Step 4-Set properties to adjust parsing
Step 5-Parse the input
Step 6-Use the input in function
Step 7- Calling function
NASA Thermodynamic File-
Thermo .dat file constainng 14 coefficent for 53 differnt element given by NASA . These Coefficints are utilized to calculate the specific heat ,enthlpy & entropy for a particular element.Each element has its own range of local tempreture.Below screenshot of the THERMO.dat file is disply.
Link For File-https://drive.google.com/file/d/1rmpXOnGdE9CC5_LaKdDsrAju95e00weK/view?usp=sharing
Coding Function-
1) Specific heat
It is the amount of energy that must be added.in the form of heat to one unit of mass of the substance in order to cause an increse of one unit in its tempreture.
Cp=(a1+a2+a3T^2+a4T^3+a5T^4)R
Code
function Cp=specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,tempmid)
% calculate specificheat
if (T<=tempmid)
Cp=R*(a8+(a9*T)+(a10*(T).^2)+(a11*(T).^3)+(a12*(T).^4));
else
Cp=R*(a1+(a2*T)+(a3*(T).^2)+(a4*(T).^3)+(a5*(T).^4));
end
end
2)Entropy
Entropy is the mesure of system themal energy per unit tempreture that is unavilable for doing using work.
Code
function S=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,tempmid)
% calculate entropy
if (T<=tempmid)
S=R*(a8.*log(T)+(a9*T)+((a10*(T).^2)/2)+((a11*(T).^3)/3)+((a12*(T).^4)/4)+a14);
else
S=R*(a1.*log(T)+(a2*T)+((a3*(T).^2)/2)+((a4*(T).^3)/3)+((a5*(T).^4)/4)+a7);
end
end
3)Enthalpy
Enthalpy is property of thermodynamic system is equal to the system internal energy plus the product of its pressure and volume.
Code
function H=enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,tempmid)
% calculate Enthalpy
if (T<=tempmid)
H=R*T.*(a8+((a9*T)/2)+((a10*(T).^2)/3)+((a11*(T).^3)/4)+((a12*(T).^4)/5)+((a13./T)));
else
H=R*T.*(a1+((a2*T)/2)+((a3*(T).^2)/3)+((a4*(T).^3)/4)+((a5*(T).^4)/5)+((a6./T)));
end
end
4) Molecular weight
The molecular weight is the mass of given molecule it is mesured in daltons.
Code
function W=Molecular_weight(species)
%define atomic name of the species
atomic_name=['H','C','O','N','Ar'];
%define atomic massesof main species
atomic_weight=[1.008,12.011,15.999,14.007,38.948];
%molecular weight starting range
W=0;
for i=1:length(species)
for j=1:length(atomic_name)
if strcmp(species(i),atomic_name(j))
W=W+atomic_weight(j);
position=j;
end
end
n=str2num(species);
if n>1
W=W+atomic_weight(position)*(n-1);
end
end
fprintf('Molecular weight of %s :- ',species);
fprintf('%f',W);
disp(' ')
end
Main Code-
clear all
close all
clc
%reading data file
f1=fopen('THERMO.dat')
gt=fgetl(f1)
%input
R=8.314
%reading tempreture for file
temp=fgetl(f1);
%splitting
s=strsplit(temp);
%convert string to number
templow=str2num(s{2});
tempmid=str2num(s{3});
temphigh=str2num(s{4});
%tempreture range
T=linspace(templow,temphigh,1000);
%skipp comment line
for i=1:3
gt=fgetl(f1);
end
%reading the species
for j=1:53
tline=fgetl(f1);
A=strsplit(tline,' ');
species=(A{1});
%converting string to number
lowtemp=str2num(A{end-3});
midtemp=str2num(A{end-2});
hightemp=str2num(A{end-1});
tline1=fgetl(f1);
a=strfind(tline1,'E');
%find first 7 higher and second 7lwer coefficient
% find higher coefficient
a1=tline1(1:a(1)+3);
a1=str2num(a1);
a2=tline1(a(1)+4:a(2)+3);
a2=str2num(a2);
a3=tline1(a(2)+4:a(3)+3);
a3=str2num(a3);
a4=tline1(a(3)+4:a(4)+3);
a4=str2num(a4);
a5=tline1(a(4)+4:a(5)+3);
a5=str2num(a5);
tline2=fgetl(f1);
b=strfind(tline2,'E');
a6=tline2(1:b(1)+3);
a6=str2num(a6);
a7=tline2(b(1)+4:b(2)+3);
a7=str2num(a7);
%find lower coefficent
a1=tline2(b(2)+4:b(3)+3);
a1=str2num(a1);
a9=tline2(b(3)+4:b(4)+3);
a9=str2num(a9);
a10=tline2(b(4)+4:b(5)+3);
a10=str2num(a10);
tline3=fgetl(f1);
c=strfind(tline3,'E');
a11=tline3(1:c(1)+3);
a11=str2num(a11);
a12=tline3(1:c(1)+4:c(3)+3);
a12=str2num(a12);
a13=tline3(1:c(2)+4:c(3)+3);
a13=str2num(a13);
a14=tline3(1:c(3)+4:c(4)+3);
a14=str2num(a14);
% calculate specific heat
Cp=specific_heat(a1,a2,a3,a4,a5,a1,a9,a10,a11,a12,T,R,tempmid);
% Calculate Entropy
S=entropy(a1,a2,a3,a4,a5,a7,a1,a9,a10,a11,a12,a14,T,R,tempmid);
% calculate enthalpy
H=enthalpy(a1,a2,a3,a4,a5,a6,a1,a9,a10,a11,a12,a13,T,R,tempmid);
% calculate molecular weight
W=Molecular_weight(species);
% writing molecular weight file
MW_file=fopen('Molecular weight.txt','W');
fprintf(MW_file,'Molecular weight of %s is %d',species,W);
fclose(MW_file);
% plott Cp,H and S with tempreture
% save in folder
mkdir(species)
cd(species)
% plot 1 cp vs T
figure(1)
plot(T,Cp,'linewidth',2,'color','b');
xlabel('Tempreture(k)');
ylabel('Specific Heat (KJ)');
title(sprintf('Specific heat Vs Tempreture range of %s',species));
grid on
saveas(figure(1),'Specific Heat.jpg');
% plot 2 S vs T
figure(2)
plot(T,S,'linewidth',2,'color','r');
xlabel('Tempreture(k)');
ylabel('Entropy (KJ/mol-k)');
title(sprintf('Entropy Vs Tempreture range of %s',species));
grid on
saveas(figure(2),'Entropy.jpg');
% plot 3 H vs T
figure(3)
plot(T,H,'linewidth',2,'color','g');
xlabel('Tempreture(k)');
ylabel('Enthalpy (KJ/mol)');
title(sprintf('Enthalpy Vs Tempreture range of %s',species));
grid on
saveas(figure(3),'Enthalpy.jpg');
cd ..
% mkdir('C:UserschauhDesktopskill lyncspecies')
%
%molecular weight
% W=Molecular_weight(species)
end
Code Explanation
- start with clear all ,close all and clc
- making directory using 'mkdir' with location
- after reading the text file 'Thermo.dat' file and opening it by using 'fopen' and ' r' reading command
- for reading the line in text file using 'frgetl'
- to obtain the tempreture range from the Thermo.dat file using'strsplit' to split the tempreture into a particular string cell.
- use 'str2num' for converting string cell to numbers
- divide the tempreture into string and the converted to a number so that tempreture value can be used sepretelyto solve the NASA thermodynamics
- using 'for & end ' loops
- reading all 53 species to plot specific heat(Cp) .enthalpy and entrophy with tempreture value to find the molecular weights.
- use 'for' loop to read 53 species.
- used 'strfind' to find string.
- using 'linspace' specific the tempreture range for low to high.
- add universal gas constant value 'R'
- Calling specific heat,enthalpy,entrophy function code
- calculate molecular weight.
Output-
Molecular weight of O :- 15.999000
W =
15.9990
Molecular weight of O2 :- 15.999000
W =
15.9990
Molecular weight of H :- 1.008000
W =
1.0080
Molecular weight of H2 :- 1.008000
W =
1.0080
Molecular weight of OH :- 17.007000
W =
17.0070
Molecular weight of H2O :- 17.007000
W =
17.0070
Molecular weight of HO2 :- 17.007000
W =
17.0070
Molecular weight of H2O2 :- 17.007000
W =
17.0070
Molecular weight of C :- 12.011000
W =
12.0110
Molecular weight of CH :- 13.019000
W =
13.0190
Molecular weight of CH2 :- 13.019000
W =
13.0190
Molecular weight of CH2(S) :- 13.019000
W =
13.0190
Molecular weight of CH3 :- 13.019000
W =
13.0190
Molecular weight of CH4 :- 13.019000
W =
13.0190
Molecular weight of CO :- 28.010000
W =
28.0100
Molecular weight of CO2 :- 28.010000
W =
28.0100
Molecular weight of HCO :- 29.018000
W =
29.0180
Molecular weight of CH2O :- 29.018000
W =
29.0180
Molecular weight of CH2OH :- 30.026000
W =
30.0260
Molecular weight of CH3O :- 29.018000
W =
29.0180
Molecular weight of CH3OH :- 30.026000
W =
30.0260
Molecular weight of C2H :- 13.019000
W =
13.0190
Molecular weight of C2H2 :- 13.019000
W =
13.0190
Molecular weight of C2H3 :- 13.019000
W =
13.0190
Molecular weight of C2H4 :- 13.019000
W =
13.0190
Molecular weight of C2H5 :- 13.019000
W =
13.0190
Molecular weight of C2H6 :- 13.019000
W =
13.0190
Molecular weight of CH2CO :- 41.029000
W =
41.0290
Molecular weight of HCCO :- 41.029000
W =
41.0290
Molecular weight of HCCOH :- 42.037000
W =
42.0370
Molecular weight of H2CN :- 27.026000
W =
27.0260
Molecular weight of HCN :- 27.026000
W =
27.0260
Molecular weight of HNO :- 31.014000
W =
31.0140
Molecular weight of N :- 14.007000
W =
14.0070
Molecular weight of NNH :- 29.022000
W =
29.0220
Molecular weight of N2O :- 30.006000
W =
30.0060
Molecular weight of NH :- 15.015000
W =
15.0150
Molecular weight of NH2 :- 15.015000
W =
15.0150
Molecular weight of NH3 :- 15.015000
W =
15.0150
Molecular weight of NO :- 30.006000
W =
30.0060
Molecular weight of NO2 :- 30.006000
W =
30.0060
Molecular weight of HCNO :- 43.025000
W =
43.0250
Molecular weight of HOCN :- 43.025000
W =
43.0250
Molecular weight of HNCO :- 43.025000
W =
43.0250
Molecular weight of NCO :- 42.017000
W =
42.0170
Molecular weight of CN :- 26.018000
W =
26.0180
Molecular weight of HCNN :- 41.033000
W =
41.0330
Molecular weight of N2 :- 14.007000
W =
14.0070
Molecular weight of AR :- 38.948000
W =
38.9480
Molecular weight of C3H8 :- 13.019000
W =
13.0190
Molecular weight of C3H7 :- 13.019000
W =
13.0190
Molecular weight of CH3CHO :- 42.037000
W =
42.0370
Molecular weight of CH2CHO :- 42.037000
W =
42.0370
>>
Screen Shot For Folder-
- Screenshot of the window where all the folders are saved.

Results-
Specific heat ,entrophy and enthalpy plot for O2,N2 and CO2 species
- Plot for O2



2. Plot for N2



3.Plot for CO2



Conclusion-
Using MATLAB code the necessary coeffiecent required to evaluate various thermodynamic parameter for different species are extracted from NASA thermodynamic file.The specific heat ,enthalpy and entrophy for all species are calculated and plotted against the local tempreture range.The molecular weight is calculated for all the species.