Project 1 - Parsing NASA thermodynamic data
Aim: To write a code to parse the thermodynamic data file provided and then calculate the thermodynamic properties of various gas species
Objective:
1)Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.
2. Calculate the molecular weight of each species.
3. Plot the Cp, Enthalpy and Entropy for the local temperature range
4. Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name.
Theory:
File parsing is a string or symbol either in a natural language,computer language conferning to the rules of former grammer
Mathematical equations:
For specific heat

For enthalpy

For entropy

Where
T=Local temperature
b1-b7 =High temperature coefficient
b8-b14=low temperature coefficient
R=Gas constant =8.314
Program:
The Program for File parsing is as follows
%NASA thermodynamic data file parsing
clear all
close all
clc
%universal gas constant
R=8.314;
%reader header information
f1=fopen('THERMO.dat','r');
tline1=fgetl(f1);
tline2=fgetl(f1);
temp=strsplit(tline2,' ');
global_low_temp=str2num(temp{2});
global_mid_temp=str2num(temp{3});
global_high_temp=str2num(temp{4});
%skipping next three lines
for i=3
skippedlines=fgetl(f1);
end
for i=1:53
tline3=fgetl(f1)
S=strsplit(tline3,' ');
species_name=S{1};
A=strfind(tline3,'G');
temp_values=tline3(A+4:length(tline3));
B=strsplit(temp_values,' ');
local_low_temp=str2double(B{1});
local_mid_temp=str2double(B{3});
local_high_temp=str2double(B{2});
tline4=fgetl(f1);
f=strfind(tline4,'E');
a1=str2double(tline4(1:(f(1)+3)));
a2=str2double(tline4(f(1)+4:f(2)+3));
a2=str2double(tline4(f(2)+4:f(3)+3));
a2=str2double(tline4(f(3)+4:f(4)+3));
a2=str2double(tline4(f(4)+4:f(5)+3));
tline5=fgetl(f1);
a6=str2double(tline5(1:(f(1)+3)));
a7=str2double(tline5(f(1)+4:f(2)+3));
a8=str2double(tline5(f(2)+4:f(3)+3));
a9=str2double(tline5(f(3)+4:f(4)+3));
a10=str2double(tline5(f(4)+4:f(5)+3));
tline6=fgetl(f1);
a11=str2double(tline6(1:(f(1)+3)));
a12=str2double(tline6(f(1)+4:f(2)+3));
a13=str2double(tline6(f(2)+4:f(3)+3));
a14=str2double(tline6(f(3)+4:f(4)+3));
t=linspace(local_low_temp,local_high_temp,100)
%to calculate specific heat using function
C_p=R*specific_heat_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
s=R*entropy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
h=R*enthalpy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
%Creating a folder
mkdir(['G:',species_name])
cd(species_name)
%Plotting for
%temperature vs specific heat
figure(1)
plot(t,c_p)
xlabel('temperature')
ylabel('specific heat')
title('temperature vs specific heat')
image=getframe(gcf);
imwrite(image.cdata,'t vs cp.png')
saveas(1,'specific heat','jpg')
%temperature vs enthalpy
figure(2)
plot(t,H)
xlabel('temperature')
ylabel('enthalpy')
title('temperature vs enthalpy')
image=getframe(gcf);
imwrite(image.cdata,'t vs H.png')
saveas(2,'enthalpy','jpg')
%temperature vs entropy
figure(3)
plot(t,S)
xlabel('temperature')
ylabel('entropy')
title('temperature vs entropy')
image=getframe(gcf);
imwrite(image.cdata,'t vs S.png')
saveas(2,'entropy','jpg')
cd..
%calculating molecular mass
[M]=molecular_wt(species_name);
K=sprintf('%s mol_wt=%f',species_name,M);
disp(K)
end
specific heat function code
Function[C_p]=specific_heat_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
if (T>local_mid_temp)
C_p=(a1+(a2*t)+(a3*(t.^2))+(a4*(t.^3))+(a5*(t.^4)));
else
C_p=(a8+(a9*t)+(a10*(t.^2))+(a11*(t.^3))+(a12*(t.^4)))
end
Enthalpy function code
Function[H]=enthalpy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
if (T>local_mid_temp)
H=(a1*t+(a2*(t.^2)/2)+(a3*(t.^3)/3)+(a4*(t.^4)/4)+(a5*(t.^5)/5)+a6);
else
H=(a8*t+(a9*(t.^2)/2)+(a10*(t.^3)/3)+(a11*(t.^4)/4)+(a12*(t.^5)/5)+a13);
end
Entropy Function code
Function[S]=entropy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
if (T>local_mid_temp)
S=(a1*log(t)+(a2*t)+(a3*(t.^2)/2)+(a4*(t.^3)/3)+(a5*(t.^4)/4)+a7);
else
S=(a8*log(t)+(a9*t)+(a10*(t.^2)/2)+(a11*(t.^3)/3)+(a12*(t.^4)/4)+a14);
end
Plots:
Plots we got from element O2



Plots we got from element N2



plots we got from CO2 Element



Molecular weight of O2=31.9980
Molecular weight of N2=28.0140
Molecular weight of CO2=44.0090
Folders:

Issues faced during the challenge:
during the challenge i faced issue in understanding in the concept and i had a one on one session with support engineer and i am very clear with the concept