Project 1 - Parsing NASA thermodynamic data
AIM :- WRITE A MATLAB PROGRAM FOR PARSE THE THERMODYNAMIC DATA FILE AND ALSO CALCULATE THERMODYNAMIC PROPERTIES OF GAS SPECIES
OBJECTIVES :-
- Write a function that extracts the 14 co-efficients and calculate the Enthalpy, Entropy & Specific heat 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 & Entropy for the local temperature ranges (low temperature : high temperature) specific for each species.
- Save the plots as images with appropriate names & dump them in separate folders for each species with suitable name. All these should be generated automatically.
- The main program that upo will submit will just take the "Thermo.dat" file as an input and generate Cp, H & S plot.
- Screenshot of the window where all the folders are saved.
- Plot for O2,N2 & CO2 species.
File Parsing :-
- Parsing: Parsing a file means reading in a data stream and building a memory model of the content of that data. This aims at facilitating perfoming some kind of transformation on the data.
- Parsing splits a file or other input into pieces of data that can be easily stored or manipulated.
- Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar. The term parsing comes from Latin pars (orationis), meaning part (of speech).
- 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 Thermodynamic File :-
- NASA (National Aeronautics and Space Administration) Thermodynamics file which is THERMO.dat file in which there are temperature range.
- Total 53 species are given in these this data and each species contains 14 co-efficients and temperature range.
- We have to parse these 14 co-efficients to find specific heat, Entropy & Enthalpy using following formulas ...

Where,
- R = Universal Gas Constant (8.3144 J. mol-1. K-1)
- T = Temperature (Degree Celcius)
- Cp = Sp. Heat (KJ)
- S = Entropy (KJ/mol*K)
- A(i) = Co-efficients ; i = 1 to 14
(i) Specific Heat (Cp) :-
The specific heat capacity is the heat or energy required to change one unit mass of a substance of a constant volume by 1 °C.
![]() |
= | heat energy |
![]() |
= | Mass |
![]() |
= | specific heat capacity |
![]() |
= | change in temperature |
above formula is general formula for sp. heat & below formula is used in NASA termodynamic file.
- 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 entropy of an object is a measure of the amount of energy which is unavailable to do work. Entropy is also a measure of the number of possible arrangements the atoms in a system can have. In this sense, entropy is a measure of uncertainty or randomness.
- For example, the molecular weight of water, which has two atoms of hydrogen and one atom of oxygen, is 18 (i.e., 2 + 16). Also called molecular mass
Main Program :-
Procudure for Main Program :-
- The code starts with clear all, close all, clc where,
- 'clear all' command is used to clear the data stored in the workspace.
- 'close all' command is used to close all plots and figures.
- 'clc' command is used to clear the commaand the window.
- Firstly, we input the parameter R (Universal Gas Constant) and we will open a file THERMO.dat file andd reading this file using fopen command.
- After that we read THERMO file using fgetl command and similarly we read temperature file.
- Then split the temperature using strsplit command to convert it into cell array and then we convert this string to number using str2num command to find low, high and mid temperatures.
- Next we assign temperature range using linspace command. Then we run loop to skip command lines the data file using fgetl command inside the loop.
- Now, we run the loop to find 53 element in the data file by assigning fgetl command and then splitting into the cell array to find the species line and thenfind species name and also find the numer of the temperature in the species line.
- Then we read te new line in order to read the co-efficient in the data file we first find 'E' string using strfind command to find before and numbers of the co-efficients similarly find remaining 14 co-efficients and convert from string to number.
- Out of which we find the first 7 co-efficient in the data file which are higher temperature & Second7 co-efficients which are for lower temperature.
- Now we need to specify Specific heat (Cp), Entropy (S) & Enthaply (H) function to find these parameters using 14 co-efficients for lower and higher temperature. After that we specify Molecular weight (W) function to find out molecular weight for different species.
- Now we chage directory using cd command and then creating directory folder where we have to save our files using mkdir command (for make directory) and then we change the directory to this created folder.
- Next, plottting the Specific heat, Entropy & enthalpy with the temperature for each species title.
- lastly, we use saveas command to save the plots of different species in the directory folder.
(1) Function Program for Sp. Heat (Cp) :-
- To find out Sp. heat we need to create Sp. heat function in new script. In which assigning Sp. heat formula, 14 co-efficients, Gas constant, Temperature & mid temperature.
- Now condition which is given in the question, create if loop & make the temperature less than and equal to mid temperature to specify lower temperature co-efficients in the formula.
- Then using else condition to specify co-efficients of higher temperature co-efficients in formula.
- Lastly, end command use for ending loop as well as function to calculate Sp. heat.
- To find out Enthalpy we need to create enthalpy function in new script. In which assigning enthalpy formula, 14 co-efficients, Gas constant, Temperature & mid temperature.
- Now condition which is given in the question, create if loop & make the temperature less than and equal to mid temperature to specify lower temperature co-efficients in the formula.
- Then using else condition to specify co-efficients of higher temperature co-efficients in formula.
- Lastly, end command use for ending loop as well as function to calculate enthalpy.
- To find out Entropy we need to create enthalpy function in new script. In which assigning Entropy formula, 14 co-efficients, Gas constant, Temperature & mid temperature.
- Now condition which is given in the question, create if loop & make the temperature less than and equal to mid temperature to specify lower temperature co-efficients in the formula.
- Then using else condition to specify co-efficients of higher temperature co-efficients in formula.
- Lastly, end command use for ending loop as well as function to calculate entropy.
- First of all for create Molecular weight (W) function aassigning species input.
- Define main elements of all 53 species in an array of atomic names like 'H', 'C', 'O', 'N' & 'Ar'.
- Taking 5 main elements from species, with respect to that we creating atomic weight array with help of internet like
H -1.00784, C -12.0107, O -15.999, N -14.0067 & Ar -39.948.
- Now molecular weight starting range W to zero and then create for loop with condition which runs to the length of the species and another nested for loop is created which runs to the length of the string atomic names.
- After that we creating a if condition use for compare species with the atomic name.
- Calculated molecular weight if found same then assign it's molecular weight.
- str2num (string to number) command assign number. After that run the condition of second if loop to find weather the species contains more than one elements.
- If there are more than one elements that is n>1 then we increments the atomic weigth by the multiplication of position nd n-1 to the atomic weigth array.
- Lastly, we prints the molecular weigth by using fprintf command & similarly disp command use for display the molecular weigth.
RESULTS/OUTPUT :-
(1) O2
(1- i) - Plot Sp. heat vs Temperature of O2

