Project

NASA Project: Parsing of Thermodynamic Data

  1. AIM :
  • To write a program for Parsing NASA's Thermodynamic data using MATLAB.
  1. OBJECTIVE :

The Objectives of this project are as follows:

  1. To extract the values of coefficients (a1 to a7) and calculate the Specific heat, Enthalpy, Entropy for all the species in THERMO data file.
  2. To calculate the molecular mass of every species and display it in the command window.
  • To plot graphs of Specific heat, Enthalpy, Entropy v/s the local temperatures.
  1. To saves these plots in a folder with name of folder as same as species name.
  1. GOVERNING EQUATION :

Where,

Cp = Specific Heat (KJ/kg-K)

E = Enthalpy (J/kg)

T = Temperature (K)

H = Entropy (J/K)

R = Universal Gas Constant (J/molK)

a1, a2, a3, a4, a5, a6, a7 are the numeric coefficient

Link for THERMO.dat

https://drive.google.com/file/d/1g187DbxFKpfYgRd3bHKGZfGX8ZAz1D70/view?usp=sharing

4. CODE :

Main Code:

clear all
close all
clc

% Reading the thermo file
f1 = fopen('THERMO.dat','r');
file_name = fgetl(f1);
tline_1 = fgetl(f1);
A = strsplit(tline_1,' ');

% Values of Global Temperature
global_low_temp = str2num(A{2});
global_mid_temp = str2num(A{3});
global_high_temp = str2num(A{4});

% Getting Comments from Thermo file
for i = 1:3
    Comments = fgetl(f1)
end

for j = 1:53
    tline_2 = fgetl(f1);
    s = strsplit(tline_2,' ');
    species_name = (s{1});
    A = strfind(tline_2,'G');
    temp_values = tline_2(A+4:length(tline_2));
    B = strsplit(temp_values,' ');
     % Values of Local Temperature
    local_low_temp = str2double(B{1});
    local_mid_temp = str2double(B{2});
    local_high_temp = str2double(B{3});
    
%   Extracting Coefficient from first line
   line_1 = fgetl(f1);
   l1 = strfind(line_1,'E');
   a1 = str2num(line_1(1:(l1(1)+3)));
   a2 = str2num(line_1((l1(1)+4:l1(2)+3)));
   a3 = str2num(line_1((l1(2)+4:l1(3)+3)));
   a4 = str2num(line_1((l1(3)+4:l1(4)+3)));
   a5 = str2num(line_1((l1(4)+4:l1(5)+3)));
   
   
%  Extracting Coefficient from second line
   line_2 = fgetl(f1);
   l2 = strfind(line_2,'E');
   a6 = str2num(line_2(1:(l2(1)+3)));
   a7 = str2num(line_2((l2(1)+4:l2(2)+3)));
   a8 = str2num(line_2((l2(2)+4:l2(3)+3)));
   a9 = str2num(line_2((l2(3)+4:l2(4)+3)));
   a10 = str2num(line_2((l2(4)+4:l2(5)+3)));
   
%  Extracting Coefficient from third line
   line_3 = fgetl(f1);
   l3 = strfind(line_3,'E');
   a11 = str2num(line_3(1:(l3(1)+3)));
   a12 = str2num(line_3((l3(1)+4:l3(2)+3)));
   a13 = str2num(line_3((l3(2)+4:l3(3)+3)));
   a14 = str2num(line_3((l3(3)+4:l3(4)+3)));
   
   %    Creating Folder
   Spe_dir = pwd;
   mkdir(species_name);
   cd(species_name);
 
   T = linspace(local_low_temp,local_high_temp,100);
   mt = local_mid_temp;
   
%    Calling the Function
   [Cp H S] = coefficient(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,mt);

