Project 1 - Parsing NASA thermodynamic data
AIM:
- To write a function that extracts the 14 co-efficients and calculates the enthaply,entropy and specific heas for all the species in the data file.
- To calculate the molecular weight of each species and display in the command window.
- To plot the Cp,enthalpy and entropy for the local temperatures range specific for each species.
REPORT & EXPLANTION:
- Firstly, the NASA Thermodynamic Data 'Theermo.dat' file was read bty usingfopen command.
- Then to navigate through the date fgetl command was used.The header line 'Thermo' was skipped by using fgetl command.
- The temperature line '300 1000 5000' was stored as a single string in a variable.To split the string into 3 strings strsplit command was used.To convert the string values into numerical values str2num command was used.The three temperature values min,mid and max were then stored in seperate variables.
- After that the three comment lines were skipped by using fgetl command.
- The 14 co-efficients for each species were calculated by using for loop.Each species contains 3 lines in which 14 coefiicients are present.To distinguish the coefficients the position of eponent were determined for each coefficient by using strfind command.
- The seperate folders were created for each species to save the plots for each species in seperate folders.
- The value of Universal gas constant R=8.31J/mol-K was delecared.Based upon the 14 co-efficients and the valus of specific heat,Enthalpy and Entropy were calculated for each species by using the following formulaes.

8.The graphs were plotted of Temperature vs Entropy , Temperature vs Enthalpy and Temperature vs Specific heat and saved in the seperate created folders for each species.
9.Finally, the values of molecular weights were calculated for each species.For this purpose a different function was created and the in the parsing code to display the molecular weight in command window.
CODE:
- PARSING CODE
clear all
close all
clc
file_1=fopen('THERMO.dat','r');
% read header information
for i=1:5
k = fgetl(file_1);
if i == 2
global_temp = k;
end
end
% reading species block
% line 1
for i=1:53
line_1 = fgetl(file_1);
temp_line = strsplit(line_1,' ');
Species_name =temp_line{1};
L_T = str2double(temp_line{(length(temp_line)-3)});
H_T = str2double(temp_line{(length(temp_line)-2)});
M_T = str2double(temp_line{(length(temp_line)-1)});
% line 2
line_2 = fgetl(file_1);
% coefficient 1
a = strfind(line_2,'E');
a_1 = line_2(1:a(1)+3);
coef_1 = str2double(a_1);
% coefficient 2
a_1= line_2(a(1)+4:a(2)+3);
coef_2 = str2double(a_1);
% coefficient 3
a_1 = line_2(a(2)+4:a(3)+3);
coef_3 = str2double(a_1);
% coefficient 4
a_1 = line_2(a(3)+4:a(4)+3);
coef_4 = str2double(a_1);
% coefficient 5
a_1 = line_2(a(4)+4:a(5)+3);
coef_5 = str2double(a_1);
% coefficient 6
%line 3
line_3 = fgetl(file_1);
a = strfind(line_3,'E');
a_1 = line_3(1:a(1)+3);
coef_6 = str2double(a_1);
% coefficient 7
a_1= line_3(a(1)+4:a(2)+3);
coef_7 = str2double(a_1);
% coefficient 8
a_1 = line_3(a(2)+4:a(3)+3);
coef_8 = str2double(a_1);
% coefficient 9
a_1 = line_3(a(3)+4:a(4)+3);
coef_9 = str2double(a_1);
% coefficient 10
a_1 = line_3(a(4)+4:a(5)+3);
coef_10 = str2double(a_1);
%line 4
% coefficient 11
line_4 = fgetl(file_1);
a = strfind(line_4,'E');
a_1 = line_4(1:a(1)+3);
coef_11 = str2double(a_1);
% coefficient 12
a_1= line_4(a(1)+4:a(2)+3);
coef_12 = str2double(a_1);
% coefficient 13
a_1 = line_4(a(2)+4:a(3)+3);
coef_13 = str2double(a_1);
% coefficient 14
a_1 = line_4(a(3)+4:a(4)+3);
coef_14 = str2double(a_1);
% temperature
T=linspace(L_T,H_T,1000);
% calculate specific heat(cp),enthalpy(H),entropy(s)
for k = 1:length(T)
[cp(k)]=specific_heat(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,...
coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T(k),M_T);
[H(k)]=enthalpy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,...
coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T(k),M_T);
[s(k)]=entropy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,...
coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T(k),M_T);
end
mol_mass = molmass(Species_name);
fprintf ('Mol_mass of %s = %f\n',Species_name,mol_mass)
% making the directery to create folder
mkdir(Species_name)
cd(sprintf(Species_name))
% ploting of specific heat
figure(1)
plot(T,cp,'color','g','linewidth',3)
xlabel('Temperature(K)')
ylabel('specific heat(J/K Kg)')
title(sprintf('specific heat vs temperature for %s & Molecular weight=%f',Species_name,mol_mass))
saveas(figure(1),'Cp vs temp.jpg')
% ploting of entalpy
figure(2)
plot(T,H,'color','b','linewidth',3)
xlabel('Temperature(K)')
ylabel('enthalpy(J/K)')
title(sprintf('enthalpy vs temperature for %s & Molecular weight=%f',Species_name,mol_mass))
saveas(figure(2),'enthalpy vs temp.jpg')
% ploting of entopy
figure(3)
plot(T,s,'color','r','linewidth',3)
xlabel('Temperature(K)')
ylabel('entorpy(J/K)')
title(sprintf('Entropy v temperature for %s & Molecular weight=%f',Species_name,mol_mass))
saveas(figure(3),'entorpy vs temp.jpg')
cd ..
end
All Function Programs which were requried to run the mai program
- Entropy.m
- Enthalpy.m
- Specific_heat.m
- Molmass.m
All these programs are shown below respectively:
function [s]=entropy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T,M_T)
R = 8.314;
if T>M_T
s=((coef_1*log(T))+(coef_2*T)+((coef_3*(T^2))/2)+((coef_4*(T^3))/3)+(coef_5*(T^4)/4)+coef_7);
else
s=((coef_8*log(T))+(coef_9*T)+((coef_10*(T^2))/2)+((coef_11*(T^3))/3)+(coef_12*(T^4)/4)+coef_14);
end
end
function [H]=enthalpy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T,M_T)
R = 8.314;
if T>M_T
H = (coef_1+(coef_2.*T/2)+ (coef_3*(T.^2)/3)+ (coef_4*(T.^3/4))+(coef_5*(T.^4)/5)+(coef_6/T))*R*T;
else
H = (coef_8+(coef_9.*T/2)+ (coef_10*(T.^2)/3)+ (coef_11*(T.^3/4))+(coef_12*(T.^4)/5)+(coef_13/T))*R*T;
end
end
function mol_mass = molmass(Species_name)
elements = ['H','C','O','N','A','S'];
atomic_weight = [1.0079 12.0107 15.999 14.0067 39.948 32.065];
mol_mass = 0;
for l = 1:length(Species_name)
for m = 1:length(atomic_weight)
if strcmp(Species_name(l), elements(m))
mol_mass = mol_mass + atomic_weight(m);
position = m;
end
end
n = str2double(Species_name(l));
if n>1
mol_mass = mol_mass + atomic_weight(position)*(n-1);
end
end
end
function [cp]=specific_heat(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T,M_T)
R = 8.314;
if T>M_T
cp=(coef_1+coef_2*T+coef_3*T^2+coef_4*T^3+coef_5*T^4)*R;
else
cp=(coef_8+coef_9*T+coef_10*T^2+coef_11*T^3+coef_12*T^4)*R;
end
end
Plots for o2, N2 and Co2 species:
For O2-



For N2-



For CO2-



WORKSPACE VALUES:

Directory folder for all species:

CONCLUSION:
By using the function for Cp,h,s calculation and molecular weight is determined in the main program using the parsing method in Matla.All the plots and values for 53 species with respect to temperature are saved in a common directory file and all the molecular weight for all species are determined.