Project

NASA Data Parsing

To calculate the thermodynamic properties like Specific Heat, Enthalpy and Entropy, the polynomials for the species must be known. To obtain these properties, the coefficients must be parsed.

Parsing is the process of taking input by analysing strings or arrays, storing the data and using it for further computations. The logic used here for the program is as follows:

1) The \'fopen\' command is used to read the thermodynamic file. For the sake of simplicity and my convinience so that I can open and read the file, the data file is converted to a txt file and read. This is allocated in f1.

2) Then a random variable named \'title\' is used to store the string \'THERMO\'.

3) The values of minimum, medium and high temperature values are stored. To alloacte them sepearately into categories like minimum, medium and high temperatures, they are seperated by identifying the space between them. To accept the values as numbers, \'str2double\' command is used instead of \'str2num\' as it to make the computations faster.

4) To ignore the upcoming three comments, they are stored in a variable named \'trash\'.

5) In the file, 53 species are present and there are four lines for each. The first line gives the name of the species and no of atoms and temp range,second,third & fourth line contains 14 coefficients in which first seven are high temperature coefficients & the last seven are low temperature coefficients, \'fgetl\' command is used to extract the name & coefficients.

6) Then functions are written to calculate the different values of Cp, H and S. Then they are called by reference in the main code. The values of the polynomials are stored in arrays.

6) Then the variation of each prooerty is plotted wrt temperature.

7) The molecular weights are obtained in an array.

The main program for the project is given below:

%program to extract the temperature co-efficients

clear all
close all
clc

