Project 1 - Parsing NASA thermodynamic data
Problem : Project Parsing project
Aim : To write a program to Extract 14 Coefficient from the Thermo Data file of Different Species. Calculate the Specific Heat, Entropy, Enthalpy, Taking that R is the universal constant and value is 8.314
Formula to calculate the Specific Heat (Cp), Entropy (S), Enthalpy(H) given.

Explanation of Project.
Step1 : Collect all the data and information and make road map to complete the project by geting the THERMO.dat file from the link given in the question itself.NASA thermodynamic data. Then we need to identify that we would require Specific Heat (Cp), Entropy (S), Enthalpy(H) and Molecular Function.
Step2 : So first write down the function for Specific Heat (Cp), Entropy (S), Enthalpy(H) based on the given formula. Here we have used the If else Comand in order to get the desire output as mentioned in the question that is to used different coefficient for different temperature.
Step3 : The Program begin with basic comands and first open the file using fopen('THERMO.dat','r') the using fgetl() command get the line by line of the thermo data and seprating the the each and variable with its coefficent with strsplit and str2num commands.
Step4 : Now till temperature the line have been read now skipping the 3 lines which are not useful using the for loop comand
Step5 : The coefficient lins comes now and we need to extract all coefficent of all the species and for that we use For Loop for 1 to 53 species total, fgetl to get all the lines of particular species that will be continued for total 53 times so it will read all line, strsplt() this seprate the each word or term and then specify the first term by Species_SP (A{1}), then find the variable term E using the strfind comand and extract all 14 coefficient for particular species using the command str2num.
Step6 : Now calling the function Specific Heat (Cp), Entropy (S), Enthalpy(H) and calculating it in order the get those values
Step7 : Now create a function for the molecular weight calculation and call the function to calculate molecular weight for each species, once that is done now print those values in the command window using the fprintf() use the %s for species and %f \n for molecular weight to display command
Step8 : Now creating the directory using mkdir('folder path',Species_SP) cd(Species_SP) and then creating plots and saving them in the respective folder of the species with proper labeling and then use cd .. (for avoiding one folder in the orther).
Results are attached at the end
Function :
Specific Heat
% Specific Heat Function
function [Cp] = Specific_Heat(Coeff_1,Coeff_2,Coeff_3,Coeff_4,Coeff_5,Coeff_6,Coeff_7,Coeff_8, Coeff_9,Coeff_10,Coeff_11,Coeff_12,temp,R,temp_mid)
% Comparision global temperature and minimum coeffeicients are taken
if temp <= temp_mid
Cp = R*(Coeff_8 + (Coeff_9*temp) + (Coeff_10*(temp).^2) + (Coeff_11*(temp).^3) + (Coeff_12*(temp).^4));
else
Cp = R*(Coeff_1 + (Coeff_2*temp) + (Coeff_3*(temp).^2) + (Coeff_4*(temp).^3) + (Coeff_5*(temp).^4));
% else Maximum Coefficient are taken
end
Entropy
% Function to Calculate Entropy [S]
function [S] = entropy(Coeff_1,Coeff_2,Coeff_3,Coeff_4,Coeff_5,Coeff_7,Coeff_8,Coeff_9,Coeff_10,Coeff_11,Coeff_12,Coeff_14,temp,R,temp_mid)
if temp <= temp_mid
S = R.*(Coeff_8.*log(temp) + (Coeff_9.*temp) + (Coeff_10*((temp).^2)/2) + (Coeff_11*((temp).^3)/3) + (Coeff_12*((temp).^4)/4) + Coeff_14);
else
% Maximum Coefficient are taken00
S = R.*(Coeff_1.*log(temp) + (Coeff_2.*temp) + (Coeff_3*((temp).^2)/2) + (Coeff_4*((temp).^3)/3) + (Coeff_5*((temp).^4)/4) + Coeff_7);
end
Enthalpy
% Function for Enthalpy Calculation
function [H] = enthalpy(Coeff_1,Coeff_2,Coeff_3,Coeff_4,Coeff_5,Coeff_6,Coeff_8,Coeff_9,Coeff_10,Coeff_11,Coeff_12,Coeff_13,temp,R,temp_mid)
% Calculating Enthalpy for both Higher and Lower temp
if temp <= temp_mid
H = R*T.*(Coeff_8 + ((Coeff_9*temp)/2) + ((Coeff_10*(temp).^2)/3) + ((Coeff_11*(temp).^3)/4) + ((Coeff_12*(temp).^4)/5) + Coeff_13./temp);
else
H = R*temp.*(Coeff_1 + ((Coeff_2*temp)/2) + ((Coeff_3*(temp).^2)/3) + ((Coeff_4*(temp).^3)/4) + ((Coeff_5*(temp).^4)/5) + Coeff_6./temp);
end
Molecular Weight
% Calculating the molecular weight for the speciese
function [Molecularweight] = molecular_weight(Species_SP)
elements = {'H','C','O','N','A'};
atomic_weight = [1,12,16,14,39];
% Staring Molecular weight
Molecularweight = 0;
for k = 1:length(Species_SP)
for l = 1:length(elements)
if strcmp(Species_SP(k),elements(l))
Molecularweight = Molecularweight + atomic_weight(l);
position = l;
end
end
n = str2num(Species_SP(k));
if n>1
Molecularweight = Molecularweight + (atomic_weight(position)*(n-1));
end
end
end
Main Code
clear all
close all
clc
f1 = fopen('THERMO.dat','r');
fgetl(f1);
T = fgetl(f1);
%Spliting the temperature
S = strsplit(T);
% Converting the cells to number
temp_low = str2num(S{2});
temp_mid = str2num(S{3});
temp_high = str2num(S{4});
% Temperature Range
temp = linspace(temp_low,temp_high,1000);
% Universal Gas Constant R {J/(mol-K)}
R = 8.314;
% Skiping the comments
for i = 1:3
get = fgetl(f1);
end
% Read the 1st Species
for j = 1:53
gt = fgetl(f1);
A = strsplit(gt,' ');
Species_SP = (A{1});
line_1 = fgetl(f1);
a = strfind(line_1,'E');
line_2 = fgetl(f1);
b = strfind(line_2,'E');
line_3 = fgetl(f1);
c = strfind(line_3,'E');
% First 7 Coefficient Higher Temperature
Coeff_1 = line_1(1:a(1)+3);
Coeff_1 = str2num(Coeff_1);
Coeff_2 = line_1(a(1)+4:a(2)+3);
Coeff_2 = str2num(Coeff_2);
Coeff_3 = line_1(a(2)+4:a(3)+3);
Coeff_3 = str2num(Coeff_3);
Coeff_4 = line_1(a(3)+4:a(4)+3);
Coeff_4 = str2num(Coeff_4);
Coeff_5 = line_1(a(4)+4:a(5)+3);
Coeff_5 = str2num(Coeff_5);
Coeff_6 = line_2(1:b(1)+3);
Coeff_6 = str2num(Coeff_6);
Coeff_7 = line_2(b(1)+4:b(2)+3);
Coeff_7 = str2num(Coeff_7);
% Second 7 Coefficient Higher Temperature
Coeff_8 = line_2(b(2)+4:b(3)+3);
Coeff_8 = str2num(Coeff_8);
Coeff_9 = line_2(b(3)+4:b(4)+3);
Coeff_9 = str2num(Coeff_9);
Coeff_10 = line_2(b(4)+4:b(5)+3);
Coeff_10 = str2num(Coeff_10);
Coeff_11 = line_3(1:c(1)+3);
Coeff_11 = str2num(Coeff_11);
Coeff_12 = line_3(c(1)+4:c(2)+3);
Coeff_12 = str2num(Coeff_12);
Coeff_13 = line_3(c(2)+4:c(3)+3);
Coeff_13 = str2num(Coeff_13);
Coeff_14 = line_3(c(3)+4:c(4)+3);
Coeff_14 = str2num(Coeff_14);
% Specific Heat Calculation
Cp = Specific_Heat(Coeff_1,Coeff_2,Coeff_3,Coeff_4,Coeff_5,Coeff_6,Coeff_7,Coeff_8,Coeff_9,Coeff_10,Coeff_11,Coeff_12,temp,R,temp_mid);
% Entropy Calculation
S = entropy(Coeff_1,Coeff_2,Coeff_3,Coeff_4,Coeff_5,Coeff_7,Coeff_8,Coeff_9,Coeff_10,Coeff_11,Coeff_12,Coeff_14,temp,R,temp_mid);
% Enthalpy Calculation
H = enthalpy(Coeff_1,Coeff_2,Coeff_3,Coeff_4,Coeff_5,Coeff_6,Coeff_8,Coeff_9,Coeff_10,Coeff_11,Coeff_12,Coeff_13,temp,R,temp_mid);
% Calculating Molecular weight of Species_SP
Molecularweight = molecular_weight(Species_SP);
%Reading and writing the list of the molecular weight
fprintf('Molecular weight of %s is %f \n',Species_SP,Molecularweight)
% Creating the directory for Species
mkdir('D:\My usefull\SkillLync\Assignement\NASA Parasing',Species_SP)
cd(Species_SP)
% Plotting the Graphs wrt tempreture
% Specific Heat vs Tempertaure
figure(1);
plot(Cp,temp,'color','r');
ylabel('Temperature [K]');
xlabel('Specific Heat [KJ]');
grid on
title('Tempurature vs Specific Heat %s',Species_SP);
saveas(figure(1),'Specific Heat.png','png')
figure(2);
plot(S,temp,'color','r');
ylabel('Temperature [K]');
xlabel('Entropy [KJ/mol-k]');
grid on
title('Tempurature vs Entropy %s',Species_SP);
saveas(figure(2),'Entropy.png','png')
figure(3);
plot(H,temp,'color','r');
ylabel('Temperature [K]');
xlabel('Enthalpy [KJ/mol]');
grid on
title('Tempurature vs Enthalpy %s',Species_SP);
saveas(figure(3),'Enthalpy.png','png')
cd ..
end
Molecular Weight in command window


Seperate Directory for the Species with respective Graph saved in it.

Graph
O2



N2



CO2



End.