Project 1 - Parsing NASA thermodynamic data
AIM:
To write a code to parse nasa thermodynamic data file and then calculate thermodynamic properties of various gas
species such as Cp, H and S.
OBJECTIVE:
Write a function that extracts the 14 coefficients and calculates the enthalpy,entropy and specific heats for all the species in the
data file.
Calculating molecular weight of each species.
Plotting the specific heat,enthalpy and entropy for the local temperature range.
Saving the plots as images with appropriate names and dumping them in seperate folders for each species.
File Parsing Theory :
File parsing is a string or symbol either in natural language computer language or data structure conferming to the rules of the
former grammer. Parsing splits a file or other input into pieces of data that can be easily stored or manipulated.
MATHEMATICAL EQUATION:
- cp/R = a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4
- H/RT = a1 +(a2.*T)./2+(a3.*T.^2)./3+(a4.*T.^3)./4+(a5.*T.^4)./5+a6
- S/R= a1.*log(T)+a2.*T + a3.*(T.^2)./2 + a4.*(T.^3)./3 + a5.*(T.^4)./4+a7
where
T=local temprature
b1-b7=high temperature coefficient
b8-b14=low temprature coefficient
R=Gas constant=8.314
3. Specific Heat:
% %Calculation of specific heat
function cp = specificheat(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,T,R,local_mid_temp);
% Comparing with global temp
% If less than global it will take min coeffs
if T <= local_mid_temp
cp = R.*(b1+b2.*T+b3.*T.^2+b4.*T.^3+b5.*T.^4);
%If temp is more it will take max coeffs
else
cp = R.*(a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4);
end
% function cp = specificheat(a1,a2,a3,a4,a5,a6,a7,b8,t9,t10,t11,t12,t13,t14,T,R,low_temp,high_temp,mid_temp)
% if T>mid_temp
% cp = (t1+t2.*(T)+t3.*(T.^2)+t4.*(T.^3)+t5.*(T.^4))*R;
% else
% cp = (t8+t9.*(T)+t10.*(T.^2)+t11.*(T.^3)+t12.*(T.^4))*R;
% end
% end
2. Enthalpy:
the sum of the internal energy and the product of the pressure and volume of a thermodynamic system. Enthalpy is an
energy-like property or state function—it has the dimensions of energy (and is thus measured in units of joules), and its value is
determined entirely by the temperature, pressure, and composition of the system and not by its history. In symbols, the enthalpy, H,
equals the sum of the internal energy, E, and the product of the pressure, P, and volume, V, of the system: H = E + PV.
Equation for the Enthalpy:
H/RT = a1 +(a2.*T)./2+(a3.*T.^2)./3+(a4.*T.^3)./4+(a5.*T.^4)./5+a6
code for Enthalpy:
%Calculation of enthalpy
function h = enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R,local_mid_temp)
if T <= local_mid_temp
h = R.*(b1.*T+(b2.*T.^2)./2+(b3.*T.^3)./3+(b4.*T.^4)./4+(b5.*T.^5)./5+b6);
else
h = R.*(a1.*T+(a2.*T.^2)./2+(a3.*T.^3)./3+(a4.*T.^4)./4+(a5.*T.^5)./5+a6);
end
1. Entropy:
the measure of a system’s thermal energy per unit temperature that is unavailable for doing useful work. Because work is
obtained from ordered molecular motion, the amount of entropy is also a measure of the molecular disorder, or randomness, of a
system. The concept of entropy provides deep insight into the direction of spontaneous change for many everyday phenomena.
Equation fro the Entropy :
S/R= a1.*log(T)+a2.*T + a3.*(T.^2)./2 + a4.*(T.^3)./3 + a5.*(T.^4)./4+a7
%Calculation of entropy
function s = entropy_calc(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,T,R,local_mid_temp)
if T<=local_mid_temp
s = R*(a1.*log(T)+a2.*T+a3.*(T.^2)./2+a4.*(T.^3)./3+a5.*(T.^4)./4+a7);
else
s = R*(b1.*log(T)+b2.*T+b3.*(T.^2)./2+b4.*(T.^3)./3+b5.*(T.^4)./4+b7);
end
4) Molecular weight :
Molecular weight is a measure of the sum of the atomic weight values of the atoms in a molecule, Usually, the units used for this are grams per mole. in this preoject we have to find the molecular mass of the atom hence we refere the Nasa file to find out
Code for the Molecular weight :
1. All the species are made of elements which are Hydrogen, Carbon, nitrogen, oxygen, Ar. So, for these their molecular weights had
been taken as input.
2. Starting with for loop one for species name and other for elements, strcmp command is used to compare the elements with
species if both matches then their molecular weight will be calculated alternately with every matching element with to species.
3. Finding a string in species name and converting into a number then taking their position for extracting their weight, if 'n' it will be
greater than one then it is used in a further step to calculate the molecular weight. this 'n' here represents the number of molecules of
an element in species.
%Function to calculate molecular weight
function MW =molecular_weight(name)
atoms = ['H','C','O','N','R'];
fprintf('Molecular Weight of ');
fprintf(name);
fprintf(' : ');
atomic_weight = [1 12 16 14 40];
MW = 0;
for i = 1:length(name)
for j = 1:length(atoms)
if strcmp(name(i),atoms(j))
MW = MW +atomic_weight(j);
position = j;
end
end
n = str2num(name(i));
if n>1
MW = MW + atomic_weight(position)*(n-1);
end
end
fprintf('%d',MW);
disp(' ');
end
5) Main code for the project:
to get all the information together as well as to get the plot and separate folder for resultes
Explaination for the code :
first open the file and read it as function :fopenf
then pass read command: 'r'
to load first line used command : fgetl
Obtaining global max, min, and medium temperatures according to the project requirement we have to find the following entities
we have to split the temperatuer range by using the split command of string : strsplit
- local minimum temperature
- loacal medium temperature
- local maximum temperature
Inputes for the for loop
i = 1:53
R = 8.314
in the for loop extract maximum temperature and minimum temperature.
to the save the result make directory as my saved file location
cd('C:\Users\91755\Desktop\NASA')
Cd=Change diretory
mkdir(name)
mkdir=make directory/folder
after
- To plot varation:
- of cp with T
- of enthapy with temperarure
- of entropy with temperarure
then loop will be completed untill all the values you will get by command : cd..
Result of the preject :
hence the molecular mass obtain and values of minimum temperature and maximum temperature obtain :

