Project 1 - Parsing NASA thermodynamic data
%Parsing NASA's thermodynamic data
clear all
close all
clc
%finding and opening the file_in_loadpath
file=fopen('THERMO.dat','r');
%header
line1=fgetl(file);
%global temperature values
line2=fgetl(file);
A=strsplit(line2,' ');
global_min_temp=str2num(A{2});
global_mid_temp=str2num(A{3});
global_max_temp=str2num(A{4});
%skipping comments
fgetl(file);
fgetl(file);
fgetl(file);
%using the for loop to consier 53 elements
for i=1:53
line3=fgetl(file); %reading the file
element=line3(1:6); %naming first variable as element
P=strfind(line3,'G');
local_low_temp=line3(P+3:55);
local_high_temp=line3(P+13:65);
local_mid_temp=line3(P+23:75);
lt=str2double(local_low_temp); %creating low temp. variable
ht=str2double(local_high_temp); %creating high temp. variable
mt=str2double(local_mid_temp); %creating mid temp. variable
%line 1 reading coefficients
cfline1=fgetl(file);
X=strfind(cfline1,'E');
a1=cfline1(1:X(1)+3);
a1=str2double(a1); %storing 1st coefficients
a2=cfline1(X(1)+4:X(2)+3);
a2=str2double(a2); %storing 2nd coefficients
a3=cfline1(X(2)+4:X(3)+3);
a3=str2double(a3); %storing 3rd coefficients
a4=cfline1(X(3)+4:X(4)+3);
a4=str2double(a4); %storing 4th coefficients
a5=cfline1(X(4)+4:X(5)+3);
a5=str2double(a5); %storing 5th coefficients
%line 2 reading coefficients
cfline2=fgetl(file);
Y=strfind(cfline2,'E');
a6=cfline2(1:Y(1)+3);
a6=str2double(a6); %storing 6th coefficients
a7=cfline2(Y(1)+4:Y(2)+3);
a7=str2double(a7); %storing 7th coefficients
a8=cfline2(Y(2)+4:Y(3)+3);
a8=str2double(a8); %storing 8th coefficients
a9=cfline2(Y(3)+4:Y(4)+3);
a9=str2double(a9); %storing 9th coefficients
a10=cfline2(Y(4)+4:Y(5)+3);
a10=str2double(a10); %storing 10th coefficients
%line 3 reading coefficients
cfline3=fgetl(file);
Z=strfind(cfline3,'E');
a11=cfline3(1:Z(1)+3);
a11=str2double(a11); %storing 11th coefficients
a12=cfline3(Z(1)+4:Z(2)+3);
a12=str2double(a12); %storing 12th coefficients
a13=cfline3(Z(2)+4:Z(3)+3);
a13=str2double(a13); %storing 13th coefficients
a14=cfline3(Z(3)+4:Z(4)+3);
a14=str2double(a14); %storing 14th coefficients
%Creating the folder for each element
mkdir(element);
%Universal gas constant
R=8.314;
%Ranging the temperature from low temperature to high temperature
T=linspace(lt,ht,100);
%Specific heat
for j=1:length(T)
if T(j)<=mt
%specific heat
sp=(a8+a9.*(T)+a10.*(T.^2)+a11.*(T.^3)+a12.*(T.^4))*R;
%Enthalpy
H=(a8.*T+(a9.*(T.^2))./2+(a10.*(T.^3))./3+(a11.*(T.^4))./4+(a12.*(T.^5))./5+a13).*R;
%Entropy
S=(a8.*log(T)+a9.*T+(a10.*(T.^2))./2+(a11.*(T.^3))./3+(a12.*(T.^4))./4+a14).*R;
else
%specific heat
sp=(a1+a2.*(T)+a3.*(T.^2)+a4.*(T.^3)+a5.*(T.^4)).*R;
%Enthalpy
H=(a1.*T+(a2.*(T.^2))./2+(a3.*(T.^3))./3+(a4.*(T.^4))./4+(a5.*(T.^5))./5+a6).*R;
%Entropy
S=(a1.*log(T)+a2.*T+(a3.*(T.^2))./2+(a4.*(T.^3))./3+(a5.*(T.^4))./4+a7).*R;
end
end
%plot 1 specific heat vs. temperature
figure(1)
plot(T,sp,'linewidth',2,'color','r')
xlabel('Temperature in K')
ylabel('Specific heat in KJ');
title('Specific heat vs. Temperature')
%plot 2 Enthalpy vs. Temperature
figure(2)
plot(T,H,'linewidth',2,'color','y')
xlabel('Temperature in K')
ylabel('Enthalpy in KJ/mol');
title('Enthalpy vs. Temperature')
%plot 3 Entropy vs. Temperature
figure(3)
plot(T,S,'linewidth',2,'color','b')
xlabel('Temperature in K')
ylabel('Entropy in KJ/molK');
title('Entropy vs. Temperature')
directory=(['G:/Matlab/Sample programs/NASA data/',element]);
%changing the file paths to save the plot
cd(element);
%Saving the plot that got generated
saveas(figure(1),'SP.png');
saveas(figure(2),'H.png');
saveas(figure(3),'S.png');
%Switching the directory back
cd ..
%Molecular mass of elements
MM=molecular_mass(element)
end
fclose(file);