PARSING NASA THERMODYNAMIC FILE
AIM: PARSING NASA THERMODYNAMIC FILE
Using MATLAB to parse the NASA Thermodynamic data file and then to calculate
thermodynamic properties of various gas species species.
OBJECTIVES:
1. Writing a function that extracts the 14 coefficients and calculates the Enthalpy, entropy, and specific heats for all the species in the 'THERMO.dat' file.
The formulae are shown below.

2. Calculate the molecular weight of each species and display it in the command window. Plot the Cp , Enthalpy, and Entropy for the local temperature range (low temperature: high temperature) specific for each species. Save the plots as images with appropriate names and dump them in separate folders for each species with a suitable name. All of these are generated automatically.
MAIN CODE:
close all
clear all
clc
f1 = fopen('THERMO.dat','r');
fgetl(f1);
% Defining temperature values
templ = str2num(fgetl(f1));
global_low_temp = templ(1);
global_mid_temp = templ(2);
global_high_temp = templ(3);
% For skipping unwanted lines
for i = 1:3
fgetl(f1);
end
for i=1:53
line1 = fgetl(f1);
l = strsplit(line1, ' ');
m = length(l);
species = l{1};
% Storing the values of the local temperature values
low_temp = str2double(l(m-3));
high_temp = str2double(l(m-2));
mid_temp = str2double(l(m-1)); % Check this later
% Storing the values of the second line of variables
line2 = fgetl(f1);
% Finding the position of E
a = strfind(line2,'E');
% Reading all the other variables
a1 = str2double(line2(1:(a(1)+3)));
a2 = str2double(line2((a(1)+4):(a(2)+3)));
a3 = str2double(line2((a(2)+4):(a(3)+3)));
a4 = str2double(line2((a(3)+4):(a(4)+3)));
a5 = str2double(line2((a(4)+4):(a(5)+3)));
% Storing the values of the 3rd line
line3 = fgetl(f1);
% Finding the position of E
b = strfind(line3,'E');
% Storing the values for the next set of variables
a6 = str2double(line3(1:b(1)+3));
a7 = str2double(line3((b(1)+4):(b(2)+3)));
a8 = str2double(line3((b(2)+4):(b(3)+3)));
a9 = str2double(line3((b(3)+4):(b(4)+3)));
a10 = str2double(line3((b(4)+4):(b(5)+3)));
% Storing ther values of the 4th line
line4 = fgetl(f1);
% Finding the position of E
c = strfind(line4,'E');
% Storing the values of variables in line 4
a11 = str2double(line4(1:c(1)+3));
a12 = str2double(line4((c(1)+4):(c(2)+3)));
a13 = str2double(line4((c(2)+4):(c(3)+3)));
a14 = str2double(line4((c(3)+4):(c(4)+3)));
% Creating Temperature values for lower and higher temperature
lower_temp = linspace(low_temp,mid_temp,100);
higher_temp = linspace(mid_temp,high_temp,100);
% Value of the universal has constant in j/mol*K
R = 8.314; % Universal Gas Constant
% Calculating the values for cp, H and S using the given formulas
for k=1:100
% lower temperature values for cp,h,s calculations i.e low to middle temp values
cp_low(k)=(a8+(a9*lower_temp(k))+(a10*(lower_temp(k)^2))+(a11*(lower_temp(k))^3)+(a12*(lower_temp(k))^4))*R;
h_low(k)=(a8+(a9*lower_temp(k))/2+(a10*lower_temp(k)^2)/3+(a11*lower_temp(k)^3)/4+a12*(lower_temp(k)^4)/5+(a13/lower_temp(k)))*R*lower_temp(k);
s_low(k)=((a8*log(lower_temp(k))+(a9*lower_temp(k))+((a10*lower_temp(k)^2)/2)+((a11*lower_temp(k)^3)/3)+((a12*lower_temp(k)^4)/4)+a14)*R);
% higher temperature values for cp,h,s calculations i.e mid to high temp values
cp_high(k)=(a1+(a2*higher_temp(k))+(a3*(higher_temp(k)^2)+(a4*(higher_temp(k))^3)+a5*(higher_temp(k))^4))*R;
h_high(k)=(a1+(a2*higher_temp(k))/2+(a3*higher_temp(k)^2)/3+(a4*higher_temp(k)^3)/4+(a5*(higher_temp(k)^4))/5+(a6/higher_temp(k)))*R*higher_temp(k);
s_high(k)=((a1*log(higher_temp(k))+a2*higher_temp(k)+((a3*higher_temp(k)^2)/2)+((a4*higher_temp(k)^3)/3)+((a5*higher_temp(k)^4)/4)+a7)*R);
end
% Making Folders for saving the plots
nasa_graphs = species;
mkdir(nasa_graphs);
current = pwd;
cd(nasa_graphs);
%Plotting the graphs
% For specific heat
figure(1)
plot(lower_temp,cp_low,'linewidth',4,'color','k');
hold on
plot(higher_temp,cp_high,'linewidth',4,'color','k');
hold off
title(['Temperature vs Specific Heat',species]);
xlabel('Temperature');
ylabel('Specific Heat');
legend('low temperature','high temperature');
fig = sprintf('Specific Heat of %s.png',species);
saveas(gca,fig);
% For Enthalpy
figure(2)
plot(lower_temp,h_low,'linewidth',4,'color','g');
hold on
plot(higher_temp,h_high,'linewidth',4,'color','g');
hold off
title(['Temperature vs Enthalpy',species]);
xlabel('Temperature');
ylabel('Enthalpy');
legend('low temperature','high temperature');
fig = sprintf('Enthalpy of %s.png',species);
saveas(gca,fig);
% For Entropy
figure(3)
plot(lower_temp,s_low,'linewidth',2,'color','b');
hold on
plot(higher_temp,s_high,'linewidth',2,'color','b');
hold off
title(['Temperature vs Entropy',species]);
xlabel('Temperature');
ylabel('Entropy');
legend('low temperature','high temperature');
fig = sprintf('Entropy of %s.png',species);
saveas(gca,fig);
cd(current)
end
STEPS_EXPLANATION:
STEP 1: In this step "THERMO.dat" file was opened using "fopen" command. And the lines of this file were read and extracted by using the "fget1" command.
global low ,mid and high temperature were read and stored in global_low_temp global_mid_temp global_high_temp.

STEP 2: Because the next three lines in the file do not have any information regarding the code and values. There lines were skipped.

Then as there are 53 species so "for" loop was run "53" times. Here local low,mid and high temperature values were stored.

STEP 3: Here the coefficients i.e.a1,a2,a3,a4,a5 were extracted using "strdouble" command.

STEP 4: Similarly ,here the coefficients i.e. a6, a7, a8,a9, a10, a11 , a12, a13, a14, a15 were extracted using "strdouble" command.

STEP 5: Here two temperature arrays were defined in the local low to mid and local mid to high temperature range. This values were stored in the arrays "lower_temp" and "higher_temp".
Now next "for" loop was run 100 times as in both 100 times "lower_temp " and "higher_temp" .Hence at each point the values were stored in "cp_low" "h_low" "s_low" and "cp_high" "h_high" "s_high"
for lower_temp range and higher_temp range respectively.

STEP 6: Now to save each species in different folder "mkdir" function was used.

STEP 7: It was the last step where three plots for each species were plotted.

OUTPUTS:
PLOTS OF O2:



PLOTS OF N2:



PLOTS OF CO2:



FOLDER WINDOW:

ERROR: The error occured was because of the wrong position naming of the temperature ranges.
