NASA file parsing
Aim:
To parse the NASA Thermodynamics data and to calculate the thermodynamic properties of the species.
Objectives :
- to calculate specific heat ,enthalpy, entropy and molecular weight '
- to create directory and save the species by there name
- plot the graph of specific heat ,enthalpy, entropy against temprerature
Theory:
parsing:
parsing in computer languages refers to syntactic analysis of the input code into its components parts in order to facilitate the writing of compilers and interpreters. It can be used to describe split or separation.
Parsing a file means reading in a data stream of some sort and building an in memory model of the semantic content of that data. This aims at facilitating perfoming some kind of transformation on the data.
Enthalpy:
a property of a thermodynamic system, is equal to the system's internal energy plus the product of its pressure and volume.In a system enclosed so as to prevent mass transfer, for processes at constant pressure, the heat absorbed or released equals the change in enthalpy.
in the given thermodynamic data to read and to calculate the enthalpy an equation is generated
`H=(a1+(a2T) /2+(a3T^2)/3+(a4T^3)/4+(a5T^4)/5+(a6)/t)RT`
Entropy:
`cp=(a1+a2T+a3T^2+a4T^3+a5t^4)*R`
the data file consist of 53 species and the indusial species has its own local temperatures and indusial 14 co-efficents for calculating the cp,h,s
initial 7co-efficents are use as the inputs to the above formulas over a range of temperature from medium temperature to high temperture and the next 7cefficents are use for temperatur range from lowest temp to medium temp to calculate enthalpy entropy and specific heat
programming part:
- fopen is used to open the data file.
- fgetl commands are used to read the commants present in the header
- strsplirt is used to split the string by using delimits
- for loop is used to run the program for n num of times till, the information is read completly
- species name is the input given by the used to the function strcmp to identifi the species in the data and compile to that species
- if the species name is compared or it reads the end statement then the for loop brakes and gets out of the for loop
- mkdir is used to make a directry for saving species characters
- cd is used to get into current directry
- plot command is used to plotting the graph of cp,s,h vs temp
Main program:
clear all
close all
clc
f1=fopen('nasa.txt','r')
line1=fgetl(f1)
line2=fgetl(f1)
line2=strsplit(line2,' ')
global_min_temp=str2num(line2{2})
global_mod_temp=str2num(line2{3})
global_max_temp=str2num(line2{4})
c1=fgetl(f1);
c2=fgetl(f1);
c3=fgetl(f1);
required = input('species')
for i=1:inf
s=fgetl(f1);
ss=strsplit(s,' ');
species_name=ss{1};
if strcmp(species_name,required)
temp=strfind(s,'G ');
min_tem=s(temp+3:temp+10);
mod_tem=s(temp+21:temp+28);
max_tem=s(temp+12:temp+19);
local_temp_min=str2num(min_tem)
local_temp_mod=str2num(mod_tem)
local_temp_max=str2num(max_tem)
line=fgetl(f1)
A=findstr(line,'E')
a1=str2num(line(1:A(1)+3));
a2=str2num(line(A(1)+4:A(2)+3));
a3=str2num(line(A(2)+4:A(3)+3));
a4=str2num(line(A(3)+4:A(4)+3));
a5=str2num(line(A(4)+4:A(5)+3));
line=fgetl(f1)
A=findstr(line,'E')
a6=str2num(line(1:A(1)+3));
a7=str2num(line(A(1)+4:A(2)+3));
a8=str2num(line(A(2)+4:A(3)+3));
a9=str2num(line(A(3)+4:A(4)+3));
a10=str2num(line(A(4)+4:A(5)+3));
line=fgetl(f1)
A=findstr(line,'E')
a11=str2num(line(1:A(1)+3));
a12=str2num(line(A(1)+4:A(2)+3));
a13=str2num(line(A(2)+4:A(3)+3));
a14=str2num(line(A(3)+4:A(4)+3));
line=fgetl(f1);
t1=linspace(local_temp_mod,local_temp_max,100);
t2=linspace(local_temp_min,local_temp_mod,100);
[cp1,h1,s1]=nasa_calculation(t1,a1,a2,a3,a4,a5,a6,a7);
[cp2,h2,s2]=nasa_calculation(t2,a8,a9,a10,a11,a12,a13,a14);
mkdir('D:\pramod g\',species_name);
cd(species_name)
figure(1)
plot(t1,cp1)
hold on
plot(t2,cp2)
xlabel('temperature')
ylabel('specific heat')
saveas(figure(1),'specific_heat');
figure(2)
plot(t1,h1)
hold on
plot(t2,h2)
xlabel('temperature')
ylabel('enthalpy')
saveas(figure(2),'enthalpy')
figure(3)
plot(t1,s1)
hold on
plot(t2,s2)
xlabel('temperature')
ylabel('entropy')
saveas(figure(3),'entropy');
cd ..
M_MASS=molecular_mass(species_name)
elseif strcmp(species_name,'END')
break
end
end
Function to calculate the cp,s,h:
function name nasa_calculation is used to call thhis fuction to the main program to calculate the enthalpy entropy and specific heat
the above writen mathamitical formula are feeded into the funcation ,we are going to call the funcation for 2times first for initial seven coefficent and the rest seven are compiled for the second time.
function [cp,h,s]=nasa_calculation(t,a1,a2,a3,a4,a5,a6,a7)
R=8.314;
cp=(a1+a2.*t+a3.*t.^2+a4.*t.^3+a5.*t.^4)*R;
h=(a1+(a2.*t./2)+(a3.*t.^2/3)+(a4.*t.^3/4)+(a5.*t.^4/5)+(a6./t))*R.*t;
s=(a1.*log(t)+a2.*t+(a3.*t.^2/2)+(a4.*t.^3/3)+(a5.*t.^4/4)+a7)*R;
end
Function to calculate the moleculae mass:
molecular_mass is the function used to calculate the moleculae mass of the speciman ,elements and the automatic mass and already entered
function M_MASS=molecular_mass(species_name)
species=upper(species_name);
elements=['H','C','N','O','A'];
automic_weight=[1.00794 12.0107 14.0067 15.9994 39.948];
M_MASS=0;
for i=1:length(species)
for j=1:length(elements);
if strcmp(species(i),elements(j))
M_MASS=M_MASS+automic_weight(j);
u=j;
end
end
num=str2num(species(i));
if num>1
M_MASS=M_MASS+automic_weight(u)*(num-1);
end
end
end
results:
outputs of o2:
outputs of N2:
outputs of CO2:
Screenshot of the folder of specimans: