Project

PARSING NASA THERMODYNAMIC DATA

PARSING NASA THERMODYNAMIC DATA

File Parsing:

  • The actual definition of parse is to split a file or other input into pieces of data that can be easily stored or manipulated. So we are splitting a string into parts then recognizing the parts to convert it into something simpler than a string.
  • In this program we are actually extracting the data\'s from the given NASA thermodynamic data file and calculating the enthalpy, entropy and specific heats for all the species in the data file.
  • And also we are calculating the molecular weight of each species and displaying it in the command window.
  • The Plots for the enthalpy, entropy and specific heats for each species will be plotted and it will be saved in separate folder.

Formulae Used:

  • To calculate enthalpy, entropy and specific heats the below formula is used

  • The temperature will vary for each species and the first 7 coefficients uses local high temperature and the last 7 coefficients uses local low temperature.
  • To calculate the molecular weight of each species the below formula is used

Molecular Weight = (Number of Atoms)*( Atomic Weight)

  • By using this we can calculate the molecular weight of all the species.

Program: 1

% Specific heat, Enthalpy & Entropy Calculation

function [Cp,H,S] = inputs(T,R,Tm1,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14)

for i = 1:length(T)
    if T(i)>Tm1

Cp= (c1 + c2.*T + c3.*T.^2 + c4.*T.^3 +c5.*T.^4).*R;
H = (c1 + (c2.*T)./2 + (c3.*T.^2)./3 + (c4.*T.^3)./4 +(c5.*T.^4)./5 + c6./T).*T.*R;
S = (c1.*log(T) + c2.*T + (c3.*T.^2)./2 + (c4.*T.^3)./3 +(c5.*T.^4)./4  + c7).*R;

else
Cp = (c8 + c9.*T + c10.*T.^2 + c11.*T.^3 +c12.*T.^4).*R;
H = (c8 + (c9.*T)./2 + (c10.*T.^2)./3 + (c11.*T.^3)./4 +(c12.*T.^4)./5 + c13./T).*T*R;
S = (c8.*log(T) + c9.*T + (c10.*T.^2)./2 + (c11.*T.^3)./3 +(c12.*T.^4)./4  + c14).*R;

    end
end
end

Code Explanation:

  • By using the function program the specific heat, enthalpy & entropy will be calculated. In this program we are using for loop to calculate for each species.
  • And we are using if & else command to calculate the high temperature for first 7 coefficients and low temperature for last 7 coefficients.

Program: 2

% Molecular Weight Calculation 

function molecular_weight_calculation = molecular_weight(sp_name)

species = (sp_name)

