Challenge

Project 1 - Parsing NASA thermodynamic data

Project No.2 :- Parsing NASA Thermodynamic Data

Aim :-

To write a Matlab program to extract 14 coefficient from the matlab 'THERMO.dat.txt file to calculate enthalpy, entropy, SP. heat for all species and plot for the same.

Objective :-

1) To write a matlab code for extracting data form all species.

2) To write a matlab code to calculate enthalpy, entropy, SP. heat for all species.

3) To write matlab code for calculating molecular weight

Theory :-

File Parsing :-

File parsing is to be done for ectract dtata from the file,it also be define as breaking the data block into smaller block, So it can be more easily interperted.

Where,

Cp :- Sp. Heat

H :- Enthalpy

S :- Entropy

R :- Gas constant

T :- Temperature

Stepwise Procedure of Logic behind extacting data :-

1) For clearing all previous data used close all, clear all,clc command.

2) Then we red THERMO.DAT.txt file to calculate process variables.

3) To read the file we assigned to a variable called 'f' in order to get data with respect to global temp.

4) To get next line we used 'fgetl' cmd

5) Now we get data in string form we have to convert into number by using 'str2num.

6) Next step is assigned value of global temp. data

7) Now next 3 lines are CMD line so it can be ignore we skid next 2 line by using 'for loop'

8) To get local temp value we used 'fgetl' & 'strplit' CMD

9) Similarly by using upper cmd we calculate 14 values of coff. form each species

10) First 7 species are of high temperature coff. and next 7 are lower temp.

11) Now we will define higher and lower temp with help of linspace cmd.

12) Next step is to calculate Cp, h, S, for lower and hight temp vlaues

13) After putting all values of enthalpy, entropy, Sp. heat we have to plot the graph to see the nature of the ghrphs

14) For saving all the plots in respective folder we use 'mkdir(species_name)' snd

15) After code get executed 'cd(current_dir) cmd helps to return to the original folder

Main Program

clear all
close all
clc

%Define gas constant
R=8.314;
f1=fopen('THERMO.dat','r');
fgetl(f1);

%Reading cmd line
globe_temp=fgetl(f1);
%spliting line with space
temp_range=strsplit(globe_temp,' ');
%define the globle temperature
low_temp=str2num(temp_range{2});
mid_temp=str2num(temp_range{3});
high_temp=str2num(temp_range{4});

cmd1=fgetl(f1);
cmd2=fgetl(f1);
cmd3=fgetl(f1);

for i=1:53
    A=fgetl(f1);
    c=strsplit(A,' ');
    species_name=c{1};
% end

%defining local Temperature in species

local_low_temp=c{end-3};
local_low_temp=str2num(local_low_temp);

local_mid_temp=c{end-1};
local_mid_temp=str2num(local_mid_temp);

local_high_temp=c{end-2};
local_high_temp=str2num(local_high_temp);

T=linspace(local_low_temp,local_high_temp,1000);

%Reading th coefficients
line1=fgetl(f1) %reading 1st line of coff.
a=strfind(line1,'E')
% a1 to a7 is high temp coff.

a1=line1(1:a(1)+3);
a1=str2num(a1)

a2=line1(a(1)+4:a(2)+3);
a2=str2num(a2)

a3=line1(a(2)+4:a(3)+3);
a3=str2num(a3)

a4=line1(a(3)+4:a(4)+3);
a4=str2num(a4)

a5=line1(a(4)+4:a(5)+3);
a5=str2num(a5)

%Reading next line to get the second set of coff.

line2=fgetl(f1)

a=strfind(line2,'E');
a6=line2(1:a(1)+3);
a6=str2num(a6)
a7=line2(a(1)+4:a(2)+3);
a7=str2num(a7)

% a8 to a14-Low temperature coefficients.

a8=line2(a(2)+4:a(3)+3);
a8=str2num(a8)

a9=line2(a(3)+4:a(4)+3);
a9=str2num(a9)

a10=line2(a(4)+4:a(5)+3);
a10=str2num(a10)

%next line to get the third set of coff.

line3=fgetl(f1);
a=strfind(line3,'E');

a11=line3(1:a(1)+3);
a11=str2num(a11)

a12=line3(a(1)+4:a(2)+3);
a12=str2num(a12)

a13=line3(a(2)+4:a(3)+3);
a13=str2num(a13)

a14=line3(a(3)+4:a(4)+3);
a14=str2num(a14)

%calculating value's for cp,H,S

for j=1:length(T)
    if T(j)<local_mid_temp
cp(j) = (a1+a2.*T(j)+a3.*T(j).^2+a4.*T(j).^3+a5.*T(j).^4).*R;
H = (a1+(a2*T)/2+(a3*T.^2)/3+(a4*T.^3)/4+(a5*T.^4)/5+(a6./T))*R.*T;
S = a1*log(T)+a2*T+(a3*T.^3)/2+(a4*T.^3)/3+(a5*T.^4)/4+a7;

 
    else
cp(j) = (a8+a9.*T(j)+a10.*T(j).^2+a11.*T(j).^3+a12.*T(j).^4).*R;
H = (a8+(a9*T)/2+(a10*T.^2)/3+(a11*T.^3)/4+(a12*T.^4)/5+(a13./T))*R.*T;
S = a8*log(T)+a9*T+(a10*T.^2)/2+(a11*T.^3)/3+(a12*T.^4)/4+a14;

    end
end

%Plotting 

figure(1)
plot(T,S,'LineWidth',3,'color','r');
title(species_name)
xlabel('Temperature(T)')
ylabel('Entropy(S)')
grid on

%Tempearture vs Enthalpy

figure(2)
plot(T,H,'LineWidth',3,'color','b');
title(species_name)
xlabel('Temperature(T)')
ylabel('Enthalpy(H)')
grid on;

% Temperature vs specific heat
figure(3)
plot(T,cp,'LineWidth',3,'color','r');
title(species_name)
xlabel('Temperature(T)')
ylabel('Specific Heat(H)')
grid on;

% making folders
mkdir(species_name);
cd(species_name);
saveas(1,'specific heat.jpg');
saveas(2,'Temp vs Entropy.jpg');
saveas(3,'Temp vs Enthalpy.jpg');
cd ..
% cd('D:\Skill-Lync\Matlab project\Challenges\Project No-01')


end

% Molecular weight calculation

elements = ['H','C','O','N','A'];
atomic_weight =[1.0079 12.0107 15.999 14.00673 39.948];

mol_mass = 0;for i = length(species_name)
    for m = 1:length(atomic_weight)
        if strcmp(species_name(1),elements(m))
            mol_mass = mol_mass+atomic_weight(m);
            position = m
        end
    end
    n = str2double(species_name(1));
    if n>1
        mol_mass = mol_mass+atomic_weight(position)*(n-1)
    end


sprintf('molecular weight of %s.%fu',species_name,mol_mass)
end





Output command window of molecular weight calculation :-

Plot of some species :-

Species Name :- AR

Species Name :- C2H

Automatic folder Generation for all species :-

Conclusion :-

We Have successfully parsed the coefficient value of ecah species from the NASA thermodymamic file and getting plot for enthalpy, entropy and Sp heat

Reference :-

1)https://skill-lync.com/student-projects/project-1-parsing-nasa-thermodynamic-data-427

2)https://skill-lync.com/student-projects/project-1-parsing-nasa-thermodynamic-data-519

3)https://skill-lync.com/student-projects/project-1-parsing-nasa-thermodynamic-data-312

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.