Project 1 - Parsing NASA thermodynamic data
- FILE PARSING OF NASA THERMODYNAMIC DATA:
- AIM:
The main aim of the project is to write a program to evaluate the thermodynamic data such as specific heat, Enthalpy,Entropy of NASA thermodynamic data and to create the plots for all the species and to display the molecular weight calculation using MATLAB coding.
- OBJECTIVE:
NASA came up with a thermodynamic data which is used to evaluate the properties such as specific heat(c_p),Enthalpy(H),Entropy(S).Now,parsing a file means reading in a data stream of some sort and building an in memory model of semantic content of that data.
- DEFINATIONS:
1. Specific Heat:
Specific Heat is a 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 SI unit of specific heat is J/KG-K.
2. Enthalpy:
The Enthalpy of a Thermodynamic system is defined as the sum of its internal energy and the work required to achieve its presure and volume. The SI unit of specific Enthalpy is kj/kg.
3. Entropy:
Entropy is a measure of degree of disorderness of the system. The SI unit of entropy is j/k.
- FILE PARSING:
From the given thermodynamic data it it clear that their are 53 species and for each species their are 14 co-efficients and for each species their is a unique low,mid and high temperature ranges . Fomula used to calculate the specific heat ,enthalpy and entropy using the coefficient is as shown below,
cpR=a1+a2⋅T+a3⋅T2+a4⋅T3+a5⋅T4cpR=a1+a2⋅T+a3⋅T2+a4⋅T3+a5⋅T4
where, cp = specific heat in j/kg-k
HRT=a1+a2⋅T2+a3⋅T23+a4⋅T34+a5⋅T45+a6THRT=a1+a2⋅T2+a3⋅T23+a4⋅T34+a5⋅T45+a6T `
R = universal gas constant (8.314j/k-mol)
H = enthalpy in kj/kg
SR=a1⋅logT+a2⋅T+a3⋅T22+a4⋅T33+a5⋅T44+a7SR=a1⋅logT+a2⋅T+a3⋅T22+a4⋅T33+a5⋅T44+a7 S = entropy in j/k
Their are 14 coefficient as said in which first 7 coefficient are High temperature coefficient and second 7 coefficient are Low temperature coefficient.
- EXPLANATION:
Molecular Weight Function:
function [molecular_weight] = mole_wt(species_name)
SPECIES = upper(species_name)
constituents = {'H','C','N','O','A'};
atomic_weight = [1 12 14 16 40];
molecular_weight = 0;
for i = 1:length(SPECIES)
for j = 1:length(constituents)
if strcmp(SPECIES(i),constituents(j))
molecular_weight = molecular_weight + atomic_weight(j);
u = j;
end
end
n = str2double(SPECIES(i));
if n > 1
molecular_weight = molecular_weight + atomic_weight(u)*(n-1);
end
function [cp, h, s]:
function [cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T)
R = 8.314;
for j = 1:length(T)
if T(j) < 300
cp = (a1 + a2.*T + a3.*T.^2 + a4.*T.^3 + a5.*T.^4).*R;
h = (a1 + (a2.*T)./2 + (a3.*T.^2)./3 + (a4.*T.^3)./4 + (a5.*T.^4)./5 + (a6./T)).*R.*T;
s = (a1.*log(T) + a2.*T + (a3.*T.^2)./2 + (a4.*T.^3)./3 + (a5.*T.^4)./4 + a7).*R;
else
cp = (a8 + a9.*T + a10.*T.^2 + a11.*T.^3 + a12.*T.^4).*R;
h = (a8 + (a9.*T)./2 + (a10.*T.^2)./3 + (a11.*T.^3)./4 + (a12.*T.^4)./5 + (a13./T)).*R.*T;
s = (a8.*log(T) + a9.*T + (a10.*T.^2)./2 + (a11.*T.^3)./3 + (a12.*T.^4)./4 + a14).*R;
end
Plotting:
% Plot between Temperature and Specific Heat
figure(1)
plot(T,cp,'linewidth',3,'color','b')
title (species_name)
xlabel('TEMPERATURE')
ylabel('SPECIFIC HEAT')
% Plot between Temperature and Enthalpy
figure(2)
plot(T,h,'linewidth',3,'color','g')
title(species_name)
xlabel('TEMPERATURE')
ylabel('ENTHALPY')
% Plot between Temperature and Entropy
figure(3)
plot(T,s,'linewidth',3,'color','c')
title(species_name)
xlabel('TEMPERATURE')
ylabel('ENTROPY')
Plot the temperature vs specific heat values using plot command and strcat command is used to concatenate strings horizontally which means it combines both the strings and store it as a data1 and give the xlabel , ylabel and title for the graph and fullfile command is used to store the entire information in data file and cd displays the current folder and the graph is saved using saveas command in jpg format and gcf command is used to handel the current figure.
- MAIN CODING:
clear all
close all
clc
% Reading the thermodynamic data file
f1 = fopen('THERMO.dat','r')
file_name = fgetl(f1);
t_line = fgetl(f1);
A = strsplit(t_line,' ');
% Defining the temperatures extracted from data file
global_low_temp = str2double(A{2});
global_mid_temp = str2double(A{3});
global_high_temp = str2double(A{4});
for i = (1:3)
comments = fgetl(f1);
end
for i = 1:53
% Extracting species name
species = fgetl(f1);
species_name = species(1:6);
% Extracting coefficients from first line
line_1 = fgetl(f1);
l1 = strfind(line_1,'E');
a1 = str2double(line_1(1:(l1(1)+3)));
a2 = str2double(line_1((l1(1)+4):(l1(2)+3)));
a3 = str2double(line_1((l1(2)+4):(l1(3)+3)));
a4 = str2double(line_1((l1(3)+4):(l1(4)+3)));
a5 = str2double(line_1((l1(4)+4):(l1(5)+3)));
% Extracting coefficients from second line
line_2 = fgetl(f1);
l2 = strfind(line_2,'E');
a6 = str2double(line_2(1:(l2(1)+3)));
a7 = str2double(line_2((l2(1)+4):(l2(2)+3)));
a8 = str2double(line_2((l2(2)+4):(l2(3)+3)));
a9 = str2double(line_2((l2(3)+4):(l2(4)+3)));
a10 = str2double(line_2((l2(4)+4):(l2(5)+3)));
% Extracting coefficients from third line
line_3 = fgetl(f1);
l3 = strfind(line_3,'E');
a11 = str2double(line_3(1:(l3(1)+3)));
a12 = str2double(line_3((l3(1)+4):(l3(2)+3)));
a13 = str2double(line_3((l3(2)+4):(l3(3)+3)));
a14 = str2double(line_3((l3(3)+4):(l3(4)+3)));
% Creating a folder 'SPECIES' to save thermodynamic plots of species
mkdir(['D:\MOOC\SKILL-LYNC\MATLAB Practice Programs\Challenges\7 - PROJECT\SPECIES\', species_name]);
T = linspace(global_low_temp, global_high_temp, 500);
% calling the thermodynamic equations function
[cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T);
% Plotting
% Plot between Temperature and Specific Heat
figure(1)
plot(T,cp,'linewidth',3,'color','b')
title (species_name)
xlabel('TEMPERATURE')
ylabel('SPECIFIC HEAT')
% Plot between Temperature and Enthalpy
figure(2)
plot(T,h,'linewidth',3,'color','g')
title(species_name)
xlabel('TEMPERATURE')
ylabel('ENTHALPY')
% Plot between Temperature and Entropy
figure(3)
plot(T,s,'linewidth',3,'color','c')
title(species_name)
xlabel('TEMPERATURE')
ylabel('ENTROPY')
directory = (['D:\MOOC\SKILL-LYNC\MATLAB Practice Programs\Challenges\7 - PROJECT\SPECIES\',species_name]);
cd(directory)
% Saving plots
saveas(1,'specific_heat.png')
saveas(2,'enthalpy.png')
saveas(3,'entropy.png')
% Changing directory for calculating molecular weight
cd('D:\MOOC\SKILL-LYNC\MATLAB Practice Programs')
molecular_weight = mole_wt(species_name);
end
fclose(f1)
- PLOTTING:
Plots of O2:
Specific heat vs temperature:

Enthalpy vs temperature:

Entropy vs temperature:

Plots of N2:
Specific Heat vs temperature:

Enthalpy vs temperature:

Entropy vs temperature:

Plots of CO2:
Specific Heat vs temperature:

Enthalpy vs temperature:

Entropy vs temperature:

- SIGNIFICANCE OF PLOTS:
- SPECIFIC HEAT VS TEMPERATURE:
Specific heat of a subustance changes when their is a change in temperature.At molecular level, the internal energy of a subustance is stored in the form of transational,rotational and vibrational energy. It has 3 degree of freedom for each form of energy.In lower temperature range vibrational energy is insignificant,thus the bulk of the energy is given by remaining two forms,hence specific heat is comparitevely low when temperature increases,vibrational energy gains signifinance hence more amount of energy is required to raise the temperature by the same amount.Thus specific heat increases with temperature.
2. ENTHALPY VS TEMPERATURE:
When temperature is increased the amount of molecular interaction also increases,then internal energy of the system rises thus, enthalpy of system increased.
H=U+PVH=U+PV where U = internal energy
H= enthalpy
3.ENTROPY VS TEMPERATURE:
When temperature is increased ,more amount of energy is put into the system which exites the random activity.Since entropy is a measure of randomness in the system, entropy of system is increased.
- CONCLUSION:
The data has been extracted and thermodynamic property such as specific heat,Enthalpy,Entropy is calculated and graphs has been plotted and the files of individual species is created.