Project 1 - Parsing NASA thermodynamic data
PROJECT :- To write a program to parse the NASA thermodynamic and calculate the thermodyanami properties
of various species using MatLab.
THEORY :-
1.File parsing :- Parsing a file means reading in data stream anf building a memory model of the contentof
the data. This aims at facilitating perfoming some kind of transformation on the data. Parsing splits a file
or otherinput into pieces of data that can be easily stored or manipulated.
2.NASA thermodynamic file :-This file contains '14' coefficient and '53' different element given by Nasa, The
coefficient are used to calculate entropy,enthalpy, specificheat for a particular element and each have
their own range and temprature.
3. Entropy :- the measure of a system’s thermal energy per unit temperature that is unavailable for doing
useful work. Because work is obtained from ordered molecular motion, the amount of entroppy is also a
measure of the molecular disorder, or randomness, of a system,Using the symbol s .
4. Enthalpy :- Enthalpy which is defined to be the sum of the internal energy plus the product of
the pressure p and volume V. Using the symbol H for the enthalpy
5. Specific heat :- It is the amount of energy the must be added in the form of heat to one unite to mass
of the subsitute in order to cause an increse of one unite in its temperature.
The NASA polynomials given as follow as,
`(Cp)/R = a1+a2T+a3T^2+a4T^3+a5T^4`
`H/RT = a1 + (a2T)/2 + (a3T^2)/3+(a4T^3)/4 +(a5T^4)/5+a6/T`
`S/R = a1lnT + a2T + (a3T^2)/2+(a4T^3)/4+(a5T^4)/4+a7`
MAIN CODE :-
clear all
close all
clc
% Make directory
mkdir 'C:\Users\Smrutismarak Nayak\Dropbox\PC\Desktop\matlab'
% Reading Data file - NASA Thermodynamic
% Open a file & 'r' Open the file for reading
f1=fopen('THERMO.dat','r')
gt=fgetl(f1);
%Obtaing Tempratures - by Reading haader Info
global_temp = fgetl(f1);
% Spliting
t = strsplit(global_temp);
% Converting string cell to numbers using str2num,
global_low_temp = str2num(t{2});
global_medium_temp = str2num(t{3});
global_high_temp = str2num(t{4});
% Temprature range & Gas Constant
% Temprature range assumed
Temp = linspace(global_low_temp,global_high_temp,1000);
% Universal gas Constant J/(mol-k)
R = 8.314;
% skipping three comment lines in the file
for i = 1:3
gt = fgetl(f1);
end
for i = 1:53
gt = fgetl(f1);
A =strsplit(gt,' ');
Species_Sp =(A{1})
line_1=fgetl(f1);
a = strfind(line_1,'E');
% Extracting higher and lower temprature coefficients
% % Extracting First 7 coefficient (High-temprature coefficient)
%1
a1 = line_1(1:a(1)+3);
a1 = str2num(a1);
%2
a2 = line_1(a(1)+4:a(2)+3);
a2 = str2num(a2);
%3
a3 = line_1(a(2)+4:a(3)+3);
a3 = str2num(a3);
%4
a4 = line_1(a(3)+4:a(4)+3);
a4 = str2num(a4);
%5
a5 = line_1(a(4)+4:a(5)+3);
a5 = str2num(a5);
line_2= fgetl(f1)
b = strfind(line_1,'E');
%6
a6 = line_2(1:b(1)+3);
a6 = str2num(a6);
%7
a7 = line_2(a(1)+4:b(2)+3);
a7 = str2num(a7);
%Extracting second 7 coefficient - Low-temprature coefficient
%8
a8 = line_2(b(2)+4:b(3)+3);
a8 = str2num(a8);
%9
a9 = line_2(b(3)+4:b(4)+3);
a9 = str2num(a9);
%10
a10 = line_2(b(4)+4:b(5)+3);
a10 = str2num(a10);
line_3 = fgetl(f1)
c = strfind(line_1,'E');
%11
a11 = line_3(1:c(1)+3);
a11 = str2num(a11);
%12
a12 = line_3(c(1)+4:c(2)+3);
a12 = str2num(a12);
%13
a13 = line_3(c(2)+4:c(3)+3);
a13 = str2num(a13);
%14
a14 = line_3(c(3)+4:c(4)+3);
a14 = str2num(a14);
%Specific heat calculation
Cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,Temp,R,global_medium_temp);
%Enthalpy calculation
H = Enthalpy_func(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,Temp,R,global_medium_temp)
%Entropy calculation
S = Entropy_func(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,Temp,R,global_medium_temp)
%Calculating molecular weight of species
Molecularweight(i) = Molecular_weight(Species_Sp)
%Read & write Molecular list
Molecular_list = fopen('Molecular weight.txt','a+');
fprintf(Molecular_list,'Molecular weight of %s is %d n',Species_Sp,Molecularweight);
fclose(Molecular_list)
%ploting(CP,H,S,Temp,Species_Sp)
%saving as a folder
cur_dir = pwd;
mkdir(Species_Sp);
cd(Species_Sp);
%Plot 1, Specific heat(cp) vs Temprature range(Temp)
figure(1)
plot(Temp,Cp,'LineWidth',2,'Color','r')
xlabel('Temprature [k]');
ylabel('Specific Heat[KJ]');
title(sprintf('varying Specific Heat with Temprature Range of %s',Species_Sp));
grid on
saveas(figure(1),'Specific Heat.jpg');
%Plot 2, Enthalpy (H) vs Temprature range(Temp)
figure(2)
plot(Temp,H,'LineWidth',2,'Color','b')
xlabel('Temprature [k]');
ylabel('Enthalpy[KJ/(mol)]');
title(sprintf('varying Enthalpy with Temprature Range of %s',Species_Sp));
grid on
saveas(figure(2),'Enthalpy.jpg');
%Plot 3, Entropy (s) vs Temprature range(Temp)
figure(3)
plot(Temp,S,'LineWidth',2,'Color','g')
xlabel('Temprature [k]');
ylabel('Entropy[KJ/(mol)]');
title(sprintf('varying Entropy with Temprature Range of %s',Species_Sp));
grid on
saveas(figure(3),'Entropy.jpg');
cd(cur_dir);
%Molecular weight
M = Molecular_weight(Species_Sp)
f2 = fopen('molecular mass','w');
fprintf('%s n %s n %f n','species','Molecular mass',M)
fclose(f2)
end
CODE EXPLANATION AND SYNTAX USED IN THE CODE :-
1. Using 'clear all','close all','clc' to clear variable in workspace ,plots and comand window respectivly
2.'mkdir' function to make directory.
3.Then we are using 'fopen' to open the thermo data file.
4. To read the file we are using 'fget'.
5. Using 'star2num' for coverting sting cell to number.
6.Using for and end loop to skip the next three comment line in the textfile.
7.'strfind' to find string.
8.Using linspace comand to give the range form high to low.
9.'Pwd' for identify current directory.
10.'cd' change working directory.
CODE FOR FUNCTIONS :-
1.Specific Heat
%Specific heat calculation function
function Cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,Temp,R,global_medium_temp)
%comparing with global temparature
%If less than global temprature - minimum coefficients are taken
if Temp <= global_medium_temp
cp = R*(a8+(a9*Temp)+(a10*(Temp).^2)+(a11*(Temp).^3)+(a12*(Temp).^4));
else
Cp = R*(a1+(a2*Temp)+(a3*(Temp).^2)+(a4*(Temp).^3)+(a5*(Temp).^4));
%else maximum coefficients are taken
end
2.Entropy
%Entropy Function
function S = Entropy_func(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,Temp,R,global_medium_temp)
%comparing with global temparature
%If less than global temprature - minimum coefficients are taken
if Temp <= global_medium_temp
S = R.*(a8.*log(Temp)+(a9.*Temp)+(a10*((Temp).^2)/2)+(a11*((Temp).^3)/3)+(a12((Temp).^4)/4)+a14);
else
%else maximum coefficients are taken
S = R.*(a1.*log(Temp)+(a2.*Temp)+(a3*((Temp).^2)/2)+(a4*((Temp).^3)/3)+(a5*((Temp).^4)/4)+a7);
end
3.Enthalpy
%Enthalpy function
function H = Enthalpy_func(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,Temp,R,global_medium_temp)
%Comparing with global Temprature
%If less than global temprature - minimum coefficients are taken
if Temp <= global_medium_temp
S = R*Temp.*(a8+(a9*Temp/2)+((a10*(Temp).^2)/3)+((a11*(Temp).^3)/4)+((a12*(Temp).^4)/5)+((a13./Temp)));
else
%else maximum coefficients are taken
H = R*Temp.*(a1+((a2*Temp)/2)+((a3*(Temp).^2)/3)+((a4*(Temp).^3)/4)+((a5*(Temp).^4)/5)+((a6./Temp)));
end
4.Molecular weight
% Molecular weight Calculation function
function Molecularweight = Molecular_weight(Species_Sp)
% Standard-Atomic Name
atomic_names = ['H','C','O','N','A'];
% Hydrogen , Carbon , Oxygen , Nitrogen , Argon
fprintf('Molecular weight of');
fprintf(Species_Sp);
fprintf(' : ');
%Standard Atomic Number
Atomic_Weight = [1.008 12.011 15.999 14.007 39.948];
% Standard Range of Molecule
Molecularweight = 0;
%Adding Atomic number to obtain paticular value
for i = 1:length(Species_Sp)
for j = 1:length(atomic_names)
if strcmpi(Species_Sp(i),atomic_names(j))
Molecularweight = Molecularweight + Atomic_Weight(j);
position = j;
end
end
n = str2num(Species_Sp(i));
if n>1
Molecularweight = Molecularweight + Atomic_Weight(position)*(n-1);
end
end
fprintf('molecular weight %s :',Species_Sp)
fprintf('%d',Molecularweight);
disp('');
end
Results :-
Specific Heat,entropy,enthalpy plot for O2,N2,Co2 species,
specific heat with temperature of O2 plot :-

Entropy with temperature of O2 plot :-

Enthapy with temperature of O2 plot :-

specific heat with temperature of N2 plot:-

Entropy with temperature of N2 plot :-

Enthalpy with temperature of N2 plot:-

specific heat with temperature of Co2 plot :-

Entropy with temperature of Co2 Plot :-

Enthalpy with temperature of Co2 plot:-

screenshot of Folders:-
CONCLUSION:-
. Using This code and Thermodynamic polynomoial ,We are able to evaluate the parameters in different
specices,and the specific heat , enthalpy ,entropy are also calculated.