Challenge

Project 1 - Parsing NASA thermodynamic data

clc
close all
clear all
%getting data file
f = fopen('THERMO.dat','r');
fgetl(f);
%reading header informations
tline = fgetl(f);
A = str2num(tline);
global_low_temp = A(:,1);
global_low_temp = A(:,2);
global_high_temp = A(:,3);
%skipping comment lines
for i = 1:3
fgetl(f)
end
%reading species data
for i = 1:53
linel = fgetl(f);
l = strsplit(linel);
m = length(1);
sp = l(1);
species = char(sp);
atom = ['H','C','O','N','Ar','S'];
atomic_weight = [1.008 12.011 15.999 14.007 39.948 32.065];
low_temp = str2double(l(m-3));
mid_temp = str2double(l(m-2));
high_temp = str2double(l(m-1));
%storing the vaue of second line
line2 = fgetl(f);
a = strfind(line2,'E');
a1 = str2double(line2(1:(a+3)));
a2 = str2double(line2((a(1)+4):(a(2)+3)));
a3 = str2double(line2((a(3)+4):(a(4)+3)));
a4 = str2double(line2((a(3)+4):(a(4)+3)));
a5 = str2double(line2((a(4)+4):(a(5)+3)));
%strong the value of 3rd line
line3 = fgetl(f);
b = strfind(line3,'E');
a6 = str2double(line3(1:(b(1)+3)));
a7 = str2double(line3((b(3)+4):(a(2)+3)));
a8 = str2double(line3((b(3)+4):(a(4)+3)));
a9 = str2double(linhe3((b(3)+4):(a(4)+3)));
a10 = str2double(line3((b(4)+4):(a(5)+3)));
%storing the value of 4th line
line4 = fgetl(f);
c = strfind(line3,'E');
a11 = str2double(line4(1:(c(1)+3)));
a12 = str2double(line4((c(1)+4:(a(2)+3)));
a13 = str2double(line4((c(2)+4:(a(3)+3)));
a14 = str2double(line4((c(3)+4:(a(4)+3)));
%creating temperature values for lower and higher temperature
TL = linspace(low_temp,mid_temp,100);
TH = linspace(mid_temp,high_temp,100);
%value of universal gas constant
R = 8.314;
%calculating specific heat ,enthalpy and entropy for lower and higher temp
for k = 1:100
%for lower temperature
cp_low(k) = (a8 + a9*TL(k) + a10*TL(k)^2 + a11*TL(k)^3 + a12*TL(k)^4)*R;
h_low(k) = (a8 + a9*TL(k)/2 + a10*(TL(k)^2)/3 + a11*(TL(k)^3)/4 + a12*(TL(k)^4)/5 + a13/TL(k))*R;
s_low(k) = (a8*log(TL(k)) + a9*TL(k) + a10*(TL(k)^2)/2 + a11*(TL(k)^3)/3 + a12*(TL(k)^4)/4 + a13*(TL(k)^5)/5)*R;
%for higher temperature
cp_high(k) = (a1 + a2*TH(k) + a3*TH(k)^2 + a4*TH(k)^3 + a5*TH(k)^4)*R;
h_high(k) = (a1+a2*TH(k)/2 + a3*TH(k)^2/3 + a4*TH(k)^3/4 + a5*TH(k)^4/5 + a6*TH(k))*R*TH(k);
s_high(k) = (a1*log(TH(k)) + a2*TH(k) + a3*TH(k)^2/2 + a4*TH(k)^3/3 + a5*TH(k)^4/4 + a6*TH(k)^5/5)*R*TH(k);
end
%creating folder
nasa_file = species;
mkdir(nasa_file);
current = pwd;
cd(nasa_file);
%creating figure of specific heat
figure(1)
plot(TL,cp_low,'LineWidth',2,'color','r');
hold on
plot(TH,cp_high,'LineWidth',2,'color','g');
hold off
title(['Temperature VS Specific heat , species']);
xlabel('Temperature');
ylabel('Speci fic Heat');
legend('Low Temperature','High Temperature');
%saving .png file of figure
fig = sprintf('specific heat of %s.png',species);
saveas(gca,fig);
%creating figure of enthalpy
figure(2)
plot(TL,cp_low,'LineWidth',2,'color','r');
hold on
plot(TH,h_high,'LineWidth',2,'color','g');
hold off
title(['Temperature VS Enthalpy ,species']);
xlabel('Temperature');
ylabel('Enthalpy');
legend('Low Temperature','High Temperature');
%saving .png file of figure
fig = sprintf('enthalpy of %s.png',species);
saveas(gca,fig);
%creating figure of entropy
figure(3)
plot(TL,s_low,'LineWidth',2,'color','r');
hold on
plot(TH,s_high,'LineWidth',2,'color','g');
hold off
title(['Temperature VS Entropy, species']);
xlabel('Temperature');
ylabel('Entropy');
legend('Low Temperature','High Temperature');
%saving .png file of figure
fig = sprintf('entropy of %s.png',species);
saveas(gca,fig);
cd(current);
%calculation of molecular weight
atom = ['H','C','O','N','Ar','S'];
atomic_weight = [1.008 12.011 15.99 14.007 39.948 32.065];
mw = 0;
for p=1 ; length(species)
for q=1 ; length(atomic_weight)
if strcmp(species(p),atom(q))
mw = mw + atomic_weight(q);
position = q;
end
end
% used for multiplication into the number of atoms
n = str2double(species(p));
if n>1
mw = mw + atomic_weight(position)*(n-1);
end
end
%display molecular weight
fprintf('molecular weight of %s :%f/n',species,mw);
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.