Project 1 - Parsing NASA thermodynamic data
AIM
To write a program in matlab to parse the NASA thermodynamic data and file and then calculate the thermodynamic properties of various gas species.
OBJECTIVE
To write a function that extracts the 14 co-efficients and calculates the enthalpy,entropy and specific heats for all species in the data file.
calculating the molecular weight of each species and displaying it in the command window.
plotting cp,enthalpy and entropy for local tempartature range specific for each species.
INTRODUCTION
PARSING DATA :
parsing means to make something understandable .for programming this means to convert information represented in form to another form thats's easier to work with.this is done by partially analusing the data,understanding its underlying structure and then explicity represnting that structure in the code
parsing a file means reading in a data stream of some sort and building an in memory model of the semantic content of the data .this aims at faciltitating perfoming some kind of transformation on the data.
EQUATIONS
The equations that we are going to use in the function to calculate cp,H,S are
where,
cp=specific heat
R=molar gas constant
T=temparature
S=entropy
H=enthalpy
a=co-efficients
FUNCTION CODE FOR SPECIFIC HEAT
function cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,global_midtemp)
if (T<=global_midtemp)
cp=R*(a8+(a9*T)+(a10*(T).^2)+(a11*(T).^3)+(a12*(T).^4));
else
cp=R*(a1+(a2*T)+(a3*(T).^2)+(a4*(T).^3)+(a5*(T).^4));
end
end
FUNCTION CODE FOR ENTHALPY
function H = enthalpy_H(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,global_midtemp)
if (T<=global_midtemp)
H =R*((a8*T)+((a9*(T).^2)/2)+((a10*(T).^3)/3)+((a11*(T).^4)/4)+((a12*(T).^5)/5)+a13);
else
H =R*((a1*T)+((a2*(T).^2)/2)+((a3*(T).^3)/3)+((a4*(T).^4)/4)+((a5*(T).^5)/5)+a6);
end
end
FUNCTION CODE FOR ENTROPY
function S = entropy_S(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,global_midtemp)
if (T<=global_midtemp)
S = R*(a8.*log(T)+(a9*T)+((a10*(T).^2)/2)+((a11*(T).^3)/3)+((a12*(T).^4)/4)+a14);
else
S = R*(a1.*log(T)+(a2*T)+((a3*(T).^2)/2)+((a4*(T).^3)/3)+((a5*(T).^4)/5)+a7);
end
end
FUNCTION CODE FOR MOLECULAR WEIGHT
function mol_weight = weight(species_names)
elements = ['H','C','O','N','A','S'];
atomic_weight = [1 12 16 14 40 32];
species=upper(species_names)
mol_weight=0;
for i=1:length(species)
for j=i:length(elements)
if strcmp(species(i),elements(j))
mol_weight=mol_weight+atomic_weight(j);
k=j;
else
n=str2double(species(i));
if (n>1)
mol_weight=mol_weight+atomic_weight(k)*(n-1);
break
end
end
end
end
MAIN PROGRAM CODE
close all
clear all
clc
% molar gas constant
R = 8.314;
% syntax to open the file
f1=fopen("THERMO.dat","r")
% TO READ LINES
l1 = fgetl(f1);
l2 = fgetl(f1);
value=strsplit(l2,' ');
%converting string to number
global_lowtemp = str2num(value{2})
global_midtemp = str2num(value{3})
global_hightemp = str2num(value{4})
%temparature range
% to skip the lines
l3 = fgetl(f1);
l4 = fgetl(f1);
l5 = fgetl(f1);
% reading species,calculating cp,H,S
for i=1:53
tline = fgetl(f1);
A = strsplit(tline,' ');
name_of_species = (A{1});
low_temp = str2num(A{end-2});
mid_temp = str2num(A{end-2});
high_temp = str2num(A{end-1});
T = linspace(low_temp,high_temp,1000);
% finding 14 coefficients
tline1=fgetl(f1);
a=findstr(tline1,'E');
a1=tline1(1:a(1)+3);
a1=str2num(a1);
a2=tline1(a(1)+4:a(2)+3);
a2=str2num(a2);
a3=tline1(a(2)+4:a(3)+3);
a3=str2num(a3);
a4=tline1(a(3)+4:a(4)+3);
a4=str2num(a4);
a5=tline1(a(4)+4:a(5)+3);
a5=str2num(a5);
tline2=fgetl(f1);
a=findstr(tline2,'E')
a6=tline2(1:a(1)+3);
a6=str2num(a6);
a7=tline2(a(1)+4:a(2)+3);
a7=str2num(a7);
a8=tline2(a(2)+4:a(3)+3);
a8=str2num(a8);
a9=tline2(a(3)+4:a(4)+3);
a9=str2num(a9);
a10=tline2(a(4)+4:a(5)+3);
a10=str2num(a10);
tline3=fgetl(f1)
a=findstr(tline3,'E');
a11=tline1(1:a(1)+3);
a11=str2num(a11);
a12=tline1(a(1)+4:a(2)+3);
a12=str2num(a12);
a13=tline1(a(2)+4:a(3)+3);
a13=str2num(a13);
a14=tline1(a(3)+4:a(4)+3);
a14=str2num(a14);
% calculating cp,H,S
cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,global_midtemp);
H = enthalpy_H(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,global_midtemp);
S = entropy_S(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,global_midtemp);
% calculating mol_weight
mol_weight = weight(name_of_species)
fprintf('molecular weight of %s= %f\n',name_of_species,mol_weight);
% plotting of cp,H,T
% creating a folder
mkdir(name_of_species);
cd(name_of_species);
% plotting T vs cp
figure(1)
plot(T,cp,'linewidth',5,'color',"r")
xlabel('temparature(T)')
ylabel('specificheat(cp)')
grid on
title(name_of_species)
saveas(figure(1),'specific_heat.jpg');
%plotting T vs H
figure(2)
plot(T,H,'LineWidth',5,'color','b')
xlabel('temparature(T)')
ylabel('ENTHALPY_H')
grid on
title(name_of_species)
saveas(figure(2),'ENTHALPY_H.jpg');
%plotting T vs S
figure(3)
plot(T,S,'LineWidth',5,'color','g')
xlabel('temparature(T)')
ylabel('ENTROPY_S')
grid on
title(name_of_species)
saveas(figure(3),'ENTROPY_S.jpg');
cd ..
end
CODE EXPLANATION
Initially the value of 'R' is being defined.
Then we use fopen command to open the file 'THERMO.dat'.














