%  Plotting
    % Temperature v/s Specific Heat
    figure(1)
    plot(T,Cp,'linewidth',3,'color','r')
    title(species_name)
    xlabel('Temperature')
    ylabel('Specific Heat')
    grid on
    
    % Temperature v/s Enthalpy
    figure(2)
    plot(T,H,'linewidth',3,'color','g')
    title(species_name)
    xlabel('Temperature')
    ylabel('Enthalpy')
    grid on

    % Temperature v/s Entropy
    figure(3)
    plot(T,S,'linewidth',3,'color','b')
    title(species_name)
    xlabel('Temperature')
    ylabel('Entropy')
    grid on
      
   %   Saving the Plots
    saveas(figure(1),'Specific Heat.jpg')
    saveas(figure(2),'Enthalpy.jpg')
    saveas(figure(3),'Entropy.jpg')
    cd(Spe_dir);
    
%     Calculating Molecular Mass
    elements = ['H','C','O','N','A'];
    atomic_weight = [1 12 16 14 40];
    mol_mass = 0;
    for l = 1:length(species_name)
       for m = 1:length(atomic_weight)
           if strcmp(species_name(l),elements(m))
               mol_mass = mol_mass + atomic_weight(m);
               position = m;
           end
       end
       n = str2double(species_name(l));
       if n>1
           mol_mass = mol_mass + atomic_weight(position)*(n-1);
       end
    end
% Printing Molecular Mass
    fprintf('Molecular Weight of %s:%f u ',species_name,mol_mass)
    fprintf('\n')
end
    
fclose(f1)    

Code for Function:

function [Cp H S] = coefficient(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,mt)
R = 8.314;
for k = 1:length(T)
        if T(k) > mt
           % Specific Heat
           Cp = (a1 + a2.*T + a3.*T.^2 + a4.*T.^3 + a5.*T.^4).*R;
           % Enthalpy
           H = (a1 + a2.*T./2 + a3.*T.^2./3 + a4.*T.^3./4 + a5.*T.^4./5 + a6./T).*R.*T;
           % Enthalpy
           S = (a1.*log(T) + a2.*T + a3.*T.^2./2 + a4.*T.^3./3 + a5.*T.^4./4 + a7).*R;
        else
            % Specific Heat
           Cp = (a8 + a9.*T + a10.*T.^2 + a11.*T.^3 + a12.*T.^4).*R;
           % Enthalpy
           H = (a8 + a9.*T./2 + a10.*T.^2./3 + a11.*T.^3./4 + a12.*T.^4./5 + a13./T).*R.*T;
           % Enthalpy
           S = (a8.*log(T) + a9.*T + a10.*T.^2./2 + a11.*T.^3./3 + a12.*T.^4./4 + a14).*R;
        end
end
end

5. EXPLAINATION OF CODE :

  • Open THERMO.dat file in ‘read’ mode and extract all the comments along with the global and local temperatures.
  • Extract all the coefficients for all the species (a1 to a14) and convert the string into number using ‘str2num’ command.
  • Create a new folder and save the species into those folders.
  • Write a function to calculate the Specific heat, Enthalpy and Entropy of each species using the equations given in the question.
  • Plot the graphs for: Temperature v/s Specific Heat, Temperature v/s Enthalpy and Temperature v/s Entropy for every species.
  • Save these plots in the new folder which we have already created.
  • Then we write the code to display the molecular weight of every species in command window. We use the ‘fprintf’ command for displaying the values of molecular weights.

6. OUTPUT :

Plot for O2:

Temperature v/s Specific Heat

Temperature v/s Enthalpy

Temperature v/s Entropy

Plot for CO2:

Temperature v/s Specific Heat

Temperature v/s Enthalpy

Temperature v/s Entropy

Plot for N2:

Temperature v/s Specific Heat

Temperature v/s Enthalpy

Temperature v/s Entropy

SCREENSHOT OF FOLDERS:

Molecular Weights:

7. CONCLUSION :

  • Thus we have successfully extracted all the data from (NASA’s) THERMO file.
  • We have also plot graphs for every species and saved it in the directory.
  • We were also able to extract the molecular mass of each species.
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.