Challenge

Project 1 - Parsing NASA thermodynamic data

 
 
 
FILE PARSING OF NASA THRMODYNAMIC DATA

•	AIM:

The main aim of  the project is to write a program to evaluate the thermodynamic data such as a specific heat,Enthalpy,Entropy.of NASA thermodynamic data and to create the plots for all the species and to display the molecular weight calculate using MATLAB coding

•	OBJECTIVE:

NASA came with a thermodynamic data which is used to evaluate the properties such as specific heat(C_P),Enthalpy(H),Entropy(S).Now, parsing a file means reading in a data stream of some sort and building an in memory model of semantic content of the data
The SI unit of specific heat is J/KG-k

•	DEFINATION:

(1)	Specific heat:
Specific heat is a ratio of the quantity of heat required to rise the temperature of body one degree to that required to rise the temperature of an equal mass of water one degree.

(2)	Enthalpy:
The enthalpy thermodynamic system is defined as the sum of its internal enthalpy and the work required to achieve its pressure and volume .
The SI unit of specific heat is  kj/kg 
 
(3)	Entropy:
Entropy is a measure of degree of disorder ness of the system 
The SI unit of Entropy is j/k

•	FILE PARSING:
From the given thermodynamic data it clear that there are 53 species and for each species there are 14 coefficient and for each species their  is a unique low.mid and high temperature ranges formula used to calculate the specific heat enthalpy and entropy using to calculate the specific heat enthalpy and entropy using the coefficient is as shown below

CP/R = a1+a2.T+a3.T^2+a4.T^3+a5.T^4

H/T = a1+a2.T/2+a3.T^2/3+a4.T^3/4+a5.T^4/5+a6/T

          R = universal gas constant (8.314 j/k-mol)

          H = Enthalpy in  kj/kg
 
S/R = a1.logT+a2.T+a3.T^2/2+a4.T^3/3+a5.T4/4+a7

S = entropy in j/k
There are 14 coefficient as said in which first 7 coefficient are high temperature coefficient and second 7 coefficient are low temperature coefficient.

•	EXPLANATION

Getting header information

clear all 
close all 
clc

% To open the thermal data file
f1 = fopen('THERMO.dat','r')
% get heading file
heading = fgetl(f1)



The program starts with the clear all close all and clc which clear the previous recorded data and to open the thermal file use command fopen ,to reading the heading line of the data fgetl command and to read the next line use same command (fgetl)
Getting the global temperature information 

% global temperature values
global_temp = fgetl(f1);
x = strsplit(global_temp)
 global_low_temp = str2double (x{2});
global_mid_temp = str2double (x{3});
global_high_temp = str2double (x{4});
fgetl(f1)
fgetl(f1)
fgetl(f1)

To get the global  temperature line fgetl command is used, usually information will stored in the form of strings, to get the numerical value use str2double  command which convert the text in string of numerical value in string to double precision value and use {} instead of () which means the global temperature line is in the form of cell array by which we can obtain the global temperature values and to skip the next three line use fgetl command.

Getting local temperature information of individual ;

% Getting local temperature information of indvidual species
line1 = fgetl(f1);
species_name = line1(1:6);
% local temperature 
local_temp1 = line1(49:55);
low_temp = str2double(local_temp1);
local_temp2 = line1(58:65);
high_temp = str2double(local_temp2);
local_temp3 = line1(68:75);
mid_temp = str2double(local_temp3);

To get the local line fgetl command and store it as line1 in which we can observe that the first is the species name and the maximum length of species name is 6 hence by giving the command line (1:6 matlab can read the species name whose maximum length is 6 and in the same line we observe the local temperatures and local low temperature is located at 49 location to the 55th location and use str2double command do convert the string from to the numerical value and store it as low temperature and repeat the same process to get high and mid temperature.

To Extract the coefficient values:

% To extract the coefficient
line2 = fgetl(f1);
line3 = fgetl(f1);
line4 = fgetl(f1);
a = strfind(line2,'E')
b = strfind(line3,'E')
c = strfind(line4,'E')

% extracting coefficient of high temperature
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(1)+3));
a7 = str2double(line3(b(1)+4:b(2)+3));

%  extracting coefficient of low temperature
a8 = str2double(line3(b(2)+4:b(3)+30));
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));

To extract the value of coefficient which is used to calculate the specific heat,enthalpy and entropy  use fgtel command once we get the coefficient line of thermal data observe that letter ‘E’ is present in each coefficient and use ‘strfind’ command used to find the string ‘E’ and store it in as a,b,c and in command window it will show location E by which we can extract the first coefficient and it will be in the form of string and to get the numerical value use str2double command by these we can obtain all 14 coefficient
 
% specific heat function 
function c_p = specic_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,mid_temp,R,t)
if t<=mid_temp
    c_p = (a8+a9.*t+a10.*t.^2+a11.^3+a12.*t.^4).*R;
else
    c_p = (a1+a2.*t.^2+a4.*t.^3+a5.*t.^4).*R;
