Project 1 - Parsing NASA thermodynamic data
AIM : To evaluate thermodynamics properties such as specific heat,entropy and enthalpy and to calculate molecular weight of atoms through NASA thermodynamics data file .
SPECIFIC HEAT : The amount of heat required to rsie temperature of 1 kg of a body through unit degree C.
ENTROPY : The measure of disorder of a system. (i.e the disorder of atoms or molecules arranged increases when a system undergoes raise in temperature)
ENTHALPY : The measure of heat aborbed or heat rejected of a system.
PROGRAM :
* clear all ,close all and clc commands are used to close variable,plots and command window respectively.
* Value of universal gas constant R is given as 8.314.
*fopen command is used to read the thermodynamics data file and opening it.
*'r' is used for reading while 'w' is used to write a text in the new file.
* 'Header' is used to read the first line.
*The first three lines of the data file has to be omitted and it is done through 'for lope'.
*Linspace command is used to provide local temperature T range between 300-1000 with 200 values.
* Next is reading of species is done using 'for loop'.
*'strsplit' command is used to split string.
*Next extracting coefficient of species is done.
*'strfind' is used to find position of 'E'.
*'str2num' is used to convert string into numeric array and thus we have used here to extract high and low temperature coefficients.
*The first line represents species name and global temperature. The first 7 values are high temperature coefficents and other 7 values are low temperature coefficients.
O L 1/90O 1 G 200.000 3500.000 1000.000 1 2.56942078E+00-8.59741137E-05 4.19484589E-08-1.00177799E-11 1.22833691E-15 2 2.92175791E+04 4.78433864E+00 3.16826710E+00-3.27931884E-03 6.64306396E-06 3 -6.12806624E-09 2.11265971E-12 2.91222592E+04 2.05193346E+00 4
*This figure shows formulae used to find three thermodynamics properties CP,S&H.

