PROJECT - Parsing NASA thermodynamic data
%Entropy
function [S] = Entropy(T,C)
R = 287;
for j = 1:length(T)
S(j) = 0;
for i = 2:5
S(j) = S(j) + R*C(i)*(T(j)^(i-1));
end
S(j) = S(j) + R*(C(1)*log(T(j))+C(6));
end
end
%Coefficients
function [C] = Coefficients(tline)
n = strfind(tline,\'E\');
for i=2:length(n)
C(1) = str2num(tline(1:n(1)+3));
C(i) = str2num(tline(n(i-1)+4:n(i)+3));
end
end
%Molecular Weight
function [Mw] = %(name)
Mw = 0;
atoms = [\'H\' \'C\' \'N\' \'O\'];
AtomWeight = [1 12 14 16];
for i = 1:length(name)
f = str2num(name(i));
for j = 1:length(atoms)
if(strcmp(name(i),atoms(j)))
k = j;
Mw = Mw + AtomWeight(k);
end
end
if(f>1)
Mw = Mw + AtomWeight(k)*(f-1);
end
end
end
%Specific Heat
function [Cp] = SpecificHeat(T,C)
R = 287;
for j = 1:length(T)
Cp(j) = 0;
for i = 1:5
Cp(j) = Cp(j) + R*C(i)*(T(j)^(i-1));
end
end
end
%Enthapy
function [H] = Enthalpy(T,C)
R = 287;
for j = 1:length(T)
H(j) = 0;
for i = 2:5
H(j) = H(j) + R*C(i)*(T(j)^(i-1));
end
H(j) = H(j) + R*(C(1)*log(T(j))+C(6));
end
end
%Species
function [name,C] = species(f1)
tline = fgetl(f1);
n = strfind(tline,\'E\');
name = tline(1:n(1)-1);
k=1;
for i = 1:3
tline = fgetl(f1);
c = Coefficients(tline);
for j = 1: length(c)
C(k) = c(j);
k=k+1;
end
end
end
close all
clear all
clc
% Read the file
f1 = fopen(\'therm.dat\',\'r\');
%Reading the Global Temperatures
fgetl(f1);
tline = fgetl(f1);
A = strsplit(tline,\' \');
Global_low_temp = str2num(A{2});
Global_mid_temp = str2num(A{3});
Global_high_temp = str2num(A{4});
T = linspace(Global_low_temp,Global_high_temp,100);
%Skipping the comments
for i = 1:3
fgetl(f1);
end
%Extracting the species information
for i= 1:53
[Name{i},C]= species(f1);
Mw(i) = MolWeight(Name{i});
Cp = SpecificHeat(T,C);
H = Enthalpy(T,C);
S = Entropy(T,C);
for r=1:length(C)
Coefficents(i,r) = C(r);
end
for j=1:length(T)
Cp(i,j) = Cp(j);
H(i,j) = H(j);
S(i,j) = S(j);
end
%Creating a folder for the species
PlotFolder([Name{i}]);
% Plott
f = figure;
set(f,\'Visible\',\'off\');
plot(T,Cp(i,:));
xlabel(\'Temperature\');
ylabel(\'Specific Heat at constant pressure\');
baseFileName = sprintf(\'SpecificHeat%s.jpg\',Name{i});
fullFileName = fullfile(Name{i}, baseFileName);
saveas(f,fullFileName);
f = figure;
set(f,\'Visible\',\'off\');
plot(T,H(i,:));
xlabel(\'Temperature\');
ylabel(\'Enthalpy\');
baseFileName = sprintf(\'Enthalpy%s.jpg\',Name{i});
fullFileName = fullfile(Name{i}, baseFileName);
saveas(f,fullFileName);
f = figure;
set(f,\'Visible\',\'off\');
plot(T,S(i,:));
xlabel(\'Temperature\');
ylabel(\'Entropy\');
baseFileName = sprintf(\'Entropy%s.jpg\',Name{i});
fullFileName = fullfile(Name{i}, baseFileName);
saveas(f,fullFileName);
end