NASA File Parsing

Aim - To parse the Nasa Thermodynamics data and to calculate the thermodynamic properties of the species.

Theory - What is Data parsing? 

Data Parsing is the technique of breaking down a large block of data into meaningful and useful smaller blocks.

In this program, we are going to parse the NASA's thermodynamic data which contain 14 variables of 53 species. We are going to extract the data and use it to calculate various thermal properties of the species.

NASA came up with polynomials to evaluate thermodynamic properties such as Cp, H and S. We are going to use this polynomial to calculate the various properties.

  • NASA POLYNOMIAL
  1. Cp/R = a1 + a2*T + a3*T^2 + a4*T^3 + a5*T^4
  2. H/RT = a1 + a2*T /2 + a3*T^2 /3 + a4*T^3 /4 + a5*T^4 /5
  3. S/R = a1 lnT + a2 T + a3 T^2/2+ a4 T^3/3 + a5 T^4/4 + a7

Program -

close all
clear all
clc

% reading file 
file=fopen('THERMO.dat','r');

%Heading 
line_1 = fgetl(file)

% global temperature value
line_2 = fgetl(file)

% reading comment for next 3 lines
for i = 1:3
   C = fgetl(file)
   comment(i) = C(i);
end

A = strsplit(line_2,' ');
global_low_temperature = str2num(A{2})
global_mid_temperature = str2num(A{3})
global_high_temperature = str2num(A{4})

