Project 1 - Parsing NASA thermodynamic data
Objective:-
1.To function that extracts the 14 co-efficients and calculate the enthalpy,entropy,specific heat for all the species from NASA thermodynamic data.
2.To calculate the molecular weight of each species and dispaly it in command window.
3.To plot Cp,Enthalpy, Entropy for the local temperature range specific for each species and save them as image with appropriate names.
Formulae for Specific Heat, Enthalpy,Entropy.
Where,
Cp=Specific heat
H=Enthalpy
S=Entropy
R=Universal gas constant
T=Temperature
Molecular Weight
Weight of molecule of compound=sum of mass of each atom present in molecule
Atomic weight of some element are
H-1.00784
O-15.999
N-14.0067
C-12.0107
Explanation of code:-
1-First THERMO.dat file is loaded.Then first line is skipped with the help of 'fgetl' command.
2-Then global temperatures are extracted.
3-then next 3 lines are skipped.
4-Then with the position of 'G' we have extracted local temperatures.
5-We have made a temperature array of 200 nos of local temperatures.
6-Then of extracting data of 53 species we have used for loop and we have extracted the high and low temperature coefficients.
7-we have create seperate folders to save plots of different species in folders.
8-Then we have displayed molecular weight of all species in command window.
main program:-
clear all
close all
clc
f1=fopen('THERMO.dat','r');
fgetl(f1);
%Extracting global temperatures
temp=fgetl(f1);
temp=str2num(temp);
global_lowtemp=temp(1);
global_midtemp=temp(2);
global_hightemp=temp(3);
fgetl(f1);
fgetl(f1);
fgetl(f1);
A=fgetl(f1);
a=strfind(A,'G');
t=strsplit(A(a+1:end-1),' ');
local_low_temp=str2num(t{2});
local_mid_temp=str2num(t{4});
local_high_temp=str2num(t{3});
temp_range=linspace(local_low_temp,local_high_temp,200);
mkdir nasa_parsing
for i=1:53
species=strtok(A);
cd nasa_parsing;
mkdir(species);
cd(species);
A2=fgetl(f1);
A3=fgetl(f1);
A4=fgetl(f1);
x=strfind(A2,'E');
y=strfind(A3,'E');
z=strfind(A4,'E');
a8=str2num(A2(1:x(1)+3));
a9=str2num(A2(x(1)+4:x(2)+3));
a10=str2num(A2(x(2)+4:x(3)+3));
a11=str2num(A2(x(3)+4:x(4)+3));
a12=str2num(A2(x(4)+4:x(5)+3));
a13=str2num(A3(1:y(1)+3));
a14=str2num(A3(y(1)+4:y(2)+3));
a1=str2num(A3(y(2)+4:y(3)+3));
a2=str2num(A3(y(3)+4:y(4)+3));
a3=str2num(A3(y(4)+4:y(5)+3));
a4=str2num(A4(1:z(1)+3));
a5=str2num(A4(z(1)+4:z(2)+3));
a6=str2num(A4(z(2)+4:z(3)+3));
a7=str2num(A4(z(3)+4:z(4)+3));
[Cp,H,S]=thermo_properties(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,temp_range);
weight=molecular_weight(species);
display(weight,species);
figure(1)
plot(temp_range,Cp,'linewidth',3);
xlabel('Temperature');
ylabel('Specific heat');
save('specific heat vs Temperature.jpg');
figure(2)
plot(temp_range,H,'linewidth',3);
xlabel('Temperature');
ylabel('Enthalpy');
save('Enthalpy vs Temperature.jpg');
figure(3)
plot(temp_range,S,'linewidth',3);
xlabel('Temperature');
ylabel('Entropy');
save('Entropy vs Temperature.jpg');
cd('C:\Users\Abhijeet Dhotre\OneDrive\Desktop\matlab programms');
A=fgetl(f1);
end
Function program for calculating thermal properties
function[Cp,H,S]=thermo_properties(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,temp_range)
R=8.3145;
t=temp_range;
if temp_range<200
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
Function program for calculating molecular weight
function[wt]=molecular_weight(A)
atom=['C','H','O','N'];
mass=[12 1 16 14];
wt=0;
for i=1:length(A)
for j=1:length(atom)
if A(i)==atom(j)
wt=wt+mass(j);
z=j;
end
end
b=str2num(A(i));
if isempty(b)==1
;
else
wt=wt+(b-1)*mass(z);
end
end