Project 1 - Parsing NASA thermodynamic data
File parshing:
file parsing refers to how nformation can be read form a particluar text file or any types to file and how that iromation can be used in a computer program.
step 1-Define the function
step 2-create an inputpaser object
step 3-add inputs to the scheme
step 4-set properties to adjust parsing
step 5-parsing the input
step 6-use the inputs in function
step 7-calling fuction
list of 53 element containned in THERMO.dat'file:
AR C C2H C2H2
C2H3 C2H4
C2H5 C2H6 C3H C3H8
CH CH2
CH(S) CH2CHO CH2CO CH2O
CH2OH CH3
CH3CHO CH3O CH3OH
CH4 CN CO
CO2 H H2 H2CN
H2O H2O2
HCCO CCOH HCN HCNN
HCNO NNH
NO NO2 O O2
OH
Enthalpy, entropy, and specific heat:
enthalpy, entropy, and specific heat, of various species values at different temperature and required extensively to analyze the thermodynamics process.
for example, if the combution process is considered during this, these are required to observed how to combution is going on and how efficieny it will be it eventuall allows seeking the scope of improvement in the processes. the other proceses like air conditioning, chemical kinetics nozzle flow, detonation processes.
NASA came up with polynomial that can be used to evalute thermodynamics properties such as Cp,H and S. they have documented the coefficients that are required to evaluated these polynomial for 1000+ species.
this NASA polynomial data have the form
Cp = a1T + a1T + a3T^2 + a4T^3 + a5T^4
H/RT = a1=a2T/2 + a3T^2/3 + a4T3/4 + a5T^4/5 + a6/T
S/R = a1ln + a2T + a3T^2/2 + a4T^3/3 + a5T^4/4 + a7
R is the universal gas constant , and T si the temperature , and a1,a2,a3,a4,a5,a6 and a7 are numerical coefficients supplied in therodyanics files.
coding functions:
1. specific heat
it is the amount of energy that must be added, in the from of heat, to one unit of mass of the substance in order to cause an increse of on eunits in its temperature.
Cp = (a1+a2T+a3T^3+a4T^3+a5T^4)*R
function for specific heat
% function heat calculation function
function Cp = specific heat(a1, a2a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,temp,R,global_medium temp)
% comparing with global temperature - minimum coefficient are taken
% if less than global temperature - minimum coefficient 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.enthalpy:
enthalpy the measure of a system theraml energy per unit temperature that is unavilable for doing useful work. because work is obtained for ordered molecular motion the amount of entropy is also a measure of molecular disorder, or randomness, of a system. the concept of entropy provieds deep provides deep inside into the direction of spontaneous change for many everyday phenomene.
s = (a1lnT + a2T + a3T^2/2 + a4T^3/3 + a5T^4/4 + a7)*R
function for entropy:
% entropy calculation function
function s = entropy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,temp,R,global_medium_temp)
%comparing with global temperature
% if less then global temperature - minimum coefficient are taken
if temp <= global_medium_temp
s = R.*(a1.*log(temp) + (a9.*temp) + (a3*((temp).^2)/2) + (a4((temp).^3/3) + (a5((temp).^4/4)
else
% else - maximum coefficients are taken
s - R.*(a1.*log(temp) + (a2.*temp) + a3*((temp).^2/20 + (a4*((temp).^3/3) + a5*((temp).^4/4) + a7);
end
3.Enthalpy:
enthalpy a property of a thermodynamics system is equal to the system internal energy plus the product of its pressure and volume. in a system enclosed so as to prevent at constant pressure, the heat absorbed or released equals the in enthalpy.
h = (a1, a2T/2 + a3T^2/3 + a4T^3/4 + a5T^4/5 + a6T)*R*T
% enthalpy calculation function
function H = enthalpy (a1,a2, a3,a3 ,a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, temp, R, global_medium_temp)
% comparing with global temperature
% if less than global temperature - minimumu coefficient are taken
if temp <= global_medium_temp
H = 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
the molecluar mass is the mass of a given molecule : it is measured in daltans. different molecular of the same compound may have different molecular masses baecause they contain different isolopes og an element.
function for molecular weight
function molecularweight = molecular_weight(species_sp)
% standard - atomic name
atomic_name = ['H','C','O','N','A'];
% hydrogen, carbon, oxygen, nitrogen, argon
fprintf('molecular weight of ')
fprintf(species_sp);
fpeintf(' : ');
% standerad atomic number
atomic_weight = [1.008 12.011 15.999 14.007 39.948];
% standard range of molecular
molecularweight 0;
%adding atomic number to obtain particular value
for i = 1:length(speciecies_sp)
for j = 1:length(atomic_number)
molecularweight = molecularweight + atomic_number(j);
position = j;
end
end
fprintf('molecular weight %s :',species_sp);
fprintf('%d',molecularweight);
disp(' ');
end
main coad:-
clear all
close all
clc
% make directory
mkdir "c:useradmindesktopNASA file parsing'
% Reading data file - NASA thermodynamics
% open a file & 'r' open the file for reading
f1 = open ('thermo.dat','r')
gt = fgetl(f1);
% obtaing temperature - by reading header information
global_temp = getfl(f1);
% spliting
t = stersplit(global_temp);
% coverting string cell to numbers using str2num,
global_low_temp = str2num(t{2});
global_medium_temp = str2num(t{3});
global_high_temp = str2num(t{4});
% temperaturerange & gas constant
% temperature range assumed
temp = linspace(global_low, 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 = getl(f1);
a = strfind(line_1,'e');
% extercting higher and lower temperature coefficients
%% exteracting FIRST 7 coefficient 1.e HIGH-temperature coefficients
a1 = line_1(1:a(1)+3);
a1 = str2num(a1); %1
a2 = line_1(a(1)+4:a(2)+(3);
a2 = str2num(a2); %2
a3 = line_1(a(2)+4:a(4)+3);
a3 = str2num(a3); %3
a4 = line_1(a(3)+4;a(4)+3);
a4 = str2num(a4)' %4
a5 = line_1(a(4)+4:a(5)+3);
a5 = str2num(a5); %5
line_2 = fgetl(f1);
b = strfind(line_1'e');;
a6 = str2num(a6); %6
a6 = line_2(a(1)+4:b(2)+3);
a7 = str2num(a7); %7
% exteracting SECOND 7 coefficients - low-temperature coefficients a8=line_29b(2)+:b(2)=3);
a8 = str2num(a80; %8
a9 = line_2(b(3)+4:b(5)+3);
a9 = str2num(a9); %9
a10 = line_2(b(4)+4;b(50+3);
a10 = str2num(a10); %10
line_3 = fgetl(f1);
c = strfind(line_1, 'e');
a11 = line_391:c(1)+3);
a11 = str2num(a11);
%11
a12 = line_3(c(1)+4:c(2)+(3);
a12 = str2num(a12);
%12
a13 = line_3(c(2)+:c(2)+3);
a13 = str2num(a13);
%13
14 = line_3(c(3)+4:c(4)+3);
a14 = str2num(a14);
%14
% specific heat calculation
Cp = Specificheat(a1, a2, a3, a4, a5, a6, a6, a7,a8, a9, a10, a11, a12, temp, R,global_medium_temp);
% enthalpy calculation
H = Enthalpy (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,a13, temp,R,global_medium_temp);
% enthalpy calculation
s = enthalpy_calc9a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, 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_list0;
% poltting (CP , H , S , TEMP,species-sp)
% saving as a folder
cur_dir = pwd;
mkdir(species_sp);
cd(speies_sp);
% plot 1, specific heat (cp) vs temperature range (temp)
figure(1)
plot(temp,cp, 'linewidth' ,2, 'color' , 'r');
xlabel('temperature [k]');
ylabel('species heat [kj]');
title(sprintf('varying specific heat with temperature range of %s' ,species_sp));
grid on
saveas(figure(1), 'specific haet with temperature range of %s' ,species_sp));
% plot 3, enthalpy (s) vs temperature range (temp)
figure(3)
plot(temp,s'linewidth" ,2, 'color' , 'b' );
xlabel('temperature [k]');
ylabel('enthalpy in [kj/(mol-k)]');
tital9sprintf('varying entropy with temperature 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');
fprintf9'%s n %s n 5s n' , 'molecular mass' ,m)
fclose(f2)
end
coad explaination:
1. 'clear all' - clear all the variable in the workspace.
'close all' - close all the plots and figure and
'clc' - clear the command window.
2. making a directory using 'mkdir' with location address.
3. after that reading the next file thermo.dat' file and opening it by using 'fopen' and 'r' as reading command.
4. for reading line in a txt file using 'fgetl'.
5. to obtain the temperature range from the thermo.dat file, using 'strsplit' to split the temperature into a particular string cell.
6. used 'str2num' for coverting string cell to numbers.
7. divided the temperature into a string and them converted to a number so that temperature value can be used separately to slove the NASA thermodynamics.
8. using 'for & end'loops to skip the next three comment lines in the file.
9. reding all the 53 species to plot species to plot species heat(cp),enthalpy(h), and entropy(s), with temperature values, and to find the molecular weights.
10. used 'for' loop to read 53 species.
11. used 'strfind' to find spring.
12. using linespace' specified the temperature range from low to high.
13. adding universal gas constant value 'R'.
14. extracted higher and lower temperautre coefficient by readding line by line from the species.
15. calling specific hat,enthalpy, entropy function codes.
16. calculating molecular weight.
Syntax used during coading
fopen; open a file obtain information about open files
'r' ;- open the file the reading
fgetl ;- read line from file
streplit ;- split string or character array or string to numeric array
strfind;- find one string within another
linspace;- generate linearly spaced vectors
fprintf;- write formatted data to file
pwd;- identify current directly
mkdir;- make new directly
cd;- change working directly
output:
>> molecular_weight AR
molecular weight of AR : molecular weight AR :3.994800e+01
ans=
39.9480
>>molecular_weight c
molecular weight of c :molecular weight :1.201100e+01
ans =
12.0110
>>molecular_weight C2H
molecular weight of C2H : molecular weight C2H :2.503000e+01
ans=
25.0300
>>molecular_weight C2H3
molecular weight of C2H3 : molecular weight C2H3 :2.704600e+01
ans=
26.0380
>>molecular_weight C2H4
molecular weight of C2H3 : molecular weight C2H3 :2.704600e+01
ans=
27.0460
>>molecular_weight C2H5
molecular weight of C2H6 : molecular weight C2H6 :3.007000e+01
ans=
29.0620
>>molecular_weight C2H6
molecular weightof C2H6 : molecular weight C2H6 : 3.007000e+01
ans=
30.0700
>>molecular_weight C3H7
molecular weight of C3H7 : molecular weight C3H7 : 4.30900e+01
ans=
43.0890
>>molecular_weight CH2
molecular weight of CH2 : molecular weight CH2 :1.402700e+01
ans=
14.0270
>>molecular_weight CH(s)
molecular weight of CH2CHO : molecular weight CH2(2) :1.402700+e01
ans=
14.0270
>>molecular_weight CH2CHO
molecular weight of CH2CHO : molecular weight CH2CHO :4.304500e+01
ans=
42.0370
>>molecular_weight CH2OH
molecular weight of CH2OH : molecular weight CH2OH : 1.503500+01
ans=
31.0340
>>molecular_weight CH3CHO
molecular weight of CH30 : molecular weight CH30 : 3.103400+01
ans=
31.0340
Results
specific heat, entropy and enthalpy plot for o2,n2 and co2 species.
1. plot for o2
a. variation of specific heat with the the temperature of O2.

b. variation of entropy with the temperature of CO2

c. variation of enthalpy with the temperature of O2

2. plots for N2:
a. variation of specific heat with the temperature of N2

b. variation of entropy with temperature of N2

c. variation of enthalpy with the temperature of N2

3. plots for CO2.
a. variation of specific heat with the temperature of co2

b. varitaion of enthalpy with the temperature of co2.

c. variation of enthalpy with the temperature of co2.

ATTACHED THE SCREESHORT OF THE WINDOW THERE ALL THE FOLDER ARE SAVED

CONCULASION
using MATLAB coad, the necessary ocefficient required to evaluate various thermodyanmic parameter for different species are extracted from NASA thermodyanmic data file. the specific heat, enthalpy, and entropy for all the species are calculate abd plot angin the local temperature range. the molecular weight is calculated for all species.