Project 1 - Parsing NASA thermodynamic data
What is File Parsing??
Parsing in computer languages refers to the syntactic analysis of the input data normally from a file into its components parts in order to facilitate the writing of compilers and interpreters. It can be used to describe split or separation.
Parsing a file means reading in a data stream of some sort and building an in-memory model of the semantic content of that data. This aims at facilitating performing some kind of transformation on the data.
Objective:
- To read and extract 14 coefficients for each element from the NASA thermodynamic data file and calculates the enthalpy, entropy, and specific heats for all the species in the data file.
- To 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 a suitable name. All these be generated automatically.
Abstract:
The purpose of this project was to parse NASA Thermodynamic Data File i.e. THERMO.dat given by NASA. The file contains the data in the raw form which needs to get separated, extracted, and converted. The data extracted from the file is used to calculate specific heat, enthalpy, entropy, and molecular mass of each element. Using these thermodynamic properties, relations are plotted between Specific Heat and Temperature, Enthalpy and Temperature, and Entropy & Temperature for each element. All the plots for each element are stored in a separate folder under the Results folder. All this is generated automatically. Plots for any element can be accessed as per the user demand.
What is Specific Heat??
Specific heat, the ratio of the quantity of heat required to raise the temperature of a body one degree to that required to raise the temperature of an equal mass of water one degree. The term is also used in a narrower sense to mean the amount of heat, in calories, required to raise the temperature of one gram of a substance by one Celsius degree.
The basic formula used for calculating Specific Heat is as follows:-
c_p=R*(b1+(b2.*t)+(b3.*(t.^2))+(b4.*(t.^3))+(b5.*(t.^4)));
What is Enthalpy??
Enthalpy is a property of a thermodynamic system, defined as the sum of the system's internal energy and the product of its pressure and volume. It is a convenient state function preferred in many measurements in chemical, biological, and physical systems at a constant pressure. The pressure-volume term expresses the work required to establish the system's physical dimensions, i.e. to make room for it by displacing its surroundings. As a state function, enthalpy depends only on the final configuration of internal energy, pressure, and volume, and not on the path taken to achieve it.
The unit of measurement for enthalpy in the International System of Units (SI) is the joule. Other historical conventional units still in use include the British thermal unit (BTU). and calorie.
H=(b1+((b2.*t)/2)+((b3.*(t.^2))/3)+((b4.*(t.^3))/4)+((b5.*(t.^4))/5)+(b6./t)).*t*R;
What is Entropy??
There are two equivalent definitions of entropy: the thermodynamic definition and the statistical mechanic's definition. Historically, the classical thermodynamics definition developed first. In the classical thermodynamics viewpoint, the microscopic details of a system are not considered. Instead, the behavior of a system is described in terms of a set of empirically defined thermodynamic variables, such as temperature, pressure, entropy, and heat capacity. The classical thermodynamics description assumes a state of equilibrium although more recent attempts have been made to develop useful definitions of entropy in nonequilibrium systems as well.
The statistical definition of entropy and other thermodynamic properties were developed later. In this viewpoint, thermodynamic properties are defined in terms of the statistics of the motions of the microscopic constituents of a system – modeled at first classically, e.g. Newtonian particles constituting a gas, and later quantum-mechanically (photons, phonons, spins, etc.).
S=((b1.*logt)+(b2.*t)+((b3.*(t.^2))/2)+((b4.*(t.^3))/3)+(b5.*(t.^4))+b7);
MATLAB Function for Specific Heat:
function [c_p]=specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if (t>local_mid_temp)
c_p=R*(b1+(b2.*t)+(b3.*(t.^2))+(b4.*(t.^3))+(b5.*(t.^4)));
else
c_p=R*(b8+(b9.*t)+(b10.*(t.^2))+(b11.*(t.^3))+(b12.*(t.^4)));
end
MATLAB Function for Enthalpy:
function [H]=enthalpy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if (t>local_mid_temp)
H=(b1+((b2.*t)/2)+((b3.*(t.^2))/3)+((b4.*(t.^3))/4)+((b5.*(t.^4))/5)+(b6./t)).*t*R;
else
H=(b8+((b9.*t)/2)+((b10.*(t.^2))/3)+((b11.*(t.^3))/4)+((b12.*(t.^4))/5)+(b13./t)).*t*R;
end
MATLAB Function for Entropy:
function [S]=entropy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if (t>local_mid_temp)
S=((b1.*logt)+(b2.*t)+((b3.*(t.^2))/2)+((b4.*(t.^3))/3)+(b5.*(t.^4))+b7);
else
S=((b8.*log(t))+(b9.*t)+((b10.*(t.^2))/2)+((b11.*(t.^3))/3)+(b12.*(t.^4))+b14)*R;
end
MATLAB Code for File Parsing:
clear all
close all
clc
f1=fopen('THERMO.dat','r');
% Reading header information
fgetl(f1);
% Global Temperature
t_line=fgetl(f1);
a=strsplit(t_line,' ');
global_low_temp=str2double(a{2});
global_mid_temp=str2double(a{3});
global_high_temp=str2double(a{4});
% Neglecting the 3 lines
fgetl(f1);
fgetl(f1);
fgetl(f1);
% Reading species block line 1
for i=1:53
t_line2=fgetl(f1);
s=strsplit(t_line2,' ');
species_name=s{1};
A=strfind(t_line2,'G');
temp_values=t_line2(A+4:length(t_line2));
B=strsplit(temp_values,' ');
local_low_temp=str2double(B{1});
local_mid_temp=str2double(B{2});
local_high_temp=str2double(B{3});
t_line=fgetl(f1);
b=findstr(t_line,'E');
% First coefficient
b1=t_line(1:b(1)+3);
b1=str2num(b1);
% Second coefficient
b2=t_line(b(1)+4:b(2)+3);
b2=str2num(b2);
% third coefficient
b3=t_line(b(2)+4:b(3)+3);
b3=str2num(b3);
% Fourth coefficient
b4=t_line(b(3)+4:b(4)+3);
b4=str2num(b4);
% Fifth coefficient
b5=t_line(b(4)+4:b(5)+3);
b5=str2num(b5);
% Line two
line2=fgetl(f1);
% Sixth coefficient
b6=t_line(1:b(1)+3);
b6=str2num(b6);
% Seventh coefficient
b7=t_line(b(1)+4:b(2)+3);
b7=str2num(b7);
% Eight coefficient
b8=t_line(b(2)+4:b(3)+3);
b8=str2num(b8);
% Nineth coefficient
b9=t_line(b(3)+4:b(4)+3);
b9=str2num(b9);
% Tenth coefficient
b10=t_line(b(4)+4:b(5)+3);
b10=str2num(b10);
% Line Three
line3=fgetl(f1);
% Eleventh coefficient
b11=t_line(1:b(1)+3);
b11=str2num(b11);
% Twelveth coefficient
b12=t_line(b(1)+4:b(2)+3);
b12=str2num(b12);
% Thirteenth coefficient
b13=t_line(b(2)+4:b(3)+3);
b13=str2num(b13);
% Fourteenth coefficient
b14=t_line(b(3)+4:b(4)+3);
b14=str2num(b14);
% Universal Gas Constant
R=8.314;
t=linspace(local_low_temp,local_high_temp,100);
%To Calculate Specific heat by creating function
c_p=specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
% To calculate Enthalpy by creating function
H=enthalpy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
% To calculate Entropy by creating function
S=entropy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
% Creating a folder
mkdir(['C:',species_name])
cd(species_name)
% Plotting for Temperature Vs Specific Heat
figure(1);
plot(t,c_p);
xlabel('TEMPERATURE');
ylabel('SPECIFIC HEAT');
title('TEMPERATURE VS SPECIFIC HEAT');
image=getframe(gcf);
imwrite(image.cdata,'t vs cp.png');
saveas(1,'specific heat','jpg');
% Plotting for Temperature Vs Enthalpy
figure(2);
plot(t,H);
xlabel('TEMPERATURE');
ylabel('ENTHALPY');
title('TEMPERATURE VS ENTHALPY');
image=getframe(gcf);
imwrite(image.cdata,'t vs H.png');
saveas(2,'enthalpy','jpg');
% Plotting for Temperature Vs Specific Heat
figure(3);
plot(t,S);
xlabel('TEMPERATURE');
ylabel('ENTROPY');
title('TEMPERATURE VS ENTROPY');
image=getframe(gcf);
imwrite(image.cdata,'t vs S.png');
saveas(3,'entropy','jpg');
cd ..
% Calculating molecular mass
[M]=molecular_wt(species_name);
K=sprintf('%s mol_wt=%f',species_name,M);
disp(K)
end
- OUTPUT:
Molecular Weight for all the given species:

Folder created successfully in the given location:

Snapshot of results shown in a workspace:

And created folders with plots are attached in the attachment please check the attached folders for plots.
CONCLUSION:
Given file data is processed and the user requested species data is displayed.