Project 1 - Parsing NASA thermodynamic data
AIM:
To write a program in matlab to parse the NASA thermodynamic data file and then calculate thermodynamic properties such as Specific heat(Cp), Enthalpy(H), Entropy(S) of various gas species.
OBJECTIVE:
- To write a function that extracts the 14th coefficient and calculates their enthalpy entropy and it's specific heat individually for all species in their data file.
- Calculating the molecular weight of each species and displaying it in command window with species name.
- Plotting CP, enthalpy and entropy for local temperature range specific for each species.
- Save the plot as images with appropriate names and dump their separated folders for each species with suitable name.
INTRODUCTION:
SPECIFIC HEAT:
In thermodynamics, the specific heat capacity of a substance is the heat capacity of a sample of the substance divided by the mass of the sample, also sometimes referred to as massic heat capacity.
ENTHALPY:
Enthalpy, a property of a thermodynamic system, is the sum of the system's internal energy and the product of its pressure and volume. It is a state function used in many measurements in chemical, biological, and physical systems at a constant pressure, which is conveniently provided by the large ambient atmosphere.
ENTROPY:
Entropy is a scientific concept as well as a measurable physical property that is most commonly associated with a state of disorder, randomness, or uncertainty.
PARSING FILE:
- Parsing means to make something understandable. Programming this means to convert information represented in one form into another form that's easier to work with. This is done by partially analyzing the data come on understanding underlying structure by making some assumptions based on what you are expecting to see second, and then explicitly representing 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 that data.This aims at facilitating performing some kind of transformation on the data
GOVERNING EQUATION:
The equations that we are doing to use in the functions to calculate CP, H,S are:

