Project 1 - Parsing NASA thermodynamic data
Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file. You will be reading this file NASA thermodynamic data(Tip: use fopen and fgetl). The formulae are shown below.
Here R is the universal gas constant, T is the temeprature
The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW-temperature coefficients.
Also use the LOCAL TEMPERATURE RANGES which is unique for each individual species, not the GLOBAL TEMPERATURE RANGE.
2. Calculate the molecular weight of each species and display it in the command window.
3. Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.
4. Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name. All these should be generated automatically.
5. The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H and S plots.
6. Please write a detailed report to describe your logic.
Program:
clear all
close all
clc
%reading the dat file
f1 =fopen('THERMO.dat','r');
%assigning variables and seperating comments
line1 =fgetl(f1);
line2 = fgetl(f1);
comment_1 = fgetl(f1);
comment_2 = fgetl(f1);
comment_3 = fgetl(f1);
A = strsplit(line2,' ');
global_low_temperature = str2num(A{2});
global_mid_temperature = str2num(A{3});
global_high_temperature = str2num(A{4});
for i=1:53
species = fgetl(f1);
species = strsplit(species,' ');
species_name = species{1};
local_low_temp = str2num(species{end-3});
local_mid_temp = str2num(species{end-1});
local_high_temp = str2num(species{end-2});
tline_1 =fgetl(f1);
A1 = findstr(tline_1,'E');
a1 = str2num(tline_1(1:(A1(1)+3)));
a2 = str2num(tline_1((A1(1)+4:(A1(2)+3))));
a3 = str2num(tline_1((A1(2)+4:(A1(3)+3))));
a4 = str2num(tline_1((A1(3)+4:(A1(4)+3))));
a5 = str2num(tline_1((A1(4)+4:(A1(5)+3))));
tline_2 =fgetl(f1);
A2 = findstr(tline_2,'E');
a6 = str2num(tline_2(1:(A2(1)+3)));
a7 = str2num(tline_2((A2(1)+4:(A2(2)+3))));
a8 = str2num(tline_2((A2(2)+4:(A2(3)+3))));
a9 = str2num(tline_2((A2(3)+4:(A2(4)+3))));
a10 = str2num(tline_2((A2(4)+4:(A2(5)+3))));
tline_3 =fgetl(f1);
A3 = findstr(tline_3,'E');
a11 = str2num(tline_3(1:(A3(1)+3)));
a12 = str2num(tline_3((A3(1)+4:(A3(2)+3))));
a13 = str2num(tline_3((A3(2)+4:(A3(3)+3))));
a14 = str2num(tline_3((A3(3)+4:(A3(4)+3))));
T = linspace(local_low_temp, local_high_temp,100);
R = 8.314;
for j = 1:length(T)
%for low to mid reange temperature
if T(j)
Function:
function M = molecular_mass(species_name)
species = upper(species_name);
elements = ['H', 'C', 'N', 'O', 'A']; %list of elemets
Atomic_weight = [1, 12, 14, 16, 40]; %respective weights
M = 0; %molecular weight initally
for i = 1:length(species_name)
for j = 1:length(elements)
if strcmp(species(i), elements(j))
M = M + Atomic_weight(j);
u =j;
end
end
n = str2num(species(i));
if n >1
M = M + Atomic_weight(u)*(n-1);
end
end
Programming Logic:
- first the thermodynamic data file is read using fopen command.
- Then using fgetl command the data is stored in a variable line after line.
- seperating the comment and the important data that needs to stored are sorted.
- There are 53 species in the data file, thus reading the data for these species are same way.
- So a for loop is prepared for to read the polynomial data for each species, then a pattern to read the variables are creted and read.
- Using the data and formulas for specific heat, enthalpy and entropy for each species.
- After calculating, they are ploted and stored as jpg file in a certain folder.
Molecular Weight:


Plots of O2:
Temperature Vs Enthalpy:

Temperature Vs Entropy:

Temperature Vs Specific Heat:

Plots of N2:
Temperature Vs Enthalpy:

Temperature Vs Entropy:

Temperature Vs Specific Heat:

plots of CO2:
Temperature Vs Enthalpy:

Temperature Vs Entropy:

Temperature Vs Specific Heat:

Inference:
Thus a matlab program is written to parse and thermodynamic data file and use the data from file to calculate and plot required results successfully.