Project 1 - Parsing NASA thermodynamic data
1. main code for the nasa temperature data:
clear all
close all
clc
%reading the data from the nasa thermo file:
thermo=fopen("THERMO.dat","r");
fgetl(thermo);
tempdata=fgetl(thermo);
A=strsplit(tempdata,' ');
%extracting the global temperature ranges:
lowgt=str2num(A{2});
midgt=str2num(A{3});
highgt=str2num(A{4});
%defining variable to store input from the end user:
get=input('enter species name','s');
while ~feof(thermo)
data=fgetl(thermo);
a=strsplit(data,' ');
b=a(1);
%comparing the end user input with the nasa data:
match=strcmpi(b,get);
if match==1
disp('species data available')
line1=fgetl(thermo);
sl1=strfind(line1,'E');
coef1=line1(1:sl1(1)+3);
coef2=line1(sl1(1)+4:sl1(2)+3);
coef3=line1(sl1(2)+4:sl1(3)+3);
coef4=line1(sl1(3)+4:sl1(4)+3);
coef5=line1(sl1(4)+4:sl1(5)+3);
a1=str2num(coef1);
a2=str2num(coef2);
a3=str2num(coef3);
a4=str2num(coef4);
a5=str2num(coef5);
line2=fgetl(thermo);
sl2=strfind(line2,'E');
coef6=line2(1:sl2(1)+3);
coef7=line2(sl2(1)+4:sl2(2)+3);
coef8=line2(sl2(2)+4:sl2(3)+3);
coef9=line2(sl2(3)+4:sl2(4)+3);
coef10=line2(sl2(4)+4:sl2(5)+3);
a6=str2num(coef6);
a7=str2num(coef7);
a8=str2num(coef8);
a9=str2num(coef9);
a10=str2num(coef10);
line3=fgetl(thermo);
sl3=strfind(line3,'E');
coef11=line3(1:sl3(1)+3);
coef12=line3(sl3(1)+4:sl3(2)+3);
coef13=line3(sl3(2)+4:sl3(3)+3);
coef14=line3(sl3(3)+4:sl3(4)+3);
a11=str2num(coef11);
a12=str2num(coef12);
a13=str2num(coef13);
a14=str2num(coef14);
%extrcting the local temperature:
mlt=a(end-1);
midlt=str2double(mlt);
hlt=a(end-2);
highlt=str2double(hlt);
llt=a(end-3);
lowlt=str2double(llt);
break
elseif match==0
disp('species not available');
else
continue
end
end
f=upper(get);
%displaying molecular weight of input molecules:
moleweight=MW(get);
disp('molecules entered')
disp(f)
disp('molecular weight')
disp(moleweight)
Trange=linspace(100,10000,9000);
r=8.314;
%specific heat;
cp=specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,midlt,Trange,r);
%entropy
s=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,midlt,Trange,r);
%enthalpy
h=enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,midlt,Trange,r);
%creating directory
mkdir(f)
%plotting cp vs t
figure(1)
plot(Trange,cp,"Color",'r')
grid on
xlabel('temperature [K]')
ylabel('specific heat[kj/kg.k]')
title(f)
%plotting s vs t
figure(2)
plot(Trange,s,"Color",'b')
grid on
xlabel('temperature [K]')
ylabel('entropy[j/k]')
title(f)
%plotting h vs t
figure(3)
plot(Trange,h,"Color",'b')
grid on
xlabel('temperature [K]')
ylabel('enthalpy[j/kg]')
title(f)
%Defining current folder
cd(f)
%Saving the images to current folder in specified formats
saveas(figure(1),'Cp vs T.jpg')
saveas(figure(2),'S vs T.jpg')
saveas(figure(3),'h vs T.jpg')
%Closing the open files
fclose('all');
2. molecular weight:
%Creating funcion for molecule weight:
function Mol_Weight = MW(get)
Weight = 0;
% atoms dealt with H C N O Ar and their atomic mass of 1 12 14 16 40 respectively
%to find molecular weight, we have to compare the atoms b from input
atoms = ['H','C','N','O','A'];
%Only A taken for Ar since A&R will be contained two positions in get
mass = [1,12,14,16,40];
%Since we have to compare each characters for mass, using 2 for loop
for i = 1:length(get)
for j = 1:length(atoms)
if strcmpi(get(i),atoms(j))
Weight = Weight + mass(j);
y = j;
end
end
%for more number of same atoms in the molecule
number = str2num(get(i));
if (number>1)
% for c2 we have to add mass of c 2 times
%initially since for C, mass is added to mol_weight
% for extra molecule we use (number -1) so adding one more weight
Weight = Weight + (mass(y)*(number - 1));
end
end
Mol_Weight = Weight;
end
3. specific heat:
%SPECIFIC HEAT function:
function cp_val=specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,midlt,Trange,r)
if (Trange>midlt)
cp_val = ( a1+ (a2*Trange) + (a3 *(Trange.^2)) + (a4*(Trange.^3)) + (a5 * (Trange.^4)))*r;
else
cp_val = ( a8+ (a9*Trange) + (a10 *(Trange.^2)) + (a11*(Trange.^3)) + (a12 * (Trange.^4)))*r;
end
4. entropy
% entropy function:
function s_val = entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,midlt,Trange,r)
if (Trange>midlt)
s_val= ((a1*log(Trange)) + (a2 *Trange) + ((a3*(Trange.^2))/2) + ((a4*(Trange.^3)) /3) + ((a5*(Trange.^4))/4) + (a7))*r;
else
s_val= ((a8*log(Trange)) + (a9 *Trange) + ((a10*(Trange.^2))/2) + ((a11*(Trange.^3)) /3) + ((a12*(Trange.^4))/4) + (a14))*r;
end
5.enthalpy:
%function for enthalpy:
function h_val = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,midlt,Trange,r)
if (Trange>midlt)
h_val = ( a1+ ((a2 .* Trange)./2) + ((a3.*(Trange.^2))./3) +((a4 .*(Trange.^3))./4) + ((a5 .* (Trange.^4))./5) + (a6./Trange)).* (r.*Trange);
else
h_val = ( a8+ ((a9 .* Trange)./2) + ((a10.*(Trange.^2))./3) +((a11 .*(Trange.^3))./4) + ((a12 .* (Trange.^4))./5) + (a13./Trange)).* (r.*Trange);
end
Aim:
to write a code of file parse the NASA data file to calculate the thermodynamic property of various gas and their thermal property.
Introduction:
Parsing:
parsing, syntax analysis or syntactic analysis is the process of analysing the string of symbol either in natural language , computer language or data structure.
the term parsing comes from latin word which means parting.
DATA source:
data source is provided by skill lync in the filename of NASA thermodynamic data.
Formula used:

