Project 1 - Parsing NASA thermodynamic data
Aim :- Parsing NASA thermodynamic data
Software Used :- Matlab 2016a
Program :- The following is the programm
clear all
close all
clc
f1 = fopen('THERMO.dat','r')
file_name = fgetl(f1);
tline_1 = fgetl(f1);
A = strsplit(tline_1,' ');
global_low_temp=str2num(A{2});
global_mid_temp=str2num(A{3});
global_high_temp=str2num(A{4});
for i = 1:3
Comments = fgetl(f1)
end
for j = 1:53
tline_2 = fgetl(f1);
s = strsplit(tline_2,' ');
species_name = s{1};
A=strfind(tline_2,'G ');
temp_values = tline_2(A+4:length(tline_2));
B = strsplit(temp_values,' ');
local_low_tempreature=str2double(B{1});
local_high_tempreature=str2double(B{2});
local_mid_tempreature=str2double(B{3});
line_1 = fgetl(f1);
l1 = findstr(line_1,'E');
a1 = str2num(line_1(1:(l1(1)+3)));
a2 = str2num(line_1((l1(1)+4:l1(2)+(3))));
a3 = str2num(line_1((l1(2)+4:l1(3)+(3))));
a4 = str2num(line_1((l1(3)+4:l1(4)+(3))));
a5 = str2num(line_1((l1(4)+4:l1(5)+(3))));
line_2 = fgetl(f1);
l2 = findstr(line_2,'E');
a6 = str2num(line_2(1:(l2(1)+3)));
a7 = str2num(line_2((l2(1)+4:l1(2)+(3))));
a8 = str2num(line_2((l2(2)+4:l1(3)+(3))));
a9 = str2num(line_2((l2(3)+4:l1(4)+(3))));
a10 = str2num(line_2((l2(4)+4:l1(5)+(3))));
line_3 = fgetl(f1);
l3 = findstr(line_3,'E');
a11 = str2num(line_3(1:(l3(1)+3)));
a12 = str2num(line_3((l3(1)+4:l1(2)+(3))));
a13 = str2num(line_3((l3(2)+4:l1(3)+(3))));
a14 = str2num(line_3((l3(3)+4:l1(4)+(3))));
spe_dir = pwd;
cd(species_name);
T = linspace(local_low_tempreature,local_high_tempreature,100);
mt = local_mid_tempreature;
[Cp H S] = coefficient(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,mt)
figure(1)
plot(T,Cp,'linewidth',3,'color','r');
xlabel('Temperature[K]')
ylabel('Specific Heat[J/mol-K]');
grid on
figure(2)
plot(T,H,'linewidth',3,'color','b');
xlabel('Temperature[K]')
ylabel('Enthalpy[J/kg]');
grid on
figure(3)
plot(T,CS,'linewidth',3,'color','r');
xlabel('Temperature[K]')
ylabel('Entropy[J/K]');
grid on
saveas(figure(1),'Specific_heat.jpg')
saveas(figure(2),'Enthalpy.jpg')
saveas(figure(3),'Entropy.jpg')
cd(Spe_dir);
elements = ['H','C','O','N','A'];
atomic_weight = [1 12 16 14 40];
mol_mass = 0;
for i = 1:length(species_name)
for m = 1:length(atomic_wight)
if strcmp(species_name(1),elements(m))
mol_mass = mol_mass+atomic_weight(m);
position = m;
end
end
n= str2double(species_name(1));
if n>1
mol_mass=mol_mass+atomic_weight(position)*(n-1)
end
end
fprintf('molecular_weight of %s:- ',species_name)
fprintf('%d amu n',mol_mass)
end
fclose(f1)
The following program is the function program.
function [Cp H S] = coefficient(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,mt)
R = 8.314;
for k = 1:length(T)
if T(k)>mt;
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
end
end
Program Explanation:-
- Write a program that extracts the 14 coefficients from given THERMO.DAT fil
- Calculate the enthalpy, entropy and specific heat for all the species in the data fil
- Calculate the molecular weight of each species and display it in the command window
- Plot the Cp, Enthalpy and Entropy for the local temperature range (specific for each species)
- To save the plots as images with appropriate names and dump them in separate folders for each species
- To save the Cp, Enthalpy and Entropy data in a text fil
- To make a program to interact with the user in order to automate the whole process where the user enter the species name and the program then retrieves the appropriate data (the plots) and display it in front of the user
- Calculate the Value of cofficients, calculating the value of Cp,Enthalpy and Entropy
- Plotting, Printing Molecular Weight Data inCommand Window
- Saving as .fig for MATLAB, Getting inputFrom User To Disply Plots
Output :-
For O2
For N2 :
For Co2 :
Molecular Weight In Command Window :
Errors : Matlab is case sensitive because of these i have faced many errors