Main Code
clear all
close all
clc
% Reading Thermo Data File.
f1 = fopen('THERMO.dat','r');
% Reading of the global temperature values.
First_line = fgetl(f1);
Temp = fgetl(f1);
% Spliting the acheived string by using string split command.
A = strsplit(Temp,' ');
Low_global_Temp = str2num(A{2}); % Low Global Temperature.
Mid_global_Temp = str2num(A{3}); % Mid Global Temperature.
HIGH_global_Temp = str2num(A{4}); % High Global Temperature.
% Skipping the in between comments in thermo dat file.
for i=1:3
fgetl(f1);
end
% Defining the universal gas constant R
R = 8.314; % in kj/kg-k.
% Getting the temperature regarding the coefficients.
molecular_weight=0;
for j=1:53
Temp1 = fgetl(f1);
B = strsplit(Temp1,' ');
Species = B{1};
Low_local_Temp = str2num(B{end-3}); % Low local Temperature.
Mid_local_Temp = str2num(B{end-1}); % Mid local Temperature.
HIGH_local_Temp = str2num(B{end-2}); % High local Temperature.
% Reading all the 14 Species temperature coefficients value
tline = fgetl(f1);
a = findstr(tline,'E');
% Coverting string value into pure no.
a1 = tline(1:a(1)+3);
a1 = str2num(tline(1:a(1)+3));
a2 = tline(a(1)+4:a(2)+3);
a2 = str2num(a2);
a3 = tline(a(2)+4:a(3)+3);
a3 = str2num(a3);
a4 = tline(a(3)+4:a(4)+3);
a4 = str2num(a4);
a5 = tline(a(4)+4:a(5)+3);
a5 = str2num(a5);
% Reading the second line of the File;
tline1 = fgetl(f1);
a = findstr(tline1,'E');
% Coverting string value into pure no.
a6 = tline(1:a(1)+3);
a6 = str2num(tline(1:a(1)+3));
a7 = tline(a(1)+4:a(2)+3);
a7 = str2num(a7);
a8 = tline(a(2)+4:a(3)+3);
a8 = str2num(a8);
a9 = tline(a(3)+4:a(4)+3);
a9 = str2num(a9);
a10 = tline(a(4)+4:a(5)+3);
a10 = str2num(a10);
% Reading the second line of the File;
tline2 = fgetl(f1);
a = findstr(tline2,'E');
% Coverting string value into pure no.
a11 = tline(1:a(1)+3);
a11 = str2num(tline(1:a(1)+3));
a12 = tline(a(1)+4:a(2)+3);
a12 = str2num(a12);
a13 = tline(a(2)+4:a(3)+3);
a13 = str2num(a13);
a14 = tline(a(3)+4:a(4)+3);
a14 = str2num(a14);
% Defining temperature range.
T = linspace(Low_local_Temp,HIGH_local_Temp,1000);
% Calculating Specific Heat Using Given Formulae.
H = Enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R,T,Mid_local_Temp);
Cp = Specific_Heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R,T,Mid_local_Temp);
S = Entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R,T,Mid_local_Temp);
% Plotting Temperature Vs Specific Heat
figure(1)
plot(T,Cp,'linewidth',1.5,'color','r');
xlabel('Temperature[K]');
ylabel('Specific_Heat[KJ]');
grid on
% Plotting Temperature Vs Enthalpy
figure(2)
plot(T,H,'linewidth',1.5,'color','b');
xlabel('Temperature[K]');
ylabel('Enthalpy[KJ]');
grid on
% Plotting Temperature Vs Entropy
figure(3)
plot(T,S,'linewidth',1.5,'color','g');
xlabel('Temperature[K]');
ylabel('Entropy[KJ]');
grid on
mkdir('C:\Users\Lenovo\Downloads\Nasa File Parsing',Species);
cd(Species);
saveas(figure(1),'Specific_Heat.png');
saveas(figure(2),'Enthalpy.png');
saveas(figure(3),'Entropy.png');
cd('C:\Users\Lenovo\Downloads\Nasa File Parsing');
Calculation Of the Molecular weight of the species mentioned in the
Thermo DAT file.
moleculer_weight_calculation(j)=moleculer_weight(Species);
end
Function Calling Code
function moleculer_weight_calculation=moleculer_weight(sp_name)
%Species(B)
elements = ['H','C','O','N','A','S'];
atomic_weight = [1 12 16 14 40 32];
moleculer_weight_calculation = 0;
for i=1:length(sp_name)
for j=1:length(atomic_weight)
if strcmp(sp_name(i),elements(j))
moleculer_weight_calculation =moleculer_weight_calculation + atomic_weight(j);
a=j;
end
end
n=str2double(sp_name(i));
if n>1
moleculer_weight_calculation = moleculer_weight_calculation + atomic_weight(a)*(n-1);
end
end
sprintf('%s species %s %f',sp_name,'moleculer mass',moleculer_weight_calculation)
end