Project 1 - Parsing NASA thermodynamic data
%NASA File Parsing Project
close all
clc
% Below coding is to open the THERMO.dat file to read the data from file
f = fopen('THERMO.dat','r');
%for extract whats written in the first line
title = fgetl(f);
% coding for extracting data for reading the global Temp. value
b = fgetl(f);
c = strsplit(b,' ');
global_low_temp = str2double(c{2});
global_mid_temp = str2double(c{3});
global_high_temp = str2double(c{4});
%coding for skipping the Header data
for i = 1:3
Header = fgetl(f);
end
%Now next step is to read the Species data whci is provided in 4 lines.
% after every 4 lines there are other species. Total no. of species are 53
% reading and extracting data of first 4 lines
for j = 1:53
L1 = fgetl(f);
L2 = fgetl(f);
L3 = fgetl(f);
L4 = fgetl(f);
%Code for extracting the species name
L11 = strsplit(L1,' ');
S_name = (L11{1});
%using '.' to use and extract number
L11 = strfind(L1,'.');
T11 = L1(L11(1)-3:L11(1)+3);
T12 = L1(L11(2)-4:L11(2)+3);
T13 = L1(L11(3)-4:L11(3)+3);
T1 = str2double(T11); % local min temperature value
T2 = str2double(T12); % Local high temperature value
T3 = str2double(T13); % Local mid value
%unlike above below code is for extracting value of co-effience that will
%be used in the polynomilas to get values for -
%Specific Head, Enthalpy and Entropy for particular species data
% using string finder
L12 = strfind(L2,'E');
L13 = strfind(L3,'E');
L14 = strfind(L4,'E');
a11 = L2(1:L12(1)+3);
a12 = L2(L12(1)+4:L12(2)+3);
a13 = L2(L12(2)+4:L12(3)+3);
a14 = L2(L12(3)+4:L12(4)+3);
a15 = L2(L12(4)+4:L12(5)+3);
a1 = str2double(a11);
a2 = str2double(a12);
a3 = str2double(a13);
a4 = str2double(a14);
a5 = str2double(a15);
a21 = L3(1:L13(1)+3);
a22 = L3(L13(1)+4:L13(2)+3);
a23 = L3(L13(2)+4:L13(3)+3);
a24 = L3(L13(3)+4:L13(4)+3);
a25 = L3(L13(4)+4:L13(5)+3);
a6 = str2double(a21);
a7 = str2double(a22);
a8 = str2double(a23);
a9 = str2double(a24);
a10 = str2double(a25);
a31 = L4(1:L14(1)+3);
a32 = L4(L14(1)+4:L14(2)+3);
a33 = L4(L14(2)+4:L14(3)+3);
a34 = L4(L14(3)+4:L14(4)+3);
a11 = str2double(a31);
a12 = str2double(a32);
a13 = str2double(a33);
a14 = str2double(a34);
% After getting values of 14 co-effcients solving the polynomials by
% substituting the co-effcients values in 2 difference conditions
% 1st be when T4 value is less than Local_mid temp.
R = 8.314;
T4 = linspace(T1,T2,100);
for k = 1:length(T4)
if T4(k)>T3
cp = (a1 + a2.*T4 + a3.*(T4.^2) + a4.*(T4.^3) + a5.*(T4.^4)).*R ;
h = (a1 + a2.*(T4./2)+ a3.*(T4.^2)./3 + a4.*(T4.^3)./4 + a5.*(T4.^4)./5 + a6./T4).*R.*T4;
s = (a1.*log(T4) + a2.*(T4) + a3.*(T4.^2)./2 + a4.*(T4.^3)./3 + a5.*(T4.^4)./4 + a7).*R ;
else
cp = (a8 + a9.*T4 + a10.*(T4.^2) + a11.*(T4.^3) + a12.*(T4.^4)).*R ;
h = (a8 + a9.*(T4./2)+ a10.*(T4.^2)./3 + a11.*(T4.^3)./4 + a12.*(T4.^4)./5 + a13./T4).*R.*T4;
s = (a8.*log(T4) + a9.*(T4) + a10.*(T4.^2)./2 + a11.*(T4.^3)./3 + a12.*(T4.^4)./4 + a14).*R ;
end
% as demanded, we are plooting the graph for
% 1. Specific heat against Temperature
% 2. Enthalpy against Temperature
% 3. Entropy against Temperature
% % Molecular Weight Calculation
elements = ['C','H','A','S','O','N'];
A_Weight = [12 1 40 32 16 14];
M_Weight = 0;
for p = 1:length(S_name)
for q = 1:length(A_Weight)
if strcmp(S_name(p),elements(q))
M_Weight = A_Weight(q) + M_Weight;
u = q;
end
end
n = str2double(S_name(p));
if n > 1
M_Weight = A_Weight(u)*(n-1) + M_Weight;
end
end
mkdir(['C:\Users\Niketan Zode\Documents\MATLAB\NASA Thermo\nik\', S_name]);
figure(1)
plot(T4,cp, 'color','b')
xlabel('Temperature')
ylabel('Specific Heat')
figure(2)
plot(T4,h, 'color','r')
xlabel('Temperature')
ylabel('Enthalpy')
figure(3)
plot(T4,s, 'color','g')
xlabel('Temperature')
ylabel('Entropy')
sprintf('Molecular Weight of %s = %f units', S_name, M_Weight)
location = (['C:\Users\Niketan Zode\Documents\MATLAB\NASA Thermo\nik\', S_name]);
cd(location);
saveas(1,'Specific Heat.jpg');
saveas(2,'Enthalpy.jpg');
saveas(3,'Entropy.jpg');
end
end