% A program of file parsing using NASA thermodynamic file
f1 = fopen('THERMO.dat','r');
for i = 1:5
fgetl(f1)
end
for i = 1:53
tline1 = fgetl(f1);
% splitting line1
A = strsplit(tline1,' ');
% Entering species name
species = char(A(1));
global_low_temp = str2num(A{1});
global_high_temp = str2num(A{2});
global_mid_temp = str2num(A{3});
tline2=fgetl(f1);
m1 = strfind(tline2,'E');
coeff1 = tline2(1:m1(1)+3);
coeff2 = tline2(m1(1)+4:m1(2)+3);
coeff3 = tline2(m1(2)+4:m1(3)+3);
coeff4 = tline2(m1(3)+4:m1(4)+3);
coeff5 = tline2(m1(4)+4:m1(5)+3);
a1 = str2num(coeff1)
a2 = str2num(coeff2)
a3 = str2num(coeff3)
a4 = str2num(coeff4)
a5 = str2num(coeff5)
tline3 = fgetl(f1);
m2= strfind(tline3,'E');
coeff6 = tline3(1:m2(1)+3);
coeff7 = tline3(m2(1)+4:m2(2)+3);
coeff8 = tline3(m2(2)+4:m2(3)+3);
coeff9 = tline3(m2(3)+4:m2(4)+3);
coeff10 = tline3(m2(4)+4:m2(5)+3);
a6 = str2num(coeff6)
a7 = str2num(coeff7)
a8 = str2num(coeff8)
a9 = str2num(coeff9)
a10 = str2num(coeff10)
tline4 = fgetl(f1);
m3 = strfind(tline4,'E');
% line4 = str2num(a11);
coeff11 = tline4(1:m3(1)+3);
coeff12 = tline4(m3(1)+4:m3(2)+3);
coeff13 = tline4(m3(2)+4:m3(3)+3);
coeff14 = tline4(m3(3)+4:m3(4)+3);
a11 = str2num(coeff11)
a12 = str2num(coeff12)
a13 = str2num(coeff13)
a14 = str2num(coeff14)
% Temperature range
temp = linspace(0,7000,7)
% Universal gas constant
R = 8.314;
% To calculate specific heat
cp = (a1 + (a2.*temp) + (a3.*(temp.^2)) + (a4.*(temp.^3)) + (a5.*(temp.^4))).*R
% To calculate enthalpy
h = (a1 + ((a2.*temp)./2) + ((a3.*(temp.^2))./3) + ((a4.*(temp.^3))./4) + ((a5.*(temp.^4))./5) + (a6./temp)).*R.*temp
% To calculate entropy
s = ((a1.*log(temp)) + (a2.*temp) + ((a3.*(temp.^2))./2) + ((a4.*(temp.^3))./3) + ((a5.*(temp.^4))./4) + a7).*R
t=sprintf('%s %s',species);
mkdir(t)
cd(t)
%plot specific heat vs temp
figure(1)
plot(temp,cp,'linewidth',3,'color','r')
xlabel('Temperature')
ylabel('Specific heat')
saveas(1,'Cp.jpg')
figure(2)
plot(temp,s,'linewidth',3,'color','r')
xlabel('Temperature')
ylabel('Entropy')
saveas(2,'S.jpg')
figure(3)
plot(temp,h,'linewidth',3,'color','r')
xlabel('Temperature')
ylabel('Enthalpy')
saveas(3,'H.jpg')
cd ..
end
Explanation:
1) Initially fopen command is used to get nasa thermodynamic file and read command is used to read it.Then fgetl command is used to extract the thermodynamic file.
2) After extracting, the first 5 lines of the data file is read using fgetl command within a for loop.
3) All 53 species are computed using a for loop.
4) The first line of each species is splitted using split command in order to extract the temperature range. Than the species name is extracted using char command.
5) Now different coefficients of each species are extracted by specifying the place.
6) For the obtained coefficients ,the specific heat(cp), Entropy(s), Enthalpy(h) is computed for all the species.
7) Plot for cp,h,s vs temperature is plotted.
8) now mkdir command is used to create a directory in order to save all the plots of each species in different folders.