Project 1 - Parsing NASA thermodynamic data
AIM-
To write a program to parse the NASA thermodynamic data that can be used to calculate thermodynamic properties of various gas species.
Parsing-
Parsing a file refers to reading a data file and building a memory model of the content of that data. This helps us to perfom some kind of transformation on the data. Parsing splits a file or other input into pieces of data that can be easily stored or manipulated.
Data Source:
NASA Thermodynamic data file
https://drive.google.com/file/d/1AikCHDlz9s_fu8whE81qee_GD4AyYpCP/view
The file contains co-efficients required to evaluate polynomials that can be used to evaluate thermodynamic properties such as Specific Heat(Cp), Enthalpy (h) and Entropy (S).
Formula used to calculate the thermodynamic properties are as follows:

Main Program-
% Code for parsing the NASA thermodynamic data
clear all
close all
clc
f1 = fopen('THERMO.dat','r'); % fopen command to import the data
fgetl(f1); % Reading the header information (getl command is used for that)
t_line = fgetl(f1) ; % reading global temperature
a=strsplit(t_line,' '); % strsplit for splitting string to get global temperatures
global_low_temp = str2double(a{2});
global_mid_temp = str2double(a{3});
global_high_temp = str2double(a{4});
for i = 1:3 % for skipping next three lines since they are irrelevent here
fgetl(f1);
end
% Gas species first line contains their name, local temp and coeffiecients
for i = 1:53
t_line2 = fgetl(f1);
s = strsplit(t_line2,' '); % splitting to get name and temp
data_parsing = s{1};
A = strfind(t_line2,'G'); % strfind to find some referance to get relevant data (here temp)
temp_values = t_line2(A+4:length(t_line2));
B = strsplit(temp_values,' ');
local_low_temp = str2double(B{1});
local_mid_temp = str2double(B{2});
local_high_temp = str2double(B{3});
t_line = fgetl(f1);
b = findstr(t_line,'E'); % using findstr to find letter 'E' for using it as a referance to get the coeff
b1 = t_line(1:b(1)+3); % to get 1st coefficient
b1 = str2num(b1);
b2 = t_line(b(1)+4:b(2)+3); % to get 2nd coefficient
b2 = str2num(b2);
b3 = t_line(b(2)+4:b(3)+3); % to get 3rd coefficient
b3 = str2num(b3);
b4 = t_line(b(3)+4:b(4)+3); % to get 4th coefficient
b4 = str2num(b4);
b5 = t_line(b(4)+4:b(5)+3); % to get 5th coefficient
b5 = str2num(b5);
% for line 2
line2 = fgetl(f1);
b6 = line2(1:b(1)+3); % to get 6th coefficient
b6 = str2num(b6);
b7 = line2(b(1)+4:b(2)+3); % to get 7th coefficient
b7 = str2num(b7);
b8 = line2(b(2)+4:b(3)+3); % to get 8th coefficient
b8 = str2num(b8);
b9 = line2(b(3)+4:b(4)+3); % to get 9th coefficient
b9 = str2num(b9);
b10 = line2(b(4)+4:b(5)+3); % to get 10th coefficient
b10 = str2num(b10);
% for line 3
line3 = fgetl(f1);
b11 = line3(1:b(1)+3); % to get 11th coefficient
b11 = str2num(b11);
b12 = line3(b(1)+4:b(2)+3); % to get 12th coefficient
b12 = str2num(b12);
b13 = line3(b(2)+4:b(3)+3); % to get 13th coefficient
b13 = str2num(b13);
b14 = line3(b(3)+4:b(4)+3); % to get 14th coefficient
b14 = str2num(b14);
R = 8.314; % universal gas constant (J/mol.K)
t = linspace(local_low_temp,local_high_temp,100);
% For calculation of specific heat
c_p = specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
% For calculation of enthalpy
H = enthalpy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
% For calculation of entropy
S = entropy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
mkdir(['D:\Skill Lync\MATLAB\File Parsing\',data_parsing]) % to save all the plots in separate folder
cd(data_parsing)
% Plotting temperature vs specific heat
figure(1)
plot(t,c_p)
xlabel('Temperature')
ylabel('Specific heat')
title('Temperature vs Specific heat')
saveas(1,'Specific heat','jpg')
% Plotting temperature vs enthalpy
figure(2)
plot(t,H)
xlabel('Temperature')
ylabel('Enthalpy')
title('Temperature vs Enthalpy')
saveas(2,'Enthalpy','jpg')
% Plotting temperature vs entropy
figure(3)
plot(t,S)
xlabel('Temperature')
ylabel('Entropy')
title('Temperature vs Entropy')
saveas(3,'Entropy','jpg')
cd('D:\Skill Lync\MATLAB\File Parsing\')
% for calculating molecular mass
[M] = molecular_wt(data_parsing);
K = sprintf('%s mol_wt = %f',data_parsing,M);
disp(K)
end
Specific heat function code -
function [c_p] = specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if (t > local_mid_temp)
c_p = R*(b1+(b2.*t)+(b3.*(t.^2))+(b4.*(t.^3))+(b5.*(t.^4)));
else
c_p = R*(b8+(b9.*t)+(b10.*(t.^2))+(b11.*(t.^3))+(b12.*(t.^4)));
end
Enthalpy function code -
function [H] = enthalpy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if (t > local_mid_temp)
H = (b1+((b2.*t)/2)+((b3.*(t.^2))/3)+((b4.*(t.^3))/4)+((b5.*(t.^4))/5)+(b6./t)).*t*R;
else
H = (b8+((b9.*t)/2)+((b10.*(t.^2))/3)+((b11.*(t.^3))/4)+((b12.*(t.^4))/5)+(b13./t)).*t*R;
end
Entropy function code -
function [S] = entropy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if (t > local_mid_temp)
S = ((b1.*logt)+(b2.*t)+((b3.*(t.^2))/2)+((b4.*(t.^3))/3)+(b5.*(t.^4))+b7);
else
S = ((b8.*log(t))+(b9.*t)+((b10.*(t.^2))/2)+((b11.*(t.^3))/3)+(b12.*(t.^4))+b14)*R;
end
Molecular weight calculation code -
function [M] = molecular_wt(data_parsing)
atomic_mass = [15.999,1.008,12.011,14.007,39.948];
elements = ['O','H','C','N','A'];
mol_wt = 0;
for i = 1:length(data_parsing)
for j = 1:length(elements)
if strcmpi(data_parsing(i),elements(j))
mol_wt = mol_wt+atomic_mass(j);
z = j;
end
end
t = str2double(data_parsing(i));
if (t>1)
mol_wt = mol_wt+(atomic_mass(z)*(t-1));
end
end
M = mol_wt
end
- The main program explanation is written the main code itself.
- The extracted coeffiecients from the main code are used to calculate the specific heat, enthaply and entropy of different gas species which is accomplished by calling the respective function in the main code.
- For calculating the molecular weight, we initially assign the character of atoms to their atomic weights by using array.
- Then, the specified string is compared with the character of atom and the respective atomic weight is taken for calculation.
- If there are more than one atom of itself, then we first take extract the number and then we calculate accordingly.
Output -
Screenshot of the window where all the folders are saved -

Some plots of gas species are as follows-
Plots of O2-




Plots of N2-




Plots of CO2-