*Next the creation of folder and plotting of temperature vs CP,S,H are done using plotting commands.
*'mkdir' is used to make new folder or directory and 'cd' is used to change the working directory.
*Seperate functions are defined for CP,S,H and molecular weight.
*'if else' statement is used in generating the values for the properties. If the t is greater than 1000 then high temperature coef are used else low temperature is used.
*Molecular weight of species is found and put in a seperate folder. 'strcmpi' is used to compare string case. The weight is calculated by MW=MW+atomic_weight(position)*(n-1);
MAIN PROGRAM :
clear all
close all
clc
%universal gas constant
R = 8.314
%opening data file and reading
f1=fopen('THERMO.dat','r')
f2=fopen('Mol weight.txt','w')
header=fgetl(f1)
%reading global temp
l1=fgetl(f1);
%omitting lines
for i=1:3
l2=fgetl(f1)
end
T=linspace(300,1000,200)
for i=1:52
l3=fgetl(f1);
A=strsplit(l3,' ');
species=strtok(l3,' ');
%extracting coef of species in 3 lines
a=fgetl(f1);
b=fgetl(f1);
c=fgetl(f1);
%finding position of E
d=strfind(a,'E');
e=strfind(b,'E');
f=strfind(c,'E');
%extracting high temp coef
a1=str2num(a(1:d(1)+3));
a2=str2num(a(d(1)+4:d(2)+3));
a3=str2num(a(d(2)+4:d(3)+3));
a4=str2num(a(d(3)+4:d(4)+3));
a5=str2num(a(d(4)+4:d(5)+3));
a6=str2num(b(1:e(1)+3));
a7=str2num(b(e(1)+4:e(2)+3));
%extracting low temp coef
b1=str2num(b(e(2)+4:e(3)+3));
b2=str2num(b(e(3)+4:e(4)+3));
b3=str2num(b(e(4)+4:e(5)+3));
b4=str2num(c(1:f(1)+3));
b5=str2num(c(f(1)+4:f(2)+3));
b6=str2num(c(f(2)+4:f(3)+3));
b7=str2num(c(f(3)+4:f(4)+3));
%specific heat,enthalpy,entropy,molecular weight
[CP]=specificheat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,T,R);
[H]=enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R);
[S]=entropy(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,T,R);
[MW]=mol_wt(species);
%creating folder for species
mkdir(species);
current_dir=pwd;
cd(species)
%plotting
%temp vs specific heat
figure(1)
plot(T,CP);
xlabel('temperature(k)');
ylabel('specific heat(KJ)');
title('temperature vs specific heat');
%temp vs enthalpy
figure(2)
plot(T,H);
xlabel('temperature(k)');
ylabel('enthalpy(KJ/mol)');
title('temperature vs enthalpy');
%temp vs entropy
figure(3)
plot(T,S);
xlabel('temperature(k)');
ylabel('KJ/mol-k)');
title('temperature vs entropy');
%changing current folder
cd(current_dir);
fprintf(f2,'Mol weight of %s is %f n',species,MW);
end
fclose(f2);
fclose(f1);
FUNCTION DEFINITION (ENTHALPY H) :
function H = enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R)
t=1000
%calculating enthalpy
if T > t
H=(a1.*T+(a2.*T.^2)./2+(a3.*T.^3)./3+(a4.*T.^4)./4+(a5.*T.^5)./5+a6).*R;
else
H=(b1.*T+(b2.*T.^2)./2+(b3.*T.^3)./3+(b4.*T.^4)./4+(b5.*T.^5)./5+b6).*R;
end
FUNCTION DEFINITION (ENTROPY S) :
function S = entropy(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,T,R)
t=1000
%calculating entropy
if T > t
S=(a1.*log(T)+a2.*T+a3.*(T.^2)./2+a4.*(T.^3)./3+a5.*(T.^4)./4+a7).*R;
else
S=(b1.*log(T)+b2.*T+b3.*(T.^2)./2+b4.*(T.^3)./3+b5.*(T.^4)./4+b7).*R;
end
FUNCTION DEFINITION (SPECIFIC HEAT CP) :
function CP = specificheat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,T,R)
t=1000
%calculating specific heat
if T > t
CP=(a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4).*R;
else
CP=(b1+b2.*T+b3.*T.^2+b4.*T.^3+b5.*T.^4).*R;
end
MOLECULAR WEIGHT FUNCTION :
%calculating molecular weight
function MW = mol_wt(species)
elements = ['H','O','C','N','A'];
atomic_weight = [1,16,12,14,40];
MW=0;
%addition of atomic number
for i=1:length(species)
for j=1:length(elements)
if strcmpi(species(i),elements(j))==1
MW=MW+atomic_weight(j);
position=j;
end
end
n=str2num(species(i));
if n>1
MW=MW+atomic_weight(position)*(n-1);
end
end
disp(['Mol weight of',species,'is']);
disp(MW)
end
MOLECULAR WEIGHT :
Mol weight of O is 16.000000 nnMol weight of O2 is 32.000000 nnMol weight of H is 1.000000 nnMol weight of H2 is 2.000000 nnMol weight of OH is 17.000000 nnMol weight of H2O is 18.000000 nnMol weight of HO2 is 33.000000 nnMol weight of H2O2 is 34.000000 nnMol weight of C is 12.000000 nnMol weight of CH is 13.000000 nnMol weight of CH2 is 14.000000 nnMol weight of CH2(S) is 14.000000 nnMol weight of CH3 is 15.000000 nnMol weight of CH4 is 16.000000 nnMol weight of CO is 28.000000 nnMol weight of CO2 is 44.000000 nnMol weight of HCO is 29.000000 nnMol weight of CH2O is 30.000000 nnMol weight of CH2OH is 31.000000 nnMol weight of CH3O is 31.000000 nnMol weight of CH3OH is 32.000000 nnMol weight of C2H is 25.000000 nnMol weight of C2H2 is 26.000000 nnMol weight of C2H3 is 27.000000 nnMol weight of C2H4 is 28.000000 nnMol weight of C2H5 is 29.000000 nnMol weight of C2H6 is 30.000000 nnMol weight of CH2CO is 42.000000 nnMol weight of HCCO is 41.000000 nnMol weight of HCCOH is 42.000000 nnMol weight of H2CN is 28.000000 nnMol weight of HCN is 27.000000 nnMol weight of HNO is 31.000000 nnMol weight of N is 14.000000 nnMol weight of NNH is 29.000000 nnMol weight of N2O is 44.000000 nnMol weight of NH is 15.000000 nnMol weight of NH2 is 16.000000 nnMol weight of NH3 is 17.000000 nnMol weight of NO is 30.000000 nnMol weight of NO2 is 46.000000 nnMol weight of HCNO is 43.000000 nnMol weight of HOCN is 43.000000 nnMol weight of HNCO is 43.000000 nnMol weight of NCO is 42.000000 nnMol weight of CN is 26.000000 nnMol weight of HCNN is 41.000000 nnMol weight of N2 is 28.000000 nnMol weight of AR is 40.000000 nnMol weight of C3H8 is 44.000000 nnMol weight of C3H7 is 43.000000 nnMol weight of CH3CHO is 44.000000 nn
GRAPHS GENERATED :

