Challenge

Project 1 - Parsing NASA thermodynamic data

AIM : Parsing the given data to get the properties of different constituents using Matlab.

OBJECTIVE :

To extract coeffiecents of all the species and calculate various properties.

To calculate the molecular weight of each species.

Plotting c_p,enthalphy and entropy for all species and also for O2,CO2 and N2

INTRODUCTION :

File parsing : Parsing a file means reading in a data stream of some sort and building an in memory model of the semantic content of that data.

This aims at facilitating perfoming some kind of transformation on the data.

MATLAB CODE FOR THE SAME :

%FILE PARSING OF NASA THERMODYNAMIC DATA

clear all
close all
clc

%Universal Gas Constant
R = 8.314; %J/mol-K

%For opening the file

f1 = fopen('THERMO.dat','r');
l1 = fgetl(f1);
l2 = fgetl(f1);
t = strsplit(l2);

global_min = str2double(t{2});
global_mid = str2double(t{3});
global_max = str2double(t{4});

temp = linspace(global_min,global_max,400);

for i= 1:3
    fgetl(f1);
end


line_1 = fgetl(f1);
A = strsplit(line_1,' ');
species_name = (A{1});

tline_2 = fgetl(f1);
tline_3 = fgetl(f1);
tline_4 = fgetl(f1);

for i=53
a = strfind(tline_2,'E');
b = strfind(tline_3,'E');
c = strfind(tline_4,'E');


% Extraction of high temperature coefficient
a1 = str2double(tline_2(1:a(1)+3));
a2 = str2double(tline_2(a(1)+4:a(2)+3));
a3 = str2double(tline_2(a(2)+4:a(3)+3));
a4 = str2double(tline_2(a(3)+4:a(4)+3));
a5 = str2double(tline_2(a(4)+4:a(5)+3));
a6 = str2double(tline_3(1:b(1)+ 3));
a7 = str2double(tline_3(b(1)+4:b(2)+3));

% Extraction of low temperature coefficient
b1 = str2double(tline_3(b(2)+4: b(3)+3));
b2 = str2double(tline_3(b(3)+4: b(4)+3));
b3 = str2double(tline_3(b(4)+4: b(5)+3));
b4 = str2double(tline_4(1:c(1)+3));
b5 = str2double(tline_4(c(1)+4: c(2)+3));
b6 = str2double(tline_4(c(2)+4: c(3)+3));
b7 = str2double(tline_4(c(3)+4: c(4)+3));

mkdir(['C:\Users\Shiv\Desktop\matlab file parsing\species',species_name]);
  
C_p = specific_heat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,R,temp,global_mid);
h = enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,R,temp,global_mid);

S = entropy(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,R,temp,global_mid);
figure(1)
subplot(3,1,1)
plot(temp,C_p,'linwidth',4,'color','b');
title('species name')
xlabel('Temperature')
ylabel('Specific Heat')

subplot(3,1,2)
plot(temp,h,'linwidth',4,'color','r');
title('species name')
xlabel('Temperature')
ylabel('Enthalpy')

subplot(3,1,3)
plot(temp,S,'linwidth',4,'color','g');
title('species name')
xlabel('Temperature')
ylabel('entropy')

directory = (['C:\Users\Shiv\Desktop\matlab file parsing\species',species_name]);
cd(directory)
saveas(1,'ouput.jpg');

cd('C:\Users\Shiv\Desktop\matlab file parsing')
MW = molecular_weight(Species_name);


end
fclose(f1);











CODE FOR CALLING THE FUNCTIONS:

C_p

function [C_p] =  specific_heat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,R,temp,global_mid);
if temp <= global_mid
    C_p = R*(b1 + (b2*(temp)) + (b3*(temp).^2) + (b4*(temp).^3) +(b5*(temp).^4));
else
    C_p = R*(a1 + (a2*(temp)) + (a3*(temp).^2) + (a4*(temp).^3) +(a5*(temp).^4)); 
end

Entropy :

function [S] =  entropy(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,R,temp,global_mid);
if temp <= global_mid
    S = R.*(b1.*log(temp) + (b2.*(temp)) + (b3*(((temp).^2)./2)) + (b4.*(((temp).^3)./3)) +(b5.*(((temp).^4)./4)) + b7);
else
    S = R.*(a1.*log(temp) + (a2.*(temp)) + (a3.*(((temp).^2)./2)) + (a4.*(((temp).^3)./3)) +(a5.*(((temp).^4)./4)) + a7); 
end

Enthalphy :

function [h] =  enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,R,temp,global_mid);
if temp <= global_mid
    h = R.*temp.*(b1 + (b2.*(temp./2)) + (b3.*(temp)./3) + (b4*(temp./4)) +(b5.*(temp)./5) + (b6./temp));
else
    h = R.temp.*(a1 + (a2.*(temp./2)) + (a3.*(temp)./3) + (a4.*(temp./4)) +(a5.*(temp./5)) + (a6./temp));
end

Molecular weight :

function[MW] = molecular_weight(species_name)

element = {'H' 'C' 'N' 'O' 'Ar' };
atomic_weight = [1 12 14 16 40];

MW = O;

for i = 1:length(species_name)
    for j = 1:length(atomic_weight)
        if strcmpi(species_name(i),element(j))
            MW = MW + atomic_weight(j);
            
 q = j;
        end
    end
    
    m = str2double(species_name(i));
  
    if m>1 
       MW = MW + (atomic_weight(q)*(m - 1));
    end
    
  fprintf('molecular weight of %s is %d' , species_name,MW);
  disp(' ')
end
    
        

EXPLAINTION OF THE CODE :

First the Thermo.dat is to be open .

It should be read then read properly.

The main criteria of coding is to obtain coefficeints of different species and plot entropy,enthalpy for the same.

All these plots are plotted with respect to Temperature and saved in an different directory.

Results and Plots :

Various Properties for different species is as shown below.

FOR CO2

FOR N2

FOR O2 :

CONCLUSION:

We have successfully completed data parsing of the given data.

We can see the properties from the above graphs like entropy,enthalpy ,specific weight etc for different 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.