Project 1 - Parsing NASA thermodynamic data
% Main code
clear all
close all
clc
f1 = fopen('THERMO.txt','r');
fgetl(f1);
t_line = fgetl(f1);
a = strsplit(t_line,' ');
global_low_temp = str2double(a{2});
global_mid_temp = str2double(a{3});
global_high_temp = str2double(a{4});
fgetl(f1);
fgetl(f1);
fgetl(f1);
for i =1:53
t_line2 = fgetl(f1);
s = strsplit(t_line2, ' ');
species_name = s{1};
A= strfind( t_line2,'G');
temp_values = t_line2(A+4: length(t_line2));
B= strsplit(temp_values,' ');
local_low_temp = str2double(B{1});
local_mid_temp = str2double(B{2});
local_high_temp = str2double(B{3});
t_line = fgetl(f1);
b = findstr(t_line, 'E');
b1 = t_line(1:b(1)+3);
b1 = str2num(b1);
b2 = t_line(b(1)+4:b(2)+3);
b2 = str2num(b2);
b3 = t_line(b(2)+4:b(3)+3);
b3 = str2num(b3);
b4 = t_line(b(3)+4:b(4)+3);
b4 = str2num(b4);
b5 = t_line(b(4)+4:b(5)+3);
b5 = str2num(b5);
line2 = fgetl(f1);
b6 = line2(1:b(1)+3);
b6 = str2num(b6);
b7= line2(b(1)+4:b(2)+3);
b7= str2num(b7);
b8 = line2(b(2)+4:b(3)+3);
b8 = str2num(b8);
b9 = line2(b(3)+4:b(4)+3);
b9 = str2num(b9);
b10 = line2(b(4)+4:b(5)+3);
b10 = str2num(b10);
line3 = fgetl(f1);
b11 = line3(1:b(1)+3);
b11 = str2num(b11);
b12= line3(b(1)+4:b(2)+3);
b12= str2num(b12);
b13 = line3(b(2)+4:b(3)+3);
b13 = str2num(b13);
b14 = line3(b(3)+4:b(4)+3);
b14 = str2num(b14);
R = 8.314;
t = linspace(local_low_temp,local_high_temp,100);
cp = specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
H = enthalpy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
S = entropy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
mkdir(['G:', species_name])
%cd(species_name)
figure(1)
plot(t,cp)
xlabel('Temperature')
ylabel('Specific heat')
title ('Temp vs specific heat')
%image = getframe(gcf);
%imwrite(image.cdata, 't vs H.png');
saveas (1, 'specific_heat', 'jpg');
figure (2)
plot(t,H)
xlabel('Temperature')
ylabel ('Enthalpy')
title ('Temp vs Enthalpy')
%image = getframe (gcf);
%imwrite (image.cdata, 't vs H. png')
saveas (2 , 'enthalpy', 'jpg' );
figure (3)
plot(t,S)
xlabel('Temperature')
ylabel ('Entropy')
title ('Temp vs Entropy')
%image = getframe (gcf);
%imwrite (image.cdata, 't vs S. png')
saveas (3 , 'entropy', 'jpg' );
end
% CODE FOR FUCNTION SPECIFIC HEAT
function [cp] = specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
if (t>local_mid_temp)
cp = R*(b1+(b2.*t)+(b3.*(t.^2))+(b4.*(t.^3))+(b5.*(t.^4)));
else
cp = R*(b8+(b9.*t)+(b10.*(t.^2))+(b11.*(t.^3))+(b12.*(t.^4)));
end
% CODE FOR FUNCTION ENTHALPY
function [H] = enthalpy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
if (t>local_mid_temp)
H = (b1+((b2.*t)/2)+((b3.*(t.^2))/3)+((b4.*(t.^3))/4)+((b5.*(t.^4))/5)+(b6./t)).*t*R;
else
H = (b8+((b9.*t)/2)+((b10.*(t.^2))/3)+((b11.*(t.^3))/4)+((b12.*(t.^4))/5)+(b13./t)).*t*R;
end
%CODE FOR FUNCTION ENTROPY
function [S] = entropy (b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
if (t> local_mid_temp)
S= ((b1.*log(t))+(b2.*t)+((b3.*(t.^2))/2)+((b4.*(t.^3))/3)+(b5.*(t.^4))+b7);
else
S= ((b8.*log(t))+(b9.*t)+((b10.*(t.^2))/2)+((b11.*(t.^3))/3)+(b12.*(t.^4))+b14)*R;
end
% CODE FOR MOLECULAR WEIGHT
function [S] = entropy (b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
if (t> local_mid_temp)
S= ((b1.*log(t))+(b2.*t)+((b3.*(t.^2))/2)+((b4.*(t.^3))/3)+(b5.*(t.^4))+b7);
else
S= ((b8.*log(t))+(b9.*t)+((b10.*(t.^2))/2)+((b11.*(t.^3))/3)+(b12.*(t.^4))+b14)*R;
end