Project 1 - Parsing NASA thermodynamic data
Project Title: Parsing NASA thermodynamic data
Objective: Read .dat file in MatLab
2. Create the code for calculating the specific heat enthalpy and entropy etc.
code
clear all
close all
clc
f = fopen('thermo.dat','r') %ll thermo,dat file
l1 = fgetl(f); % give name to 1st line of file
l2 = fgetl(f); % give name to 2nd line of file
l3 = fgetl(f); % give name to 3rd line of file
l4 = fgetl(f); % give name to 4th line of file
l5 = fgetl(f); % give name to 5th line of file
tr = strsplit(l2,' '); % Splite the line at space
glt = str2double(tr{2}); % Extract globle lower temp
gmt = str2double(tr{3}); % Extract globle middle temp
ght = str2double(tr{4}); % Extract globle high temp
for i = 1:53 % for different spacies
l6 = fgetl(f); %give name to 6th line of file
s = strsplit(l6,' '); % Splite the line at space
species_name = s(1); % Extract spacies name
z = length(s); % Find out size of s
llt = str2double(s{z-3}); % Extract local lower temp
lht = str2double(s{z-2}); % Extract local high temp
lmt = str2double(s{z-1}); % Extract local middle temp
T = linspace(llt,lht,500); % Temp range
R = 8.314; % Universal gas constant
line1 = fgetl(f);
line2 = fgetl(f);
line3 = fgetl(f);
A = strfind(line1,'E'); % Separating the coefifirnt fron each other
B = strfind(line1,'E'); % Separating the coefifirnt fron each other
C = strfind(line1,'E'); % Separating the coefifirnt fron each other
a1 = str2double(line1(1:A(1)+3)); % giving the name to the coefficients
a2 = str2double(line1(A(1)+4:A(2)+3)); % giving the name to the coefficients
a3 = str2double(line1(A(2)+4:A(3)+3)); % giving the name to the coefficients
a4 = str2double(line1(A(3)+4:A(4)+3)); % giving the name to the coefficients
a5 = str2double(line1(A(4)+4:A(5)+3)); % giving the name to the coefficients
a6 = str2double(line2(1:B(1)+3)); % giving the name to the coefficients
a7 = str2double(line2(B(1)+4:B(2)+3)); % giving the name to the coefficients
b1 = str2double(line2(B(2)+4:B(3)+3)); % giving the name to the coefficients
b2 = str2double(line2(B(3)+4:B(4)+3)); % giving the name to the coefficients
b3 = str2double(line2(B(4)+4:B(5)+3)); % giving the name to the coefficients
b4 = str2double(line2(1:C(1)+3)); % giving the name to the coefficients
b5 = str2double(line2(C(1)+4:C(2)+3)); % giving the name to the coefficients
b6 = str2double(line2(C(2)+4:C(3)+3)); % giving the name to the coefficients
b7 = str2double(line2(C(3)+4:C(4)+3)); % giving the name to the coefficients
cp = specific_heat(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,T,R,lmt); % clculating specific heat
h = enthalpy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,T,R,lmt); %lculating enthalphy
s = entropy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,T,R,lmt); %lculating entropy
% ploting command
figure(1)
plot(T,h,'linewidth',3,'color','b')
title(species_name)
xlabel('temperature')
ylabel('enthalpy')
figure(2)
plot(T,cp,'linewidth',3,'color','r')
title(species_name)
xlabel('temperature')
ylabel('specific_heat')
figure(3)
plot(T,s,'linewidth',3,'color','g')
title(species_name)
xlabel('temperature')
ylabel('entropy')
end
the code calculates entropy enthalpy and specific heat for different species available in thermo.dat file.
Code explanation mention in programme with % sign in front of code
this is the formula I used to calculate the variable.
Specific heat function
function cp=specific_heat(a1,a2,a3,a4,a5,~,~,b1,b2,b3,b4,b5,~,~,T,R,lmt)
for i = 1:length(T)
if T(i) >lmt
cp = R.*(a1+a2.^T+a3.*T.^2+a4.*T.^3+a5.*T.^4);
else
cp = R.*(b1+b2.^T+b3.*T.^2+b4.*T.^3+b5.*T.^4);
end
end
end
this function is used to calculate the Specific heat values for various gas species
in this if a temp is less than lmt then first cp formula is used and if not then use the second formula.
Enthalpy function
function h=enthalpy(a1,a2,a3,a4,a5,a6,~,b1,b2,b3,b4,b5,b6,~,T,R,lmt)
for i = 1:length(T)
if T(i) >=lmt
h=R.*(a1.*T+(a2.*T.^2)./2+(a3.*T.^3)./3+(a4.*T.^4)./4+(a5.*T.^5)./5+a6);
else
h=R.*(b1.*T+(b2.*T.^2)./2+(b3.*T.^3)./3+(b4.*T.^4)./4+(b5.*T.^5)./5+b6);
end
end
end
this function is used to calculate the enthalpy values for various gas species
Entropy function
function s=entropy(a1,a2,a3,a4,a5,~,a7,b1,b2,b3,b4,b5,~,b7,T,R,lmt)
for i = 1:length(T)
if T(i)>=lmt
s = R.*(a1.*log(T)+(a2.*T)+(a3.*T.^2)/2+(a4.*T.^3)/3+(a5.*T.^4)/4+a7);
else
s = R.*(b1.*log(T)+(b2.*T)+(b3.*T.^2)/2+(b4.*T.^3)/3+(b5.*T.^4)/4+b7);
end
end
end
This function calculates entropy for various gas species
Output
Enthalpy vs temperature plot for CH2CHO gas species
Specific Heat vs temperature plot for CH2CHO gas species
Entropy vs temperature plot for CH2CHO gas species
Enthalpy vs temperature plot for O gas species
Entropy vs temperature plot for O gas species