Challenge

Project 1 - Parsing NASA thermodynamic data

AIM:-

  • To prase THERMO.dat file having NASA's thermodynamic data and to calculate thermodynamic properties

OBJECTIVES:-

  • To Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.

THEORY:-

file prasing

  • Parsing in computer languages refers to syntactic analysis of the input data normally from a file into its components parts in order to facilitate the writing of compilers and interpreters. It can be used to describe split or separation.

MATHEMATICAL EQUATION:

cp-specific heat

H-enthalpy

S-entropy

R-universal gas constant

T-temperature

function code of specific heat

function [cp]=specific_heat(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T,M_T)
R  = 8.314
if T>M_T
    cp=(coef_1+coef_2*T+coef_3*T.^2+coef_4*T.^3+coef_5*T.^4)*R
else 
    cp=(coef_8+coef_9*T+coef_10*T.^2+coef_11*T.^3+coef_12*T.^4)*R
end
end 

function code of enthalpy

function [H]=enthalpy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T,M_T)
R  = 8.314;
if T>M_T
H = (coef_1+(coef_2.*T/2)+ (coef_3*(T.^2)/3)+ (coef_4*(T.^3/4))+(coef_5*(T.^4)/5)+(coef_6/T))*R*T;
    
else
    
H = (coef_8+(coef_9.*T/2)+ (coef_10*(T.^2)/3)+ (coef_11*(T.^3/4))+(coef_12*(T.^4)/5)+(coef_13/T))*R*T;
end

end

function code of entropy

function [s]=entropy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T,M_T)
R  = 8.314;
if T>M_T
 s=((coef_1*log(T))+(coef_2*T)+((coef_3*(T^2))/2)+((coef_4*(T^3))/3)+(coef_5*(T^4)/4)+coef_7); 
else
 s=((coef_8*log(T))+(coef_9*T)+((coef_10*(T^2))/2)+((coef_11*(T^3))/3)+(coef_12*(T^4)/4)+coef_14); 
   
end

end

function code to calculate molar mass

function mol_mass = molmass(Species_name)     

     elements = ['H','C','O','N','A','S'];
     atomic_weight = [1.0079 12.0107 15.999 14.0067 39.948 32.065];
     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
end

main code

clear all 
close all
clc

file_1=fopen('THERMO.dat','r');
% read header information
for i=1:5
    k = fgetl(file_1);
    
    if i == 2
        global_temp = k;
    end
end
% reading species block
% line 1
for i = 1:53
line_1 = fgetl(file_1);
temp_line = strsplit(line_1,' ');

Species_name =temp_line{1};

L_T = str2double(temp_line{(length(temp_line)-3)});
H_T = str2double(temp_line{(length(temp_line)-2)});
M_T = str2double(temp_line{(length(temp_line)-1)});
% line 2
line_2 = fgetl(file_1);
% coefficient 1
a = strfind(line_2,'E');
a_1 = line_2(1:a(1)+3);
coef_1 = str2double(a_1);
% coefficient 2

a_1= line_2(a(1)+4:a(2)+3);
coef_2 = str2double(a_1);

% coefficient 3
a_1 = line_2(a(2)+4:a(3)+3);
coef_3 = str2double(a_1);


% coefficient 4
a_1 = line_2(a(3)+4:a(4)+3);
coef_4 = str2double(a_1);

% coefficient 5
a_1 = line_2(a(4)+4:a(5)+3);
coef_5 = str2double(a_1);
% coefficient 6
%line 3
line_3 = fgetl(file_1);

a = strfind(line_3,'E');
a_1 = line_3(1:a(1)+3);
coef_6 = str2double(a_1);

% coefficient 7
a_1= line_3(a(1)+4:a(2)+3);
coef_7 = str2double(a_1);

% coefficient 8
a_1 = line_3(a(2)+4:a(3)+3);
coef_8 = str2double(a_1);

% coefficient 9

a_1 = line_3(a(3)+4:a(4)+3);
coef_9 = str2double(a_1);

% coefficient 10
a_1 = line_3(a(4)+4:a(5)+3);
coef_10 = str2double(a_1);

