Project 1 - Parsing NASA thermodynamic data
Aim:
To write a program that extracts the 14 Coefficient of species and calculates entropy, enthalpy, and specific heat of all species in the data file and plot them. Calculate the molecular weight of each species.
Objective:
To write a program that extracts the 14 coefficients of all species and Calculates, and plots entropy, enthalpy, and specific heat of all species.
To calculate the molecular weight of all species and display it command window
To save the plots as images with appropriate names and dumb all the species in a separate folder with a suitable names.
Introduction:
Parsing:
Parsing a file means reading in a data stream and building a memory model of the content of that data. This aims at facilitating performing some kind of transformation on the data. Parsing splits a file or other input into pieces of data that can be easily stored or manipulated.
calculation of entropy, enthalpy and specific heat of all species
This is the formula that calculates the Specific heat, Entropy, and Enthalpy for all species,
Program:
The program that extracts the 14 co-efficients of all species
clear all
close all
clc
%Open the required given file and reading
f1=fopen('THERMO.dat','r');
l1=fgetl(f1); % first headerline of the file and skip line
tl2=fgetl(f1); % Global temperature values
A=strsplit(tl2,' '); % split the temp values and change to number
global_low_temp=str2num(A{2});
global_mid_temp=str2num(A{3});
global_high_temp=str2num(A{4});
l3=fgetl(f1); % l3,l4 & l5 are Comments, so to be negligible these line
l4=fgetl(f1);
l5=fgetl(f1);
%Create a loop for calculating total species
%lets take first species 'O' in the given data
for k=1:53
st1=fgetl(f1); % In species given Local Temperature
st1=strsplit(st1,' '); %split the local temperature change to number
species_name=st1{1};
local_low_temp=str2num(st1{end-3});% Local low temperature
local_mid_temp=str2num(st1{end-2});% Local mid temperature
local_high_temp=str2num(st1{end-1});% Local low temperature
sl1=fgetl(f1); % First line co efficients of Species
sy1=strfind(sl1,'E'); % Have to find E where to be placed for using split the coefficients
%Changing coeficients of the species string into number
%Changing first line coefficients to number
a1=str2double(sl1(1:sy1(1)+3));
a2=str2num(sl1(sy1(1)+4:sy1(2)+3));
a3=str2num(sl1(sy1(2)+4:sy1(3)+3));
a4=str2num(sl1(sy1(3)+4:sy1(4)+3));
a5=str2num(sl1(sy1(4)+4:sy1(5)+3));
%Changing second line coefficients to number
sl2=fgetl(f1);
sy2=strfind(sl2,'E');
a6=str2num(sl2(1:sy2(1)+3));
a7=str2num(sl2(sy2(1)+4:sy2(2)+3));
a8=str2num(sl2(sy2(2)+4:sy2(3)+3));
a9=str2num(sl2(sy2(3)+4:sy2(4)+3));
a10=str2num(sl2(sy2(4)+4:sy2(5)+3));
%Changing third line coefficients to number
sl3=fgetl(f1);
sy3=strfind(sl3,'E');
a11=str2num(sl3(1:sy3(1)+3));
a12=str2num(sl3(sy3(1)+4:sy3(2)+3));
a13=str2num(sl3(sy3(2)+4:sy3(3)+3));
a14=str2num(sl3(sy3(3)+4:sy3(4)+3));
% Calculating Specific heat(Cp), Entropy(S)and Enthalpy(H) with using Local
% temperatures
temp=linspace(local_low_temp,local_high_temp,100);
R=8.3145; % Universal gas constant (R) unit is Joule/mole.kelvin
%using for loop to calculate properties of upper and lower temperature
for i=1:length(temp)
if temp(i)>local_mid_temp
Cp(i)=R*(a1+(a2*temp(i))+(a3.*temp(i).^2)+(a4.*temp(i).^3)+(a5.*temp(i).^4));
H(i)=R.*temp(i)*(a1+((a2.*temp(i))/2)+((a3.*temp(i).^2)/3)+((a4.*temp(i).^3)/4)+((a5.*temp(i).^4)/5)+(a6./temp(i)));
S(i)=R*(a1.*log(temp(i))+a2.*temp(i)+((a3.*temp(i).^2)/2)+((a4.*temp(i).^3)/3)+((a5.*temp(i).^4)/4)+a7);
else
Cp(i)=R*(a8+(a9.*temp(i))+(a10.*temp(i).^2)+(a11.*temp(i).^3)+(a12.*temp(i).^4));
H(i)=R.*temp(i).*(a8+((a9.*temp((i)))/2)+((a10.*temp(i).^2)/3)+((a11.*temp(i).^3)/4)+((a12.*temp(i).^4)/5)+(a13./temp(i)));
S(i)=R*(a8.*log(temp(i))+a9.*temp(i)+((a10.*temp(i).^2)/2)+((a11.*temp(i).^3)/3)+((a12.*temp(i).^4)/4)+a14);
end
end
%Plotting Temperature with Specific Heat of species 'O'
figure(1)
plot(temp,Cp,'linewidth',2,'Color','r');
xlabel('Temperature');
ylabel('Specific Heat');
title('Temperature vs Specific Heat');
grid on
%Plotting Temperature with Enthalpy of species 'O'
figure(2)
plot(temp,H,'linewidth',2,'Color','g');
xlabel('Temperature');
ylabel('Enthalpy');
title('Temperature vs Enthalpy');
grid on
%Plotting Temperature with Entropy of species 'O'
figure(3)
plot(temp,S,'linewidth',2,'Color','b');
xlabel('Temperature');
ylabel('Entropy');
title('Temperature vs Entropy');
grid on
% creating folder to save the plots of species
mkdir(['File_parsing\',species_name]);
cd(['File_parsing\',species_name]);
saveas(1,'Specific heat','png');
saveas(2,'Enthalpy','png');
saveas(3,'Entropy','png');
cd ..
cd ..
% Function to calculating molecular mass of each species
mm=Molecular_weight(species_name);
s=sprintf('%sMolecular_weight=%f',species_name,mm);
disp(s);
end
fclose(f1);
Explanation:
- In this program first, we have to open the given file (NASA thermodynamic data) by using fopen command and its takes in a variable f1.then have to extract and skip the unneeded lines such as the header which is given in the file by using fgetl command.
- Then we have to split the global temperatures into the string and change to number by the str2num command. after having to split the next three lines that we do not need to refer to in this program.
- let's move from the 6 th line, there are 53 species in the file, that's we have to extract and calculate the specific heat, entropy, and enthalpy for all species. let's take the first species 'O' to extract each coefficient and calculate the thermodynamic properties and it is all calculated under the for a loop because we have to calculate for all 53 species.
- In the first line of the species, take the temperatures that are called local temperatures. to split the temperature as low, mid and high in the string and change to number, then extract each coefficient by line by line using fgetl and findstr (which used to find string 'E' in the line) and change all 14 coefficients to number.
Below is a program that calculates thermodynamic properties such as Specific heat, Entropy, and Enthalpy for Species:
% Calculating Specific heat(Cp), Entropy(S)and Enthalpy(H) with using Local
% temperatures
temp=linspace(local_low_temp,local_high_temp,100);
R=8.3145; % Universal gas constant (R) unit is Joule/mole.kelvin
%using for loop to calculate properties of upper and lower temperature
for i=1:length(temp)
if temp(i)>local_mid_temp
Cp(i)=R*(a1+(a2*temp(i))+(a3.*temp(i).^2)+(a4.*temp(i).^3)+(a5.*temp(i).^4));
H(i)=R.*temp(i)*(a1+((a2.*temp(i))/2)+((a3.*temp(i).^2)/3)+((a4.*temp(i).^3)/4)+((a5.*temp(i).^4)/5)+(a6./temp(i)));
S(i)=R*(a1.*log(temp(i))+a2.*temp(i)+((a3.*temp(i).^2)/2)+((a4.*temp(i).^3)/3)+((a5.*temp(i).^4)/4)+a7);
else
Cp(i)=R*(a8+(a9.*temp(i))+(a10.*temp(i).^2)+(a11.*temp(i).^3)+(a12.*temp(i).^4));
H(i)=R.*temp(i).*(a8+((a9.*temp((i)))/2)+((a10.*temp(i).^2)/3)+((a11.*temp(i).^3)/4)+((a12.*temp(i).^4)/5)+(a13./temp(i)));
S(i)=R*(a8.*log(temp(i))+a9.*temp(i)+((a10.*temp(i).^2)/2)+((a11.*temp(i).^3)/3)+((a12.*temp(i).^4)/4)+a14);
end
end
- In the program, we have to calculate the thermodynamics properties of each species. first, we take the temperate values from low to high using linspace and write the universal gas constant value.
- Then we determine the formula in the loop for calculating each temperature value and using the if condition to find properties in low and high temperatures and plot the specific heat, enthalpy, and entropy with temperatures.
Program to save plots of all species in a separate folder:
% creating folder to save the plots of species
mkdir(['File_parsing\',species_name]);
cd(['File_parsing\',species_name]);
saveas(1,'Specific heat','png');
saveas(2,'Enthalpy','png');
saveas(3,'Entropy','png');
cd ..
cd ..
Results:
Calculated the molecular weights of all species:
Plots:
Below shown some sample plots which calculate the thermodynamic properties of species.
Plots of 'O':
PLots of 'N'
PLots of 'OH'
In the below figure shown we saved all plots of thermodynamic properties of 53 species in a separate folder.
