Project 1 - Parsing NASA thermodynamic data
for making to read the thermo data file
and making the minimum global temperature values of each elements such as o2 ,n2 etc
first step is open the data file,
f1=fopen('THERMO.dat','r')
fgetl(f1)
we can making the temperature value,
temp=str2num(fgetl(f1))
global_low_temp=temp(1)
global_mid_temp=temp(2)
global_high_temp=temp(3)
we can creating the specific loof for the thermo data
then put the a is strsplit and b is length of a
a=strsplit(tline,' ');
b=length(a);
species=a{1};
for making the variation in a special case such as i is in beween 1 to 4 in 212 time
tline is the chage of taking the fi values
for making the values of temperature for a given equations
low_temp=str2double(a(b-3));
mid_temp=str2double(a(b-2));
high_temp=str2double(a(b-1));
for making the second line variation of f1 values
for finding the position of E , that is the normal righ and left of e can be used to determine the values of e can changing
that can calculate using ,
c=strfind(line2,'E');
for making the individaul coefficent in the line 2 ' for such as the 5 values can be gevening in the line2
that is ,
a1=str2double(line2(1:(c(1)+3)));
a2=str2double(line2((c(1)+4):(c(2)+3)));
a3=str2double(line2((c(2)+4):(c(3)+3)));
a4=str2double(line2((c(3)+4):(c(4)+3)));
a5=str2double(line2((c(3)+4):(c(5)+3)));
for making the 3rd line variation of f1 values
for finding the position of E , that is the normal righ and left of e can be used to determine the values of e can changing
that can calculate using ,
c=strfind(line3,'E');
for making the individaul coefficent in the line 3 ' for such as the 5 values can be gevening in the line3
that is ,
a6=str2double(line3(1:(d(1)+3)));
a7=str2double(line3((d(1)+4):(d(2)+3)));
a8=str2double(line3((d(2)+4):(d(3)+3)));
a9=str2double(line3((d(3)+4):(d(4)+3)));
a10=str2double(line3((d(4)+4):(d(5)+3)));
for making the 3rd line variation of f1 values
for finding the position of E , that is the normal righ and left of e can be used to determine the values of e can changing
that can calculate using ,
c=strfind(line4,'E');
for making the individaul coefficent in the line 4 ' for such as the 4 values can be gevening in the line4
that is ,
a11=str2double(line4(1:(e(1)+3)));
a12=str2double(line4((e(1)+4):(e(2)+3)));
a13=str2double(line4((e(2)+4):(e(3)+3)));
a14=str2double(line4((e(3)+4):(e(4)+3)));
for finding the temperature range for lowest and highest temperature, for given equation is,
lower_temp=linspace(low_temp,mid_temp,100)
higher_temp=linspace(mid_temp,high_temp,100)
for the r isa universal gas constant such as the value of r 8.314
for calculating the value of cp ,h ,s in case of lower temperature and higher temperature
in a lower temeperature,
cp_low is,
cp_low(k)=(a8+(a9*lower_temp(k))+(a10*(lower_temp(k)^2)+(a11*lower_temp(k))^3)+a12*(lower_temp(k)^4))*R;
h_low is,
h_low(k)=(a8+(a9*lower_temp(k))/2+(a10*lower_temp(k)^2)/3+(a11*lower_temp(k)^3)/4+a12*(lower_temp(k)^4)/5+(a13/lower_temp(k)))*R*lower_temp(k);
s_low is,
s_low(k)=((a8*log(lower_temp(k))+(a9*lower_temp(k))+((a10*lower_temp(k)^2)/2)+((a11*lower_temp(k)^3)/3)+((a12*lower_temp(k)^4)/4)+a14)*R);
in a higher temperature case,
cp_high,
cp_high(k)=(a1+(a2*higher_temp(k))/2+(a3*higher_temp(k)^2)/3+(a4*higher_temp(k)^3)/4+(a5*(higher_temp(k)^4))/5+(a6/higher_temp(k)))*R*higher_temp(k);
h_high,
h_high(k)=(a1+(a2*higher_temp(k))/2+(a3*higher_temp(k)^2)/3+(a4*higher_temp(k)^3)/4+(a5*(higher_temp(k)^4))/5+(a6/higher_temp(k)))*R*higher_temp(k);
s_high,
s_high(k)=((a1*log(higher_temp(k))+a2*higher_temp(k)+((a3*higher_temp(k)^2)/2)+((a4*higher_temp(k)^3)/3)+((a5*higher_temp(k)^4)/4)+a7)*R);
for creating a folder for saving all the drawn plots
such as,
nasa_garphs=species;
mkdir(nasa_garphs);
current_dir=pwd;
cd(nasa_garphs);
for making the plots for all elements in the given thermo data,
to the specific heat , enthalpy and entropy are plot for each elements
figure(1) is specific heat
figure(2) is enthalpy
figure(3) is enthropy
for calulating the molecular weight of each elements,
such as H, N, C, R, S
mol_weight and attom_weight is molecular weight
atom_weight=[1.00784 12.0109 16.002 39.065 32.067]
mol_weight=0;
for equation is,
mol_weight=mol_weight+(atom_weight(j)*(x-1))
clear all
close all
clc
f1=fopen('THERMO.dat','r');
fgetl(f1);
%for grtting temperture value
temp=str2num(fgetl(f1));
global_low_temp=temp(1);
global_mid_temp=temp(2);
global_high_temp=temp(3);
%for skipping unwanted lines
for i=1:3
fgetl(f1);
end
%creating loop for all spicies that calculate data,plot graph and molecular weight
for i=1:4:212
tline=fgetl(f1);
a=strsplit(tline,' ');
b=length(a);
species=a{1};
%storing values of temperture
low_temp=str2double(a(b-3));
mid_temp=str2double(a(b-2));
high_temp=str2double(a(b-1));
%storing second line values
line2=fgetl(f1);%storing the value 2nd line in a veriable
%finding the position of E
c=strfind(line2,'E');
%creating individual coefficients
a1=str2double(line2(1:(c(1)+3)));
a2=str2double(line2((c(1)+4):(c(2)+3)));
a3=str2double(line2((c(2)+4):(c(3)+3)));
a4=str2double(line2((c(3)+4):(c(4)+3)));
a5=str2double(line2((c(3)+4):(c(5)+3)));
%storing the values of 3rd line
line3=fgetl(f1);
%finding position of E
d=strfind(line3,'E');
%storing the value in 3rd line
a6=str2double(line3(1:(d(1)+3)));
a7=str2double(line3((d(1)+4):(d(2)+3)));
a8=str2double(line3((d(2)+4):(d(3)+3)));
a9=str2double(line3((d(3)+4):(d(4)+3)));
a10=str2double(line3((d(4)+4):(d(5)+3)));
%storing the values of 2th line
line4=fgetl(f1);
%finding the postion of E
e=strfind(line4,'E');
%storing the values of fourth line
a11=str2double(line4(1:(e(1)+3)));
a12=str2double(line4((e(1)+4):(e(2)+3)));
a13=str2double(line4((e(2)+4):(e(3)+3)));
a14=str2double(line4((e(3)+4):(e(4)+3)));
% creating ranges for low amd high temperture
lower_temp=linspace(low_temp,mid_temp,100)
higher_temp=linspace(mid_temp,high_temp,100)
%inputing the values of universal gas constant R=8.314 j/mol*k
R=8.314;
%calculating the values for Cp,H and S using the for loop given formula
for k=1:100
%lower temperature values for Cp,H,S
cp_low(k)=(a8+(a9*lower_temp(k))+(a10*(lower_temp(k)^2)+(a11*lower_temp(k))^3)+a12*(lower_temp(k)^4))*R;
h_low(k)=(a8+(a9*lower_temp(k))/2+(a10*lower_temp(k)^2)/3+(a11*lower_temp(k)^3)/4+a12*(lower_temp(k)^4)/5+(a13/lower_temp(k)))*R*lower_temp(k);
s_low(k)=((a8*log(lower_temp(k))+(a9*lower_temp(k))+((a10*lower_temp(k)^2)/2)+((a11*lower_temp(k)^3)/3)+((a12*lower_temp(k)^4)/4)+a14)*R);
%higher tempertyure values for cp,h,s
cp_high(k)=(a1+(a2*higher_temp(k))/2+(a3*higher_temp(k)^2)/3+(a4*higher_temp(k)^3)/4+(a5*(higher_temp(k)^4))/5+(a6/higher_temp(k)))*R*higher_temp(k);
h_high(k)=(a1+(a2*higher_temp(k))/2+(a3*higher_temp(k)^2)/3+(a4*higher_temp(k)^3)/4+(a5*(higher_temp(k)^4))/5+(a6/higher_temp(k)))*R*higher_temp(k);
s_high(k)=((a1*log(higher_temp(k))+a2*higher_temp(k)+((a3*higher_temp(k)^2)/2)+((a4*higher_temp(k)^3)/3)+((a5*higher_temp(k)^4)/4)+a7)*R);
end
%making folder for saving the plots
nasa_garphs=species;
mkdir(nasa_garphs);
current_dir=pwd;
cd(nasa_garphs);
%plotting graph
%specific heat
figure(1)
plot(lower_temp,cp_low,'LineWidth',3)
hold on
plot(higher_temp,cp_high,'LineWidth',3)
hold off
title(['TEMPURATURE VS SPECIFIC HEAT',species])
xlabel('TEMPERTURE');
ylabel('SPECIFIC HEAT');
legend('Low Temperature','High Temperatute');
fig=sprintf('Specific Heat of %s.png',species);
saveas(gca,fig);
%For Enthalpy
figure(2)
plot(lower_temp,h_low,'LineWidth',3)
hold on
plot(higher_temp,h_high,'LineWidth',3)
hold off
title(['Tempurature vs Entalpy',species])
xlabel('TEMPURTURE')
ylabel('ENTALPY')
legend('low Temperature','high Temperature')
fig=sprintf('Enthalpy of %s.png',species);
saveas(gca,fig);
%for entropy
figure(3)
plot(lower_temp,s_low,'LineWidth',3)
hold on
plot(higher_temp,s_high,'LineWidth',3)
hold off
title(['Temperature vs Entropy',species])
xlabel('Temperture')
ylabel('Entropy')
legend('low temperature','high temperature');
fig=sprintf('Entropy of %s.png',species);
saveas(gca,fig);
cd(current_dir)
end
%Calculating Molecular weight
atoms=['H','C','N','R','S'];
atom_weight=[1.00784 12.0109 16.002 39.065 32.067]
mol_weight=0;
species_check=char(species);
for i=1:length(species_check)
for j=1:length(atom)
if(strcmp(species_check(i),atoms(j)))
mol_weight=mol_weight+atom_weight(j)
position=j;
end
end
x=str2double(species_check(i));
if x>1
mol_weight=mol_weight+(atom_weight(j)*(x-1))
end
fprintf('Molecular Weight of %s is : %f /n',species_check,mol_weight)
end