Project 1 - Parsing NASA thermodynamic data
Aim : Write a code in matlab to parse the NASA Thermodynamic data file and then calculate the thermodynamic properties of various gas species.
Objective :
- Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.
- Calculate the molecular weight of each species and display it in the command window.
- Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.
-
Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name. All these should be generated automatically.
- The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H and S plots.
- To write a detailed report to describe your logic.
Formula :

Where
R = Universal gas Constant
T= Temperature
cp = Specific Heat (KJ)
S = Entropy(KJ/mol-K)
H = Enthalpy(KJ/mol)
a(i) = coefficients, ( i = 1 to 14)
Theory :
File parsing
Parsing, syntax analysis, or syntactic analysis is the process of analyzing a strings of symbols, either in natural anguage, computer languages or data structures, conforming to the rules of a formal grammer. The term parsing comes from Latin pars (orationis), meaning part . The term has slightly different meanings in different branches of linguistics and computer science. Traditional sentence parsing is often performed as a method of understanding the exact meaning of a sentence or word, sometimes with the aid of devices such as sentence diagrams. It usually emphasizes the importance of grammatical divisions such as subject and predicate. Within computational linguistics the term is used to refer to the formal analysis by a computer of a sentence or other string of words into its constituents, resulting in a parse tree showing their syntactic relation to each other, which may also contain semantic and other information (p-values). Some parsing algorithms may generate a parse forest or list of parse trees for a syntactically ambiguous input.
NASA Thernodynamic file
dat file is a data file containing 14 coefficients for 53 different elements given by NASA. These coefficients are utilized to calculate the specific heat, enthalpy & entropy for a particular element. Each element has its own range of local temperature.
Specific Heat
specific heat is the the quantity of heat required to raise the temperature of one gram of a substance by one Celsius degree. The units of specific heat are usually calories or joules per gram per Celsius degree. For example, the specific heat of water is 1 calorie (or 4.186 joules) per gram per Celsius degree. The Scottish scientist Joseph Black, in the 18th century, noticed that equal masses of different substances needed different amounts of heat to raise them through the same temperature interval, and, from this observation, he founded the concept of specific heat.
Heat energy = (mass of the object or substance) × (specific heat) × (Change in temperature)
Q = m × c × ΔT
Or
Q = mcΔT
Derviation of specific heat formula
Q = refers to the heat energy in Joules (J)
m = refers to the mass of the substance in kilogram (kg)
c = refers to the specific heat in joules per kilogram (J/kg⋅k)
Δ = refers to the symbol of change
Δt = refers to the change in temperature in kelvins (K)
Enthalpy
When a process takes place at constant pressure, the heat absorbed or released is equal to the Enthalpy change. Enthalpy is sometimes known as “heat content”, but “enthalpy” is an interesting and unusual word, so most people like to use it. Etymologically, the word “entropy” is derived from the Greek, meaning “turning” and “enthalpy” is derived from the Greek meaning “warming”. As for pronunciation, Entropy is usually stressed on its first syllable, while enthalpy is usually stressed on the second.
Enthalpy H can be written as,
H = U + pV
Where, H = Enthalpy of the system
U = Internal energy of the system
p = Pressure of the system
V = Volume of the system
Entropy
Entropy can be defined as the measure of disorder or randomness of a system. A German physicist named Rudolf Clausius introduced the term entropy. It is also the measure of the system’s thermal energy per unit temperature that is unavailable for doing useful work. It is used to explain the behaviour of a system in terms of thermodynamic properties such as temperature heat capacity and pressure.
File Parsing Explanation :
File parsing means reading the file file from outer folder inside matlab or extracting the value of a folder provided extracting the value inside the folder. The name parse refers in matlab reading a function, script or internal code inside the memory. Some common commands used are (fopen, fgetl, fgets etc.,)
Procedure :
- Getting the heading of the file
- The given program will get the header of the file which start with clear all colse all and clc
- The command fopen will used for reading the thermodynamic data.
- The fgetl command returns the next line of the specified file, removing the newline characters.
- If the file is non empty, then fgetl returns tline as a character vector.
- if the file is empty and contains only the end of file marker, the fgetl returns tline as a numeric value-1.
code :
- The global temp info is stored in string so we use the command str2double so that it returns the value in{} as a string.
- Which gives us the cell array. From which we can get the global temperature value.
- For skipping the next three comments we use fgetl command
code :
Getting the Temperature info of individual species :
- Species name is store in length of 6 for that l used line(1:6) matlab will get me the value and so on for getting the low_temp value which is on 49 to 55 th location, here used the command line1(49:55) matlab will get me the value. As well for higher temp and midtemp.
- Here in this section i have used the terms local_temp which show i'm targetting the temperature of the species.
- And then converting to the string by using again str2double command with giving temeperature name low_temp, high_temp, mid_temp.
code :
Extracting the coefficient values :
- In order to extract co-efficient value, got the lines by fgetl command and marked the lines as line2, line3, line4 and i use these line to extract the coefficient.
code :
Function for the Specific Heat, Enthalpy and Entropy :
- here i have used the same formula as mention above, to calculate the cp, H, S values
- For loop is for repeating these condition for all three at once cp, H, S
- If loop is used here because there are condition applied for finding value all 7 coefficient of higher temperature and value of 7-coefficient of lower temperature.
Code :
Functiom for Molecular weight :
- Hence we can see the thermodynamic data contains 5 species that are oxygen, carbon, nitrogen, hydrogen and argon.
- These are named as elements and are stored in array.
- Where as their atomic masses are stored in atomic mass array.
- Here i have used for loop so that the process is to be repeated for each and every species.
- Strcmp command is used to compare the elements and corresponding atomic mass and the molecular weight is stored in mol_wt.
- Hence the molecular weight is calculated and can be applied in main code.
Code :
- In order to create a folder i have used the command mkdir which allows matlab to create new folder to store the species data.
- Strcat command is used to concatenate a string to identify the name of the folder.
- Pwd command is used to identify the nature of the folder.
Code :
Main Code :
plot(T,cp,'lineWidth',3,'Color','r')
title('Specific Heat vs Temperature',species_name);
xlabel('Temperature[K]')
ylabel('Specific heat [Kj/kg.K]')
f = fullfile(species_name);
cd(f);
saveas(gcf,[pwd '/Specific Heat vs temperature.jpg']);
cd(file);
plot(T,h,'lineWidth',3,'Color','b')
title('Enthalpy vs Temperature',species_name);
xlabel('Temperature[K]')
ylabel('Enthalpy [Kj]')
f = fullfile(species_name);
cd(f);
saveas(gcf,[pwd '/enthalpy vs temperature.jpg']);
cd(file);
plot(T,s,'lineWidth',3,'Color','c')
title('Entropy vs Temperature',species_name);
xlabel('Temperature[K]')
ylabel('Entropy [Kj/K]')
f = fullfile(species_name);
cd(f);
saveas(gcf,[pwd '/entropy vs temperature.jpg']);
cd(file);









