Parsing NASA Thermodynamic data in Octave
REPORT:
I. AIM:
To generate a code to parse the NASA Thermodynamic data file and to calculate the thermodynamic properties of specified gases.
II. EXPLANATION:
1. Declaring the Universal Gas constant R as input.
2. In order to get the temperature values, first open the file using \'fopen\' to load the file from the directory.
\'3. fgetl\' is used to get the values of the temperature.
4. The next step is to find the low and high temperature values for which \'linspace\' is used.
5. \'strsplit\' can be used to split the line.
6. Each species is saved in a variable \'species_N\'.
7. Two different coefficients are created using strfind where onw is for high temperature coefficient and another for low temperature coefficient.
8. The different functions for defferent variables like Specific heat, enthalpy, entropy and molecular weight are coded and called in the main program.
III. FUNCTION CODE:
1. Entropy Function:
% Function for Entropy
function [S] = entropy(h1,h2,h3,h4,h5,h6,h7,n1,n2,n3,n4,n5,n6,n7,R,temp,global_intermediate_temp);
for i = 1:length(temp)
% For temperature greater than global_intermediate_temp
if temp(i) <= global_intermediate_temp
S(i) = R.*((h1.*log10(temp(i))) + (h2.*temp(i)) + (h3.*(((temp(i)).^2)./2)) + (h4.*(((temp(i)).^3)./3)) + (h5.*(((temp(i)).^4./4))+h7));
else
S(i) = R.*((n1.*log10(temp(i))) + (n2.*temp(i)) + (n3.*(((temp(i)).^2)./2)) + (n4.*(((temp(i)).^3)./3)) + (n5.*(((temp(i)).^4/4))+n7));
end
end
end
2. Enthalpy Function:
% Function for Enthalpy
function [H] = enthalpy(h1,h2,h3,h4,h5,h6,n1,n2,n3,n4,n5,n6,R,temp,global_intermediate_temp)
for i = 1:length(temp)
% For temperature greater than global_intermediate_temp
if temp(i) >= global_intermediate_temp
H =(h1 + (h2.*(temp./2)) + (h3.*(temp.^2./2)) + (h4.*(temp.^3./3)) + (h5.*(temp.^4./4)) + (h6./temp(i))).* R.*temp;
else
H = (n1 + (n2.*(temp./2)) + (n3.*(temp.^2./2)) + (n4.*(temp.^3./3)) + (n5.*(temp.^4./4)) + (n6./temp(i))).*R.*temp;
end
end
end
3. Specific Heat:
% Function for Specific Heat
function [c_p] = specific_heat(h1,h2,h3,h4,h5,n1,n2,n3,n4,n5,R,temp,global_intermediate_temp);
for i = 1:length(temp)
%For temperature above the global_intermediate_temp
if temp(i) <= global_intermediate_temp
c_p(i) = R*(h1+(h2*temp(i)) + (h3*(temp(i)).^2) + (h4*(temp(i)).^3) + (h5*(temp(i)).^4));
else
c_p(i) = R*(n1+(n2*temp(i)) + (n3*(temp(i)).^2) + (n4*(temp(i)).^3) + (n5*(temp(i)).^4));
end
end
end
4. Molecular Weight:
% Function for Molecular Weight
function [m_w] = molecular_weight(species_N)
%species_N=\'O\'
elements = {\'H\', \'C\', \'O\', \'N\', \'A\', \'S\'};
atomic_weight = [1.007, 12.011, 15.999, 14.006, 39.948, 32.064];
m_w = 0
for i = 1:length(species_N)
for j = 1:length(elements)
if strcmp(species_N(i), elements(j));
m_w = (m_w + atomic_weight(j));
p = j;
end
end
q = str2double(species_N(i));
if q>1
m_w = m_w + atomic_weight(p)*(q-1);
end
end
end
IV. MAIN CODE:
clear all
close all
clc
% Input Details
% Gas Constant (R)
R = 8.314;
% Data file
data = fopen(\'THERMO.dat\', \'r\');
% Header data file
fgetl(data);
% Datas on Global temperature
global_temp_range = fgetl(data);
a = strsplit(global_temp_range);
global_low_temp = 200;%str2double (a{2});
global_intermediate_temp = 1000;%str2double (a{3});
global_high_temp = 3500;%str2double (a{4});
temp = linspace(global_low_temp, global_high_temp, 400)
for i = 1:3
fgetl(data)
end
for i = 1:53
line1 = fgetl(data)
A = strsplit(line1, \' \');
species_N = (A{1});
t2 = fgetl(data);
t3 = fgetl(data);
t4 = fgetl(data);
j = strfind(t2, \'E\');
k = strfind(t3, \'E\');
l = strfind(t4, \'E\');
% For high temperature coefficients
h1 = str2double(t2(1:j(1)+3));
h2 = str2double(t2(j(1)+4:j(2)+3));
h3 = str2double(t2(j(2)+4:j(3)+3));
h4 = str2double(t2(j(3)+4:j(4)+3));
h5 = str2double(t2(j(4)+4:j(5)+3));
h6 = str2double(t3(1:k(1)+3));
h7 = str2double(t3(k(1)+4:k(2)+3));
% For low temperature coefficients
n1 = str2double(t3(k(2)+4:k(3)+3));
n2 = str2double(t3(k(3)+4:k(4)+3));
n3 = str2double(t3(k(4)+4:k(5)+3));
n4 = str2double(t4(1:l(1)+3));
n5 = str2double(t4(l(1)+4:l(2)+3));
n6 = str2double(t4(l(2)+4:l(3)+3));
n7 = str2double(t4(l(3)+4:l(4)+3));
h=[h1 h2 h3 h4 h5 h6 h7 n1 n2 n3 n4 n5 n6 n7];
% Specific Heat Function
[c_p] = specific_heat(h1,h2,h3,h4,h5,n1,n2,n3,n4,n5,R,temp,global_intermediate_temp);
%
% % Enthalpy
[H] = enthalpy(h1,h2,h3,h4,h5,h6,n1,n2,n3,n4,n5,n6,R,temp,global_intermediate_temp);
%
% % Entropy
[S] = entropy(h1,h2,h3,h4,h5,h6,h7,n1,n2,n3,n4,n5,n6,n7,R,temp,global_intermediate_temp);
%[H]=enthalp_func(h,1000,temp,R)
mkdir(species_N);
current_dir = pwd;
cd(species_N);
% Plotting
figure(1)
plot(temp, c_p, \'linewidth\', 3, \'color\', \'r\');
title(species_N)
xlabel(\'TEMPERATURE\');
ylabel(\'SPECIFIC HEAT\');
figure(2)
plot(temp,H,\'linewidth\', 3, \'color\', \'g\');
title(species_N)
xlabel(\'TEMPERATURE\');
ylabel(\'ENTHALPY\');
figure(3)
plot(temp,S,\'linewidth\', 3, \'color\', \'b\');
title(species_N)
xlabel(\'TEMPERATURE\');
ylabel(\'ENTROPY\');
saveas(1,\'Specific_heat.png\')
saveas(2,\'Enthalpy.png\')
saveas(3,\'Entropy.png\')
cd(current_dir);
m_w(i)= molecular_weight(species_N);
disp(m_w(i))
end
V. ERRORS
1. Function declaration error:
The entropy and enthaly function codes where declared wrong initially later checked and rectified.
2. Wrong Outputs:
VI. OUTPUTS:
FOR CH2CHO:
1. Specific Heat:
2. ENTHALPY:
3.ENTROPY:
4. FOLDERS CONTAINING OUTPUT: