PARSING NASA THERMODYNAMIC DATA AND USING MATLAB
REPORT
ON
PARSING NASA THERMODYNAMIC DATA
- INTRODUCTION
This project is all about reading the NASA thermodynamic data and then calculatimg the thermodynamic properties (Specific heat, Enthalpy, Entropy and Molar mass) of the different species. Also to plot the graph (Temperature VS specific heat, Temperature 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 the information about all the species.
So, for this NASA Thermodynamic data file was first read using the command fopen(\'THERMO.dat\',\'r\').
Now to get the particular line fgetl command was used. Function were created trough MATLAB progarmming for calculating (specific heat, entropy, enthalpy, molar mass) and plotting the graphs.
- OBJECTIVE
- Write a function that extracts the 14 co-efficients for a given species.
- Write functions that calculate the enthalpy, entropy and specific heats using the NASA polynomials.
- Write a function that calculates the molecular weight of each species
- Write a function that plots the Cp, Enthalpy and Entropy of an input species
- Save the plots with appropriate names.
- Display useful plots (enthalpy, entropy and cp) for o2, N2 and Co2.
- MAIN PROGRAM
In this program fopen command is used to read the THERMO.dat file which contains the NASA thermodynamic data.
R is 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 the 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 global minium to global maximum temperature.
Command \"mkdir\" is used here to make the folder named \"elements_data\".
Next three lines are skiped using fgetl
And 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 species. 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\" & \"high\" temperatures and converting
%them from string 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 no. of species i the data
line=0;
for i=1:Inf
L1=fgetl(f);
if L1==\"END\"
break
end
line=line+1;
end
T_species=(line)/4
frewind(f)
%skipping the next five lines
for i=1:5
skip=fgetl(f);
end
%calling the functions for name of the species(name_species), extracting
%the coefficients(ext_coff), calculating specific heat, enthalpy entropy
%and molecular mass (specific_heat, enthalp_func, entropy_func, mol_weight
%) and then finally function for plotting the graphs and saving them 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 coefficients, 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 containing 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 coefficient 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 coefficients 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\"
function [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)+5:A(2)+3);
a_2=str2num(a2);
a3=f1(A(2)+5:A(3)+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);
c4=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, temperature 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)
%Cp=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, temperature 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 /4 + a5 T^4 /5 + a6/T
In the function if command is used to calculate the Enthalpy for temperature range lower than global medium temperature and temperature range higher than global medium temperature.
function [H]=enthalp_func(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 +F(3).*(T.^3)/3 + F(4).*(T.^4)/4 + F(5).*(T.^5)/5 + F(6).*(T.^2)).*R.*T;
else
H= (F(8).*T + F(9).*(T.^2)/2 +F(10).*(T.^3)/3 + F(11).*(T.^4)/4 + F(12).*(T.^5)/5 + F(13).*(T.^2)).*R.*T;
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, temperature range (T) is used, and the universal gas constant (R) is used.
Entropy is calculating using the following formula
S/R = a1 lnT + a2 T + a3 T^2 /2 + a4 T^3 /3 + a5 T^4 /4 + a7
In the function if command is used to calculate the Entropy for temperature range lower than global 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 + (a4 T^3)/3 + (a5 T^4)/4 + a7
for i=1:length(T)
if T(i)>=T_MED
S=(F(1).*log10(T)+F(2).*T+(F(3).*T.^2)/2+(F(4).*T.^3)/3+(F(5).*T.^4)/4+F(7)).*R;
else
S=(F(8).*log10(T)+F(9).*T+(F(10).*T.^2)/2+(F(11).*T.^3)/3+(F(12).*T.^4)/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 every species.
Here elements (\"H,C,N,O,A\") are taken and the reason for doing so is that all the species are made of these elements only. Also we have taken A_W a 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 not, 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\'};
A_W = [1 12 14 16 40];
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 PLOTTING AND SAVING THE PLOTS IN THE PARTICULAR SPECIE FOLDER
Here, a function \"ploting\" is created to plot the Temperature VS specific heat, Enthalpy and Entropy plots.
Temperature range \"T\", \"folder\", specific heat(\"Cp\"), enthalpy (\"H\"), Entropy(\"S\") and \"name_species\" are taken as the inputs for this function.
Command \"pwd\" is used to store the path of the folder in \'c\'. Then \"cd\" is used to change the directory to the new folder.
Now all the species name wise are called and stored in \'thermo_Data\' and made a folder of that.
In figure 1, the plot temperature vs specific heat is shown
In figure 2, the plot temperature vs enthalpy is shown
In figure 3, the plot temperature vs entropy is shown
Now these plots are saved in the folder of particular species.
function [plots]=plotting(T,folder,Cp,H,S,name_species)
c = pwd;
cd(folder);
thermo_Data = sprintf(\'%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(\'ENTHALPY\')
figure(3)
plot(T,S,\'linewidth\',2,\'color\',\'g\')
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
MOLECULAR WEIGHT = 28
1. SPECIFIC HEAT (N2)
2. ENTHALPY (N2)
3. ENTROPY (N2)
PLOTS FOR O2
MOLECULAR WEIGHT = 32
1. SPECIFIC HEAT (O2)
2. ENTHAPLY (O2)
3. ENTROPY (O2)
PLOTS FOR CO2
MOLECULAR WEIGHT = 44
1. SPECIFIC HEAT (CO2)
2. ENTHALPY (CO2)
3. ENTROPY (CO2)