molecular_weight_cal =
16
molecular_weight_cal of Property...O:16 amunProperty...O mol-wt = 16.000000
molecular_weight_cal =
32
molecular_weight_cal of Property...O2:32 amunProperty...O2 mol-wt = 32.000000
molecular_weight_cal =
1
molecular_weight_cal of Property...H:1 amunProperty...H mol-wt = 1.000000
molecular_weight_cal =
2
molecular_weight_cal of Property...H2:2 amunProperty...H2 mol-wt = 2.000000
molecular_weight_cal =
17
molecular_weight_cal of Property...OH:17 amunProperty...OH mol-wt = 17.000000
molecular_weight_cal =
18
molecular_weight_cal of Property...H2O:18 amunProperty...H2O mol-wt = 18.000000
molecular_weight_cal =
33
molecular_weight_cal of Property...HO2:33 amunProperty...HO2 mol-wt = 33.000000
molecular_weight_cal =
34
molecular_weight_cal of Property...H2O2:34 amunProperty...H2O2 mol-wt = 34.000000
molecular_weight_cal =
12
molecular_weight_cal of Property...C:12 amunProperty...C mol-wt = 12.000000
molecular_weight_cal =
13
molecular_weight_cal of Property...CH:13 amunProperty...CH mol-wt = 13.000000
molecular_weight_cal =
14
molecular_weight_cal of Property...CH2:14 amunProperty...CH2 mol-wt = 14.000000
molecular_weight_cal =
14
molecular_weight_cal of Property...CH2(S):14 amunProperty...CH2(S) mol-wt = 14.000000
molecular_weight_cal =
15
molecular_weight_cal of Property...CH3:15 amunProperty...CH3 mol-wt = 15.000000
molecular_weight_cal =
16
molecular_weight_cal of Property...CH4:16 amunProperty...CH4 mol-wt = 16.000000
molecular_weight_cal =
28
molecular_weight_cal of Property...CO:28 amunProperty...CO mol-wt = 28.000000
molecular_weight_cal =
44
molecular_weight_cal of Property...CO2:44 amunProperty...CO2 mol-wt = 44.000000
molecular_weight_cal =
29
molecular_weight_cal of Property...HCO:29 amunProperty...HCO mol-wt = 29.000000
molecular_weight_cal =
30
molecular_weight_cal of Property...CH2O:30 amunProperty...CH2O mol-wt = 30.000000
molecular_weight_cal =
31
molecular_weight_cal of Property...CH2OH:31 amunProperty...CH2OH mol-wt = 31.000000
molecular_weight_cal =
31
molecular_weight_cal of Property...CH3O:31 amunProperty...CH3O mol-wt = 31.000000
molecular_weight_cal =
32
molecular_weight_cal of Property...CH3OH:32 amunProperty...CH3OH mol-wt = 32.000000
molecular_weight_cal =
25
molecular_weight_cal of Property...C2H:25 amunProperty...C2H mol-wt = 25.000000
molecular_weight_cal =
26
molecular_weight_cal of Property...C2H2:26 amunProperty...C2H2 mol-wt = 26.000000
molecular_weight_cal =
27
molecular_weight_cal of Property...C2H3:27 amunProperty...C2H3 mol-wt = 27.000000
molecular_weight_cal =
28
molecular_weight_cal of Property...C2H4:28 amunProperty...C2H4 mol-wt = 28.000000
molecular_weight_cal =
29
molecular_weight_cal of Property...C2H5:29 amunProperty...C2H5 mol-wt = 29.000000
molecular_weight_cal =
30
molecular_weight_cal of Property...C2H6:30 amunProperty...C2H6 mol-wt = 30.000000
molecular_weight_cal =
42
molecular_weight_cal of Property...CH2CO:42 amunProperty...CH2CO mol-wt = 42.000000
molecular_weight_cal =
41
molecular_weight_cal of Property...HCCO:41 amunProperty...HCCO mol-wt = 41.000000
molecular_weight_cal =
42
molecular_weight_cal of Property...HCCOH:42 amunProperty...HCCOH mol-wt = 42.000000
molecular_weight_cal =
28
molecular_weight_cal of Property...H2CN:28 amunProperty...H2CN mol-wt = 28.000000
molecular_weight_cal =
27
molecular_weight_cal of Property...HCN:27 amunProperty...HCN mol-wt = 27.000000
molecular_weight_cal =
31
molecular_weight_cal of Property...HNO:31 amunProperty...HNO mol-wt = 31.000000
molecular_weight_cal =
14
molecular_weight_cal of Property...N:14 amunProperty...N mol-wt = 14.000000
molecular_weight_cal =
29
molecular_weight_cal of Property...NNH:29 amunProperty...NNH mol-wt = 29.000000
molecular_weight_cal =
44
molecular_weight_cal of Property...N2O:44 amunProperty...N2O mol-wt = 44.000000
molecular_weight_cal =
15
molecular_weight_cal of Property...NH:15 amunProperty...NH mol-wt = 15.000000
molecular_weight_cal =
16
molecular_weight_cal of Property...NH2:16 amunProperty...NH2 mol-wt = 16.000000
molecular_weight_cal =
17
molecular_weight_cal of Property...NH3:17 amunProperty...NH3 mol-wt = 17.000000
molecular_weight_cal =
30
molecular_weight_cal of Property...NO:30 amunProperty...NO mol-wt = 30.000000
molecular_weight_cal =
46
molecular_weight_cal of Property...NO2:46 amunProperty...NO2 mol-wt = 46.000000
molecular_weight_cal =
43
molecular_weight_cal of Property...HCNO:43 amunProperty...HCNO mol-wt = 43.000000
molecular_weight_cal =
43
molecular_weight_cal of Property...HOCN:43 amunProperty...HOCN mol-wt = 43.000000
molecular_weight_cal =
43
molecular_weight_cal of Property...HNCO:43 amunProperty...HNCO mol-wt = 43.000000
molecular_weight_cal =
42
molecular_weight_cal of Property...NCO:42 amunProperty...NCO mol-wt = 42.000000
molecular_weight_cal =
26
molecular_weight_cal of Property...CN:26 amunProperty...CN mol-wt = 26.000000
molecular_weight_cal =
41
molecular_weight_cal of Property...HCNN:41 amunProperty...HCNN mol-wt = 41.000000
molecular_weight_cal =
28
molecular_weight_cal of Property...N2:28 amunProperty...N2 mol-wt = 28.000000
molecular_weight_cal =
40
molecular_weight_cal of Property...AR:40 amunProperty...AR mol-wt = 40.000000
molecular_weight_cal =
44
molecular_weight_cal of Property...C3H8:44 amunProperty...C3H8 mol-wt = 44.000000
molecular_weight_cal =
43
molecular_weight_cal of Property...C3H7:43 amunProperty...C3H7 mol-wt = 43.000000
molecular_weight_cal =
44
molecular_weight_cal of Property...CH3CHO:44 amunProperty...CH3CHO mol-wt = 44.000000
molecular_weight_cal =
43
molecular_weight_cal of Property...CH2CHO:43 amunProperty...CH2CHO mol-wt = 43.000000
ans =
0
>>
Screen shot of all folders where all species saved :


Conclusion :
- Using octave code, the necessary coefficients required to evaluate various thermodynamic parameters for different species are extracted from NASA thermodynamic data file .
- The specific heat, Entropy, enthalpy for all the species are calculated and plotted against the local temperature range. The molecular weight is calculated for all the species.
References :
- https://en.wikipedia.org/wiki/Parsing
- https://www.britannica.com/science/heat-capacity
- https://byjus.com/physics/enthalpy/
- https://byjus.com/jee/entropy/
- https://www.toppr.com/guides/physics-formulas/specific-heat-formula/