%line 4
% coefficient 11
line_4 = fgetl(file_1);

a = strfind(line_4,'E');
a_1 = line_4(1:a(1)+3);
coef_11 = str2double(a_1);

% coefficient 12
a_1= line_4(a(1)+4:a(2)+3);
coef_12 = str2double(a_1);

% coefficient 13
a_1 = line_4(a(2)+4:a(3)+3);
coef_13 = str2double(a_1);

% coefficient 14

a_1 = line_4(a(3)+4:a(4)+3);
coef_14 = str2double(a_1);
% temperature
T=linspace(L_T,H_T,1000);
% calculate specific heat(cp),enthalpy(H),entropy(s)
for k = 1:length(T)
 [cp(k)]=specific_heat(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,...
     coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T(k),M_T);
 
  
[H(k)]=enthalpy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,...
    coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T(k),M_T);


[s(k)]=entropy(coef_1,coef_2,coef_3,coef_4,coef_5,coef_6,coef_7,coef_8,...
    coef_9,coef_10,coef_11,coef_12,coef_13,coef_14,T(k),M_T);

end
% making the directery to create folder
     mkdir(Species_name)
     cd(sprintf(Species_name))
% ploting of specific heat
     figure(1)
     plot(T,cp,'color','g','linewidth',3)
     xlabel('Temperature(K)')
     ylabel('specific heat(J/K Kg)')
     title({'specific heat vs temperature','Species name = species_name & Molecular weight = num2str(mol_mass)'});
     saveas(figure(1),'Cp vs temp.jpg')
% ploting of entalpy
     figure(2)
     plot(T,H,'color','b','linewidth',3)
     xlabel('Temperature(K)')
     ylabel('enthalpy(J/K)')
     title({'enthalpy vs temperature','Species name = species_name & Molecular weight = num2str(mol_mass)'});
     saveas(figure(2),'enthalpy vs temp.jpg')
% ploting of entopy
     figure(3)
     plot(T,s,'color','r','linewidth',3)
     xlabel('Temperature(K)')
     ylabel('entorpy(J/K)')
     title({'entorpy vs temperature','Species name = species_name & Molecular weight = num2str(mol_mass)'});
     saveas(figure(3),'entorpy vs temp.jpg')

     oldfolder = cd('C:\Users\Lenovo\Documents');
%      calculating the molar mass
     mol_mass = molmass(Species_name);
     fprintf ('Mol_mass of %s = %f\n',Species_name,mol_mass);
    
end

out put

for O2

for N2

for CO2

like this plots created for all 53 species

current folder

work space

molar masses

which printed in command window

Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of O = 15.999000
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of O2 = 31.998000
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of H = 1.007900
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of H2 = 2.015800
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of OH = 17.006900
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of H2O = 18.014800
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of HO2 = 33.005900
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of H2O2 = 34.013800
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of C = 12.010700
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH = 13.018600
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH2 = 14.026500
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH2(S) = 46.091500
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH3 = 15.034400
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH4 = 16.042300
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CO = 28.009700
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CO2 = 44.008700
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of HCO = 29.017600
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH2O = 30.025500
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH2OH = 31.033400
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH3O = 31.033400
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH3OH = 32.041300
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of C2H = 25.029300
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of C2H2 = 26.037200
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of C2H3 = 27.045100
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of C2H4 = 28.053000
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of C2H5 = 29.060900
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of C2H6 = 30.068800
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of CH2CO = 42.036200
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of HCCO = 41.028300
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of HCCOH = 42.036200
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of H2CN = 28.033200
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of HCN = 27.025300
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of HNO = 31.013600
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of N = 14.006700
Warning: Directory already exists.
> In file_prasing (line 110)
Mol_mass of NNH = 29.021300
Warning: Directory already exists.
> In file_prasing (line 110)

RESULTS

  1. Thermodynamic properties are calculated of specific heat ,enthalpy, entropy
  2. specific heat ,enthalpy, entropy vs temperature All plots are saved for all 53 species
  3. molar masses are calculated and printed in command window
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.