Project

Project on Parsing NASA thermodynamic data file

Here in this project I extract the file THERMO.dat which given by NASA. In which around 47 specices coefficient is contain and it also contain temperature range.

Link of file : https://drive.google.com/file/d/1AikCHDlz9s_fu8whE81qee_GD4AyYpCP/view

from here you can download the file THERMO.dat

I make code to calculate entropy , enthalpy and specific heat of given species from data. and also plot graph of this three properties with respect to temperature on X-axis. and calculate molecular weight of given species.

HERE IN MY MAIN CODE WHEN YOU RUN IT TAKE VALUE(NAME) OF SPECIES AS INPUT AND YOU HAVE TO ENTER THE NAME SPECIES FROM GIVEN NAME AT TIME OF RUNNING THE CODE.(NAME OF SHOULD BE IN CAPITAL LATTER BECAUSE ITS CASE CANSETIVE)

This code take all the value from the NASA data file (THERMO.dat). so, which value you are getting that all with respect to that file data only not versatile. This code for some given specices only.

Here in my code I use six function to read the file lines, extract coefficient, calculate entropy, calculate enthalpy, calculate specific heat, and calculate molecular weight and one my main code in which I plot the graph this different properties. all the function are discuss belove.

1) readline(n) : Here in this function it take line number as input and read the n+1 line from the file. So what ever n number line you want to read you have enter n-1 number and pass through from the function. Here in this function only it use THERMO.dat file to take input from file other function just use this function as input.

function [tline] = readline(n)

% this function read the n+1 line from given inpur of function. 
% if gave input as 6 its read line number_7.
A1 = fopen(\'THERMO.dat\',\'r\');
 lineData= fgetl(A1);
if A1 ~= -1
  for i= 2:n
    fgetl ( A1 );
  end
  tline = fgetl ( A1 );
  fclose ( A1 );
end

end

2) cof(n) : This function extract all the 14 co-efficient for the given species which we gave as input in main code. Here i extract all the 14 co-efficient one by one. fist of all this function read line by using readline function. and then convert all the value in string array and then in to a number. From this 14 co-efficient first 7 are high temperature co-efficient and last 7 are low temperature co-efficient.

function [E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14] = cof(i)

%this extract all the 14 coefficient for given species. 
b = i;
Z = findstr(readline(b),\'E\');
y = findstr(readline(b+1),\'E\');
u = findstr(readline(b+2),\'E\');

tline = readline(b);
E1 = tline(1:Z(1)+3);
E1 = str2num(E1);


E2 = tline(Z(1)+4:Z(2)+3);
E2 = str2num(E2);

E3 = tline(Z(2)+4:Z(3)+3);
E3 = str2num(E3);

E4 = tline(Z(3)+4:Z(4)+3);
E4 = str2num(E4);

E5 = tline(Z(4)+4:Z(5)+3);
E5 = str2num(E5);

tline = readline(b+1);
E6 = tline(1:y(1)+3);
E6 = str2num(E6);

E7 = tline(y(1)+4:y(2)+3);
E7 = str2num(E7);

E8 = tline(y(2)+4:y(3)+3);
E8 = str2num(E8);

E9 = tline(y(3)+4:y(4)+3);
E9 = str2num(E9);

E10 = tline(y(4)+4:y(5)+3);
E10 = str2num(E10);

tline = readline(b+2);
E11 = tline(1:u(1)+3);
E11 = str2num(E11);

E12 = tline(u(1)+4:u(2)+3);
E12 = str2num(E12);

E13 = tline(u(2)+4:u(3)+3);
E13 = str2num(E13);

E14 = tline(u(3)+4:u(4)+3);
E14 = str2num(E14);



end

3) antropy(n,T_min,T_mid,T_max) : This code calculate entropy of given species. This function take line number, mid ,minimum, and maximum temperature as input. calculate enthalpy for the minimum temperature renge to maximum temperature range. there two formula in the function first for high temperature range and second one for low temperature range. Both are use diffrent co-efficient value. range of temperature is given in the file and extact in main code. also mid temperature is given in file.

function [S] = antropy(n,T_min,T_mid,T_max)

% for given species calculate value of entropy at different low and high
% temperature
[E1, E2, E3, E4, E5, E6, E7, E8, E9 ,E10, E11, E12, E13, E14] = cof(n);
j = linspace(T_min,T_max,900);

if any(j>1000)
  S = E1.*log(j) + E2.*j + (E3.*(j.^2))/2 + (E4.*(j.^3))/3 + (E5.*(j.^4))./4 + E7
else
    S =  E8.*log(j) + E9.*j + (E10.*(j.^2))./2 + (E11.*(j.^3))./3 + (E12.*(j.^4))./4 + E14;
end


end

4) anthalpy(n,T_min,T_mid,T_max,R) : This function calculate enthalpy for the given input species. This function take line number, mid ,minimum, and maximum temperature as input and also take gas constant R as input. calculate enthalpy for minimum to maximum range of temperature and for both range its use different formulas.

function [H] = anthalpy(n,T_min,T_mid,T_max,R)

% for given species calculate value of enthalpy at different low and high
% temperature
[E1, E2, E3, E4, E5, E6, E7, E8, E9 ,E10, E11, E12, E13, E14] = cof(n);
k = linspace(T_min,T_max,900);
if any(k>1000)
    H = (E1 + E2.*(k./2) + (E3.*(k.^2))/3 + (E4.*(k.^3))./4 + (E5*(k.^4))./5 + (E6./k)).*(R.*k);

else
    H = (E8 + E9.*(k./2) + (E10.*(k.^2))./3 + (E11.*(k.^3))./4 + (E12.*(k.^4))./5 + (E13./k)).*(R.*k);
end

end

5) specific_heat(n,T_min,T_mid,T_max,R) : This function calculate the specific heat for given species. Its take line number , mid, minimum and maximum temperature as input and also take gas constant as input. Its also use to diffrent formulas to calculate specific heat for given species from minimum temperature range to maximum temperature range.

