Project 1 - Parsing NASA thermodynamic data
clear all- used for clear all the data stored in previous workspace
close all- used for colse the all the figures and plots of before program
clc-use for clear the command window
R-is Unevarcel gas comstant 8.314
fopen-command is used for open the file and 'r' stands for read the file
fgetl-is used for Read line from file, removing newline characters
strsplit- Split string or character vector at specified delimiter
str2double- used for Convert strings to double precision values
strfind-used for Find strings within other strings
mkdir-used for Make new folder
cd-used for Change current folder
imwrite-command used for Write image to graphics file
getframe-used for figure as movie frame
gcf-used for get current frame
fprintf-command is used for Format data into string or character vector
These are the commands used in the Program
Fomule:-
specific heat=
Code:-
close all
clear all
clc
f1=fopen('THERMO.dat','r');
tline1=fgetl(f1);
tline2=fgetl(f1);
temp=strsplit(tline2,' ');
global_low_temp=str2double(temp(2));
global_mid_temp=str2double(temp(3));
global_hig_temp=str2double(temp(4));
for i=1:3
skippedlines=fgetl(f1);
end
for i=1:53
tline3=fgetl(f1);
S=strsplit(tline3,' ');
species_name = S{1};
B=strfind(tline3,'G ');
temp_values=tline3(B+4:length(tline3));
C=strsplit(temp_values,' ');
local_low_temp=str2double(C{1});
local_mid_temp=str2double(C{2});
local_high_temp=str2double(C{3});
tline4=fgetl(f1);
f=strfind(tline4,'E');
a1=str2double(tline4(1:(f(1)+3)));
a2=str2double(tline4(f(1)+4:(f(2)+3)));
a3=str2double(tline4(f(2)+4:(f(3)+3)));
a4=str2double(tline4(f(3)+4:(f(4)+3)));
a5=str2double(tline4(f(4)+4:(f(5)+3)));
tline5=fgetl(f1);
a6=str2double(tline5(1:(f(1)+3)));
a7=str2double(tline5(f(1)+4:(f(2)+3)));
a8=str2double(tline5(f(2)+4:(f(3)+3)));
a9=str2double(tline5(f(3)+4:(f(4)+3)));
a10=str2double(tline5(f(4)+4:(f(5)+3)));
tline6=fgetl(f1);
a11=str2double(tline6(1:(f(1)+3)));
a12=str2double(tline6(f(1)+4:(f(2)+3)));
a13=str2double(tline6(f(2)+4:(f(3)+3)));
a14=str2double(tline6(f(3)+4:(f(4)+3)));
R=8.314;
T=linspace(local_low_temp,local_high_temp,100);
c_p=specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
s=entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
h=enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
mkdir(species_name)
cd(species_name)
figure(1)
plot(T,c_p,'LineWidth',5,'color','r')
title ('specific heat Vs Tempareture')
xlabel('tempareture')
ylabel('specific heat')
image=getframe(gcf);
imwrite(image.cdata,'T vs c_p ','jpg')
saveas(1,'specific heat','jpg')
figure(2)
plot(T,s)
title('enthalpy Vs Tempareture')
xlabel('tempareture')
ylabel('enthalpy')
image=getframe(gcf);
imwrite(image.cdata,'t vs S','jpg')
saveas(2,'Enthalpy','jpg')
figure(3)
plot(T,h )
title('entropy Vs Tempareture')
xlabel('tempareture')
ylabel('entropy')
image=getframe(gcf);
imwrite(image.cdata,'T vs h','jpg')
saveas(3,'enytropy','jpg')
cd ..
molecular_wt=molecular_weight(species_name);
end
functional code:-
enthalpy
function [h] = enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R)
T=linspace(local_low_temp,local_high_temp,100)
if ( T>local_mid_temp)
h=(a1*T+(a2*T.^2)/2+(a3*T.^3)/2+(a4*T.^4)/2+(a5*T.^5)/2+a6).*T.*R;
else
h=(a8*T+(a9*T.^2)/2+(a10*T.^3)/2+(a11*T.^4)/2+(a12*T.^5)/2+a13).*T.*R;
end
end
entropy
function[s]=entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R)
T=linspace(local_low_temp,local_high_temp,100);
if ( T>local_mid_temp)
s=(a1*log(T)+a2*T+(a3*T.^2)/2+(a4*T.^3)/3+(a5*T.^4)/4+a7);
else
s=(a8*log(T)+a9*T+(a10*T.^2)/2+(a11*T.^3)/3+(a12*T.^4)/4+a14).*R;
end
end
molecular weights
function [M]=molecular_weight(species_name)
atomic_mass=[15.999 1.008 12.011 14.007,39.948];
elements=[ 'O', 'H', 'C', 'N', 'A'];
Mol_wt = 0;
for i=1:length(species_name)
for j=1:length(elements)
if strcmpi(species_name(i),elements(j))
Mol_wt=Mol_wt+atomic_mass(j);
z=j;
end
end
var=str2double(species_name(i));
if (var>1)
Mol_wt=Mol_wt+(atomic_mass(z)*(var-1));
end
end
M=Mol_wt;
K=sprintf('%s Mol_wt= %f',species_name,M);
disp(K)
end
Result figures



Molecular weights of species

Folders file:-

Errors

I rectifying this error by changing the formate of the file from .png to .jpg

I rectifying this the error by entering the Double '==' insead of Single '='