end

from formula observe that specific heat is a function of coefficients , universal gas constant , temperature if loop is used because there is a condition that first 7 coefficient are high temperature coefficient and second 7 coefficient are low temperature coefficient. Hence the function is coded as above

 % Enthalpy Function
function H = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,R,t,mid_temp)
if t<=mid_temp
    H = (a8+(a9.*t./2)+(a10.*t.^2/3)+(a11.*t.^3/4)+(a12.*t.^4/5)+(a13./t)).*R.*t;
else
    H = (a1+(a2.*t/2)+(a3.*t.^2/3)+(a4.*t.^3/4)+(a5.*t.^4/5)+(a6./t)).*R.*t;
End

from formula observe that Enthalpy is a function of coefficients , universal gas constant , temperature if loop is used because there is a condition that first 7 coefficient are high temperature coefficient and second 7 coefficient are low temperature coefficient. Hence the function is coded as above


% Entropy Function
function s = entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a14,R,t,mid_temp)
if t<=mid_temp
    s = (a8*log(t)+a9.*t+(a10.*t.^2/2)+(a11.*t.^3/3)+(a12.*t.^4/4)+a14).*R;
    s = (a1*log(t)+a2.*t+(a3.*t.^2/2)+(a4.*t.^3/3)+(a5.*t.^4/4)+a7).*R;
end

from formula observe that Entropy is a function of coefficients , universal gas constant , temperature if loop is used because there is a condition that first 7 coefficient are high temperature coefficient and second 7 coefficient are low temperature coefficient. Hence the function is coded as above


% molecular weight function
function molecular_weight_calc = molecular_weight(species_name) 
element = ['O','H',C','N','A'];
atomic_mass = [15.999,1.008,12.011,14.007,39.948];
mol_wt = 0;
for i = 1:length(species_name)
    for j = 1:length(element)
        if strcmpi(species_name(i),element(j))
            mol_wt = mol-wt+atomic_mass(j);
            z = j;
        end
    end
    t = str2num(species_name(i))
    if (t>1)
        mol_wt = mol_wt+(atomic_mass(z)*(t-1));
    end
    molecular_weight_calc=mol_wt
end


% main coding
clear all 
close all 
clc

% To open the thermal data file
f1 = fopen('THERMO.dat','r');
% get heading file
heading = fgetl(f1);
% global temperature values
global_temp = fgetl(f1);
x = strsplit(global_temp);
 global_low_temp = str2double (x{2});
global_mid_temp = str2double (x{3});
global_high_temp = str2double (x{4});
fgetl(f1)
fgetl(f1)
fgetl(f1)
% their are 53 species
for i = 1:53
line1 = fgetl(f1);
species_name = line1(1:6);
% local temperature 
local_temp1 = line1(49:55);
low_temp = str2double(local_temp1);
local_temp2 = line1(58:65);
high_temp = str2double(local_temp2);
local_temp3 = line1(68:75);
mid_temp = str2double(local_temp3);

% To extract the coefficient
line2 = fgetl(f1);
line3 = fgetl(f1);
line4 = fgetl(f1);
a = strfind(line2,'E');
b = strfind(line3,'E');
c = strfind(line4,'E');

% extracting coefficient of high temperature
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(1)+3));
a7 = str2double(line3(b(1)+4:b(2)+3));

%  extracting coefficient of low temperature
a8 = str2double(line3(b(2)+4:b(3)+30));
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));

% universal gas constant
R = 8.314;
t = linspace(low_temp,high_temp,500);

% calculating Spacific Heat

c_p = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,mid_temp,R,t);

% calculate Enthalpy

H = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a3,mid_temp,R,t);

% calculating Entropy

S = entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,R,t,mid_temp);

% creating folder
data = strcat('properties of.....',species_name);
mkdir(data);
file = pwd;

% plotting
figure(1)
plot(t,c_p)
data1 = strcat(species_name,'temperature vs specific heat');
xlabel('Temperature')
ylabel('Specific heat')
title(species_name)
f = fullfile(data);
cd(f)
saveas(gcf,[pwd '/specific heat vs tempreature.jpg'])
cd(file)


figure(2)
plot(t,H)
data1 = strcat(species_name,'temperature vs enthalpy');
xlabel('Temperature')
ylabel('Enthalpy')
title(species_name)
f = fullfile(data);
cd(f)
saveas(gcf,[pwd '/enthalpy vs temperature.jpg'])
cd(file)

figure(3)
plot(t,S)
data1 = strcat(species_name,'temperature vs entropy');
xlabel('Temperature')
ylabel('Entropy')
title(species_name)
f = fullfile(data);
cd(f)
saveas(gcf,[pwd '/entropy vs temperature.jpg'])
cd(file)


molecular_weight_calc = molecular_weight(species_name);
k = sprintf('%s mol_wt = %f',species_name,molecular_weight_calc);
disp(k)
end

fclose(f1)




































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.

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.