Parsing NASA thermodynamic data
Parsing NASA thermodynamic data
Parsing can refer to breaking up ordinary text.simply we can say that by using parsing we can easily find the alphabet in the the text file. For example we can read a text file we can locate the alphabet so while computing we can get the location of the alphabet .
- In the very first step all extra windows are close and command data is cleared
- Then we read the thermo.dat file given by the skill lync to calculate the specific heat,entropy and enthalpy.
- The read file is assigned to f1 in order to get the data related to the global temperature,local temperature and the coefficients to calculte the thermodynamic properties.
- fgetl command is used to go to the the next line in the file
- strsplit is used to split the value in a line
- The split values are assaigned to vector A_G_T
- String generated is converted to double and stored in G_L_T,G_M_T and G_H_T
- Next three lines can be skipped because those are not important
- In order to generate thermodynamic properties for each element we are using for loop
- In the next line local temeratures and molecule name of specific species are extracted by using strfing command
- For the next few lines by using strfind we can extract the coefficients to calculate the thermodynamic properties
- mkdir command is used to create folder for every species
- Function for solving thermodunamic process is written
- plots are generated and saved in to the assagned directory
- cd command is used to go to the specific directory
- At last function to calculate the molecular weight is created
% FINAL PROJECT PARSING
clear all
close all
clc
%% step1
%first read the thermo.dat to read the file
f1=fopen(\'THERMO.DAT\',\'r\');
Title= fgetl(f1);
%G_T global temeratures
G_T= fgetl(f1);
%% second step
%A_G_T all global temperature
A_G_T=strsplit(G_T,\' \');
%converting string to double
%G_L_T=Global low temperature
%G_M_T=Global medium temperature
%G_H_T=Global high temperature
G_L_T=str2double(A_G_T{1});
G_M_T=str2double(A_G_T{2});
G_H_T=str2double(A_G_T{3});
fgetl(f1);
fgetl(f1);
fgetl(f1);
%% step 3
%first species is taken to extract the local temperatures and coefficients then convert to number
for i=1:53
o_line1=fgetl(f1);
A=strsplit(o_line1,\' \');
L_T=strfind(o_line1,\'G\');
molecule_name=o_line1(1:6)
L_l_t=o_line1(L_T+3:55);
L_m_t=o_line1(L_T+23:75);
L_h_t=o_line1(L_T+13:65);
L_l_t=str2double(L_l_t);
L_m_t=str2double(L_m_t);
L_h_t=str2double(L_h_t);
o_line2=fgetl(f1);
l1=strfind(o_line2,\'E\');
cf_h_1=o_line2(1:l1(1)+3);
cf_h_2=o_line2(l1(1)+4:l1(2)+3);
cf_h_3=o_line2(l1(2)+4:l1(3)+3);
cf_h_4=o_line2(l1(3)+4:l1(4)+3);
cf_h_5=o_line2(l1(4)+4:l1(5)+3);
o_line3=fgetl(f1);
l2=strfind(o_line3,\'E\');
cf_h_6=o_line3(1:l2(1)+2);
cf_h_7=o_line3(l2(1)+4:l2(2)+3);
cf_l_1=o_line3(l2(2)+4:l2(3)+3);
cf_l_2=o_line3(l2(3)+4:l2(4)+3);
cf_l_3=o_line3(l2(4)+4:l2(5)+3);
o_line4=fgetl(f1);
l3=strfind(o_line4,\'E\');
cf_l_4=o_line4(1:l3(1)+2);
cf_l_5=o_line4(l3(1)+4:l3(2)+3);
cf_l_6=o_line4(l3(2)+4:l3(3)+3);
cf_l_7=o_line4(l3(3)+4:l3(4)+3);
%%step 4 converting string to cell
hf1=str2double(cf_h_1);
hf2=str2double(cf_h_2);
hf3=str2double(cf_h_3);
hf4=str2double(cf_h_4);
hf5=str2double(cf_h_5);
hf6=str2double(cf_h_6);
hf7=str2double(cf_h_7);
lf1=str2double(cf_l_1);
lf2=str2double(cf_l_2);
lf3=str2double(cf_l_3);
lf4=str2double(cf_l_4);
lf5=str2double(cf_l_5);
lf6=str2double(cf_l_6);
lf7=str2double(cf_l_7);
%This is to create the folder with molecule name
mkdir([\'C:\\Users\\ramsa\\Desktop\\skill lync\\Test\\\',molecule_name]);
%% step 4 write the formulae to calculate the Cp,S and H
%local temperature is(low temperature,high temperature)
T=linspace(L_l_t,L_h_t,500);
[Cp, H, S]=thermalproperties(L_l_t,L_h_t,t_mid,T,R,lf1,lf2,lf3,lf4,lf5,lf6,lf7,hf1,hf2,hf3,hf4,hf5,hf6,hf7);
%% Step 5 plotting graph
figure(1);
plot(T,Cp)
xlabel(\'temperature(k)\')
ylabel(\'Specific heat(kj)\')
title(\'Specific heat vs Temperature\')
figure(2);
plot(T,S)
xlabel(\'temperature(k)\')
ylabel(\'Entropy(kj/kg.k)\')
title(\'Entropy vs Temperature\')
figure(3);
plot(T,H)
xlabel(\'temperature(k)\')
ylabel(\'Enthalpy (kj/kg)\')
title(\'Enthalpy vs Temperature\')
%Inorder to save the the generated images into Test
directory=([\'C:\\Users\\ramsa\\Desktop\\skill lync\\Test\\\',molecule_name]);
cd(directory)
saveas(1,\'Cp.png\');
saveas(2,\'S.png\');
saveas(3,\'H.png\');
%Going back to the directory
cd(\'C:\\Users\\ramsa\\Desktop\\skill lync\\\')
%% Step 6 calculating the molecular weight of the species
MW=molecular_mass(molecule_name)
end
Funtion to calculate the thermodynamic properties
Here in this code the outputs are Cp,H and S and the inputs are local temperatures of the species and there low temperature and high temperature coefficients with respective to that real gas constant is also given as input. In this i assumed the temperature below 1000 uses low temperature coefficient to calculate the thermal properties and for above 1000 we use high temperature coefficient. so in order to meet the above condition i used if else command.
function [Cp, H, S]=thermalproperties(L_l_t,L_h_t,t_mid,T,R,lf1,lf2,lf3,lf4,lf5,lf6,lf7,hf1,hf2,hf3,hf4,hf5,hf6,hf7)
for k=1:length(T)
if T(k)<t_mid
Cp=R*(lf1+lf2*T+lf3*T.^2+lf4*T.^3+lf5*T.^4);
H=R*(lf1+lf2*(T/2)+lf3*((T.^2)/3)+lf4*((T.^3)/4)+lf5*((T.^4)/5)+lf6./T);
S=R*(lf1*(log10(T))+lf2*T+lf3*((T.^2)/2)+lf4*((T.^3)/3)+lf5*((T.^4)/4)+lf7);
else
Cp=R*(hf1+hf2*T+hf3*T.^2+hf4*T.^3+hf5*T.^4);
H=R*(hf1+hf2*(T/2)+hf3*((T.^2)/3)+hf4*((T.^3)/4)+hf5*((T.^4)/5)+hf6./T);
S=R*(hf1*(log10(T))+hf2*T+hf3*((T.^2)/2)+hf4*((T.^3)/3)+hf5*((T.^4)/4)+hf7);
end
end
(i have problem in copying code in sample code)
(function [Cp, H, S]=thermalproperties(L_l_t,L_h_t,t_mid,T,R,lf1,lf2,lf3,lf4,lf5,lf6,lf7,hf1,hf2,hf3,hf4,hf5,hf6,hf7)
for k=1:length(T)
if T(k)<t_mid
Cp=R*(lf1+lf2*T+lf3*T.^2+lf4*T.^3+lf5*T.^4);
H=R*(lf1+lf2*(T/2)+lf3*((T.^2)/3)+lf4*((T.^3)/4)+lf5*((T.^4)/5)+lf6./T);
S=R*(lf1*(log10(T))+lf2*T+lf3*((T.^2)/2)+lf4*((T.^3)/3)+lf5*((T.^4)/4)+lf7);
else
Cp=R*(hf1+hf2*T+hf3*T.^2+hf4*T.^3+hf5*T.^4);
H=R*(hf1+hf2*(T/2)+hf3*((T.^2)/3)+hf4*((T.^3)/4)+hf5*((T.^4)/5)+hf6./T);
S=R*(hf1*(log10(T))+hf2*T+hf3*((T.^2)/2)+hf4*((T.^3)/3)+hf5*((T.^4)/4)+hf7);
end
end)
Function to calculate the molecular weight of the species
This function is used to calculate the molecular weight of the 53 species present in the thermo.dat file.Here calculation is done by using molecular name, In the main fuction we already extracted the molecule name. we found 5 as the common elements which combinly forms a molecule. So we take atomic weights of the common 5 elements and store in a vector. initially we assume MW=0(MW=molecular weight).for loop is used to know the length of the molecular name, the next inner for loop is used to calculate length of atomic weight. condition command is used to compare strings molecule name and atoms, if they match then molecular weight of the element is calculated but not the components weight for that we need to know how many elements are there that is found out by str2double and then the we are going to get the molecular weight of the molecule.
function MW=molecular_mass(molecule_name)
atoms={\'H\',\'C\',\'N\',\'O\',\'AR\'};
Atomic_weight=[1 12 14 16 40];
MW=0;
for i=1:length(molecule_name)
for j=1:length(Atomic_weight)
if(strcmp(molecule_name(i),atoms(j))==1)
MW=MW+Atomic_weight(j);
p=j;
break
end
end
n=str2double(molecule_name(i));
if (n>1)
MW=MW+(Atomic_weight(p)*(n-1));
end
end
end
Location of species thermodynamic properties
Plotted Graphs
1)O2 Plots
Temperature vs Specific heat
Temperature vs Enthalpy
Temperature vs Entropy
2)N2 Plots
Temperature vs Specific heat
Temperature vs Enthalpy
Temperature vs Entropy
3)CO2 plots
Temperature vs Specific heat
Temperature vs Enthalpy
Temperature vs Entropy
Molecular Weights screenshots(PDF is created with all Molecular weights please find it in google drive link)
The above picture gives the molecular weights of all the species in the termo.dat. I created a PDF with all the molecular weights from the command window
End