Project 1 - Parsing NASA thermodynamic data
- AIM:
The main aim of the project is to write a program to evaluate the thermodynamic data such as specific heat, Enthalpy,Entropy of NASA thermodynamic data and to create the plots for all the species and to display the molecular weight calculation using MATLAB coding.
- OBJECTIVE:
NASA came up with a thermodynamic data which is used to evaluate the properties such as specific heat(c_p),Enthalpy(H),Entropy(S).Now,parsing a file means reading in a data stream of some sort and building an in memory model of semantic content of that data.
- DEFINATIONS:
1. Specific Heat:
Specific Heat is a ratio of the quantity of heat required to raise the temperature of a body one degree to that required to raise the temperature of an equal mass of water one degree.The SI unit of specific heat is J/KG-K.
2. Enthalpy:
The Enthalpy of a Thermodynamic system is defined as the sum of its internal energy and the work required to achieve its presure and volume. The SI unit of specific Enthalpy is kj/kg.
3. Entropy:
Entropy is a measure of degree of disorderness of the system. The SI unit of entropy is j/k.
- FILE PARSING:
From the given thermodynamic data it it clear that their are 53 species and for each species their are 14 co-efficients and for each species their is a unique low,mid and high temperature ranges . Fomula used to calculate the specific heat ,enthalpy and entropy using the coefficient is as shown below,
cpR=a1+a2⋅T+a3⋅T2+a4⋅T3+a5⋅T4cpR=a1+a2⋅T+a3⋅T2+a4⋅T3+a5⋅T4
where, cp = specific heat in j/kg-k
HRT=a1+a2⋅T2+a3⋅T23+a4⋅T34+a5⋅T45+a6THRT=a1+a2⋅T2+a3⋅T23+a4⋅T34+a5⋅T45+a6T `
R = universal gas constant (8.314j/k-mol)
H = enthalpy in kj/kg
SR=a1⋅logT+a2⋅T+a3⋅T22+a4⋅T33+a5⋅T44+a7SR=a1⋅logT+a2⋅T+a3⋅T22+a4⋅T33+a5⋅T44+a7 S = entropy in j/k
Their are 14 coefficients as said in which first 7 coefficient are High temperature coefficient and second 7 coefficient are Low temperature coefficient.
Matlab program for parsing nasa thermodynamic data file and calculate parameters:
close all
clear all
clc
%Program to read or parse a nasa thermodynamic data
f0=fopen('THERMO.dat','r'); % opening a file and reading it
header=fgetl(f0);
%extracting temperatures
tline=fscanf(f0,'%f \n',[1 3]); %to extract temperatures
global_low_temp = tline(1);
global_mid_temp = tline(2);
global_high_temp = tline(3);
%skipping next three lines
for i=1:3
s=fgetl(f0)
end
%extracting species data
%species name
for i=1:53
Sp_name = fgetl(f0);
Sp = strtok(Sp_name);
%species value
line1 = fgetl(f0);
p = strfind(line1,'E'); %finding a string
a1 = str2double(line1(1:(p(1)+3)));
a2 = str2double(line1((p(1)+4):(p(2)+3)));
a3 = str2double(line1((p(2)+4):(p(3)+3)));
a4 = str2double(line1((p(3)+4):(p(4)+3)));
a5 = str2double(line1((p(4)+4):(p(5)+3)));
line2 = fgetl(f0);
q = strfind(line2,'E');
a6 = str2double(line2(1:(q(1)+3)));
a7 = str2double(line2((q(1)+4):(q(2)+3)));
a8 = str2double(line2((q(2)+4):(q(3)+3)));
a9 = str2double(line2((q(3)+4):(q(4)+3)));
a10 = str2double(line2((q(4)+4):(q(5)+3)));
line3 = fgetl(f0);
r = strfind(line3,'E');
a11 = str2double(line3(1:(r(1)+3)));
a12 = str2double(line3((r(1)+4):(r(2)+3)));
a13 = str2double(line3((r(2)+4):(r(3)+3)));
a14 = str2double(line3((r(3)+4):(r(4)+3)));
%temperature value range
mkdir('C:/Users/laxmikant/Desktop/matlab/fileparsing/speciesdata',Sp)%creating new %folder
trange=linspace(global_low_temp,global_high_temp,300); %temperature range
R= 8.321;
[cp,H,s] = thermo_formulas(trange,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R,global_mid_temp);
%PLOTTING
figure(1)
plot(trange,cp,'linewidth',3,'color','b')
xlabel('temperature');
ylabel('specific heat');
title('specific heat vs temperature')
grid on
figure(2)
plot(trange,H,'linewidth',3,'color','r')
xlabel('temperature');
ylabel('enthalpy');
title('enthalpy vs temperature')
grid on
figure(3)
plot(trange,s,'linewidth',3,'color','g')
xlabel('temperature');
ylabel('entropy');
title('entropy vs temperature')
grid on
molecular_mass = molecular_weight(Sp);
%saving all the plots
save = (['C:/Users/laxmikant/Desktop/matlab/fileparsing/speciesdata/',Sp]);
cd(save)
saveas(1,'specific heat','png')
saveas(2,'enthalpy','png')
saveas(3,'entropy','png')
f1=fopen('molecular_mass.txt','w'); %creating text file
fprintf(f1,'%s\n %s %f \n',Sp,'molecular-mass',molecular_mass)
fclose(f1);
cd('C:/Users/laxmikant/Desktop/matlab/fileparsing/')
end
Function for calculation of Cp, enthalpy and entropy:
function [cp,H,s]= thermo_formulas(trange,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R,global_mid_temp)
cp = zeros(size(trange));
H = zeros(size(trange));
s = zeros(size(trange));
for i=1:length(trange)
if(trange(i)>global_mid_temp)
cp(i)= R*(a1+a2*trange(i)+a3*trange(i)^2+a4*trange(i)^3+a5*trange(i)^4);
H(i)= R*trange(i)*(a1+a2*trange(i)+a3*(trange(i)^2/3)+a4*(trange(i)^3/4)+a5*(trange(i)^4/5)+a6/trange(i));
s(i)= R*(a1*log(trange(i))+a2*trange(i)+a3*trange(i)^2/2+a4*trange(i)^3/3+a5*trange(i)^4/4+a7);
else
cp(i)= R*(a8+a9*trange(i)+a10*trange(i)^2+a11*trange(i)^3+a12*trange(i)^4);
H(i)= R*trange(i)*(a8+a9*trange(i)+a10*(trange(i)^2/3)+a11*(trange(i)^3/4)+a12*(trange(i)^4/5)+a13/trange(i));
s(i)= R*(a8*log(trange(i))+a9*trange(i)+a10*trange(i)^2/2+a11*trange(i)^3/3+a12*trange(i)^4/4+a14);
end
end
Function for calculation of Cp, enthalpy and entropy:
function [cp,H,s]= thermo_formulas(trange,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R,global_mid_temp)
cp = zeros(size(trange));
H = zeros(size(trange));
s = zeros(size(trange));
for i=1:length(trange)
if(trange(i)>global_mid_temp)
cp(i)= R*(a1+a2*trange(i)+a3*trange(i)^2+a4*trange(i)^3+a5*trange(i)^4);
H(i)= R*trange(i)*(a1+a2*trange(i)+a3*(trange(i)^2/3)+a4*(trange(i)^3/4)+a5*(trange(i)^4/5)+a6/trange(i));
s(i)= R*(a1*log(trange(i))+a2*trange(i)+a3*trange(i)^2/2+a4*trange(i)^3/3+a5*trange(i)^4/4+a7);
else
cp(i)= R*(a8+a9*trange(i)+a10*trange(i)^2+a11*trange(i)^3+a12*trange(i)^4);
H(i)= R*trange(i)*(a8+a9*trange(i)+a10*(trange(i)^2/3)+a11*(trange(i)^3/4)+a12*(trange(i)^4/5)+a13/trange(i));
s(i)= R*(a8*log(trange(i))+a9*trange(i)+a10*trange(i)^2/2+a11*trange(i)^3/3+a12*trange(i)^4/4+a14);
end
end
Function for calculation of molecular weight:
function [mw]= molecular_weight(Sp)
p_element = ['H','C','N','O','A'];
Atomic_mass = [1,12,14,16,40];
mw=0;
for i=1:length(Sp)
for j=1:length(p_element)
if strcmp(Sp(i),p_element(j))
mw = mw +Atomic_mass(j);
position = j;
end
end
n = str2num(Sp(i));
if (n>1)
mw = mw + (Atomic_mass(position))*(n-1);
end
end
sprintf('molecular weight of %s is %f',Sp,mw)
end
O2 enthalpy, entropy, and specific heat vs temperature:



CO2 enthalpy, entropy, and specific heat vs temperature:



N2 enthalpy, entropy, and specific heat vs temperature:



Windows where all values are stored:

Molecular weight data file:
https://drive.google.com/file/d/13C1RGFVsUrt2l5v4lcCay2984CTShhra/view?usp=sharing
Workspace data:

Conclusion:
In this technique we can parse data from any file, and we can calculate any parameters out of it.
I got a plot for all values such as cp,H ,s and molecular weight and the calculated molecular weight is same to that of real molecular weight.