Project 1 - Parsing NASA thermodynamic data
AIM: TO PARSE THE THERMODYNAMIC DATA FROM NASA USING MATLAB
THEORY: The official record of values thermodynamic temperatures has been stored by NASA in the form of polynomials with specified constants ranging from one to fourteen for various species. In order to quantify the values, the polynomials can be solved with defined temperature values in accordance with our requirements.at different The term 'parsing' refers to MATLAB reading an m-file (script or function) and translating it into an internal code that it stores in memory.
It is this 'parsed' file in memory that is actually run when you execute the code.
where,
Cp = Specific Heat
H = Enthalpy
S = Entropy
R = Universal Gas Constant (8.314 J/mol.K)
T = Temperature
The First 7 Coefficients are High Temperature Coefficients and the Second 7 Coefficients are Low Temperature Coefficients.
OBJECTIVE:
1. To write a function extracting the 14 coefficients from the data file and calculating the specific heat, enthalpy and entropy of all species.
2. To calculate molecular weight of every species and displaying in command window.
3. To plot specific heat, enthalpy and entropy with temperature range distributed from global high temperature to global low temperature.
4. To create a separate folder for all the plots and saving them in '.png' format.
coeff function program:
function [cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T)
R=8.314;
for j = 1:length(T)
if T(j) < 300
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 + (a6./T)).*R.*T;
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)./4 + a14).*R;
s = (a8.*log(T) + a9.*T + (a10.*T.^2)./2 + (a11.*T.^3)./3 + (a12.*T.^4)./4 + a14).*R;
end
end
end
molecular weight function program :
function [moleculer_weight] = mole_wt(species_name)
species = upper(species_names)
constituents= {'H','C','N','O','A'};
atomic_weight= [1 12 14 16 40];
moleculer_weight=0;
for i = 1:length(species)
for j= 1:length(constituents)
if strcmp(species(i),constituents(j))
moleculer_weight = moleculer_weight + atomic_weight(j);
u= j;
end
end
n = str2double(species(i));
if n > 1
moleculer_weight = moleculer_weight + atomic_weight(u)*(n-1);
end
end
fprintf('moleculer_weight of %s;- ',species_name)
fprintf('%d',moleculer_weight)
fprintf(' ')
fprintf('amu')
fprintf('n')
end
MAIN PROGRAM:
clear all
close all
clc
%reading the thermodynamic data file
f1 =fopen('THERMO.dat','r')
file_name= fgetl(f1);
t_line = fgetl(f1);
A = strsplit(t_line,' ');
%defining the temperature extracted
global_low_temp = str2double(A{2});
global_mid_temp = str2double(A{3});
global_high_temp = str2double(A{4});
for i = (1:3)
comments = fgetl(f1);
end
for i =1:53
%extracting species name
species = fgetl(f1);
species_name = species(1:6);
%Extracting coefficient from first line
line_1 = fgetl(f1);
l1 = strfind(line_1,'E');
a1 = str2double(line_1(1:(l1(1)+3)));
a2 = str2double(line_1((l1(1)+4):(l1(2)+3)));
a3 = str2double(line_1((l1(2)+4):(l1(3)+3)));
a4 = str2double(line_1((l1(3)+4):(l1(4)+3)));
a5 = str2double(line_1((l1(4)+4):(l1(5)+3)));
%extracting coefficient from second line
line_2 = fgetl(f1);
l2 = strfind(line_2,'E');
a6 = str2double(line_2(1:(l2(1)+3)));
a7 = str2double(line_2((l2(1)+4):(l2(2)+3)));
a8 = str2double(line_2((l2(2)+4):(l2(3)+3)));
a9 = str2double(line_2((l2(3)+4):(l2(4)+3)));
a10 = str2double(line_2((l2(4)+4):(l2(5)+3)));
%extracting coefficents from third line
line_3 = fgetl(f1);
l3 = strfind(line_3,'E');
a11 = str2double(line_3(1:(l3(1)+3)));
a12 = str2double(line_3((l3(1)+4):(l3(2)+3)));
a13 = str2double(line_3((l3(2)+4):(l3(3)+3)));
a14 = str2double(line_3((l3(3)+4):(l3(4)+3)));
%creating a folder 'species' to save the4 thermodynamic plot
mkdir(['D:MOOCSKILL-LYNCMATLAB practice programschallenge 7 - PROJECTSPECIES',species_name]);
T = linspace(global_low_temp , global_high_temp,500);
%calling the thermodynamic equation function
[cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T);
%plotting
%plot between temperature and specific heat
figure(1)
plot(T,cp,'linewidth',3,'color','b')
title(species_name)
xlabel('temperature')
ylabel('specific heat')
%plot between temperature and entropy
figure(2)
plot(T,s,'linewidth',3,'color','c')
title(species_name)
xlabel('temperature')
ylabel('entropy')
%plot between temperature and enthalpy
figure(3)
plot(T,h,'linewidth',3,'color','b')
title(species_name)
xlabel('temperature')
ylabel('enthalpy')
directory = (['D:MOOCSKILL-LYNCMATLAB practice programchallenge 7 - PROJECTSPECIES',species_name]);
cd(directory)
%saving plots
saveas(1,'specific_heat.png')
saveas(3,'enthalpy.png')
svaeas(2,'entropy.png')
%cahnging directory for calculating ,oleculer weight
cd('D:MOOCSKILL-LYNCMATLAB practice programs')
moleculer_weight = mole_wt(species_name);
end
fclose(f1)
EXPLANATION OF PROGRAM:
- Initially, a code is written to read the desired data file and values are assigned.Here, comments and other data is read using respective commands.
- The coefficient values are determined and allotted to a constant.
- A new folder with the name 'SPECIES' is created to desired location. The coefficient function is called and plotting of graphs is carried out.
- Plots are saved in the specified folder and the process of determining molecular weight is carried out.
- The molecular weight function is called and the values are printed in the command window.
OUTPUT OF SCREEN:
PLOT OF THE SPECIES:
CONCLUSION:
The parsing of thermodynamic data file by NASA is done using certain commands in MATLAB. Also, the plots of thermodynamic properties vs temperature are saved in a separate folder created by writing a specific code. Moreover, a function has been coded to calculate the molecular weight of the species mentioned in the given data file. From the above program, it can be exerted that new folders with desired information can be created and the files can be easily saved for further use.