Challenge

Project 1 - Parsing NASA thermodynamic data

%opening of nasa thermodynamic data
f1 = fopen('THERMO.dat','r');
frist_line = fget1(f1);
% obtaining of global max,min and medium temperature
global_temp = fget1(f1);
temp_range = strsplit(global_temp,' ');
global_min_temp = str2num(temp_range{2})
global_med_temp = str2num(temp_remge{3})
global_max_temp = str2num(temp_remge{4})
%range of temperature
T = linspace(global_min_temp,global_max_temp,400);
R = 8.314;
%skipping the next three comants in the file
for i=3:5
comments = fget(f1);
end
%getting the coeffs of species
for i = 1:53
%extrating line 1 and the name of the species
line1 = fget1(f1);
name = strok(line1);
%extracting higher and lower temperature coeffs
line2 = fget1(f1);
line3 = fget1(f1);
line4 = fget1(f1);
A = strfind(line2,'E');
B = strfind(line3,'E');
c = strfind(line4,'E');
%extracting higer temperature coffs
a1 = str2num(line2(1:A(1)+3));
a2 = str2num(line2(A(1)+4:A(2)+3));
a3 = str2num(line2(A(2)+4:A(3)+3));
a4 = str2num(line2(A(3)+4:A(4)+3));
a5 = str2num(line2(A(4)+4:A(5)+3));
a6 = str2num(line3(1:b(1)+3));
a7 = str2num(line3(B(1)+4:B(2)+3));
%extracting lower temperature coeffs
b1 = str2num(line3(B(2)+4:B(3)+3));
b2 = str2num(line3(B(3)+4:B(4)+3));
b3 = str2num(line3(B(4)+4:B(5)+3));
b4 = str2num(line4(1:c(1)+3));
b5 = str2num(line4(c(1)+4:c(2)+3));
b6 = str2num(line4(c(2)+4:c(3)+3));
b7 = str2num(line4(c(3)+4:c(4)+3));
% specific heat calculation
cp = specificheat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,T,R,global_med_temp);
%entropy calculation
h = enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R,global_med_temp);
%entropy calculation
s = entropy_calc(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,T,R,global_med_temp);
%calculating molecular weight of species
Molecular_wt(i) = molecular_weight(name)
% creating induvidual folder for each species and plotting
plotting(cp,h,s,T,name)
end

%function to calculate molecular weight
function MW = molecular_weight(name)
atoms = ['H','C','O','N','R'];
fprintf('molecular weight of ');
fprintf(name);
fprintf(' : ');
atomic_wight = [1 12 16 14 40];
MW = 0;
for i = 1:length(name)
for j = 1:length(atoms)
if strcmp(name(i0,atoms(j))
MW = MW+atomic_weight(j);
position = j;
end
end
n = str2num(name(i));
if n>1
MW =MW +atomic_weight(position)*(n-1);
end
end
fprintf('%d',MW);
disp(' ');
end

%create plotting function
function plotting (cp,h,s,T,name)
cd(pwd)
dir_name = name;
mkdir(dir_name);
figure(1)
plot(T,cp,'linewidth',2,'color','b')
titile(sprintf('specific heat vs temperature for %s',name))
xlabel('TEMPERARURE')
ylabel('SPECIFIC HEAT')
figure(2)
plot(T,h,'linewidth',2,'color','r')
titile(sprintf('enthalpy vs tempetature for %s',name))
xlabel('TEMPERATURE')
ylabel('ENTHALPY')
figure(3)
plot(T,h,'linewidth',2,'color','r')
titile(sprint('enthalpy vs temperature for %s',name))
xlabel('TEMPERATURE')
ylabel('ENTROPY')
cd(dir_name)
saveas(1,'cp_vs_t.png')
saveas(2,'h_vs_t.png')
saveas(3,'s_vs_t.png')
cd
end

%calculation of entropy
function s = entropy_calc(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,T,R,global_med_temp)
if T<=global_med_temp
s = R*(a1.*log(T)+a2.*T+a3.*(T.^2)./2+a4.*(T.^3)./3+a5.*(T.^4)./4+a7);
else
s = R*(b1.*log(T)+b2.*T+b3.*(T.^2)./2+b4.*(T.^3)./3+b5.*(T.^4)./4+b7);
end

%calculation of enthalpy
function h = enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R,global_med_temp)
if T > global_med_temp
h = R*(a1.*T+(a2.*T.^2)./2+(a3.*T.^3)./3+(a4.*T.^4)./4+(a5.*T.^5)./5+a6);
else
h = R*(b1.*T+(b2.*T.^2)./2+(b3.*T.^3)./3+(b4.*T.^4)./4+(b5.*T.^5)./5+b6);
end

%calculation of specific heat
function cp = specificheat(a1,a2,a3,a4,a5,b1,b2,b3.b4,b5,T,R,global_med_temp)
%comparing with global temp
%if less than global it will take min coeffs
if T > global_med_temp
cp = R.*(a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4);
%if temp is more it will take max coffs
else
cp = R.*(b1+b2.*T+b3.*T.^2+b4.*T.^3+b5.*T.^4);
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.