NASA file parsing from Thermodynamic data file
Project-1 File parsing
clear all
close all
clc
%INPUTS
R=8.31;
%Reading the NASA thermodynamic data file
f1 = fopen(\'therm.txt\',\'r\')
Header_Thermo=fgetl(f1)
thermo=fgetl(f1)
%skiping three ! lines
for i=1:3
skip=fgetl(f1);
end
%temperatute
temp=linspace(200,3500,500);
%Reading
for i=1:300
skip=fgets(f1);
Species = sscanf(skip,\'%c\')
exit=Species(1:3);
last=\'END\';
if exit==last
break
end
%Calculating molar mass
mol_mass=0;
position=25;
for i=0:2
x=(position+(5*i));
y=str2num(Species(x+4));
if strcmp(Species(x),\'C\')
mol_mass=mol_mass+12*y;
elseif strcmp(Species(x),\'O\')
mol_mass=mol_mass+16*y;
elseif strcmp(Species(x),\'H\')
mol_mass=mol_mass+1*y;
elseif strcmp(Species(x),\'A\')
mol_mass=mol_mass+40*y;
elseif strcmp(Species(x),\'N\')
mol_mass=mol_mass+14*y;
else
break;
end
end
molecular_weight=0;
molecular_weight=num2str(mol_mass);
%Creating unique folder name
q=Species(1:8);
w=molecular_weight;
e=sprintf(\'%s %s\',q,w)
unique_folder=mkdir(e)
%Taking values from the \"Speciesblock\"
a2=fgets(f1);
data2=sscanf(a2,\'%f\');
a3=fgets(f1);
data3=sscanf(a3,\'%f\');
a4=fgets(f1);
data4=sscanf(a4,\'%f\');
ht=[data2(1) data2(2) data2(3) data2(4) data2(5) data3(1) data3(2)] %High temp data
lt=[data3(3) data3(4) data3(5) data4(1) data4(2) data4(3) data4(4)] %Low temp data
for j=1:length(temp)
t=1000; %mid temp calculation
if temp(j)<t
Cp(j) = R*(lt(1)+lt(2)*temp(j)+lt(3)*(temp(j))^2 +lt(4)*(temp(j))^3 +lt(5)*(temp(j))^4);
H(j) = R*temp(j)*(lt(1)+lt(2)*temp(j)/2 +lt(3)*((temp(j))^2)/3 +lt(4)*((temp(j))^3)/4 + lt(5)*((temp(5))^4)/5 + lt(6)/temp(j));
S(j) = R*(lt(1)*log(temp(j))+lt(2)*temp(j)+lt(3)*((temp(j))^2)/2 +lt(4)*((temp(j))^3)/3 + lt(5)*((temp(j))^4)/4 + lt(7));
else
Cp(j) = R*(ht(1)+ht(2)*temp(j)+ht(3)*(temp(j))^2 +ht(4)*(temp(j))^3 +ht(5)*(temp(j))^4);
H(j) = R*temp(j)*(ht(1)+ht(2)*temp(j)/2 +ht(3)*((temp(j))^2)/3 +ht(4)*((temp(j))^3)/4 + ht(5)*((temp(5))^4)/5 + ht(6)/temp(j));
S(j) = R*(ht(1)*log(temp(j))+ht(2)*temp(j)+ht(3)*((temp(j))^2)/2 +ht(4)*((temp(j))^3)/3 + ht(5)*((temp(j))^4)/4 + ht(7));
end
end
%Ploting
figure(1)
plot(temp,Cp)
title(\'Cp vs Temp.\')
xlabel(\'Temperature\')
ylabel(\'Cp\')
figure(2)
plot(temp,H)
title(\'H vs Temp.\')
xlabel(\'Temperature\')
ylabel(\'H\')
figure(3)
plot(temp,S)
title(\'S vs Temp.\')
xlabel(\'Temperature\')
ylabel(\'S\')
%Saving the plot with unique name
file1=sprintf(\'Cp vs Temp %s\',e);
file2=sprintf(\'H vs Temp %s\',e);
file3=sprintf(\'S vs Temp %s\',e);
%File saving
parent_folder=pwd;
cd(e)
savefig(1,file1);
saveas(1,file1,\'png\');
savefig(2,file2);
saveas(2,file2,\'png\');
savefig(3,file3);
saveas(3,file3,\'png\');
cd(parent_folder)
end
fclose(f1);