elements = [\'H\',\'C\',\'O\',\'N\',\'A\',\'S\'];
atomic_weight = [1.00794 12.0107 15.999 14.0067 39.948 32.065];

molecular_weight_calculation = 0;

for i = 1:length(species)
    for j = 1:length(elements)
        if strcmp(species(i),elements(j))
            molecular_weight_calculation = molecular_weight_calculation + atomic_weight(j);
            a = j;
        end
    end
    
    n = str2num(species(i));
    if n>1
        molecular_weight_calculation = molecular_weight_calculation + atomic_weight(a)*(n-1);
    end
end
end

Code Explanation:

  • By using the above code we can calculate the molecular weight of all the species. In this program the atomic name and atomic weight all the species is given as input.
  • Then we are using the for loop to calculate the molecular weight of each species individually. And we are using strcmp to compare the species with the elements and calculate the molecular weight.
  • And then we are converting the string to number using str2num command.

Program: 3

 % Parsing NASA Thermodynamic Data

clear all 
close all
clc

% Getting the Data from the Provided File

f1 = fopen(\'THERMO1.dat\',\'r\');
fgetl(f1);
tline = fgetl(f1);
A = strsplit(tline,\' \');
Global_low_temp = str2num(A{2});
Global_mid_temp = str2num(A{3});
Global_high_temp = str2num(A{4});

% Eliminating the Lines

for i = 3:5
    b = fgets(f1);
end

% Getting the Temperature & Coefficients for each Species

for j = 1:53  
species = fgetl(f1);
t = findstr(species,\'.\');

% Local Temperature for each species

species(52-3:52+3);
Tl = species(52-3:t(1)+3);
Tl1 =str2num(Tl);

species(t(1)+6:62+3);
Th = species(t(1)+6:t(2)+3);
Th1 =str2num(Th);

species(t(2)+6:72+3);
Tm = species(t(2)+6:t(3)+3);
Tm1 = str2num(Tm);

sp_name = species(1:6);

% Coefficients of each species

coeff_line_1 = fgetl(f1);
A11 = strfind(coeff_line_1,\'E\');
coeff_line_1(1:12+3);

a1 = coeff_line_1(1:A11(1)+3);
c1 = str2num(a1);
a2 = coeff_line_1(A11(1)+4:A11(2)+3);
c2 = str2num(a2);
a3 = coeff_line_1(A11(2)+4:A11(3)+3);
c3 = str2num(a3);
a4 = coeff_line_1(A11(3)+4:A11(4)+3);
c4 = str2num(a4);
a5 = coeff_line_1(A11(4)+4:A11(5)+3);
c5 = str2num(a5);

coeff_line_2 = fgetl(f1);
A12 = strfind(coeff_line_2,\'E\');
coeff_line_2(1:12+3);

a6 = coeff_line_2(1:A12(1)+3);
c6 = str2num(a6);
a7 = coeff_line_2(A12(1)+4:A12(2)+3);
c7 = str2num(a7);
a8 = coeff_line_2(A12(2)+4:A12(3)+3);
c8 = str2num(a8);
a9 = coeff_line_2(A12(3)+4:A12(4)+3);
c9 = str2num(a9);
a10 = coeff_line_2(A12(4)+4:A12(5)+3);
c10 = str2num(a10);

coeff_line_3 = fgetl(f1);
A13 = strfind(coeff_line_3,\'E\');
coeff_line_3(1:12+3);

a11 = coeff_line_3(1:A13(1)+3);
c11 = str2num(a11);
a12 = coeff_line_3(A13(1)+4:A13(2)+3);
c12 = str2num(a12);
a13 = coeff_line_3(A13(2)+4:A13(3)+3);
c13 = str2num(a13);
a14 = coeff_line_3(A13(3)+4:A13(4)+3);
c14 = str2num(a14);

% Creating the folder to save the plots

if  ~exist(\'D:NASA File parsing\\Species\', \'dir\')
    
% Folder does not exist so create it.

    mkdir(\'D:NASA File parsing\\Species\',sp_name)
end

% Calculating the Specific heat, Enthalpy, Entropy

T = linspace(Tl1,Th1,100);
R = 8.314;

[Cp,H,S] = inputs(T,R,Tm1,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14);

% Plotting

figure(1)
plot(T,Cp,\'linewidth\',2,\'color\',\'r\')
grid on
title(sp_name)
xlabel(\'Temperature\')
ylabel(\'Specific Heat\')

figure(2)
plot(T,H,\'linewidth\',2,\'color\',\'b\')
grid on
title(sp_name)
xlabel(\'Temperature\')
ylabel(\'Enthalpy\')

figure(3)
plot(T,S,\'linewidth\',2,\'color\',\'y\')
grid on
title(sp_name)
xlabel(\'Temperature\')
ylabel(\'Entropy\')

% Changing the Directory

program = ([\'D:\\matlab programs\\NASA File parsing\\Species\\\',sp_name]);
cd(program)

% Saving the Plots

saveas(1,\'Specific Heat.jpg\')
saveas(2,\'Enthalpy.jpg\')
saveas(3,\'Entropy.jpg\')

cd(\'D:\\matlab programs\\NASA File parsing\')

%Calculating the Molecular weight for each Species

molecular_weight = molecular_weight_calculation(sp_name)
end

fclose(f1)

Code Explanation:

  • Initially we are opening the given THERMO.dat file using fopen command and then we are extracting all the information provided in the file using fgetl command.
  • First we are getting the given global temperature by using the strsplit command and then we are skiping some lines using fgets command which is not required.
  • And then we are using for loop to get all the temperature and coefficients present in the file.
  • For getting the temperture and coefficients we are using findstr command to input the accurate spot and the specifying it so that we can get all the data\'s.
  • The data\'s we get from the file will be the string we are then converting it to number by using the str2num command. By this we will get all the coefficients and temperature for each species.
  • Then we are creating the folder for each species by using if command. So if the folder exist it simply saves the plot if not it will create the folder to save the plots.
  • As explained in the calculation of specific heats, enthalpy and entropy function program it is calculated and the plotted.
  • The three figures are plotted using the plot command and each species name is displayed using title command and then its labelled using the xlabel & ylabel command.
  • And then we are changing the directory using cd command and then we are saving the plot as images using saveas command.
  • Finally we are again changing the directory using cd command to calculate the molecular weight of each species using the function program and then closing the file using fclose command.

Errors Faced:

This error is resolved by using the elementwise operator.

This error is resolved by using the (\\) at the end of species

This error is resolved by using if ~exist command.

Outputs:

Screenshots containing the plots of all the species in the folder:

O2 Plots:

N2 Plots:

CO2 Plots:

Molecular weight of the species in the command window:

Result:

The code to parse the NASA thermodynamic data file has been programmed and the thermodynamic properties & the molecular weight of various species has calculated and plotted.

References:

https://in.mathworks.com/help/referencelist.html?type=function&s_tid=CRUX_gn_function

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.