Project 1 - Parsing NASA thermodynamic data
Aim:Write a matlab code to find thermodynamic properties of given species
Objective:
- Write a code that read NASA thermodynamic file.
- Write a function that extracts the 14 co-efficients.
- Calculate thermodynamic properties using the coefficients.
- Calculate molecular weight of given species.
Definations:
- Specific Heat: It is the quantity of heat required to raise the temperature of one gram of a substance by one celsius degree.
- Entropy: It is a thermodynamic quantity representing the unavailability of a system's thermal energy for conversion into mechanical work, often interpreted as the degree of disorder or randomness in the system.
- Enthalphy: It is defined as the sum of the system's internal energy and the product of its pressure and volume.
- Molecular Weight:It is calculated in practice by summing the atomic weight of the atoms making up the substance’s molecular formula.
Program:
Here we have created a 'DATAU' file which contain all the species name and the corresponding line number of that species.
Here is the link to access this file: https://drive.google.com/file/d/128Fpen-BPyUBIO45asYrxL1UuAKRehpo/view?usp=sharing
clear all
close all
clc
%here we open the given file and we also display DATAU table for user to decide species he need
f=fopen('THERMO.dat','r')
readtable('datau')
%after checking the table user will enter line number corresponding to the species user selected.
linenum=input('enter the tagreted species line number as shown above:')
p=textscan(f,'%f %f %f %f %f',5,'delimiter',',','headerlines',linenum);
%this has scan all three lines under each species name and now we have to seperate this lines
line1=p{1};
line2=p{2};
line3=p{3};
line4=p{4};
line5=p{5};
%from here we start extracting the coefficients of respective species
%first 7 are high temperature coefficients
h1=line1(1);
h2=line2(1);
h3=line3(1);
h4=line4(1);
h5=line5(1);
h6=line1(3);
h7=line2(3);
%next 7 are lower temperature coefficients
l1=line3(3);
l2=line4(3);
l3=line5(3);
l4=line1(5);
l5=line2(5);
l6=line3(5);
l7=line4(5);
%this is the temperature of each species according to the species number.
if linenum<78
t=linspace(200, 3500, 1000);
elseif linenum==82
t=linspace( 300, 3000, 1000);
elseif linenum>82 & linenum<114
t=linspace( 200, 3500, 1000);
elseif linenum==118 & linenum==126
t=linspace(300, 4000, 1000);
elseif linenum==122
t=linspace(300, 5000, 1000);
elseif linenum>129 &linenum<166
t=linspace(200, 6000, 1000);
elseif linenum==170
t=linspace(300, 5000, 1000);
elseif linenum==174
t=linspace(300, 5000, 1000);
elseif linenum==178
t=linspace(300, 5000, 1000);
elseif linenum>181 & linenum<187
t=linspace( 200, 6000, 1000);
elseif linenum>189 & linenum<207
t=linspace(300, 5000, 1000);
elseif linenum==210
t=linspace(200, 6000, 1000);
else
t=linspace(300, 5000, 1000);
end
%from here we start calculating cp,h,s for higher and lower temperature respectivelly
for j=1:1000
if t>=1000
c_p=(l1+l2.*t+l3.*t.^2+l4.*t.^3+l5.*t.^4).*8.314;
h=(l1+l2.*(t./2)+l3.*((t.^2)./3)+l4.*((t.^3)./4)+l5.*((t.^4)./5)+l6.*(1./t)).*8.314.*t;
s=(l1*log(t)+l2.*t+l3.*((t.^2)./2)+l4.*((t.^3)./3)+l5.*((t.^4)./4)+l7).*8.314;
else
c_p=(h1+h2.*t+h3.*t.^2+h4.*t.^3+h5.*t.^4).*8.314;
h=(h1+h2.*(t./2)+h3.*((t.^2)/3)+h4.*((t.^3)/4)+h5.*((t.^4)/5)+h6.*(1./t)).*8.314.*t;
s=(h1*log(t)+h2.*t+h3.*((t.^2)./2)+h4.*((t.^3)./3)+h5.*((t.^4)./4)+h7).*8.314;
end
end
figure(1)
plot(t,c_p)
xlabel('Temperature')
ylabel('specific heat')
figure(2)
plot(t,h)
xlabel('Temperature')
ylabel('Enthalphy')
figure(3)
plot(t,s)
xlabel('Temperature')
ylabel('entropy')
%here we start to calculate molecular weight of species.
species=input('What compund do you want to check?','s')
species=upper(species)
mol_weight=molecular_weight(species);
k=sprintf('molecular weight of %s is %f',species,mol_weight);
disp(k)
%************************************************************************************************************************
Function program:
function M=molecular_weight(species)
atoms=['H','C','N','O','A'];
atomic_weight=[1,12,14,16,40];
M=0;
for i=1:length(species)
for j=1:length(atoms)
if strcmp(species(i),atoms(j))
M=M+atomic_weight(j);
p=j;
end
end
n=str2num(species(i));
if n>1
M=M+(atomic_weight(p))*(n-1);
end
end
Result:
- The code which i have made is user defined code.
- plots for 'O'




In the same way we can find plots and molecular weight of any species present in the THERMO file.