(1- ii) - Plot Enthalpy vs Temperature of O2

(1- iii) - Plot Entropy vs Temperature of O2

(2) N2
(2- i) - Plot Sp. Heat vs Temperature of N2

(2- ii) - Plot Enthalpy vs Temperature of N2

(2- iii) - Plot Entropy vs Temperature of N2

(3) CO2
(3- i) - Plot Sp. Heat vs Temperature of CO2

(3- ii) - Plot Enthalpy vs Temperature of CO2

(3- iii) - Plot Entropy vs Temperature of CO2

DIRECORY where all 53 species saved in folder :-

Molecular weigth of all 53 species :-
Molecular Weight ofO = 15.999000Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofO2 = 31.998000Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofH = 1.007840Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofH2 = 2.015680Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofOH = 17.006840Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofH2O = 18.014680Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHO2 = 33.005840Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofH2O2 = 34.013680Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC = 12.010700Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH = 13.018540Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH2 = 14.026380Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH2(S) = 14.026380Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH3 = 15.034220Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH4 = 16.042060Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCO = 28.009700Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCO2 = 44.008700Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHCO = 29.017540Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH2O = 30.025380Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH2OH = 31.033220Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH3O = 31.033220Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH3OH = 32.041060Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC2H = 25.029240Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC2H2 = 26.037080Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC2H3 = 27.044920Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC2H4 = 28.052760Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC2H5 = 29.060600Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC2H6 = 30.068440Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH2CO = 42.036080Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHCCO = 41.028240Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHCCOH = 42.036080Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofH2CN = 28.033080Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHCN = 27.025240Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHNO = 31.013540Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofN = 14.006700Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofNNH = 29.021240Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofN2O = 44.012400Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofNH = 15.014540Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofNH2 = 16.022380Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofNH3 = 17.030220Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofNO = 30.005700Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofNO2 = 46.004700Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHCNO = 43.024240Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHOCN = 43.024240Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHNCO = 43.024240Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofNCO = 42.016400Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCN = 26.017400Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofHCNN = 41.031940Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofN2 = 28.013400Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofAR = 39.948000Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC3H8 = 44.094820Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofC3H7 = 43.086980Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH3CHO = 44.051760Warning: Directory already exists.
> In Kailas_thermo (line 81)
Molecular Weight ofCH2CHO = 43.043920Warning: Directory already exists.
> In Kailas_thermo (line 81)
>>
CONCLUSION :-
After this program, we know how actually file parsing done in MatLab and also know several things as follows...
- Specific Heat, Enthalpy & Entropy increases with an increase in temperature as seen in graph.
- Specific Heat of CO2 is maximum and minimum for N2 in other words carbon dioxide can hold more heat than the N2 & O2.
- As temperature increase, the rotation and vibration energy of molecules increase which is internal energy
- Similarly, as the temperature increase more rotational & vibrational energy levels become excited so species can store more heat that will lead to a rapid increase in geat capacity.
- But with further increase in temperature the slope of of specific heat vs temperature will reduce and after that a certain point, it will become flat not shown in graph) means specific heat has becomes constant.
- This due to the fact that many energy has become constant thus the specific heat capacity has attained the constant value.
- Enthaply shows in plot an almost linear variation with an increase in temperature.
- By Kirchoff's law, we know the relationship between enthaply and temperature variation. We can see below formula given by Kirchoff's law, with temperature increases, Enthaply of substances increases, which means both the products and the enthalpies increase.
- Entropy also increases with an increase in temperature. As we put more energy into the system. Randomness in the system will increase and gases will expands so the entropy will increase.
Errors During Program :-


- Forgot to put semicolon (;) in main program & function program of molecular weight.





