Project 1 - Parsing NASA thermodynamic data
https://drive.google.com/drive/folders/1faj7vZIN0190F3_Dl62vCJxpQO496Js6?usp=sharing
PARSING NASA THERMODYNAMIC DATA
AIM:
To write a function that extract the 14 co-coefficients and calculates the enthalpy, entropy and specific heat for all the species in the data file. You will be reading this file NASA thermodynamic data. Calculate molecular weight of each species and display in the command window. To plot Cp, enthalpy and entropy for the local temperature range (low temperature: high temperature) specific for each species.
Specific Heat:
Specific heat is the quantity of heat essential to raise the temperature of one gram of any substance by one degree celcius
Enthalpy:
A thermodynamic quantity equivqlent to the total heat content of system. It is equal to the internal energy of the system plus the product of pressure and volume.
Entropy:
Entropy is scientific concept as well as measurable physical property that is most commonly associated with the state of disorder, randomness, or uncertainty.
MAIN CODE
clear all
close all
clc
% opening thermo file
f1 = fopen('THERMO.dat','r')
%skip the first line
a = fgetl(f1);
temps = fgetl(f1);
temps =str2num(temps);
global_low_temp=temps(1);
global_mid_temp =temps(2);
global_high_temp =temps(3);
R = 8.314;
for i = 1:3;
fgetl(f1);
end
for i = 1:53
header = fgetl(f1);
speciesheader = strsplit(header,' ')
species_name = speciesheader{1};
t=strfind(header,'G');
t1 = str2double(header(t+3:t+8));
t2 = str2double(header(t+12:t+20));
t3 = str2double(header(t+22:t+30));
line_1 = fgetl(f1)
a = strfind(line_1,'E')
a1 = str2double(line_1(1:a(1)+3))
a2 = str2double(line_1(a(1)+4:a(2)+3))
a3 = str2double(line_1(a(2)+4:a(3)+3))
a4 = str2double(line_1(a(3)+4:a(4)+3))
a5 = str2double(line_1(a(4)+4:a(5)+3))
line_2 = fgetl(f1)
a_1 = strfind(line_2,'E')
a6 = str2double(line_2(1:a_1(1)+3))
a7 = str2double(line_2(a_1(1)+4:a_1(2)+3))
a8 = str2double(line_2(a_1(2)+4:a_1(3)+3))
a9 = str2double(line_2(a_1(3)+4:a_1(4)+3))
a10 = str2double(line_2(a_1(4)+4:a_1(5)+3))
line_3 = fgetl(f1)
a_2 = strfind(line_3,'E')
a11 = str2double(line_3(1:a_2(1)+3))
a12 = str2double(line_3(a_2(1)+4:a_1(2)+3))
a13 = str2double(line_3(a_2(2)+4:a_1(3)+3))
a14 = str2double(line_3(a_2(3)+4:a_1(4)+3))
% creating a folder
T = linspace(t1,t3,1000);
if T>t2
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;
else
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;
end
mkdir(species_name)
cd(species_name)
figure(1)
plot (T,cp)
xlabel('temperature')
ylabel('specific heat')
title('specific heat vs temperature of %s', species_name)
saveas(figure(1),'cp vs T.jpg')
figure(2)
plot (T,H)
xlabel('temperature')
ylabel('Enthalpy')
title('Enthalpy vs temperature of %s',species_name)
saveas(figure(2),'H vs T.jpg')
figure(3)
plot (T,S)
xlabel('temperature')
ylabel('Entropy')
title('Entropy vs temperature of %s',species_name)
saveas(figure(3),'S vs T.jpg')
cd ..
M = molicular_weight(species_name)
K = (sprintf('%smol_wt=%f',species_name,M))
disp(K)
end
MOLICULAR WEIGHT FUNCTION CODE:
function [M] = molicular_weight (species_name)
atomic_weight = [1.008,12.011,15.999,14.0067,39.948];
elements = ['H','C','O','N','A']
mol_wt = 0
for i = 1:length(species_name)
for j = 1:length(elements)
if strcmpi(species_name(i),elements(j))
mol_wt = mol_wt+atomic_weight(j);
z =j;
end
end
n = str2double(species_name(i));
if n>1
mol_wt = mol_wt+(atomic_weight(z)*(n-1))
end
end
M = mol_wt
CODE EXPLANATION:
First fopen command used to open the THERMO.dat file and ‘r’ is used to read the file
Then fgetl used to skip the line then we take different temperature values from the string using
Then we skip 3 lines using for loop and split the header and find the position of G in the string and take the temperature values using str2duoble then the same strfind command used to find the E value and taking each coefficient using str2double command after taking 14 coefficients we apply the coefficient into specific heat enthalpy entropy equations. the we plot the values and create directories and save the values. Next is to find the molecular weight of ‘H,C,O,N,A’ we take the atomic weight and add the values in equation using function for loop and if else statement.
Command explanation:
clear all :this command is used to clear the commands in work space
close all: it is the command used to close all previously opened plots
clc: clear all text in the command window
fopen: it is the command used to open the file in library the file should be in programme directory
here we using fopen command to open ‘THERMO.dat’ file.then the ‘r’ is used to read the file.
Fgetl(f1):it is the command used to skip the line.
Str2um:it is used to conversion of character array to numeric matrix.
Strsplit:this command used to split the line values
Str2double :it is used to convert the text to values.it coverts the exponential values to digit
Strfind:it is used to find the particular text or a value
Linspace:it is the command which used to create temperature value in array
If,else:it is used to take values in different conditions
Mkdir: it is used to create folder
Plot : it is used to plot the values
Cd: it is used to change the directory or it is used to change the folder
Saveas:here saveas used to save the figure in particular format
Sprint:it is used to print the molecular weight values
Disp:it is the command which used to display the values
CONCLUSION:
The coefficients were extracted from the file and the molecular weight calculated and plot saved in their respective compound folder
The attached files:
• Output plot of mentioned compounds in question
• Snap of molecular weight of each species
• Image of compound folder directory