Project 1 - Parsing NASA thermodynamic data
clear all
close all
clc
% Load the given file
f1 = fopen('THERMO.dat','r');
% Skip 1st Line
skip_1 = fgetl(f1);
% Get 2nd line of Global temperature range
gt_range = fgetl(f1);
% Split the Global Temperatures
GT = strsplit(gt_range,' ');
% In a Global Temperature cell array 1st cell contains no values.
% Low Global Temperature
GT_low = str2double(GT{2});
% Medium Global Temperature
GT_med = str2double(GT{3});
% High Global Temperature
GT_high = str2double(GT{4});
% Skip 3rd,4th,5th lines
for i = 1:3
fgetl(f1);
end
% Calculation of Cp, H(Enthalphy) and S(Entrophy) for given 53 Species
% Species = 53;
species = 53;
for j = 1:species
% Local temperature ranges are given in first line for every species
L1 = fgetl(f1);
S = strsplit(L1,' ');
Species_name{j} = S{1};
G = strfind(L1,'G');
local_temp = L1(G+4:end);
LT = strsplit(local_temp,' ');
LT1(j) = str2double(LT{1});
LT2(j) = str2double(LT{2});
LT3(j) = str2double(LT{3});
% 14 Co-efficients for each Species
% Second line contains 5 co-efficients
L2 = fgetl(f1);
E = strfind(L2,'E');
C_01(j) = str2double(L2(1:E(1)+3));
C_02(j) = str2double(L2(E(1)+4:E(2)+3));
C_03(j) = str2double(L2(E(2)+4:E(3)+3));
C_04(j) = str2double(L2(E(3)+4:E(4)+3));
C_05(j) = str2double(L2(E(4)+4:E(5)+3));
% Third line contains 5 co-efficients
L3 = fgetl(f1);
E = strfind(L3,'E');
C_06(j) = str2double(L3(1:E(1)+3));
C_07(j) = str2double(L3(E(1)+4:E(2)+3));
C_08(j) = str2double(L3(E(2)+4:E(3)+3));
C_09(j) = str2double(L3(E(3)+4:E(4)+3));
C_10(j) = str2double(L3(E(4)+4:E(5)+3));
% Fourth line contains 4 co-efficients
L4 = fgetl(f1);
E = strfind(L4,'E');
C_11(j) = str2double(L4(1:E(1)+3));
C_12(j) = str2double(L4(E(1)+4:E(2)+3));
C_13(j) = str2double(L4(E(2)+4:E(3)+3));
C_14(j) = str2double(L4(E(3)+4:E(4)+3));
% Creating a New folder and Sub-folders
mkdir ('Species',Species_name{j});
% To Find the Local Temperature Range
T_min(j) = LT1(j);
T_max(j) = LT2(j);
T_range = linspace(T_min(j),T_max(j),100);
% Calculation of Specific heat(Cp), Enthalphy(H) and Entrophy(S) for all 53 Species
Cp = specific_heat(C_01(j),C_02(j),C_03(j),C_04(j),C_05(j),C_08(j),C_09(j),C_10(j),C_11(j),C_12(j),T_range,LT3(j));
H = enthalphy(C_01(j),C_02(j),C_03(j),C_04(j),C_05(j),C_06(j),C_08(j),C_09(j),C_10(j),C_11(j),C_12(j),C_13(j),T_range,LT3(j));
S = entrophy(C_01(j),C_02(j),C_03(j),C_04(j),C_05(j),C_07(j),C_08(j),C_09(j),C_10(j),C_11(j),C_12(j),C_14(j),T_range,LT3(j));
% Plotting
% Plot between Specific heat and Temperature
figure(1);
plot(T_range,Cp,'linewidth',3,'color','r');
xlabel('Temperature');
ylabel('Specific heat');
title('Specific heat Vs Temperature for',Species_name{j});
% Plot between Enthalphy and Temperature
figure(2);
plot(T_range,H,'linewidth',3,'color','b');
xlabel('Temperature');
ylabel('Enthalphy');
title('Enthalphy Vs Temperature for',Species_name{j});
% Plot between Entrophy and Temperature
figure(3);
plot(T_range,S,'linewidth',3,'color','g');
xlabel('Temperature');
ylabel('Entrophy');
title('Entrophy Vs Temperature for',Species_name{j});
% Save the Plots of each species in specified folders.
cd 'D:\MATLAB\RUNNING\File parsing\Species';
path = cd(Species_name{j});
saveas(figure(1),'Plot between Specific heat and Temperature.jpg');
saveas(figure(2),'Plot between Enthalphy and Temperature.jpg');
saveas(figure(3),'Plot between Entrophy and Temperature.jpg');
cd 'D:\MATLAB\RUNNING\File parsing';
% Calculation of Molecular Weight
M = mol_wt(Species_name{j});
% Printing the values of each Species
fprintf('%s Molecular Weight = %d\n',Species_name{j},M);
end
function Cp = specific_heat(C_01,C_02,C_03,C_04,C_05,C_08,C_09,C_10,C_11,C_12,T_range,LT3)
% Here 'R' is the Universal Gas constant
R = 8.314;
% Here T_range is the Local temperature range
if (T_range>LT3)
% First 7 co-efficients are High temperature co-efficients
Cp = R*(C_01+(C_02.*T_range)+(C_03.*(T_range.^2))+(C_04.*(T_range.^3))+(C_05.*(T_range.^4)));
else
% Second 7 co-efficients are low temperature co-efficients
Cp = R*(C_08+(C_09.*(T_range))+(C_10.*(T_range.^2))+(C_11.*(T_range.^3)+(C_12.*T_range.^4)));
end
function H = enthalphy(C_01,C_02,C_03,C_04,C_05,C_06,C_08,C_09,C_10,C_11,C_12,C_13,T_range,LT3)
% Here 'R' is the Universal Gas constant
R = 8.314;
% Here T_range is the Local temperature range
if (T_range>LT3)
% First 7 co-efficients are High temperature co-efficients
H = (C_01+(C_02.*(T_range)/2)+(C_03.*(T_range.^2)/3)+(C_04.*(T_range.^3)/4)+(C_05.*(T_range.^4)/5)+(C_06./(T_range))).*T_range*R;
else
% Second 7 co-efficients are low temperature co-efficients
H = (C_08+(C_09.*(T_range)/2)+(C_10.*(T_range.^2)/3)+(C_11.*(T_range.^3)/4)+(C_12.*(T_range.^4)/5)+(C_13./(T_range))).*T_range*R;
end
function S = entrophy(C_01,C_02,C_03,C_04,C_05,C_07,C_08,C_09,C_10,C_11,C_12,C_14,T_range,LT3)
% Here 'R' is the Universal Gas constant
R = 8.314;
% Here T_range is the Local temperature range
if (T_range>LT3)
% First 7 co-efficients are High temperature co-efficients
S = ((C_01.*log(T_range))+(C_02.*T_range)+(C_03.*(T_range.^2)/2)+(C_04.*(T_range.^3)/3)+(C_05.*(T_range.^4)/4)+C_07)*R;
else
% Second 7 co-efficients are low temperature co-efficients
S = ((C_08.*log(T_range))+(C_09.*T_range)+(C_10.*(T_range.^2)/2)+(C_11.*(T_range.^3)/3)+(C_12.*(T_range.^4)/4)+C_14)*R;
end
function M = mol_wt(Species_name)
% Here is the gas names
gases = ['O','H','C','N','A'];
% Atomic mass for the each gases given above
atm_mass = [15.999,1.00784,12.011,14.0067,39.948];
% Initial Condition
M = 0;
% First loop contains All species given in NASA Thermo.dat file
for i = 1:length(Species_name)
% Second loop contains gases mentioned above
for j = 1:length(gases)
% Compare the given Species with gases
cp = strcmpi(Species_name(i),gases(j));
% Check whether it is equal or not.
if (cp ==1)
% If they are equal, then it add with atomic mass
M = M + atm_mass(j);
% Then value of 'j' is assigned for variable 'a'
a = j;
end
end
% Convert the Species name from string to double
% In other way it finds how many molecules present in the each Species
b = str2double(Species_name(i));
% If 'b' contains values of greater than 1, given condition is executed
if (b>1)
M = M+(atm_mass(a)*(b-1));
end
end
end
https://drive.google.com/file/d/13irNSwIOgI9V6sfS8uaoH7TPho09Y1KU/view?usp=drivesdk
https://drive.google.com/file/d/13XFWQCCm6K4DQKmPX4-EwtD3hPlB5SXu/view?usp=drivesdk
https://drive.google.com/file/d/139mjOyU5tWOJ5GLhAb8tPpCF97xeJaN8/view?usp=drivesdk
https://drive.google.com/file/d/13LfQCfmcwgUnHof_jZZ1UjoZnK5Vzxhn/view?usp=drivesdk
https://drive.google.com/file/d/13VpYEMUb8hQG_NShbxFOanNExyvWZ5cf/view?usp=drivesdk











