Project

Parsing NASA thermodynamic data

AIM:Parsing thermodynamics data.

The thermodynamic properties for various species are given below.



clear all
close all
clc

f1 = fopen(\'thermo30.dat\',\'r\')
Heading = fgetl(f1);

% Global Temperatures

global_temp = fgetl(f1);
for i = 1:3
    comments{i} = fgetl(f1);
end
a = strsplit(global_temp,\' \');
global_low_temp = str2num(a{2});
global_mid_temp = str2num(a{3});
global_high_temp = str2num(a{4});

%Atomic Mass
O = 16;

for k=1:53
    v1 = fgetl(f1);
    v2 = fgetl(f1);
    v3 = fgetl(f1);
    v4 = fgetl(f1);
    v{1} = v2;
    v{2} = v3;
    v{3} = v4;
    
    % Getting Species Names
    n = strsplit(v1,\' \');
    Name{k} = n{1};
    
    
    
    
    
    % Getting Temperature for Species
    G = findstr(v1,\'.\');
    x = v1(G(1)-3:G(1)+23);
    G_temp = strsplit(x,\'  \');
    G_temp_low(k) = str2num(G_temp{1});
    G_temp_mid(k) = str2num(G_temp{2});
    G_temp_high(k) = str2num(G_temp{3});
    
    % Getting Species Coefficients
    for j = 1:3
        E = strfind(v{j},\'E\');
        p(1) = -3;
        o = v{j};
        for i = 1:length(E)
            p(1+i) = E(i);
            Spicies{i} = o(p(i)+4:p(i+1)+3);
            sp(k,j,i)= str2num(Spicies{i});
        end
        clearvars E;
        clearvars o;
    end
    clearvars v1 v2 v3 v4 v G_temp;
end

fclose(f1)

% Solving

% The gas constant R is 8.314 J / mol
R = 8.314;

% High Temperature Coefficients Arrangment
for k = 1:53
    for i = 1:5
        High_temp_coefficiants(k,i) = sp(k,1,i);
    end
    for i = 6:7
        High_temp_coefficiants(k,i) = sp(k,2,i-5);
    end
end

% Low Temperature Coefficients Arrangment
for k = 1:53
    for i = 1:3
        low_temp_coefficiants(k,i) = sp(k,2,i+2);
    end
    for i = 4:7
        low_temp_coefficiants(k,i) = sp(k,3,i-3);
    end
end

% Calculation of Cp
for k = 1:53
    
    % High Temperature 
    Cp_high(k) = R*(High_temp_coefficiants(k,1)+High_temp_coefficiants(k,2)*G_temp_high(k)+High_temp_coefficiants(k,3)*G_temp_high(k)^2+High_temp_coefficiants(k,4)*G_temp_high(k)^3+High_temp_coefficiants(k,5)*G_temp_high(k)^4);
    Cp_low(k) = R*(low_temp_coefficiants(k,1)+low_temp_coefficiants(k,2)*G_temp_low(k)+low_temp_coefficiants(k,3)*G_temp_low(k)^2+low_temp_coefficiants(k,4)*G_temp_low(k)^3+low_temp_coefficiants(k,5)*G_temp_low(k)^4);
end

% Calculation of H
for k = 1:53
     % High Temperature 
    H_high(k) = R*G_temp_high(k)*(High_temp_coefficiants(k,1)+High_temp_coefficiants(k,2)*(G_temp_high(k))/2+High_temp_coefficiants(k,3)*(G_temp_high(k)^2)/3+High_temp_coefficiants(k,4)*(G_temp_high(k)^3)/4+High_temp_coefficiants(k,5)*(G_temp_high(k)^4)/5+High_temp_coefficiants(k,6)/G_temp_high(k));
    H_low(k) = R*G_temp_low(k)*(low_temp_coefficiants(k,1)+low_temp_coefficiants(k,2)*(G_temp_low(k))/2+low_temp_coefficiants(k,3)*(G_temp_low(k)^2)/3+low_temp_coefficiants(k,4)*(G_temp_low(k)^3)/4+low_temp_coefficiants(k,5)*(G_temp_low(k)^4)/5+low_temp_coefficiants(k,6)/G_temp_low(k));
end

% Calculation of S
for k = 1:53
     % High Temperature 
    S_high(k) = R*(High_temp_coefficiants(k,1)*log(G_temp_high(k))+High_temp_coefficiants(k,2)*G_temp_high(k)+High_temp_coefficiants(k,3)*(G_temp_high(k)^2)/2+High_temp_coefficiants(k,4)*(G_temp_high(k)^3)/3+High_temp_coefficiants(k,5)*(G_temp_high(k)^4)/4+High_temp_coefficiants(k,7));
    S_low(k) = R*(low_temp_coefficiants(k,1)*log(G_temp_low(k))+low_temp_coefficiants(k,2)*G_temp_low(k)+low_temp_coefficiants(k,3)*(G_temp_low(k)^2)/2+low_temp_coefficiants(k,4)*(G_temp_low(k)^3)/3+low_temp_coefficiants(k,5)*(G_temp_low(k)^4)/4+low_temp_coefficiants(k,7));
end

% Species Name Arrangment
names_species = categorical(Name);
for k =1:53
    for i=1
        cp(k,i)= Cp_high(k);
        H(k,i) = H_high(k);
        S(k,i) = S_high(k);
    end
    for i=2
        cp(k,i)= Cp_low(k);
        H(k,i) = H_low(k);
        S(k,i) = S_low(k);
    end
end


% Plotting


figure(1)
bar(names_species,cp)
legend(\'Cp for High Temp\',\'Cp for Low temp\')
saveas(gcf,\'Cp.jpg\')
saveas(gcf,\'Cp.pdf\')

figure(2)
bar(names_species,H)
legend(\'H for High Temp\',\'H for Low temp\')
saveas(gcf,\'H.jpg\')
saveas(gcf,\'H.pdf\')

figure(3)
bar(names_species,S)
legend(\'S for High Temp\',\'S for Low temp\')
saveas(gcf,\'S.jpg\')
saveas(gcf,\'S.pdf\')


% Calculating Molecular mass of Species

for k = 1:53
    nam = Name{k};
   % Checking for C
   Carbon = strfind(nam,\'C\');
   % Checking for H
   Hydrogen = strfind(nam,\'H\');
   % Checking for O
   Oxygen = strfind(nam,\'O\');
   % Checking for N
   Nitrogen = strfind(nam,\'N\');
   % Checking for Ar
   Argon = strfind(nam,\'AR\');
   
   %Mass of Carbon
   if ~isempty(Carbon)
       Mass_C = 0;
       for i = 1:length(Carbon)
           if ischar(nam(Carbon(i))+1) ~= 0 && Carbon(i)+1 > length(nam)
               num = str2num(nam(Carbon(1))+1);
               Mass_C = 12.011*num +Mass_C;
               num = 0;
           else
               Mass_C = 12+Mass_C;
           end
       end
   else
       Mass_C = 0;
   end
   
 %Mass of Hydrogen
   if ~isempty(Hydrogen)
       Mass_H = 0;
       for i = 1:length(Hydrogen)
           if ischar(nam(Hydrogen(i))+1) ~= 0 && Hydrogen(i)+1 < length(nam)
               num = str2num(nam(Hydrogen(1))+1);
               Mass_H = 12*num +Mass_H;
               num = 0;
           else
               Mass_H = 1.008+Mass_H;
           end
       end
   else
       Mass_H = 0;
   end
   
   %Mass of Nitrogen
   if ~isempty(Nitrogen)
       Mass_N = 0;
       for i = 1:length(Nitrogen)
           if ischar(nam(Nitrogen(i))+1) ~= 0 && Nitrogen(i)+1 < length(nam)
               num = str2num(nam(Nitrogen(1))+1);
               Mass_N = 12*num +Mass_N;
               num = 0;
           else
               Mass_N = 14.007+Mass_N;
           end
       end
   else
       Mass_N = 0;
   end
   
    %Mass of Oxygen
   if ~isempty(Oxygen)
       Mass_O = 0;
       for i = 1:length(Oxygen)
           if ischar(nam(Oxygen(i))+1) ~= 0 && Oxygen(i)+1 < length(nam)
               num = str2num(nam(Oxygen(1))+1);
               Mass_O = 15.999*num +Mass_O;
               num = 0;
           else
               Mass_O = 1+Mass_O;
           end
       end
   else
       Mass_O = 0;
   end
   
    %Mass of Argon
   if ~isempty(Argon)
       Mass_AR = 0;
       for i = 1:length(Argon)
           if ischar(nam(Argon(i))+1) ~= 0 && Argon(i)+1 < length(nam)
               num = str2num(nam(Argon(1))+1);
               Mass_AR = 39.948*num +Mass_AR;
               num = 0;
           else
               Mass_AR = 1+Mass_AR;
           end
       end
   else
       Mass_AR = 0;
   end
           
   molecule_mass(k) = Mass_C+Mass_H+Mass_O+Mass_N+Mass_AR
  
   
end

% Writing Results
f2 = fopen(\'result.txt\',\'w\');
fprintf(f2,\'%s %s %s %s %s %s %s\',\'Species\',\'Cp High Temp\',\'Cp Low Temp\',\'Enthalpy High Temp\',\'Enthalpy Low Temp\',\'Entropy High Temp\',\'Entropy Low Temp\');
fprintf(f2,\'\\n\');
for k= 1:53
    % Since FPRINTF Do not support array
    N = Name{k};
    CPH = Cp_high(k);
    CPL = Cp_low(k);
    HH = H_high(k);
    HL = H_low(k);
    SH = S_high(k);
    SL = S_low(k);
    
    fprintf(f2,\'%s %f %f %f %f %f %f\',N,CPH,CPL,HH,HL,SH,SL);
    fprintf(f2,\'\\n\');
    
    clearvars N CPH CPL HH HL SH SL;
end
fclose(f2)

PLOTS

O2:

CO2:

N2:

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.