% Species information
for i = 1:53
    
    species = fgetl(file);
    species_name = species(1:6)
    
    line1 = fgetl(file);
    
    L1 = strfind(line1,'E');
    
    c1 = str2num(line1(1:(L1(1)+3)));
    
    c2 = str2num(line1((L1(1)+4):(L1(2)+3)));
    
    c3 = str2num(line1((L1(2)+4):(L1(3)+3)));
    
    c4 = str2num(line1((L1(3)+4):(L1(4)+3)));
    
    c5 = str2num(line1((L1(4)+4):(L1(5)+3)));
    
    % 2nd line
    
    line2 = fgetl(file);
    
    L2 = strfind(line2,'E');
    
    c6 = str2num(line2(1:(L2(1)+3)));
    
    c7 = str2num(line2((L2(1)+4):(L2(2)+3)));
    
    c8 = str2num(line2((L2(2)+4):(L2(3)+3)));
    
    c9 = str2num(line2((L2(3)+4):(L2(4)+3)));
    
    c10 = str2num(line2((L2(4)+4):(L2(5)+3)));
    
    % line 3
    
    line3 = fgetl(file);
    
    L3 = strfind(line3,'E');
    
    c11 = str2num(line3(1:(L3(1)+3)));
    
    c12 = str2num(line3((L3(1)+4):(L3(2)+3)));
    
    c13 = str2num(line3((L3(2)+4):(L3(3)+3)));
    
    c14 = str2num(line3((L3(3)+4):(L3(4)+3)));
    
    % creating folder for each species
    
    mkdir(['C:\Users\hp\Desktop\skill lync\matlab\species\',species_name]);
    
    Temperature = linspace(300,5000,100);
    
    R = 8.314;
    
    % calculations for properties in lower and upper temperature range
    for j = 1:length(Temperature)
        if Temperature(j)<3000
            Cp = (c1+c2.*Temperature+c3.*Temperature.^2+c4.*Temperature.^3+c5.*Temperature.^4).*R;
            H = (c1+(c2.*Temperature)./2+(c3.*Temperature.^2)/3+(c4.*Temperature.^3)/4+(c5.*Temperature.^4/5)+c6./Temperature).*Temperature.*R;
            S = (c1*log(Temperature)+c2.*Temperature+(c3.*Temperature.^2)/2+(c4.*Temperature.^3)/3+(c5.*Temperature.^4)/4+c7).*R;
        else
            Cp = (c8+c9.*Temperature+c10.*Temperature.^2+c11.*Temperature.^3+c12.*Temperature.^4).*R;
            H = (c8 +(c9.*Temperature)/2+(c10.*Temperature.^2)/3+(c11.*Temperature.^3)/4+(c12.*Temperature.^4/5)+c13./Temperature).*Temperature.*R;
            S = (c8.*log(Temperature)+c9.*Temperature+(c10.*Temperature.^2)/2+(c11.*Temperature.^3)/3+(c12.*Temperature.^4)/4+c14).*R;
        end
    end
    
    % plotting the graphs
    
    % Temperature Vs Entropy
    figure(1)
    plot(Temperature,S,'linewidth',4,'color','b')
    title(species_name)
    xlabel('temperature')
    ylabel('Entropy')
    
    % Temperature Vs Enthalpy
    figure(2)
    plot(Temperature,H,'linewidth',4,'color','r')
    title(species_name)
    xlabel('Temperature')
    ylabel('Enthalpy')
    
    % Temperature Vs specific heat
    figure(3)
    plot(Temperature,Cp,'linewidth',4,'color','g')
    title(species_name)
    xlabel('Temperature')
    ylabel('Specific heat')
    
    directory = (['C:\Users\hp\Desktop\skill lync\matlab\species\',species_name]);
    cd(directory)
    
    %saving the plots
    
    saveas(1,'Entropy.jpg');
    saveas(2,'Enthalpy.jpg');
    saveas(3,'Specific heat.jpg');
    
    cd('C:\Users\hp\Desktop\skill lync\matlab\file_parsing\')
    
    MM = molecular_mass(species_name)

end
fclose(file)    

Function code  -

function MM = molecular_mass(species_name)

species = upper(species_name);

constituents =['H','C','N','O','A'];

Atomic_weight = [ 1.00794 12.0107 14.0067 15.9994 39.948];

MM = 0;

for i = 1:length(species)
    for j = 1:length(constituents)
        if strcmp(species(i),constituents(j))
            MM = MM + Atomic_weight(j);
            u = j;
        end
    end
    n = str2num(species(i));
    if n>1
        MM = MM + Atomic_weight(u)*(n-1);
    end
end
end

Working -

  1. We start the program with close all, clear all and clc.
  2.  fopen command is used to open the 'thermo.dat' file and is stored in a variable called 'file'.
  3. first line of the document is a heading and is stored inside a variable called line_1. fgetl command is used to read the line.
  4. The second line of the program contains the range of global temperature. the data is saved inside a variable called line_2.
  5. next 3 lines in the document are comments which are irrelevant to the program. so we use a for loop to read the lines and store them in a variable called 'comment'.
  6. strsplit command is used to identify the pattern so that the data can be processed properly. The data is stored in a variable called A and line_2 is given as input. '  ' is used to identify the pattern gap.
  7. global low mid and high temperatures are extracted using str2num command and are stored in different variables.
  8. A For loop is used to extract the 14 coefficients of all the 53 species.
  9. We store the 1st line of the coefficient into a variable called line1.
  10. L1 is used to store the pattern of line1 with 'E' as a marker.
  11. values of the coefficients are stored inside the variables c1, c2.......etc.
  12. the same operation is performed for all 3 lines of the coefficients.
  13. mkdir command is used to create a new directory where individual folders of each species are created.
  14. for different temperature ranges, linspace command is used.
  15. R is provided as input.
  16. For loop is used to run the set of commands for all the values of temperature array.
  17. if and else statements are used for different temperature ranges. if the value is less then 3000 different sets of commands are used otherwise the commands under else statement is used.
  18.  plot command is used to plot the temp vs enthalpy,entropy and specific heat.
  19. save as command is used to save the plots for each species
  20. molecular mass of the species are calculated using the function molecular_mass and the values are stored inside a function called MM.
  21. Fclose is used to close the file.

Results

folder containing all the species data - 

plots of O2 - 


Projects by Harsh Samadhiya

Aim - to write a matlab program which can solve for the value of  global maxima in a given set of data using ga function. Theory -  A genetic algorithim is a search technique  inspired by the theory of natural evolution of Charles darwin. This algor Read more

Objective - To write a MATLAB program that measures the various state variables involved in an otto cycle and maps the relationship between them. Theory -  The "Otto cycle" also reffered to as "constant volume Air standard cycle" is a set of termodynamic processes Read more


Loading...

The End