Challenge

Project 1 - Parsing NASA thermodynamic data

AIM : PARSING NASA THERMODYNAMIC DATA

DEFINATIONS :

1) File Parsing -

Parsing a file means reading in a data stream and building a memory model of the content of that data. This aims at facilitating perfoming some kind of transformation on the data. Parsing splits a file or other input into pieces of data that can be easily stored or manipulated.

We are using this technique to read the Thermodynamic data by using file parsing to get the value of Cp, H, and S.

2) Enthalpy -

Enthalpy, the sum of the internal energy and the product of the pressure and volume of a thermodynamic system.

h = e + p * v.

3) Entropy -

A thermodynamic quantity representing the unavailability of a system's thermal energy for conversion into mechanical work, often interpreted as the degree of disorder or randomness in the system.

4) Specific Heat -

The specific heat capacity of a substance is the heat capacity of a sample of the substance divided by the mass of the sample. Informally, it is the amount of energy that must be added, in the form of heat, to one unit of mass of the substance in order to cause an increase of one unit in its temperature. The SI unit of specific heat is joule per kelvin and kilogram, J/.

gamma = cp / cv.

MAIN CODE :

% NASA Thermodynamic Data (FILE PARSING)
clear all
close all
clc
% Opening Nasa Thermodynamic data
f1 = fopen('THERMO.dat', 'r');
header = fgetl(f1);
% Getting the global max,min,med tempertaure
global_temp = fgetl(f1);
x = strsplit(global_temp);
global_temp_low = str2double(x{2});
global_temp_mid = str2double(x{3});
global_temp_high = str2double(x{4});
fgetl(f1);
fgetl(f1);
fgetl(f1);
% Getting into the line
for i = 1:53
line1 = fgetl(f1);
species_name = line1(1:6);
% Getting local temp
local_temp1 = line1(49:55);
low_temp = str2double(local_temp1);
local_temp2 = line1(58:65);
mid_temp = str2double(local_temp2);
local_temp3 = line1(68:75);
high_temp = str2double(local_temp3);
% Extracting the main coefficients from the data
% coefficient
line2 = fgetl(f1);
line3 = fgetl(f1);
line4 = fgetl(f1);
a = strfind(line2, 'E');
b = strfind(line3, 'E');
c = strfind(line4, 'E');
% For low temp
a1 = str2double(line2(1:a(1)+3));
a2 = str2double(line2(a(1)+4:a(2)+3));
a3 = str2double(line2(a(2)+4:a(3)+3));
a4 = str2double(line2(a(3)+4:a(4)+3));
a5 = str2double(line2(a(4)+4:a(5)+3));
a6 = str2double(line3(1:b(2)+3));
a7 = str2double(line3(b(1)+4:b(2)+3));
a8 = str2double(line3(b(2)+4:b(3)+3));
a9 = str2double(line3(b(3)+4:b(4)+3));
a10 = str2double(line3(b(4)+4:b(5)+3));
a11 = str2double(line4(1:c(1)+3));
a12 = str2double(line4(c(1)+4:c(2)+3));
a13 = str2double(line4(c(2)+4:c(3)+3));
a14 = str2double(line4(c(3)+4:c(4)+3));
% Creating a folder 'SPECIES' to save all the species_name
species_name = strcat('Property ...',species_name);
file = pwd;
% Applying universal gas constant
R = 8.314;
T = linspace(global_temp_low,global_temp_high,500);
% Calculation speicfic heat
[cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T);
% Plotting the graph
%plotting between Temperature and specific heat
figure(1)
plot(T,cp,'linewidth',3,'color','r')
title('specific heat vs temperature',species_name);
xlabel('Temperature[k]')
ylabel('Specific Heat [kj/kg.k]')
f = fullfile(species_name);
saveas(gcf,[pwd '/specific_heat vs temperature.jpg']);
cd(file);
%plotting between Temperature and Enthalphy
figure(2)
plot(T,h,'linewidth',3,'color','b')
title('Enthalpy vs Temperature',species_name);
xlabel('Temperature[K]')
ylabel('Enthalpy[KJ]')
f = fullfile(species_name);
saveas(gcf,[pwd '/enthalphy vs temperature.jpg']);
cd(file);
%plotting between Temperature and Entropy
figure(3)
plot(T,s,'LineWidth',3,'color','c');
title('Entropy vs Temperature',species_name)
xlabel('Temperature[K]')
ylabel('Entropy[KJ/K]')
f = fullfile(species_name);
saveas(gcf,[pwd '/entropy vs temperature.jpg']);
cd(file);
molecular_weight_cal = mole_wt(species_name);
k = sprintf('%s mol-wt = %f',species_name,molecular_weight_cal);
disp(k);
end
fclose(f1)
FUNCTION CODE (1):
function [molecular_weight_cal] = mole_wt(species_name)
elements = {'H','N','O','C','A'};
atomic_mass = [1 14 16 12 40];
mol_wt = 0;
for i = 1:length(species_name)
for j = 1:length(elements)
if strcmp(species_name(i),elements(j))
mol_wt = mol_wt + atomic_mass(j);
m = j;
end
end
s = str2double(species_name(i));
if s > 1
mol_wt = mol_wt+(atomic_mass(m)*(s-1));
end
end
molecular_weight_cal = mol_wt
fprintf('molecular_weight_cal of %s:- ',species_name)
fprintf('%d',molecular_weight_cal)
fprintf(' ')
fprintf('amu')
fprintf('\n')
end
FUNCTION CODE(2):
function [cp, h, s] = coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T)
% Given conditions
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+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
BASIC EXPLANATION OF CODES:

1.Code starts with clear all, close all, clc.

2.File THERMO.dat is opened using fopen command and r is used to read the file and file is stored in f1 variable.

3.fgetl is used to get the line wise information from the file f1.

4.Every time fgetl is used next line is read from the file.

5.strsplit is used to split the line wherever space is there in the line.

6.str2num is used to convert the string to a number.

7.Local temperature values are read from 1st line of given species and 500 equal intervals are split between them using linspace command.

8.14 coefficients from given species is extracted from next 3 linesand named a1 to a14.

9.For loop is used for extracting information from 53 species.

10.Separate functions are created for Cp, H ands and are called in main code to calculate them.

11.Molecular weight of each species is calculated by calling the function that is created to calculate Molecular weight.

PLOTS :
O2
CO2 :
N2 :
CH3 :

ERRORS FACED :

There are basic syntactic error and some new command error which have been resolved immediately.

REFERENCE :

SKILL LYNC

GOOGLE ETC

.....FAIZ AMIR AZMI.....

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.