Project

PARSING NASA s THERMODYNAMIC DATA using MATLAB

PARSING NASA THERMODYNAMIC DATA

Thermodynamic properties like Specific heat(Cp), Enthalpy(h), Entropy(s) are used in thermodynamic applications. These properties are dependent on temperature for which NASA has established an empirical relation. The values of coefficients in the relation for different temperature ranges are listed and stored in a text file format. This report gives a detailed explanation of parsing the text file and calculating the properties.

The thermodynamic data are in the form of least-squares coefficients, which are generated by fitting heat capacity, enthalpy, and entropy simultaneously. Heat capacity is represented by a fourth-degree polynomial in temperature. In addition to the coefficients for heat capacity, integration constants are provided to obtain enthalpy and entropy. The temperature range over which the data have been fitted is not the same for all species.

The code starts as input data is first provided for thermodynamic co-relations. fopen function is used to read the file.

Again use fopen for writing the molecular weights. Each line of the file that was read and stored them in a variable can be read by fgetl function and store that line in a variable in the form of string.

for loop can be used to read the coefficients and local temperatures of each gas.

Using fgetl function ,each time the loop run, each line is stored in a variable.

To load the local temperature ranges in a variable after converting them to double precision values. These values are used to make lower local temperature ranges and higher local temperature ranges using linspace function.

To note down the values of the coefficients and store each of them in a different variable after converting them to double precision values. Then they are divided as lower temperature coefficients and higher temperature coefficients and are store in a variable.

Again for loop is used to calculate the specific heat, enthalpy, entropy. For lower local temperature ranges, lower temperature coefficients are used to calculate cp, H, S. Similarly for higher local temperature ranges, higher temperature coefficients are used to calculate cp, H, S.

To store the plots of each species in respective folders mkdir is used to create a folder on species name then cd is used to open the folder, after storing the plots again cd is used to get back to the current folder using pwd.

Creating plots plot command is used to create plots for each species.

Molecular weights have also been calculated.

clear all 
close all
clc

