Challenge

Project 1 - Parsing NASA thermodynamic data

AIM:
To write a matlab code for parse the NASA Thermodynamic data file and evaluate the Thermodynamic properties of various gas species.


OBJECTIVES:
1.To write a function for coefficient extraction and calculates the properties like entalpy, entropy and specific heats for all the species in NASA Thermodynamic data file.
2.Calculating the molecular weight of all species and displaying it in command window.
3.Plot the Graph for Cp, Enthaliy and Entropy with local Temperature range with ratio of (Low Temperature: High Temperature)
4.Save the Graphs as image and dump it in separate folder for all species with their Name.


THEORY:
a)File Parsing:
1.It is defined as the divide the file or inputs into a piece of data's and can be clearly and stored easily and changable. In this procus the string is divide into the multiple sections for making easy string.
2.This project is explains about splitting the NASA Thermodynamic data which is having gas species values. The coefficient values and Temperature ranges are selected in NASA file. Here we do a parse the values for over requirement.


b)Specific Heat:
It is defined as the amount of heat required to raaise the Temperature of 1 gram of a subdtamce by 1 degree C The unit of s[ecofoc heat is "Joules per kg Kelvin


c)Enthalpy:
It is the property of a THermodynamic System. Enthalpy is the amount of Heat absorbed by the system to cause a change in the system, or the Amount of Heat expelled by the system as a result of a change in the system.


d)Entropy:
The Entropy is defined as the measure of the level of disorder in a closed But changing system, a system in which energy can pnly be Transfered.


e)Gas constant:
The Gas Constant is the general constant in an equation of a gaseous state which is equivalent to the product of the pressure and volume of one mile divided by Absolute Temperature.

It is the measure of the sum of atomic weight of the atoms in a molecule. The molercular weight is used describe the equations.


STEPS IN FILE PARSING:
1.Function Definition.
2.Generate parseris.
3.Write the Inputs.
4.Create the properties.
5.Input parsing.
6.Input are used in function.
7.Function calling.


GOVERNING EQUATION:


1. CP/R= a1+a2.T+a3.T^2+a4.T^3+a5.T^4
2. H/RT= a1+a2.T/2+a3.T^2/3+a4.T^3/4+a5.T^4/5+a6/T
3. S/R = a1.lnT+a2.T+a3.T^2/2+a4.T^3/3+a5.T4/4+a7


Where,
CP- Specific Heat (J/Kg k)
H- ENthaly (J)
S- Enthropy (J/K)
R- Universal gas constant (J/mol.k)
T- Temperature (k)

Code:

Function codes:

The function codes are separately written and calling to the main program

1.Code for calculating specific heat(cp):

%function code for calculating the specific heat
%the function is created for assigning the inputs
function[Cp]= specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,l_mid_temp,temp_range,R)
%high temp- a1 a2 a3 a4 a5
%low temp- a8 a9 a10 a11 a12
%calculating the the cp with if else command
if temp_range<=l_mid_temp
Cp= R*(a8 + (a9*temp_range) + (a10*(temp_range.^2)) +(a11*(temp_range.^3)) + (a12*(temp_range.^4)));
%if above statement not statisfied it moves to this else cal
else
Cp= R*(a1 + (a2*temp_range) + (a3*(temp_range.^2)) + (a4*(temp_range.^3)) + (a5*(temp_range.^4)));
end

end

-----------------------------------------------------------------------------------------------------------------------

2.code for calculating Entropy(s):

%function code for calculating the entropy
%the function is created for assigning the inputs
function[S]= entropy_1(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,temp_range,R)
%high temp- a1 a2 a3 a4 a5
%low temp- a8 a9 a10 a11 a12
%calculating the the cp with if else command
for i= 1:length(temp_range)
if temp_range(i)<=temp(2)
S(i)= R.*((a8*log(temp_range(i))) + (a9*temp_range(i)) + (a10*((temp_range(i).^2)/2)) + (a11*((temp_range(i).^3)/3)) + (a12*((temp_range(i).^4)/4)) + a14);
%if above statement not statisfied it moves to this else cal
else
S(i)= R.*((a1*log(temp_range(i))) + (a2*temp_range(i)) + (a3*((temp_range(i).^2)/2)) + (a4*((temp_range(i).^3)/3)) + (a5*((temp_range(i).^4)/4)) + a7);
end
end

------------------------------------------------------------------------------------------------------------------------------

3.code for calculating Enthalpy(H):

