Project

project-1-parsing nasa thermodynamic data

% main code

clc
close all
clear all

% opening and reading file
f1 = fopen(\'thermo30.dat\',\'r\');
header = fgetl(f1);

% getting temperatures
tline = fgetl(f1);
temp = strsplit(tline,\' \');
low_temp = str2double(temp{2});
mid_temp = str2double(temp{3});
high_temp = str2double(temp{4});

% removing unnecessary lines
for i=1:3
t = fgetl(f1);
end

% now getting all 53 individual species data

for r=1:53
% getting species name
tline = fgetl(f1);
s = strsplit(tline,\' \');
name = s{1} % species name
species = strcat(\'for__\',s{1},\'__species\')

% getting coefficients
% for all 3 lines
for j=1:3 % j is the line number
tline = fgetl(f1);
A = findstr(tline,\'E\');
p = 1; % p is the starting number of the coefficient in the line
q = 5; % q is no of coefficients in each line

if j==3 % j=3 means for third line
q = 4; % q=4 as 3rd line has only 4 coefficients
end

for i=1:q % q is no of coefficients in each line
c = tline(p:A(i)+3); % getting coefficients as strings
coeff(i) = str2num(c); % converting coefficient strings into numbers
p = A(i)+4;
end

for i=1:q
a(i+5*(j-1)) = coeff(i); % saving the all 14 coefficient value as from a(1) to a(14)
end
end

t = [low_temp,mid_temp,high_temp]; % t is temperature array
R = 8.314;
i=7; % here for low temp i=7 the coefficient values are from a(7) to a(14)
if t==high_temp
i=0; % here for high temp i=0 the coefficient values are from a(1) to a(7)
end


cp = (a(i+1)+a(i+2).*t+a(i+3).*t.^2+a(i+4).*t.^3+a(i+5)*t.^4).*R


H = (a(i+1) + a(i+2).*t/2 + a(i+3).*t.^2/3 + a(i+4).*t.^3/4 + a(i+5).*t.^4/5 + a(i+6)./t).*R.*t


S = (a(i+1).*log(t) + a(i+2).*t + a(i+3).*t.^2/2 + a(i+4).*t.^3/3 + a(i+5).*t.^4/4 + a(i+7))*R

% mole_wt function to calculate the molrcular weight of the species
molecular_weight = mole_wt(name)

% plotting function to plot the graphs
plotting(t,S,H,cp,name,species)

end

**************************************************************************

% function code of plotting graphs

function plotting(t,S,H,cp,name,species)

% creating the directory and path and to save the plot images
directory=sprintf(\'%s\',name);
mkdir(directory);

% ploting cp vs t
figure(1)
plot(t,cp,\'r\')
xlabel(\'temperature\')
ylabel(\'specific heat\')
title(species)

%plotting enthalphy vs t
figure(2)
plot(t,H,\'g\')
xlabel(\'temperature\')
ylabel(\'enthalphy\')
title(species)

% plotting entropy vs t
figure(3)
plot(t,S,\'b\')
xlabel(\'temperature\')
ylabel(\'entropy\')
title(species)

pf = pwd;
cd(directory);

%saving the images under the mentioned names in jpeg format
saveas(figure(1), \'cp.jpeg\');
saveas(figure(2), \'H.jpeg\');
saveas(figure(3), \'S.jpeg\');
cd(pf);
end

**************************************************************************

% moecular weight calculating function code

clc
clear all
close all


function m_wt = mole_wt(name)
elements = [\'H\' \'O\' \'C\' \'N\' \'AR\'];
at_wt = [1 16 12 14 40]; % atomic weights of respective elements
m=0;
for i=1:length(name)
for j =1:5
if strcmp(name(i),elements(j))
m=m+at_wt(j);
r=at_wt(j);
end
end
s = name(i); % in case of numbers in the strings
if ( s==\'2\' || s==\'3\'|| s==\'4\'|| s==\'5\'|| s==\'6\'|| s==\'7\'|| s==\'8\'|| s==\'9\')

b = str2num(s); % converting num string to number
m=m+r*(b-1);
end
end
% molecular weight of the species
m_wt = m
end

**************************************************************************

% plots for O2

**************************************************************************

% plots for N2

**************************************************************************

% plots for CO2

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.