where,
cp is specific heat, h is enthalpy, s is entropy and r is gas constant.
procedure:
in this program we have 5 division. where it contain 1 main program and 4 functions such as molecular weight,enthalpy, entropy and specific heat.
now , we discuss this in the following.
1. main program:
first we have open the matlab program and create a new scrpit. then write the code at begining it contain close all, clear all, and clc to clear the previous work.
then read the entire nasa thermodynamic data using fgetl . then extracting the global temperature range.
now get the input from the end user. compare the end user data with value in nasa data and begin with function while. we have to split the data.here it contain 14 value by numbering a1 to a14 split the values.
store the values . then fing the mid temperature, least and high temperature from the data.then end the program.
the concept is to check the full nasa data to find the end user data and retrive the data for calculation.
now the molecular weigth, enthalpy, entropy and specific heat has to calculated. for this the function are used.
creating a new directory for the file and then plot the 3 graphs. cp vs t; h vs t and s vs t.
2.molecular weight function:
the molecular weigth function is used to calculate the mole weigth by using mass of the substance to number of moles.
mass of the substance is obtained from the periodic charts. number of moles by avagaroda number.
then find the molecular mass and display in the command window.
3.enthalpy, entropy and specific heat function:
by using the formula in the above these three function are created.where in the data first 7 values are higher temperature and next 7 values are lower temperature. by the dat and formula we can easily found out the value of these three function.
output:
here the output is taken for 0,n2 and co2.
plot 0;
cp vs t graph of o:

s vs t graph of 0:

h vs t graph of o:

molecular weigth of o:

plot of n2:
cp vs t of n2:

s vs t of n2:

h vs t of n2:

molecular weight of n2:

plot of co2:
cp vs t of co2:

s vs t of co2:

h vs t of co2:

molecular weight of co2:

conclusion :
thus the file parsing to NASA thermodynamic data is done.