%function code for calculating the enthalpy
%the function is created for assigning the inputs
function[H]= enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,temp_range,R)
%high temp- a1 a2 a3 a4 a5
%low temp- a8 a9 a10 a11 a12
for i= 1:length(temp_range)
%calculating the the cp with if else command
if temp_range(i)<=temp(2)
H(i)= R*(a8*temp_range(i)) + (a9*((temp_range(i).^2)/2)) + (a10*((temp_range(i).^3)/3)) + (a11*((temp_range(i).^4/4)) + (a12*((temp_range(i).^5)/5)) + a13);
%if above statement not statisfied it moves to this else cal
else
H(i)= R*((a1*temp_range(i)) + (a2*((temp_range(i).^2)/2)) + (a3*((temp_range(i).^3)/3)) +(a4*((temp_range(i).^4)/4)) + (a5*((temp_range(i).^5)/5)) + a6);
end
end

-----------------------------------------------------------------------------------------------------------------------------

4.code for calculating molecular weight:

%code for finding molecular weight
function[W]= m_weight(species_name)
element= {'H','O','N','C','Ar'}
atomic_mass= [1.008, 15.999, 14.007, 12.011,39.948];
%for intial w=0
W=0;
%create the for loop ranging of species name
for i= 1:length(species_name)
% create the another loop for the element
for j= 1:length(element)
%create the if statemnt with str cmp command
if strcmp(species_name(i),element(j))
W= W + atomic_mass(j);
a= j;
end
end
%convert the string to number and calculate the w
b= str2num(species_name(i));
if b>1
W= W + atomic_mass(a)*(b-1);
end

end

--------------------------------------------------------------------------------------------------------------------------

MAIN PROGRAM

%main program for parsing of NASA thermodynamic data
close all
clear all
clc
%using fopen command to open thermo data file from the same folder
f1=fopen('THERMO.dat','r')
%using fgetl command to read the file and skip
line_1= fgetl(f1);
line_2= fgetl(f1);
%for getting the global temperature
%keeping them as numbers
global_values= strsplit(line_2,' ');
%separate values are created for low,mod,high
g_low_temp= str2num(global_values{2})
g_mid_temp= str2num(global_values{3})
g_high_temp= str2num(global_values{4})
%it is for skiping the line
line_3= fgetl(f1);
line_4= fgetl(f1);
line_5= fgetl(f1);
%assigning the universal gasa constant as R unit is KJ/K-mol-K
R= 8.314;
%the for loop is created
for i= 1:53
T= fgetl(f1);
%species name are extracted in str
A=strsplit(T,' ')
species_name=A{1}
%now the species temperature are extracted
species_temp= T(49:75);
local_values= strsplit(species_temp,' ');
%converting them as numbers
l_low_temp= str2num(local_values{1});
l_mid_temp= str2num(local_values{3});
l_high_temp= str2num(local_values{2});
%storing them as a variable
temp= [l_low_temp l_mid_temp l_high_temp];
%for creating the temperature the linspace command used
temp_range=linspace(l_low_temp,l_high_temp,500);
%the coefficients are created by using fgetl command
coeff= fgetl(f1);
%the E is find using findstr command
coeff1= findstr(coeff,'E');
%coefficients we assigned is extracted with str
%for high temp
a1= coeff(1:coeff1(1)+3);
a1= str2num(a1);
a2= coeff(coeff1(1)+4:coeff1(2)+3);
a2= str2num(a2);
a3= coeff(coeff1(2)+4:coeff1(3)+3);
a3= str2num(a3);
a4= coeff(coeff1(3)+4:coeff1(4)+3);
a4= str2num(a4);
a5= coeff(coeff1(4)+4:coeff1(5)+3);
a5= str2num(a5);
%an another one created for mid temp
new_line= fgetl(f1);
coeff2= findstr(new_line,'E');
a6= new_line(1:coeff2(1)+3);
a6= str2num(a6);
a7= new_line(coeff2(1)+4:coeff2(2)+3);
a7= str2num(a7);
a8= new_line(coeff2(2)+4:coeff2(3)+3);
a8= str2num(a8);
a9= new_line(coeff2(3)+4:coeff2(4)+3);
a9= str2num(a9);
a10= new_line(coeff2(4)+4:coeff2(5)+3);
a10= str2num(a10)
%again another one created for low temp
new_line1= fgetl(f1);
coeff_3= findstr(new_line1,'E');
a11= new_line1(1:coeff_3(1)+3);
a11= str2num(a11);
a12= new_line1(coeff_3(1)+4:coeff_3(2)+3);
a12= str2num(a12);
a13= new_line1(coeff_3(2)+4:coeff_3(3)+3);
a13= str2num(a13);
a14= new_line1(coeff_3(3)+4:coeff_3(4)+3);
a14= str2num(a14);
%the function created for the calculating the cp,H,S,m_weight
%assigning the variable for specific heat calculation
Cp= specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,l_mid_temp,temp_range,R);
%for calculating the enthalpy
H= enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,temp_range,R);
%for calculating the entropy
S= entropy_1(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,temp_range,R);
%for claculating the molecular weight
W=m_weight(species_name);
%it is for storing and saving molecular weight
species_w= fopen('species_mass.txt','w');
fprintf(species_w,'molecular mass of %s is %f',species_name,W);
fclose(species_w);
%for saving in location
cur_dir=pwd;
%creating the separate and new folder for each species
mkdir(species_name);
cd(species_name);
%plotting
%plotting for temp range vs specific heat
figure(1)
plot(temp_range,Cp,'linewidth',2,'color',[0.2345 0.4567 0.7874])
xlabel('Temperature(K)');
ylabel('specific heat(kJ/kg-K)');
title(species_name);
%plott for temp range and enthalpy
figure(2)
plot(temp_range,H,'LineWidth',2,'color',[0.4532 0.1234 0.3324])
xlabel('Temperature(K)');
ylabel('Enthalpy(KJ/kg)');
title(species_name);
%plot for temprange and entropy
figure(3)
plot(temp_range,S,'LineWidth',2,'color',[0.4532 0.1234 0.3324])
xlabel('Temperature(K)');
ylabel('Entropy(KJ/k)');
title(species_name);
%saved them seprately as jpg format
saveas(1,'specific heat.jpg');
saveas(2,'enthaply.jpg');
saveas(3,'entropy.jpg');
cd(cur_dir);
%for showing the molecular weight for each species
sprintf('molecular weight of %s = %f',species_name,W)
end
%closing the file
fclose(f1)

