Project 1 - Parsing NASA thermodynamic data
CODE :-
clear all
close all
clc
% make directory
mkdir 'c:usersadmindesktopnasa file parsing'
% reading data file - nasa thermodynami
% open a file & 'r' open the file for reading
f1=fopen('THERMO.dat','r')
gt=fgetl(f1);
%opting temperature - by reading header information
global_temp=fgetl(f1);
%spliting
t=strsplit(global_temp);
%converting string cells to numbers using str2num
global_low_temp=str2num(t{2});
global_medium_temp=str2num(t{3});
global_high_temp=str2num(t{4});
%temperature range & gas constant
%temperature 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 temperature coefficients
% extracting first 7 coefficients i.e high-temperature coefficient
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(3)+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=line_2(1:b(1)+3);
a6=str2num(a6); %6
a7=line_2(a(1)+4:b(2)+3);
a7=str2num(a7); %7
% extracting second 7 coefficients - low-temperature coefficients
a8=line_2(b(2)+4:b(3)+3);
a8=str2num(a8); %8
a9=line_2(b(4)+4:b(4)+3);
a9=str2num(a9); %9
a10=line_2(b(4)+4:b(5)+3);
a10=str2num(a10); %10
line_3=fgetl(f1);
c=strfind(line_1,'E');
a11=line_3(1: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)+4:c(3)+3);
a13=str2num(a13); %13
a14=line_3(c(3)+4:c(4)+3);
a14=str2num(a14); %14
% specfic heat calculation
cp = specficheat(a1,a2,a3,a4,a5,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);
% entropy calculation
s = entropy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a14,temp,R,global_medium_temp);
% calculating the molecular weight of species
molecularweight(i) = molecular_weight(species_sp);
%read & write molecular list
molecular_list = fopen('molecular weight.txt','a+');
fprint(mlecular_list,'molecular weightof %s is %d n',species_sp,molecularweight);
fclose(molecular_list);
cur_dir=pwd;
mkdir(species_sp);
cd(species_sp);
%plot 1. specific heat (cp) vs temperature range (temp)
figure(1)
plot(temp,cp,'linewidth',2,'color','r');
xlabel('temperature [k]');
ylabel('specific heat [k]');
title(sprintf('varying specific heat with temperature range of %s',species_sp));
grid on
saveas(figure(1),'specific heat.jpg');
% plot 2, enthalpy (h) vs temperature range (temp)
figure(2)
plot(temp,H,'linewidth',2,'color','g');
xlabel('temperature [k]');
ylabel('enthalpy in [k]/(mol)]');
title(sprintf('varying enthalpy with temperature range of %s',species_sp));
grid on
saveas(figure(2),'ethalpy.jpg');
% plot 3, entropy (s) vs temperature range (temp)
figure(3)
plot(temp,s,'linewidth',2,'color','b');
xlabel('temperature [k]');
ylabel('entropy in [k]/(mol-k)]');
title(sprintf('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');
fpriintf('%s n %s n %f n','species','molecular mass',m)
fclose(f2)
end
CODE EXPLANATION :-
- clear all = clear the all variables in the workspace
- close all = close all plots and figure
- clc = clear command window
- making a directory using mkdir with address
- reading the text file thermo.data file and opening its by using fopen and r reading command
- reading a line in text fiel using fgetl
- to optain thr temperature range from the thermo.dat file using strsplit to split temperature into a paticular string cell
- using str2num is converting string cellto number
- divided the temperature into a string and then converting to a number so that temperature values can be used to solve nasa thermodynamics
- using for and end loop to skip the next three comment lines in the file
- reading all the 53 species to plot specific heat cp ,enthalpy h, entropy s, with temperature value to find the molecular weight
- use for loop to read 53 species
- used strfind to find string
- used linspace specific the temperature range from low to high
- adding universlal gas constant value r
- extracting heat and low temperature coefficient by reading line by line from the species
- calling specific heat enthalpy entropy function code
- calculating molecular weight
FUNCTION FOR SPECIFIC HEAT :-
% specfic heat calculation function
function cp = specficheat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,temp,R,global_medium_temp)
% comparing with global temperature
% if less then global temperature - 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
- it is the amount of energy that must be added to the form of heatto one unit of mass and order to increase of one unit its temperature
FUNCTION FOR ENTHALPY :-
% enthalpy calculation function
function H = enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,aa9,a10,a11,a12,a13,temp,R,global_medium_temp)
% comparing with global temperature
% if less than global temperature - minimum coefficients are taken
if temp <= global_medium_temp
H = R*temp.*(a8 + ((a9*temp)/2) + ((a10*(temp).^2)/3) + ((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
- enthalpy is a property of thermodynamic system is equal to the system internal energy pluse the prodect of this pressure and volume ina system enclosed as to prevent the mass transfer released equal the change in enthalpy
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 than global temperature - minimum coefficient 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 coefficient are taken
s = R.*(a1.*log(temp) + (a2.*temp) + (a3*((temp.^2)/2) + (a4*((temp).^3)/3) + (a5*((temp.^4)/4) + a7)));
end
- ENTROPY the measure of a system thermal energy per unit temperature that is unavailable for doing useful work because work is optain from ordered molecular motion the amount of entropy is also measure molicular disorder
FUNCTION FOR MOLECULAR WEIGHT :-
% molecular weight calculation function
function molecularweight = molecular_weight(species_sp)
% standard - atomic name
atomic_name = ['H','C','O','N','A'];
% hydrogen, carbon, oxygen, nitogen, argon
fprintf('molecular weight of');
fprintf(species_sp);
fprintf(' : ');
% standard atomic number
atomic_weight = [1.008 12.011 15.999 14.007 39.948];
%starting range of molecular
molecularweight = 0;
% adding atomic number to obtain particular value
for i = 1:length(species_sp)
for j = 1:length(atomic_name)
if strcmpi(species_sp(i),atomic_name(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
- the molecular mass is the mass of a given molecule it is measured in dalton different molecules of thr same compound may be have different molecular masses because they contain different isotopes of an elemrnt
ATTACHMENT :-

RESULTS :-
- plot for o2



- plot for n2



- plot for co2



MOLECULAR WEIGHT OF ALL SPECIES :-














CONCLUTION :-
using matlab code necessary coefficents required to evalute various thermodynamic parameters for different species are extracted from nasa thermodynamics data file the specific heat entalpy and entropy for all the species are calculated and potted against the local temperature range the molecular weight is calculated for all the species
google drive link for folder :-
https://drive.google.com/drive/folders/1AQVgGLDjgOzGwnSQL-d2Scl6qFn-UsCO?usp=sharing
REFERANCE :-
https://in.mathworks.com/help/matlab/ref/mkdir.html
https://in.mathworks.com/matlabcentral/answers/317006-create-new-folders-by-mkdir
https://in.mathworks.com/help/matlab/ref/saveas.html
https://in.mathworks.com/matlabcentral/answer/17580-how-to-define-a-path-in-saveas-command
https://in.mathworks.com/help/matlab/ref/msgbox.html
https://in.mathworks.com/matlabcentral/answer/151692-display-value-in-message-box
https://in.mathworks.com/help/matlab/ref/fprintf.html
https://in.mathworks.com/help/matlab/ref/sprintf.html
https://combustion.berkeley.edu/gri-mech/data/nasa_plnm.html
https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19940013151.pdf
https://link.springer.com/chapter/10.1007/978-1-4684-0186-8_8