% Parsing NASA Thermodynamic Data \'nasathermo.txt\'
close all
clear all
clc
% Read the file
f1 = fopen(\'nasathermo.txt\',\'r\');
%Reading the Global Temperatures
fgetl(f1); % To read the first line so that next will be the 2nd line
tline = fgetl(f1);
A = strsplit(tline,\' \'); % Spliting the values using \' \'
T_l = str2num(A{2});
T_m = str2num(A{3});
T_h = str2num(A{4});
T = linspace(T_l,T_h,100);
%Skipping the comments
for i = 1:3
fgetl(f1); %Skip the next 3 lines
end
%Extracting the species information
for i= 1:53 % Total 53 Species
[Name{i},C]= Species_info(f1); % Assining names to the specific Species
MW(i) = Mol_wt(Name{i});
c_p = Specific_heat(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)
C_p(i,j) = c_p(j);
H(i,j) = h(j);
S(i,j) = s(j);
end
%Creating a folder for the required species
mkdir([Name{i}]);
% Plotting and Saving
f = figure;
set(f,\'Visible\',\'off\'); % Plot will not be displaed but saved in folders
plot(T,C_p(i,:));
xlabel(\'Temperature (K)\');
ylabel(\'Specific Heat (kJ)\');
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 (K)\');
ylabel(\'Enthalpy (kJ/mol)\');
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 (kJ/mol K)\');
baseFileName = sprintf(\'Entropy%s.jpg\',Name{i});
fullFileName = fullfile(Name{i}, baseFileName);
saveas(f,fullFileName);
end
fclose(f1)
% Function for Enthalpy
function [H] = Enthalpy(T,C)
R = 287;
for j = 1:length(T)
H(j) = 0;
for i = 1:5
H(j) = H(j) + ((R*C(i)*(T(j)^i))/i);
end
H(j) = H(j) + C(6);
end
end
% Function for 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
%Function for Line coefficient
function [c] = Line_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
%Function for Molicular Weight
function [MW] = Mol_wt(name)
MW = 0;
atoms = [\'H\' \'C\' \'N\' \'O\'];
at_wt = [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 + at_wt(k);
end
end
if(f>1)
MW = MW + at_wt(k)*(f-1);
end
end
end
% Function for Species information
function [name,C] = Species_info(f1)
tline = fgetl(f1);
n = strfind(tline,\' \');
name = tline(1:n(1)-1);
k=1;
for i = 1:3
tline = fgetl(f1);
c = Line_coefficients(tline);
for j = 1: length(c)
C(k) = c(j);
k=k+1;
end
end
end
%Function for Specific Heat
function [C_p] = Specific_heat(T,C)
R = 287;
for j = 1:length(T)
C_p(j) = 0;
for i = 1:5
C_p(j) = C_p(j) + R*C(i)*(T(j)^(i-1));
end
end
end