-----------------------------------------------------------------------------------------------------------------------
CODE EXPLANATION:
1.As jusual the proguam starts with the "clear all", "close all" and "dc" commands. 2.By using "fopen" command the NASA Thermodynamic data file is opened for the Reading for the content Reading the "fgetl" command is used.
3.The "fl" command is added in fgetl command (fgetl(fl)) which act as as line cursor for the file abtaining again and again.
4.At the next step we introducing the fot loop it is for the gas species.
5.The gas species is coded as "find str" command and denoted it as string ('')
6.The Next prcess is to find location of the species do the "A (l:z(1)-1)" command used and species stored as "species_Name"
7.The local Temperature is coded using findstr command and then denoted if as string
low_temp-lower Temperature
mid_temp-mid Temperature
high_temp- high Temperature
8.By chaning the string into the Numbers using "str2num" command.
9.The Next step is gas species coeffiect extraction the locations of the coefficients are 2,3 and 4^th rows.
10.Its is extracted by using "findstr" and "str2num" and then stored it in a1,a2.....a14 variables.
11.The variable a1 to a7 - High Temperature coefficients
a8 to a14 - Low temperature coefficients.
12.The "linspace" command is used for temperature Ranging.
13.Again the for loop command is introduced for finding the specific heat ,enthalpy and entropy.
14.For calculating the milecular weight the atomic mass is formed in array and the intial weight is set as zero.
15.Then Again the For loop is created for finding repeating species Name and thier gas speicies values are calculated.
16.For canverting the string into number using "studouble" command.
17.The command window shows the molecular weights for the gas species.
18.This is the process for making the plots for specific heat, Enthalpy Entropy values and then saved it.
19.For create a new folder with their species_name the "mkdir" command is used fir creating the new folder for changing the directory using the "cd' command
20.The plots are:
Specific heat Vs Temperature
Enthalpy Vs Temperature
Entropy Vs Temperature
It is plotted and the axis labelled with Naming the title
21.The "save as" command is used save the plots ans then the directory changed by using "old folder=(dc)" command.

Errors:

1.The error came due to the the function coding is not saved properly and in the same folder and the THERMO.dat file is not opening and this problem is solved by myself and creating the one to one sessions

2.The error came due to the code is typed into wrong directory and this is rectified by support engineer

OUTPUTS:

1.This below pictures shows about the all species are saved in separate folder in the same directory

--------------------------------------------------------------------------------------------------------------------------

2.This below picture shows about the molecular weight of the species(command window output)

FOR N2:

FOR CO2

FOR O2

only few pictures of molecular weight only shown likewise the molecular weight display for all 53 species

--------------------------------------------------------------------------------------------------------------------------

3. This below output shows about the plots of O2,N2,CO2 corresponding to entropy,enthalpy and specific heat

plots of O2

1.for entropy

2.for enthalpy

3.for specific heat

plots of N2

1.for entropy

2.for enthalpy

3.for specific heat

plots of CO2

1.for entropy

2.for enthalpy

3.for specific heat

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.