Data = fopen(\'THERMO.dat\',\'r\');

Weights = fopen(\'weights.txt\',\'w\');


line = fgetl(Data);

%gas constant
R = 8.314

%Reading global temperatures
g_temp_range = fgetl(Data)
S = strsplit(g_temp_range,\' \');
temp = str2double(S);
gmin = temp(:,2);
gmid = temp(:,3);
gmax = temp(:,4);

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

%Reading the values
for i = 1:54
    l1 = fgetl(Data);
    A_1 = strsplit(l1,\' \');
    species = A_1{1};
    min = l1(45+4:45+10);
    max = l1(45+13:45+20);
    mid = l1(45+23:45+30);
    l1_temp_min = str2double(min);
    l1_temp_max = str2double(max);
    l1_temp_mid = str2double(mid);
    
    Tl = linspace(l1_temp_min,l1_temp_mid,100);
    Th = linspace(l1_temp_mid,l1_temp_max,100);
    
    l2 = fgetl(Data);
    h1 = strfind(l2,\'E\');
    
    c1 = l2(1:h1(1)+3);
    c2 = l2(h1(1)+4:h1(2)+3);
    c3 = l2(h1(2)+4:h1(3)+3);
    c4 = l2(h1(3)+4:h1(4)+3);
    c5 = l2(h1(4)+4:h1(5)+3);
    
    l3 = fgetl(Data);
    h1 = strfind(l3,\'E\');
    
    c6 = l3(1:h1(1)+3);
    c7 = l3(h1(1)+4:h1(2)+3);
    c8 = l3(h1(2)+4:h1(3)+3);
    c9 = l3(h1(3)+4:h1(4)+3);
    c10 = l3(h1(4)+4:h1(5)+3);
    
    l4 = fgetl(Data);
    h1 = strfind(l4,\'E\');
    
    c11 = l4(1:h1(1)+3);
    c12 = l4(h1(1)+4:h1(2)+3);
    c13 = l4(h1(2)+4:h1(3)+3);
    c14 = l4(h1(3)+4:h1(4)+3);
    
    C1 = str2double(c1);
    C2 = str2double(c2);
    C3 = str2double(c3);
    C4 = str2double(c4);
    C5 = str2double(c5);
    C6 = str2double(c6);
    C7 = str2double(c7);
    C8 = str2double(c8);
    C9 = str2double(c9);
    C10 = str2double(c10);
    C11 = str2double(c11);
    C12 = str2double(c12);
    C13 = str2double(c13);
    C14 = str2double(c14);
    
    lc = [ C1 C2 C3 C4 C5 C6 C7 ]
    uc = [ C8 C9 C10 C11 C12 C13 C14 ]
    
 for j = 1:100
        cp_1(j) = R*[lc(1)+(lc(2)*Tl(j))+(lc(3)*Tl(j)^2)+(lc(4)*Tl(j)^3)+(lc(5)*Tl(j)^4)]; 
        H_1(j) = R*Tl(j)*[lc(1)+((lc(2)*Tl(j))/2)+((lc(3)*Tl(j)^2)/3)+((lc(4)*Tl(j)^3)/4)+((lc(5)* Tl(j)^4)/5)+(lc(6)/Tl(j))];
        S_1(j) = R*[(lc(1)*log(Tl(j)))+(lc(2)*Tl(j))+((lc(3)*Tl(j)^2)/2)+((lc(4)*Tl(j)^3)/3)+((lc (5)*Tl(j)^4)/4)+lc(7)]; 
        cp_2(j) = R*[uc(1)+uc(2)*Th(j)+uc(3)*Th(j)^2+uc(4)*Th(j)^3+uc(5)*Th(j)^4];
        H_2(j) = R*Th(j)*[uc(1)+((uc(2)*Th(j))/2)+((uc(3)*Th(j)^2)/3)+((uc(4)*Th(j)^3)/4)+((uc(5)* Th(j)^4)/5)+(uc(6)/Th(j))]; 
        S_2(j) = R*[(uc(1)*log(Th(j)))+(uc(2)*Th(j))+((uc(3)*Th(j)^2)/2)+((uc(4)*Th(j)^3)/3)+((uc (5)*Th(j)^4)/4)+uc(7)];
 end

   mkdir(species)
   cur_dir = pwd;
   cd(species)
   
   %plots with lowertemperature ranges and lower temp coefficients
   %plot between lower temperature range and specific heat 1
   figure(1);
   plot(Tl,cp_1);
   xlabel(\'lower temperature\');
   ylabel(\'specific heat\');
   title(\'lower temperatures vs specific heat\');
   
   %plot between lower temperature and enthalpies
   figure(2);
   plot(Tl,H_1);
   xlabel(\'lower temperatures\');
   ylabel(\'Enthalpy\');
   title(\'lower temperature vs enthalpy\');
   
   %plot between lower temperature range and entropy
   figure(3);
   plot(Tl,S_1);
   xlabel(\'lower temperature\');
   ylabel(\'entropy\');
   title(\'lower temperature vs entropy\');
   
   %plots between higher temperature range and higher coeff.
   %plot between higher temp and specific heat
   figure(4);
   plot(Th,cp_2);
   xlabel(\'higher temp\');
   ylabel(\'specific heat\');
   title(\'higher temp vs specific heat\');
   
   %plot between high temp and enthalpy
   figure(5);
   plot(Th,H_2);
   xlabel(\'higher temperature\');
   ylabel(\'enthalpy\');
   title(\'higher temp vs enthalpy\');
   
   %plot between higher temp and entropy
   figure(6);
   plot(Th,S_2);
   xlabel(\'higher temperature\');
   ylabel(\'entropy\');
   title(\'higher temp vs entropy\');
   
   %saving the plot
   saveas(figure(1),\'lowtemp_vs_specific_heat.png\');
   saveas(figure(2),\'lowtemp_vs_enthalpy.png\');
   saveas(figure(3),\'lowtemp_vs_entropy.png\');
   saveas(figure(4),\'hightemp_vs_specific_heat.png\');
   saveas(figure(5),\'hightemp_vs_enthalpy.png\');
   saveas(figure(6),\'hightemp_vs_entropy.png\');
   
   
   cd(cur_dir);
   
   M(i) = molecular_weight(species);
   fprintf(Weights, \'%s %s %f \\n\',species,\'Molecular Weight = \',M(i));
   
end
   
   
    


function [mol_weight] = molecular_weight(element)

Atoms = [\'O\',\'H\',\'N\',\'C\',\'AR\'];
Atomic_weights = [16,1,14,12,40];
mol_weight = 0;

for i = 1:length(element)
    for j = 1:length(Atoms)
        if strcmp(element(i),Atoms(j))
            mol_weight = mol_weight + Atomic_weights(j);
            k = j;
        end
    end
    num = str2double(element(i));
    if num>1
        mol_weight = mol_weight + Atomic_weights(k)*(num-1);
    end
end
end

****O2****

****N2****

****CO2****

MOLECULAR WEIGHTS :

SAVING OF ALL FILES

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.