f1=fopen(\'THERMO.txt\',\'r\');

%ignoring the title \'THERMO\'
title=fgetl(f1);

%reading and storing the global maximum, minimum and mid temperature
temp_range=fgetl(f1);
global_temp=strsplit(temp_range,\' \');
global_min_temp=str2double(global_temp{2});
global_mid_temp=str2double(global_temp{3});
global_max_temp=str2double(global_temp{4});

t=linspace(global_min_temp,global_max_temp,500);

%ignoring the first three instruction statements
for i=1:3
trash=fgetl(f1);
end

%for the 53 species in the file

for i=1:53

%line containing the information for species working temp range & no of molecules
CH2CHO_line=fgetl(f1);

%reading the name of the species
CH2CHO=strtok(CH2CHO_line);

%reading the three lines containing high & low temperature coefficients
temp1=fgetl(f1);
temp2=fgetl(f1);
temp3=fgetl(f1);

%finding the position of E so that we can extract the coefficients
a=strfind(temp1,\'E\');
b=strfind(temp2,\'E\');
c=strfind(temp3,\'E\');

%high temperature coefficients
a1=str2double(temp1(1:a(1)+3));
a2=str2double(temp1(a(1)+3:a(2)+3));
a3=str2double(temp1(a(2)+4:a(3)+3));
a4=str2double(temp1(a(3)+4:a(4)+3));
a5=str2double(temp1(a(4)+4:a(5)+3));
a6=str2double(temp2(1:b(1)+3));
a7=str2double(temp2(b(1)+4:b(2)+3));

%low temp coefficients
b1=str2double(temp2(b(2)+4:b(3)+3));
b2=str2double(temp2(b(3)+4:b(4)+3));
b3=str2double(temp2(b(4)+4:b(5)+3));
b4=str2double(temp3(1:c(1)+3));
b5=str2double(temp3(c(1)+4:c(2)+3));
b6=str2double(temp3(c(2)+4:c(3)+3));
b7=str2double(temp3(c(3)+4:c(4)+3));

%value of universal gas constant in J/mol.K
R=8.314; 

%calling specific heat function by reference
Cp=specific_heat(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,t,R,global_max_temp,global_min_temp,global_mid_temp);

%calling enthalpy function by reference
H=enthalpy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,t,R,global_max_temp,global_min_temp,global_mid_temp);

%calling entropy function by reference
S=entropy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,t,R,global_max_temp,global_min_temp,global_mid_temp);

%plotting specific heat as a function of temperature
figure(1)
plot(t,Cp,\'linewidth\',3)
xlabel(\'Temperature\')
ylabel(\'Specific Heat\')

%plotting enthalpy as a function of temperature
figure(2)
plot(t,H,\'linewidth\',3)
xlabel(\'Temperature\')
ylabel(\'Enthalpy\')

%plotting entropy as a function of temperature
figure(3)
plot(t,S,\'linewidth\',3)
xlabel(\'Temperature\')
ylabel(\'Entropy\')

%calculating molecular weight of each species
molecular_weight(i) = mol_wt(CH2CHO);
end

The functions used for Specific Heat, Entropy and Enthalpy are :

%function for evaluating specific heat

function Cp=specific_heat(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,t,R,global_max_temp,global_min_temp,global_mid_temp)
%computing the values for Cp for min. temp to mid temp 
if t<=1000
    Cp=(a1+a2.*(t)+a3.*(t.^2)+a4.*(t.^3)+a5.*(t.^4))*R;
else
%computing the values for Cp for mid temp to max temp   
    Cp=(b1+b2.*(t)+b3.*(t.^2)+b4.*(t.^3)+b5.*(t.^4))*R;
end
%function for enthalpy

function H=enthalpy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,t,R,global_max_temp,global_min_temp,global_mid_temp)
if t<=1000
%computing the values for Cp for min. temp to mid temp
    H=(a1.*t+a2.*(t.^2)./2+a3.*(t.^3)./3+a4.*(t.^4)./4+a5.*(t.^5)./5+a6)*R;
else
%computing the values for Cp for mid temp to max temp
    H=(b1.*t+b2.*(t.^2)./2+b3.*(t.^3)./3+b4.*(t.^4)./4+b5.*(t.^5)./5+b6)*R;
end
%function for Entropy

function S=entropy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,t,R,global_max_temp,global_min_temp,global_mid_temp)
if t<=global_mid_temp
%computing the values for Cp for min. temp to mid temp
    S=(a1.*log(t)+a2.*t+a3.*(t.^2)./2+a4.*(t.^3)./3+a5.*(t.^4)./4+a7)*R;
else
%computing the values for Cp for mid temp to max temp
    S=(b1.*log(t)+b2.*t+b3.*(t.^2)./2+b4.*(t.^3)./3+b5.*(t.^4)./4+b7)*R;
end

The variation obtained for Enthalpy,Entropy and Specific Heat vs Temperature are plotted as follows:

As shown in the figure, the enthalpy increase is very minimal at the start. At 300K, the value of enthalpy is 25203 J/kg. Till 2000K, the increase in enthalpy appears to be linear. It then appears to increase in parabolic manner.

At 300K, the entropy value is 268.134 J/K. It increases exponentially to 2208.9 J/K.

The specific heat increase is very minimal at the start. At 300K, the value of specific heat is as low as 55.128 J/K. Till 2000K, the increase in enthalpy appears to be linear. It then appears to increase in parabolic manner till 8328 J/K.

%function for molecular weight

function [MW] = mol_wt(name)

s = {\'H\' \'C\' \'N\' \'O\' \'AR\'}; 

%atomic weights of Hydrogen, carbon, nitrogen, oxygen and argon
atomicweight = [1 12 14 16 40];                                               
                                                                                   
MW = 0;                                                                       

for i = 1:length(name)  
 for j = 1:length(s)
 if strcmp(name(i), s(j))                           
 MW = MW + atomicweight(j); 
 position = j;                                                         
  end 
  end 
           
n = str2double(name(i));
if n > 1                                                      
MW = MW + atomicweight(position)*(n-1);                                        
end 
end
end

The molecular weights obtained of the 53 species are as follows:

16 32 1 2 17 18 33 34 12 13 14 14 15 16 28 44 29 30 31 31 32 25 26 27 28 29 30 42 41 42 28 27 31 14 29 44 15 16 17 30 46 43 43 43 42 26 41 28 0 44 43 44 43
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.