Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
clc
close all

f1 = fopen('THERMO.dat','r');
line1 = fgetl(f1);
header = fgetl(f1);
A = strsplit(header,' ');
g_low_temp = str2double(A{2});
g_mid_temp = str2double(A{3});
g_high_temp = str2double(A{4});
for i = 1:3
fgetl(f1);
end
for i = 1:53
tline = fgetl(f1);
C = strsplit(tline,' ');
elements = C{1};
local_temp_low = str2double(C{end-3});
local_temp_high = str2double(C{end-2});
local_temp_mid = str2double(C{end-1});

line = fgetl(f1);
A = findstr(line,'E');
A1 = line(1:A(1)+3);
A1 = str2double(A1);
A2 = line(A(1)+4:A(2)+3);
A2 = str2double(A2);
A3 = line(A(2)+4:A(3)+3);
A3 = str2double(A3);
A4 = line(A(3)+4:A(4)+3);
A4 = str2double(A4);
A5 = line(A(4)+4:A(5)+3);
A5 = str2double(A5);

line2 = fgetl(f1);
sl = findstr(line,'E');
A6 = line2(1:sl(1)+3);
A6 = str2double(A6);
A7 = line2(sl(1)+4:sl(2)+3);
A7 = str2double(A7);
A8 = line2(sl(2)+4:sl(3)+3);
A8 = str2double(A8);
A9 = line2(sl(3)+4:sl(4)+3);
A9 = str2double(A9);
A10 = line2(sl(4)+4:sl(5)+3);
A10 = str2double(A10);

line3 = fgetl(f1);
sl3 = findstr(line,'E');
A11 = line3(1:sl3(1)+3);
A11 = str2double(A11);
A12 = line3(sl3(1)+4:sl3(2)+3);
A12 = str2double(A12);
A13 = line3(sl3(2)+4:sl3(3)+3);
A13 = str2double(A13);
A14 = line3(sl3(3)+4:sl3(4)+3);
A14 = str2double(A14);

R = 8.314;
T = linspace(local_temp_low,local_temp_high,500);
Cp = specific_heat(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,T,R,local_temp_mid);
H = enthalpy(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,T,R,local_temp_mid);
S = entropy(A1,A2,A3,A4,A5,A7,A8,A9,A10,A11,A12,A14,R,T,local_temp_mid);
M = moler_mass(elements);
mkdir(elements);
cd(elements);

figure(1)
plot(T,Cp,'LineWidth',2,'Color','g')
title(elements)
xlabel('temperture in K')
ylabel('specific heat in KJ')


figure(2)
plot(T,H,'linewidth',2,'Color','b')
title(elements)
xlabel('temperture in K')
ylabel('enthalpy in kj/mol ')

figure(3)
plot(T,S,'linewidth',2,'Color','r')
title(elements)
xlabel('temperture in K')
ylabel('entropy kj/mol*k')

saveas(1,'specific_heat','jpg')
saveas(2,'enthalpy','jpg')
saveas(3,'entropy','jpg')
cd ..
end

functions

Enthalpy

function [H] = enthalpy(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,T,R,local_temp_mid)
if T>=local_temp_mid
H = (A1.*T+A2.*(T.^2)./2+A3.*(T.^3)./3+A4.*(T.^4)./4+A5.*(T.^5)./5+A6)*R;
else
H = (A7.*T+A8.*(T.^2)./2+A9.*(T.^3)./3+A10.*(T.^4)./4+A11.*(T.^5)./5+A12)*R;
end
end

Entropy

function [S] = entropy(A1,A2,A3,A4,A5,A7,A8,A9,A10,A11,A12,A14,R,T,local_temp_mid)
if T>=local_temp_mid
S = (A1.*log(T)+A2.*(T)+A3.*(T.^2)./2+A4.*(T.^3)./3+A5.*(T.^4)./4+A7)*R;
else
S = (A8.*log(T)+A9.*(T)+A10.*(T.^2)./2+A11.*(T.^3)./3+A12.*(T.^4)./4+A14)*R;
end
end

Specific heat

function [Cp] = specific_heat(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,R,T,local_temp_mid )
if T>=local_temp_mid
Cp = (A1+A2.*(T)+A3.*(T.^2)+A4.*(T.^3)+A5.*(T.^4))*R;
else
Cp = (A6+A7.*(T)+A8.*(T.^2)+A9.*(T.^3)+A10.*(T.^4))*R;
end
end

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.