result for the folder file save in the location :

Result for Molecular values are obtain in this project :
Molecular Weight of O : 16
Molecular Weight of O2 : 32
Molecular Weight of H : 1
Molecular Weight of H2 : 2
Molecular Weight of OH : 17
Molecular Weight of H2O : 18
Molecular Weight of HO2 : 33
Molecular Weight of H2O2 : 34
Molecular Weight of C : 12
Molecular Weight of CH : 13
Molecular Weight of CH2 : 14
Molecular Weight of CH2(S) : 14
Molecular Weight of CH3 : 15
Molecular Weight of CH4 : 16
Molecular Weight of CO : 28
Molecular Weight of CO2 : 44
Molecular Weight of HCO : 29
Molecular Weight of CH2O : 30
Molecular Weight of CH2OH : 31
Molecular Weight of CH3O : 31
Molecular Weight of CH3OH : 32
Molecular Weight of C2H : 25
Molecular Weight of C2H2 : 26
Molecular Weight of C2H3 : 27
Molecular Weight of C2H4 : 28
Molecular Weight of C2H5 : 29
Molecular Weight of C2H6 : 30
Molecular Weight of CH2CO : 42
Molecular Weight of HCCO : 41
Molecular Weight of HCCOH : 42
Molecular Weight of H2CN : 28
Molecular Weight of HCN : 27
Molecular Weight of HNO : 31
Molecular Weight of N : 14
Molecular Weight of NNH : 29
Molecular Weight of N2O : 44
Molecular Weight of NH : 15
Molecular Weight of NH2 : 16
Molecular Weight of NH3 : 17
Molecular Weight of NO : 30
Molecular Weight of NO2 : 46
Molecular Weight of HCNO : 43
Molecular Weight of HOCN : 43
Molecular Weight of HNCO : 43
Molecular Weight of NCO : 42
Molecular Weight of CN : 26
Molecular Weight of HCNN : 41
Molecular Weight of N2 : 28
Molecular Weight of AR : 40
Molecular Weight of C3H8 : 44
Molecular Weight of C3H7 : 43
Molecular Weight of CH3CHO : 44
Molecular Weight of CH2CHO : 43
Result for the obtain graph by ploting the element :
1) for Enthalpy Vs Temperature :

2) graph for the Entropy Vs Temperature:

3) graph for the specific heat Vs temperature:

Error:
The error that was occurred to me during the programming were after the programming was complete and ran.
I noticed that the 'data ' file was not mentioned in the Directory of the program.
Which gave me this error

Result :
- function that extracts the 14 coefficients and calculates the enthalpy,entropy and specific heats for all the species in the
data file coding done. - Calculating molecular weight of each species done.
- Plotting the specific heat,enthalpy and entropy for the local temperature range are done
- Saving the plots as images with appropriate names and dumping them in seperate folders for each species is done.