%main program
clear all
close all
clc
%opening the data
f1= fopen('THERMOS.DAT','r')
%reading the header files
b1 = fgetl(f1)
global_temp = fgetl(f1)
%getting the global temperature
temp_range = strsplit(global_temp,' ')
%changing the values into numbers
global_lt = str2num(temp_range{2})
global_mt = str2num(temp_range{3})
global_ht = str2num(temp_range{4})
%The range of the temperature
T = linspace(global_lt,global_ht,400)
R = 8.314
%skipping the lines
for i = 3:5
n = fgetl(f1)
end
%coeffs of the species
for a = 1:53
line1= fgetl(f1)
name = strtok(line1)
%extracting the coeffs
line2 = fgetl(f1)
line3= fgetl(f1)
line4 = fgetl(f1)
A = strfind(line2,'E')
B = strfind(line3,'E')
C = strfind(line4,'E')
%higher coeffs
a1 = str2num(line2(1:A(1)+3))
a2 = str2num(line2(A(1)+4 :A(2)+3))
a3 = str2num(line2(A(2)+4 :A(3)+3))
a4 = str2num(line2(A(3)+4:A(4)+3))
a5 = str2num(line2(A(4)+4:A(5)+3))
a6 = str2num(line3(1:B(1)+3))
a7 = str2num(line3(B(1)+4:B(2)+3))
%lower coeffs
b1 = str2num(line3(B(2)+4:B(3)+3))
b2 = str2num(line3(B(3)+4:B(4)+3))
b3 = str2num(line3(B(4)+4:B(5)+3))
b4 = str2num(line4(1:C(1)+3))
b5 = str2num(line4(C(1)+4:C(2)+3))
b6 = str2num(line4(C(2)+4:C(3)+3))
b7 = str2num(line4(C(3)+4:C(4)+3))
%calculating the specific heat
cp = specificheat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,T,R,global_mt);
%calculating the enthalpy
h = enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R,global_mt)
%calculating the entropy
s = entropycalc(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,T,R,global_mt)
%calulating the molecular weight
mt(i) = molecularweight(name);
%creating the folders for the species
mkdir(name)
%ploting
plot(cp , h , s , T)
end
function MW = molecularWeight(name)
atoms = ['H','C','O','N','R']
fprintf('molecular weight of ')
sprintf(name)
fprintf(':')
atomic_weight = [1 12 16 14 40]
MW = 0
for i = 1:length(name)
for j = 1:length(atoms)
if strcmp(name(i) , atoms(j))
MW = MW+atomic_weight(j)
position = j
end
end
n = str2num(name(i))
if n>1
MW = MW + atomic_weight(position)*(n-1)
end
end
fprintf('%d',MW)
disp(' ')
end
function MW = molecularWeight(name)
atoms = ['H','C','O','N','R']
fprintf('molecular weight of ')
sprintf(name)
fprintf(':')
atomic_weight = [1 12 16 14 40]
MW = 0
for i = 1:length(name)
for j = 1:length(atoms)
if strcmp(name(i) , atoms(j))
MW = MW+atomic_weight(j)
position = j
end
end
n = str2num(name(i))
if n>1
MW = MW + atomic_weight(position)*(n-1)
end
end
fprintf('%d',MW)
disp(' ')
end
function cp = specific_heat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,T,R,global_mt)
if T > global_mt
cp = R*(a1+a2*T+a3*T.^2+a4*T.^3+a5*T.^4);
else
cp = R*(b1+b2*T+b3*T.^2+b4*T.^3+b5*T.^4);
end
function h = enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R,global_mt)
if T>global_mt
h = R*(a1*T+(a2*T.^2)/2+(a3*T.^3)/3+(a4*T.^4)/(a5*T.^5)/5+a6);
else
h = R*(b1*T+(b2*T.^2)/2+(b3*T.^3)/3+(b4*T.^4)/+(b5*T.^5)/5+b6);
end
function s = entropy_calc(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,T,R,global_mt)
if T<=global_mt
s = R*(a1*log(T)+a2*T+a3*(T.^2)/2+a4*(T.^3)/3+a5*(T.^4)/4+7);
else
s = R*(b1*log(T)+b2*T+b3*(T.^2)/2+b4*(T.^3)/3+b5*(T.^4)/4+b7);
end