Project 1 - Parsing NASA thermodynamic data
Aim:- To write a code in MATLAB to parse the NASA thermodynamic data file and then calculate the thermodynamic properties of various species.
Introduction:-
File Parsing - file parsing is all about reading the information from the text file & how that information can be used in a computer language. By using the file parsing we can decode the parsing method. file parsing can be used to do the calculations required for the specific purpose of the application. parsing helps us make something understandable by analyzing its parts &bits. This is done by partially analyzing the data understanding its underlying structure ( By making some assumptions based on what you're expecting to see), and then explicitly representing that structure in the code.
Input equation:-
Procedure:- The value of universal gas R is given by as 8.31 as an input. then the given THERNO.dat file has to be accessed to obtain the necessary data 'open' command is used to open the desired file and the keyword 'r' is used to read the file. this thermo.dat file is assigned to a variable 'f1' the file is read line by line 'get' command. the first line represents the title so it is ignored. the second line has the global maximum, global mid, and global minimum values which are split into three values by using the strsplit command and converted into a number AN array of temperatures is generated using the space command the next three lines are ignored as they contain only commands. A for loop is created to read the data of all the species. 'fgetl' command inside the loop makes our task easier than the next three lines of the file are read which contains the high and low-temperature data of the particular species. the read lines are in the form of s string so they are converted into numbers using the sternum command and stored in specific variables so they can be used for further calculations. the low temperatures values are stored in variables lc1, lc2, lc3, lc4, lc5, lc6, lc7, and high-temperature values are stored in variables hc1, hc2, hc3, hc4, hc5, hc6, hc7 the next part of the program contains a for loop formulas to calculate specific heat, enthalpy, entropy for lower temperatures given T<=t. an else command is used to calculate the thermodynamic properties at a higher temperature if the temperature fails to satisfy the criteria given above plot of specific heat vs temperature is plotted using the save as command the three figures are saved in the new folder which is created by element name. using the "cd" command the folder is back to the original folder. the functions run 52 times through the for loop and create a separate folder for each species and save all the plots. the molecular weight of different species is calculated.
MATLAB Code:-
Thermodynamics propeties of functions codes
function[cp,h,s]= thermodynamics_properties(a1, a2,a3,a4,a5,a6,a7,a8,a9,a10, a11,a12,a13,a14,R,temperature_ range,medium_global_ temperature)
for k=1:length(temperature_range);
if temperature_range(k)>medium_ global_temperature
cp(k)=R.*(a1+(a2.*temperature_ range(k))+(a3.*(temperature_ range(k)).^2)+(a4.*( temperature_range(k)).^3)+(a5. *(temperature_range(k).^4)));
h(k)=R.*temperature_range(k).* (a1+(a2.*temperature_range(k)) ./(2)+(a3.*(temperature_range( k)).^2)./(3)+(a4.*( temperature_range(k)).^3)./(4) +(a5.*(temperature_range(k).^ 4)./(5)+(a6)./(temperature_ range(k)));
s(k)=R.*((a1.*log(temperature_ range(k)))+(a2.8temperature_ range(k))+(a3.*(temperature_ range(k)).^2+(a4.*( temperature_range(k)).^4)./(4) +(a7));
else
cp(k)=R.*(a8+(a9.* 9temperature_range(k))+(a10.*( temperature_range(k)).^2)+( a11.*(temperature_range(k)).^ 3)+(a12.*(temperature_range(k) ).^4)));
h(k)=R.*temperature_range(k).* (a8+(a9.*temperature_range(k)) ./(2)+(a10.*(temperature_ range(k).^2)(3)+9a11.*( temperature_range(k)).^4)./(5) +(a13./(temperature_range(k))) ;
s(k)=R.*((a8.*log(temperature_ range(k)).^3)./(3)+(a12.*( temperature_range(k)).^4)./(4) +a14);
end
end
Molecular weight function code
this function for molecular weights calculations requires an element as an input argument and it is saved in the variables 'element' and the output argument is the molecular weight.
1. A string array is created which contains the name of atoms.
2. A variableatomic_wt is created which contains the atomic weight of respective atoms in the string array.
3. Then used the 'stamp' command to compare the name of the element with the string array.
4. If there is a repetition of an element . 'str2double' is used to find that and (n-1) is multiplied by atomic_wt of the element to calculate the molecular weight.
function [molecular_weight]=molecular_ mass(species_name)
atoms=['O','C','H','A','N'];
atomic_weight=[15.999 , 12.0107 , 1.00784 , 39.948 , 14.0067];
molecular_weight=0
x=1;
for i=1:length(species_name);
for j=1:length(atoms);
if strcmp(species_name(i),atoms( j))==1;
molecular_weight=atomic_ weight(j)+molecular_weight;
atomicweight=atomic_weight(j);
end
end
t=isstrprop(species_name(i),' digit');
c=str2double(regexp(species_ name,'d*','match'));
if t==1
molecular_weight=atomicweight* (c(x)-1)+molecular_weight;
x=x+1;
end
end
end
O2 PLOTS
CO2 PLOTS
N2 PLOTS
CONCLUSION
Here we can conduct file parsing as the best approach to parse any file with large data available in the file using any programming software for extracting the decoding data available in the file. this type of file parsing is very useful in the current era of industries where we transfer the large engineering data file from one place to another.