Project 1 - Parsing NASA thermodynamic data
PARSING NASA THERMODYNAMIC DATA
AIM :
The program in matlab to calculate the parsing NASA thermodynamic data.
PROCEDURE :
The file parsing is a method of spliting the data with their own analysis, it is a method of taking the content of a file.
Steps to program,
- Analyse the given data, then for open the data into the matlab with fopen command.
- To read the data line by line use fgetl command. then to change the string to number i used str2num command.
- In this program i used local temperature instead of global temperature. also for spliting the string i used strsplit command. bt using the linspace command calculate the coefficient from low to high temperature.
- To find the string which is common to all coefficient use findstr command. by using the string between the coefficient we can seperate it for high & low temp coefficient.
- here we are calculating the specific heat(cp), entropy(S) & enthalpy(H) with the 14 coefficient for all species.
- Plot the cp, H & S with the temperature and also save the graph in the respectable folder, for saving the graph use cd, mkdir commands.
- After plotting find the molecular weight of each species here i used strcmp command which compare the 2 string for equality.
- strcmp command will only return true if every character of both strings is the same & same length also i use %s (which denotes the character variable) and %d (which prints the integer).
- complete the above process cycle for every species by using for loop.
Formula used,
Program code,
clear all
close all
clc
% reading_thermodynamic_data
t = fopen('thermo.dat','r');
% skip_header
fgetl(t);
fgetl(t);
% comment_skip
fgetl(t);
fgetl(t);
fgetl(t);
for i = 1:53
species = fgetl(t);
split = strsplit(species,' ');
species_name = species(1:6);
% local_temperature
l_temp_low = str2num(split{length(split)-3});
l_temp_med = str2num(split{length(split)-1});
l_temp_high = str2num(split{length(split)-2});
T = linspace(l_temp_low,l_temp_high,100);
% universal_gas_constant(R)j*mol^-1*K^-1
R = 8.3145;
% coefficient
l1 = fgetl(t);
l2 = fgetl(t);
l3 = fgetl(t);
% locating_the_string_between_the_coefficient
a = findstr(l1,'E');
b = findstr(l2,'E');
c = findstr(l3,'E');
% high_temp_coefficient
x1 = str2num(l1(1:a(1)+3));
x2 = str2num(l1(a(1)+4:a(2)+3));
x3 = str2num(l1(a(2)+4:a(3)+3));
x4 = str2num(l1(a(3)+4:a(4)+3));
x5 = str2num(l1(a(4)+4:a(5)+3));
x6 = str2num(l2(1:b(1)+3));
x7 = str2num(l2(b(1)+4:b(2)+3));
% low_temp_coeffocient
y1 = str2num(l2(b(2)+4:b(3)+3));
y2 = str2num(l2(b(3)+4:b(4)+3));
y3 = str2num(l2(b(4)+4:b(5)+3));
y4 = str2num(l3(1:c(1)+3));
y5 = str2num(l3(c(1)+4:c(2)+3));
y6 = str2num(l3(c(2)+4:c(3)+3));
y7 = str2num(l3(c(3)+4:c(4)+3));
% specific_heat,ehthalpy,entropy
for i = 1:length(T)
if T(i) > l_temp_med
cp = (x1 + x2*T + x3*T.^2 + x4*T.^3 + x5*T.^4)*R;
H = (x1 + x2.*(T/2) + x3.*(T.^2/3) + x4.*(T.^3/4) + x5.*(T.^4/5) + x6./T).*R.*T;
S = (x1*log(T) + x2*T + x3.*(T.^2/2) + x4.*(T.^3/3) + x5.*(T.^4/4) + x7)*R;
else
cp = (y1 + y2*T + y3*T.^2 + y4*T.^3 + y5*T.^4)*R;
H = (y1 + y2.*(T/2) + y3.*(T.^2/3) + y4.*(T.^3/4) + y5.*(T.^4/5) + y6./T).*R.*T;
S = (y1*log(T) + y2*T + y3.*(T.^2/2) + y4.*(T.^3/3) + y5.*(T.^4/4) + y7)*R;
end
end
cd(pwd)
directory = char(species_name)
p = sprintf('%s',directory)
mkdir(directory)
cd(directory)
% plotting
% specific_heat(cp)
figure(1)
plot(T,cp,'color','g')
t1 = sprintf('specific heat for : %s',species_name);
title(t1)
xlabel('temperature[k]')
ylabel('specific heat[cp]')
saveas(1,'specific_heat.png')
% enthalpy(H)
figure(2)
plot(T,H,'color','r')
t2 = sprintf('enthalpy for : %s',species_name);
title(t2)
xlabel('temperature[k]')
ylabel('enthalpy[H]')
saveas(2,'enthalpy.png')
% entropy
figure(3)
plot(T,S,'color','b')
t3 = sprintf('entropy for : %s',species_name);
title(t3)
xlabel('temperature[k]')
ylabel('entropy[S]')
saveas(3,'entropy.png')
cd ..
% molecular_weight
elements = ['H','C','O','N','A'];
atomic_weight = [1.0079,12.0107,15.999,14.0067,39.948];
mol_w = 0;
for l = 1:length(species_name)
for m = 1:length(atomic_weight)
if strcmp(species_name(1),elements(m))
mol_w = mol_w + atomic_weight(m);
position = m;
end
end
n = str2double(species_name(1));
if n > 1
mol_w = mol_w + atomic_weight(position)*(n-1);
end
end
sprintf('molecular weight of %s is: %d',species_name,mol_w)
end
RESULTS :
for O2,
for N2,
for CO2,
CONCLUSION :
Thus the program in matlab to calculate the parsing NASA thermodynamic data is concluded sucessfully.