Where,
Cp - Specific heat
R - molar gas constant
T - Temperature
S - Entropy
H - Enthalpy
a - coefficient
FUNCTIONS:
Code for calling function of Specific_heat():
EXPLANATION:
- Create the function by the name of Specific_heat() to pass the required arguments for the functions.
- Calcularting the Specific heat for individual species in if condition.
- Calculating Specific heat for higher and lower temperature respectively.
- Evaluate the function of Specific heat to passing a arguments.
CODE:
function Cp = Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,global_midtemp)
Code for calling function Enthalpy():
EXPLANATION:
- Create the function by the name of Enthalpy() to pass the required argumqnts for the the function.
- Calculating the Enthalpy for individual species in if conditon.
- Calculating Enthalpy for higher and lower temperature respectively.
- Evaluate the function of Enthalpy to passing a arguments.
CODE:
function H = Enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,global_midtemp)
Code for calling function Entropy():
EXPLANATION:
- Create the function by the name of Entropy() pass the required arguments for the function.
- Calculating the Entropy for individual species in if condition.
- Calculating Entropy for higher ad lower temperature respectively.
- Evaluate the function of Entropy to passing a arguments.
CODE:
function S=Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,global_midtemp)
Code for calling function calculating molecular weight of wt():
EXPLANATION:
Create the function by the name of wt() of molecular_weight.
CODE:
function Molecular_weight=wt(species_name)
Elements=['H' 'C' 'O' 'N' 'A' 's'];
Atomic_weight=[1 12 16 14 40 32];
species=upper(species_name)
Molecular_weight=0;
for i=1:length(species)
for j=1:length(Elements)
if strcmp(species(i),Elements(j))
Molecular_weight=Molecular_weight+Atomic_weight(j);
k=j;
else
n=str2double(species(i));
if (n>1)
Molecular_weight=Molecular_weight+Atomic_weight(k)*(n-1);
break
end
end
end
end
end
MAIN CODE:
close all
clear all
clc
% R=molar gas constant
R=8.314;
%syntax to open the file THERMO.dat
f1=fopen('THERMO.dat','r');
% to read lines
l1=fgetl(f1);
l2=fgetl(f1);
value=strsplit(l2,' ');
%To get global temperatures from file in number from
global_lowtemp=str2num(value{2})
global_midtemp=str2num(value{3})
global_hightemp=str2num(value{4})
%temperaturerange
T=linspace(global_lowtemp,global_hightemp,1000);
%skipping these 3 lines
l3=fgetl(f1);
l4=fgetl(f1);
l5=fgetl(f1);
%Reading species , calculating cp,h,s and plotting
for i=1:53
tline=fgetl(f1);
A=strsplit(tline,' ');
name_of_species=(A{1});
lowtemp= str2num(A{end -3});
midtemp=str2num(A{end -2});
hightemp= str2num(A{end -1});
%Finding 7 higher coefficients and 7 lower coefficients
tline1=fgetl(f1);
a=findstr(tline1,'E');
a1=tline(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=tline3(1:a(1)+3);
a11=str2num(a11);
a12=tline3(a(1)+4:a(2)+3);
a12=str2num(a12);
a13=tline3(a(2)+4:a(3)+3);
a13=str2num(a13);
a14=tline3(a(3)+4:a(4)+3);
a14=str2num(a14);
%calculate specific heat(cp),Enthalpy(H),Entropy(S)
Cp=Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,global_midtemp);
H=Enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,global_midtemp);
S=Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,global_midtemp);
%calculating molecular weight and printing it.
Molecular_weight=wt(name_of_species);
fprintf('molecular weight of %s= %fn',name_of_species,Molecular_weight);
%PLOTTING CP,H,T
cd('C:\Users\ramak\Desktop\works')
%creating the folder
cd(name_of_species);
%plotting T vs cp
figure(1)
plot(T,Cp,'LineWidth',3,'Color','r')
xlabel('Temperature(T)')
ylabel('Specific heat(cp)')
grid on
title(name_of_species)
saveas(figure(1),'specific heat.jpg')
%plotting T vs H
figure(2)
plot(T,H,'LineWidth',3,'Color','g')
xlabel('Temperature(T)')
ylabel('Enthalpy(H)')
grid on
title(name_of_species)
saveas(figure(2),'Enthalpy.jpg')
%plotting T vs S
figure(3)
plot(T,S,'LineWidth',3,'color','b')
xlabel('Temperature(T)')
ylabel("Entropy(s)")
grid on
title(name_of_species)
saveas(figure(3),'Entropy.jpg')
end
CODE EXPLANATION:
- Initially value of 'R' is being defined.
- Then we use a command to open the file THERMO.dat.

- Further we used the 'fgetl' to start reading the lines and after reading the first two lines, from the second line converting the strings to numbers and assigning global (low mid and high) temperatures.

- Then we have written a command to get the temperature range for calculation and plotting purpose.
- Then again using the fgetl command to go to thel next 3 lines and skipping it.
- Then we use a fo loop to get 53 species and their temperatures (low, mid, high) and the 14 coefficents.

- In the for loop we again use the fgetl command and then the next line is read and from that line the species name, the three local tempertures are read and stored.
- Then we use fgetl command to go to further line and get the first 7 coefficients and store them. Similarly using the fgetl command we move to the next two lines and get the remaining coefficients.

- Then after getting the 14 coefficients, we use these coefficients and by calling the functions we calculate cp,H,S.
- Further we use the molecular weight function and calculate molecular weight for that species.
- Further I have used a command to change the directory so that I can save the files at a particular location .After changing the directory I have use 'mkdir' to create a new folder with the name of current species and then a 'cd' command to make 'mkdir' as the current directory.

- Then further we use plot command to plot temperature versus (CP,enthalpy,entropy).
- In this plotting team we use the figure Command to get three different plots and saves command to save the figure in the
- Then again we change our directory to again start the loop. So the loop continues to function till we get all the 53 species and then gets terminated.


- Here I face the error of "'Specific_heat' is not found in the current folder or on the MATLAB path, but exists in:C:\Users\ramak\Desktop\works" I did change or add the folder the error is rectified.
OUTPUT:
plots of Oxygen (O2):
Specifc heat of Oxygen (O2)

Enthalpy of Oxygen (O2)

















