Project 1 - Parsing NASA thermodynamic data
Project-prasing NASA thermodynamic data
Aim:
To write a program to extarct 14 coefficients and calculate entropy,enthalapy,specific heats of the data in the file
Governing equations If any:
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;
Objectives of the project:
To find the enthalapy,entropy
Specic heats and molecular weights of the given data
clear all
close all
clc
%universal gas constant
R=8.314;
%loading nasa thermodynamic data intlo file
file=fopen('thermo.dat','r');
%reading the first header line
fgetl(file);
%collecting global temperatures
%getting second line
tline=fgetl(file);
%splitting when there is space
global_temp=strsplit(tline,' ');
%global low temp
global_low_temp=str2num(global_temp{2});
%global mid temp
global_mid_temp=str2num(global_temp{3});
%global high temp
global_high_temp=str2num(global_temp{4});
%skipping the next three lines
fgetl(file);
fgetl(file);
fgetl(file);
for i=1:53
tline1=fgetl(file);
x=strsplit(tline1,' ');
y=length(x);
species_name=x{1};
low_temp=str2num(x{y-3});
mid_temp=str2num(x{y-2});
high_temp=str2num(x{y-1});
% mkdir(species_name);
% cd(species_name);
tline2=fgetl(file);
a=findstr(tline2,'E');
a1=str2num(tline2(1:a(1)+3));
a2=str2num(tline2(a(1)+4:a(2)+3));
a3=str2num(tline2(a(2)+4:a(3)+3));
a4=str2num(tline2(a(3)+4:a(4)+3));
a5=str2num(tline2(a(4)+4:a(5)+3));
tline3=fgetl(file);
a=findstr(tline3,'E');
a6=str2num(tline3(1:a(1)+3));
a7=str2num(tline3(a(1)+4:a(2)+3));
a8=str2num(tline3(a(2)+4:a(3)+3));
a9=str2num(tline3(a(3)+4:a(4)+3));
a10=str2num(tline3(a(4)+4:a(5)+3));
tline4=fgetl(file);
a=findstr(tline4,'E');
a11=str2num(tline4(1:a(1)+3));
a12=str2num(tline4(a(1)+4:a(2)+3));
a13=str2num(tline4(a(2)+4:a(3)+3));
a14=str2num(tline4(a(3)+4:a(4)+3));
T=linspace(low_temp,high_temp,100);
for j=1:length(T)
if (T<1000)
CP=(a8+a9*T+a10*T.^2+a11*T.^3+a12*T.^4)*R;
H=(a8+a9*T./2+a10*T.^2./3+a11*T.^3./4+a12*T.^4./5+a13./T)*R.*T;
S=(a8*log(T)+a9*T+a10*T.^2./2+a11*T.^3./3+a12*T.^4./4+a14)*R;
else
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
end
%plotting
figure(1)
plot(T,CP);
xlabel('temperature');
ylabel('cp')
title('cp vs temperaure')
figure(2)
plot(T,H)
xlabel('temperature');
ylabel('H');
title('H vs temperature')
figure(3)
plot(T,S)
xlabel('temperature')
ylabel('s')
title('S vs temperature')
% saveas(1,'cp.png')
% saveas(2,'enthalpy.png')
% saveas(3,'entropy.png')
% cd ..
%calculating molecular weight
elements=['O' 'H' 'N' 'A' 'C'];
mass=[16 1 14 40 12];
molwt=0;
for i=1:length(species_name)
for j=1:length(elements)
if strcmp(species_name(i),elements(j))
molwt=molwt+mass(j);
p=j;
end
end
n=str2double(species_name(i));
if (n>1)
molwt=molwt+mass(p)*(n-1);
end
end
mol=sprintf('molecular weight for species name %s =%d',species_name,molwt)
end
Code explanation:
Open the thermo.dat file and read the read files
Second is for global,high,mid,low,temperatures are given
File is given as for open the command
Next three lines are skipped
From on wards we have to read the species name and local tempertaures
Using loop command we have to get 1:53 species
For the three lines we have to use fgetl command and add those 5 coeffiecients
By adding three times so 14 coefficients are taken
provide temperature low,high using linspace command we have to use local temperature instead of global temperature
create a directory using mkdir
And we have to calcultae enthalpy,entropy,heat ny using the given equation
And plotting the figures for the three images
using cd to comeback to original position
We have to find the molecular weights for the main[0,h,n,a,s]
By the forloop given for species and mass using I and j
Strcmp is given to read them
Str2num converts string to number given and multiplied with (n-1)
End
species:
plot fig1:



molecular weights:





