Parsing NASA thermodynamic data
REPORT NO PARSING NASA THERMODYNAMIC DATA
• INTRODUCTON
This project is all about reading the NASA thermodynamic data and then calculatimg the thermod ynamic properties (Specific heat, Enthalpy, Entropy and Molar mass) of the different species. Als o to plot the graph (Temperature VS specific heat, Te
mperature VS Enthalpy, Temperature VS Entropy) for all species and saving them in a particular folder. For doing this program was created in MATLAB that parse the THERMO.dat file which contains t he information about all the species. So, for this NASA Thermodynamic data file was first read using the command fopen(\'THERMO.d at\',\'r\'). Now to get the particular line fgetl command was used. Function were created trough MATLAB p rogarmming for calculating (specific heat, entropy, enthalpy, molar mass) and plotting the graph.
• OBJECTIVE
1. Write a function that extracts the 14 co-efficients for a given species
2 Write functions that calculate the enthalpy, entropy and specitic heats using the NASA polynomials
3. Wite a hunction that calculates the molecular weight of each species 4 Wite a function that plots the Cp
4. Write a function that plots the Cp. Enthalpy and Entropy of an input species
5. Save the plots with appropriate names.
6. Display useful plots (enthaipy, entropy and cp) for 02, N2 and Co2.
• MAIN PROGRAM
In this program fopen command is used to read the THERMO.dat file which contains the NASA th ermodynamic data. Ris the variable used as universal gas constant now the line containing global maximum, global medium and global minimum was taken by using fgetl command, Now strsplit command is used to split the string and space is used as the spliting tool for spliting t he string. And then these strings are converted into number using str2num command. With this we get our global maximun medium and minimum temperatures. Now a temperature array (T) is created which is containing 100 values of temperature between gl obal minium to global maximum temperature. Command \"mkdir is used here to make the folder named \"elements data\". Next three lines are skiped using fgetlAnd after this from the next line information about the species starts and the first line contains the species name and next three lines contains coefficient of the species and it goes the saame way. So now total number of species is calculated. \"T_species\" contains the value of total number of s pecies. So total number of species \"T_species=53\". \"frewind\" is the command used to get to the top of the data again, Now \'for loop is used to call all the functions created for the length of the number of species.
close all
clear all
clc
%command for reading the NASA thermodynamic data
f=fopen(\'THERMO.dat\',\'rt\')
%universal gas constant (R)
R=8.314;
fgetl(f);
%extracting the global \'low\'\'medium\' and \'high\' temaprature and converting them from staring to number
Tp=fgetl(f);
T_A=strsplit(TP,\'\');
T_LOW=str2num(T_A{2});
T_MED=str2num(T_A{3});
T_HIGH=str2num(T_A{4});
T=linspace(T_LOW,T_HIGH,100);
%creating the folder elements data
folder=\'elements_data\';
mkdir(folder)
%skipping the unwanted comments
for i=1:3
skip=fgetl(f)
end
%calculating total o of species i in the data
line=0;
for i=1nf
L1=fgetl(f)
if L1=\'END\'
end
line=line+1;
end
T_species=(line)/4
frewind(f)
%skkipping the next five lines
for i=1:5
skip=fgetl(f);
end
%calling the functions for name of the specis (name-species),extracting
%the coefficients(ext_coff),calculating specific hear , enthalpy entropy
%and molecular mass(specific_heat,enthalp_func,entropy_func,mol_weight
%and then finally function for plotting the graphs and saving in the
%folder(plotting)
for j=1:T_species
name_species=sp_name(f)
F=ext_coff(f);
Cp=specific_heat(F,T_MED,T,R);
H=enthalp_func(F,T_MED,T,R);
S=entropy_func(F,T_MED,T,R);
MW=mol_weight(name_species)
plotting(T,Folder,Cp,H,S,name_species
end
fclose(f)
FUNCTION FOR CALLING SPECIES NAME
function [species_name]=sp_name(f)
species_line=fgetl(f)
species_name=species_line(1:6);
end
FUNCTION FOR EXTRACTING CO-EFFICIENTS
Here is the function for extracting the 14 coefficients. Every specie in the data is having 14 coeffic ients, and out of these 14 first seven (1-7) are low temperature coefficients and next seven (8-14) are high temperature coefficients. Here fgetl is used to get the line for the coefficients. Coefficients are distributed in three lines, 1st line containing first five coefficients, 2nd line containing next five coefficients and the 3rd line cont aining next 4 coefficients. Now to extract the coefficient we use strfind command to find the \'E\' character in the coefficient. This was done because letter \'E\' common in all the coefficients. Now thorugh this \'E\' letter 1st co efficient was extracted through the line. And all other coefficient was extracted from the line. After this another line was called using fgetl command and by the same way all the five coefficien ts were extracted of that line and similarly coeffiicients of next line were extracted. coefficients of line 1 (a_1, a_2, a_3, a_4, a_5) coefficients of line 2 (b_1, b_2, b_3, b_4, b_5) coefficients of line 3 (c_1, c_2, c_3, c_4) All these cofficients were stored in \"F\"
fuction[F}=ext_coff(f)
f1=fgetl(f);
A=strfind(f1,\'E\');
a1=f1(1:A(1)+3);
a_1=str2num(a1);
a2=f1(A(1)+:A(2)+3);
a_2=str2num(a2);
a3=f1(A(2)+5:A(4)+3);
a_3=str2num(a3);
a4=f1(A(3)+5:A(4)+3);
a_4=str2num(a4);
a5=f1(A(4)+5:A(5)+3);
a_5=str2num(a5);
f2=fgetl(f);
B=strfind(f2,\'E\');
b1=f2(1:B(1)+3);
b_1=str2num(b1);
b2=f2(B(1)+5:B(2)+3);
b_2=str2num(b2);
b3=f2(B(2)+5:B(3)+3);
b_3=str2num(b3);
b4=f2(B(3)+5:B(4)+3);
b_4=str2num(b4);
b5=f2(B(4)+5:B(5)+3);
b_5=str2num(b5);
f3=fgetl(f);
C=strfind(f3,\'E);
c1=f3(1:C(1)+3);
c_1=str2num(c1);
c2=f3(C(1)+5:C(2)+3);
c_2=str2num(c2);
c3=f3(C(2)+5:C(3)+3);
c_3=str2num(c3);
c2=f3(C(3)+5:C(4)+3);
c_4=str2num(c4);
F=[a_1 a_2 a_3 a_4 a_5 b_1 b_2 b_3 b_4 b_5 c_1 c_2 c_3 c_4];
end
FUNCTION FOR CALCULATING SPECIFIC HEAT
Here is the function to calculate the speccific heat for the species. Function ame:- \"specific_heat\" In ths function F where the coeffictients are stored is used, global medium temperature is used, t emperature range (T) is used, and the universal gas constant (R) is used. Specific heat is calculating using the following formula Cp/R = a1 + a2 T + a3 T^2 + a4 T^3 + a5 T^4 In the function if command is used to calculate the specific heat for temperature range lower than global medium temperature and temperature range higher than global medium temperature.
function [C_P]=specific_heat(F,T_MED,T,R)
5Cp=R(a1+a2T+a3T^2+a4T^3+a5T^4)
for i=1:length(T)
if T(i)>=T_MED
C_P=(F(1)+F(2).*T+F(3).*T.^2+F(4).*T.^3+F(5).*T.^4).*R;
else
C_P=(F(8)+F(9).*T+F(10).*T.^2+F(11).*T.^3+F(12).*T.^4).*R;
end
end
end
FUNCTION FOR CALCULATING ENTHALPY
Here is the function to calculate the Enthalpy for the species. Function ame:- \"enthalp_func\" In ths function F where the coeffictients are stored is used, global medium temperature is used, t emperature range (T) is used, and the universal gas constant (R) is used. Enthalpy is calculating using the following formula H/RT= a1 + a2 T /2 + a3 T^2 /3 + a4 T^3 14 + a5 T^4 /5 + a6/T In the function if command is used to calculate the Enthalpy for temperature range lower than glo bal medium temperature and temperature range higher than global medium temperature.
function[H]=enthalp_finc(F,T_MED,T,R];
%H=(a1T+a2T^2/2+a3T^3/3+a4T^4/4,a5T^5/5+a6T^2)R*T
for i=1:length(T)
if T(i)>=T_MED
H=(F(1).*T+F(2).*(T.^2)/2.*T+F(3).*(T.^3)/3.*T+F(4).*(T.^4)/4.*T+F(5).*(T.^5)/5.*T+F(6).*(T.^6)/6.
2)).*R.*T;
else
H=(F(8).*T+F(9).*(T.^2)/2.*T+F(10).*(T.^3)/3.*T+F(11).*(T.^4)/4.*T+F(12).*(T.^5)/5.*T+F(13).*(T.^6)/6.
end
end
end
FUNCTION FOR CALCULATING ENTROPY
Here is the function to calculate the Entropy for the species. Function ame:- \"entropy_func\" In ths function F where the coeffictients are stored is used, global medium temperature is used, t emperature range (T) is used, and the universal gas constant (R) is used. Entropy is calculating using the following formula S/R = a1 InT + a2 T + a3 T^2 /2 + a4 T^3 /3 + a5 T^4 14 + a7 In the function if command is used to calculate the Entropy for temperature range lower than glob al medium temperature and temperature range higher than global medium temperature.
function [S]=entropy_func(F,T_MED,T,R)
%s=a1*lnT+a2T+(a3T^2)/2+(a4T^3)/3+(a5T^4)/4a7
for i=1:length(T)
if T(i)>=T_MED
S=(F(1).*log10(T)+F(2).*T+(F(3).*T.^2)/+(F(4).*T.^3)/3+(F(5).*T.^4)/+F(7)).*R;
else
S=(F(8).*log10(T)+F(9).*T+(F(10).*T.^2)/+(F(11).*T.^3)/3+(F(12).*T.^4)/+F(14)).*R;
end
end
end
FUNCTION FOR CALCULATING MOLAR WEIGHT
Here is the function to calculate the Molar weight for the species. Function ame:- \"mol_weight\" In ths function species name function (name_species) is used to calculate the molar weight of ev ery species. Here elements (\"H,C,N,O,A\") are taken and the reason for doing so is that all the species are ma de of these elements only. Also we have taken A_Wa variable that contains the atomic weight of the above elements. now command \"strcmp\" command is used to compare that if the element exist in the specie or n ot, and that existance will decide the molecular weight. \"for and \'if lops are used to satisfy the conditions and calculate molecular weight
function [M_W]=mol_weight(name_species)
R_elem={\'H\',\'C\',\'N\',\'O\',\'A\'};
M-W=0;
for i=1:length(name_species)
for j=1:length(R_elem)
if strcmp(name_species(i),R_elem(j))
M_W=M_W+A_W(j);
c=j;
end
end
n=str2num(name_species(i));
if n>1
M_W=M_W+A_W(c)*(n-1);
end
end
end
FUNCTION FOR CALCULATING MOLAR WEIGHT
Here is the function to calculate the Molar weight for the species. Function ame:- \"mol_weight\" In ths function species name function (name_species) is used to calculate the molar weight of ev ery species. Here elements (\"H,C,N,O,A\") are taken and the reason for doing so is that all the species are ma de of these elements only. Also we have taken A_Wa variable that contains the atomic weight of the above elements. now command \"strcmp\" command is used to compare that if the element exist in the specie or n ot, and that existance will decide the molecular weight. \"for and \'if lops are used to satisfy the conditions and calculate molecular weight
function[plots]=plotting(T,folder,Cp,H,S,name_species)
c=pwd;
cd(folder);
thermo_Data=sprentf(\'%s\',name_species);
mkdir(thermo_Data);
figure(1)
plot(T,Cp,\'linewidth\',2,\'color\',\'r\')
title(name_species)
xlabel(\"TEMPERATURE\')
ylabel(\'SPECIFIC HEAT\')
figure(2)
plot(T,H,\'linewidth\',2,\'color\',\'b\')
title(name_species)
xlabel(\"TEMPERATURE\')
ylabel(\'ENTHAPLY\')
figure(3)
plot(T,S,\'linewidth\',2,\'color\',\'b\')
title(name_species)
xlabel(\"TEMPERATURE\')
ylabel(\'ENTROPY\')
cd(thermo_Data)
saveas(1,\'Specific_heat.png\')
saveas(2,\'Enthalpy.png\')
saveas(3,\'Entropy.png\')
cd(c)
end
Results
Plots for N2;
1. Specific heat
2. Entholpy
3.Entropy
Plots for O2;
1. Specific heat
2. Entholpy
3.Entropy
Plots for CO2;
1. Specific heat
2. Entholpy
3.Entropy