function [Cp] = specific_heat(n,T_min,T_mid,T_max,R)
% for given species calculate value of specific heat at different low and high
% temperature
[E1, E2, E3, E4, E5, E6, E7, E8, E9 ,E10, E11, E12, E13, E14] = cof(n);
l = linspace(T_min,T_max,900);
if any(l>1000)
    Cp = E1 + E2.*l + E3.*(l.^2) + E4.*(l.^4) + E5.*(l.^5);

else
    Cp = E8 + E9.*l + E10.*(l.^2) + E11.*(l.^4) + E12.*(l.^5);

end

end

6) weight(X) : This function calculate the molecular weight of the given species but this function is not versatile. You can use it only for given file species as given in the file because in this function I compare all the species molecular weight and when you input as \"O\" its gave the function and compare with \"O\" string or latter. this function pass character or string as input. When the value is compare and condition is true at that time that value asign as molecular weight of that species and its give that value in output.

function [M] = weight (X)
x = X;

% here compare all value of molecular weight by assign elseif condition
if strcmp(x,\'O\') == 1;
    M = 16;
    return;
elseif strcmp(x,\'O2\') == 1;
    M = 32;
    return;
elseif strcmp(x,\'H\') == 1;
    M = 1;
    return;
elseif strcmp(x,\'H2O\') == 1;
    M = 18;
    return;
elseif strcmp(x,\'OH\') == 1;
    M = 17;
    return;
elseif strcmp(x,\'H2\') == 1;
    M = 2;
    return;
elseif strcmp(x,\'HO2\') == 1;
    M = 33;
    return;
elseif strcmp(x,\'H2O3\') == 1;
    M = 50;
    return;
elseif strcmp(x,\'C\') == 1;
    M = 12;
    return;
elseif strcmp(x,\'CH\') == 1;
    M = 13;
    return;
elseif strcmp(x,\'CH2\') == 1;
    M = 14;
    return;   
elseif strcmp(x,\'CH2(S)\') == 1;
    M = 14;
    return;
elseif strcmp(x,\'CH3\') == 1;
    M = 15;
    return;
elseif strcmp(x,\'CH4\') == 1;
    M = 16;
    return;
elseif strcmp(x,\'CO\') == 1;
    M = 28;
    return;
elseif strcmp(x,\'CO2\') == 1;
    M = 44;
    return;
elseif strcmp(x,\'HCO\') == 1;
    M = 29;
    return;
elseif strcmp(x,\'CH2O\') == 1;
    M = 30;
    return;
elseif strcmp(x,\'CH2OH\') == 1;
    M = 31;
    return;
elseif strcmp(x,\'CH3O\') == 1;
    M = 31;
    return;
elseif strcmp(x,\'C2H2\') == 1;
    M = 26;
    return;
elseif strcmp(x,\'C2H6\') == 1;
    M = 30;
    return;
elseif strcmp(x,\'CH2CO\') == 1;
    M = 42;
    return;
elseif strcmp(x,\'HCCOH\') == 1;
    M = 42;
    return;
elseif strcmp(x,\'H2CN\') == 1;
    M = 28;
    return;
elseif strcmp(x,\'HCN\') == 1;
    M = 27;
    return;
elseif strcmp(x,\'HNO\') == 1;
    M = 31;
    return;
elseif strcmp(x,\'N\') == 1;
    M = 14;
    return;
elseif strcmp(x,\'NNH\') == 1;
    M = 29;
    return;
elseif strcmp(x,\'N2O\') == 1;
    M = 44;
    return;
elseif strcmp(x,\'NH\') == 1;
    M = 15;
    return;
elseif strcmp(x,\'NH2\') == 1;
    M = 16;
    return;
elseif strcmp(x,\'NH3\') == 1;
    M = 17;
    return;
elseif strcmp(x,\'NO\') == 1;
    M = 30;
    return;
elseif strcmp(x,\'HCNO\') == 1;
    M = 43;
    return;
elseif strcmp(x,\'HOCN\') == 1;
    M = 43;
    return;
elseif strcmp(x,\'HNCO\') == 1;
    M = 43;
    return;
elseif strcmp(x,\'NCO\') == 1;
    M = 42;
    return;
elseif strcmp(x,\'CN\') == 1;
    M = 26;
    return;
elseif strcmp(x,\'HCNN\') == 1;
    M = 37;
    return;
elseif strcmp(x,\'N2\') == 1;
    M = 28;
    return;
elseif strcmp(x,\'AR\') == 1;
    M = 40;
    return;
elseif strcmp(x,\'C3H8\') == 1;
    M = 44;
    return;
elseif strcmp(x,\'C3H7\') == 1;
    M = 43;
    return;
elseif strcmp(x,\'CH3CHO\') == 1;
    M = 44;
    return;
elseif strcmp(x,\'CH2CHO\') == 1;
    M = 43;
    return;
       
end
end

MAIN CODE : In this main code first of all, I extract value of temperature from the file by using readline function and give that function output as input to code and convert string array in the number.

Then I display all the 47 species of the file. so, user can input one of them. and get the output.

Then I take input from user and write a loop to find line number of that given input species. Then I call all the function in my main code and base on that output of function my code preaper plot for enthalpy, entropy , and specific heat with respect to temperature and also give molecular weight value as output.

This plot is save as .png file in current folder in which our code and function is exist. and assign name of file as \"plot for (name of species)\".

clc
clear all
close all

%Take the value of temperature from the file first and assign them proper
%name
tline1 = readline(0);
R = 8.314;
T = strsplit(tline1,\'\');
Tm = str2num(T{1});
T_min = Tm(1);
T_mid = Tm(2);
T_max = Tm(3);

% disple different species to the user to enter the one of them
disp(\'you can enter name of substance as : O, O2, H, H2, H2O, OH, HO2, H2O3, C, CH, CH2, CH2(S), CH3, CH4, CO, CO2, HCO, CH2O\')
disp(\'CH2OH, CH3O, C2H2, C2H6, CH2CO, HCCOH, H2CN, HCN, HNO, N, NNH, N2O, NH, NH2, NH3, NO, NO2, HCNO, HOCN, HNCO, NCO, CN, HCNN\')
disp(\'N2, AR, C3H8, C3H7, CH3CHO, CH2CHO (ALL LETTER ARE CASE SENSETIVE WRITE IN CAPITAL)\')
%weight = MolMass(x)

x = input(\'enter subtance: \', \'s\')    % take the name of species as input from user 
for a = 5:4:213
    R = readline(a);
idx = strfind(R,x);
n = a+1;
V = isempty(idx);
if V == 0 
break;
end

end

%plot the graph for enthalpy, entropy, and specific heat

j = linspace(T_min,T_max,900);
S = antropy(n,T_mid,T_min,T_max); 

k = linspace(T_min,T_max,900);
H = anthalpy(6,500,1000,5000,8.314);

l = linspace(T_min,T_max,900);
Cp = specific_heat(n,T_min,T_mid,T_max,R);

M = weight(x)
disp (sprintf(\'mass of substance: %d\', M))    % display the molecular weight

figure 
subplot(3,1,1)                          % plot for entropy
plot(S,j,\'color\',\'r\')          
title(sprintf(\'entropy of %s \',x))

subplot(3,1,2)                           % plot for enthalpy
plot(H,k,\'color\',\'b\')        
title(sprintf(\'enthalpy of %s\',x))

subplot(3,1,3)                          % plot for specific heat
plot(Cp,l,\'color\',\'k\')        
title(sprintf(\'specific heat of %s\',x))

saveas(gcf,sprintf(\'plot for %s.png\',x)) % this will save plot as .png figure in your current file.  
%  its save as \"plot for (name of species)\"

Plot for O2:

Plot for N2:

Plot for CO2:

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.