Challenge

Project 1 - Parsing NASA thermodynamic data

Aim:

1. To extract all the coefficients of the species mentioned in the data file and calculate their parameteres like enthalpy,entropy and specific heat.

2. To plot the variation of these parameters for the specified local temperature range.

3. To determine the molecular masses of the indivisual special mentioned in the data file.

Procedure:

1) Initially open the given thermodynamic data file and read the data in the file and store the data to the variable F.

2) Then read the header file of thermodynamic data and calculate the global loe,mid,and high temperature from the second line of header file.

3) By using fgetl(),& str2num() & strsplit() command find out the global low,mid and high temperatures in the second line.

4) Then calculate the 14 coefficients for all the species in the given thermodynamic data file.

5) In data file each species has three lines in which 14 coefficients are there.

6) By using the for loop ,calculate the 14 coefficients for all the species.

7) By using strfind() command,find out the number of exponential in first line,by which we can find out the number of coefficient in first line.

8) once you find out then convert the coefficient from to number from by using str2num() command.

9 )First 7 coefficient are high temperature coefficients and calculate cp,H,S.

10) Assuming universal gas constant R=8.314j/mol-k and assuming temperature range from low temperature to high temperature take 100 values by linspace () command.

11) once you calculate the entropy,enthalpy and specific heat for all the species,plot the graph between:

a)Temperature vs Entropy,

b)Temperature vs Enthalpy,

c)Temperature vs Specific Heat.

12) Store all the three plots for all the species in the file.The stored file is shown in the above picture.

13) Finally calculating the molecular weight for all the species and displyed in the command window.

14) The method for calculating molecular weight is shown in the function program.

MATLAB CODE:

clear all
close all
clc
%opening and reading the required file
file = fopen('THERMO.dat','r')

%Heading 
line1 = fgetl(file)

%Global temperature values
line2 = fgetl(file)

%next three lines are comments
des_1 = fgetl(file)
des_2 = fgetl(file)
des_3 = fgetl(file)
A = strsplit(line2,' ');
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)
m=strsplit(species,' ')
  species_name=m{1}
  local_low_temp=str2num(m{end-3})
   local_high_temp=str2num(m{end-2})
   local_mid_temp=str2num(m{end-1})
    Line_1 = fgetl(file);
    
    L1 = strfind(Line_1,'E');
    
    c1 = str2num(Line_1(1:(L1(1)+3)));  
    
    c2 = str2num(Line_1((L1(1)+4):(L1(2)+3)));
    
    c3 = str2num(Line_1((L1(2)+4):(L1(3)+3)));
    
    c4 = str2num(Line_1((L1(3)+4):(L1(4)+3)));
    
    c5 = str2num(Line_1((L1(4)+4):(L1(5)+3)));
    
    Line_2 = fgetl(file);
    
    L2 = strfind(Line_2,'E');
    
    c6 = str2num(Line_2(1:(L2(1)+3)));  
    
    c7 = str2num(Line_2((L2(1)+4):(L2(2)+3)));
    
    c8 = str2num(Line_2((L2(2)+4):(L2(3)+3)));
    
    c9 = str2num(Line_2((L2(3)+4):(L2(4)+3)));
    
    c10 = str2num(Line_2((L2(4)+4):(L2(5)+3)));
    
    Line_3 = fgetl(file);
    
    L3 = strfind(Line_3,'E');
    
    c11 = str2num(Line_3(1:(L3(1)+3)));  
    
    c12 = str2num(Line_3((L3(1)+4):(L3(2)+3)));
    
    c13 = str2num(Line_3((L3(2)+4):(L3(3)+3)));
    
    c14 = str2num(Line_3((L3(3)+4):(L3(4)+3)));
    
    %creating folder for each species 
   % mkdir('A:/Users/Athul/File parsing NASA/Species/',species_name);
    
    %Temperature ranges assumed for calculation purpose 
    Temperature = linspace(local_low_temp,local_high_temp,100);
    
    %Universal gas constant
    R =8.314;
    
    %calculation of properties based on the lower and upper temperature
    for j = 1:length(Temperature)
        if Temperature(j)>local_mid_temp
    Cp(j) = (c1+c2.*Temperature(j)+c3.*Temperature(j).^2+c4.*Temperature(j).^3+c5.*Temperature(j).^4).*R;
    H(j) = (c1+(c2.*Temperature(j))./2+(c3.*Temperature(j).^2)/3+(c4.*Temperature(j).^3)/4+(c5.*Temperature(j).^4/5)+c6./Temperature(j)).*Temperature(j).*R;
    S(j) = ((c1*log(Temperature(j))+c2.*Temperature(j)+(c3.*Temperature(j).^2)/2+(c4.*Temperature(j).^3)/3)+(c5.*Temperature(j).^4)/4+c7).*R;
        else
    Cp(j) = (c8+c9.*Temperature(j)+c10.*Temperature(j).^2+c11.*Temperature(j).^3+c12.*Temperature(j).^4).*R;       
    H(j) = (c8+(c9.*Temperature(j))/2+(c10.*Temperature(j).^2)/3+(c11.*Temperature(j).^3)/4+(c12.*Temperature(j).^4/5)+c13./Temperature(j)).*Temperature(j).*R;
    S(j) = ((c8*log(Temperature(j))+c9.*Temperature(j)+(c10.*Temperature(j).^2)/2+(c11.*Temperature(j).^3)/3)+(c12.*Temperature(j).^4)/4+c14).*R;
        end
    end
    
    %plotting
    
%     %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 = (['A:/Users/Athul/File parsing NASA/species/',species_name]); 
    %changing the filepath to save the plots
    mkdir(species_name)
    cd(species_name)
    
    %saving the plots 
    
    saveas(1,'Entropy.jpg');
    saveas(2,'Enthalpy.jpg');
    saveas(3,'specific heat.jpg');
    
    cd ..
    
    MM = molecular_mass(species_name)
    
end

fclose(file)
    
    

Function to calculate the molecular masses of individual species:

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

1. Location of species folder in desktop:

2. Molecular masses displyed in the command window:

PLOTS FOR O2:

PLOTS FOR N2:

PLOTS FOR CO2:

This 9 graphs of temperature, enthaply and entropy of element O2,N2 & CO2 respectively.

References:

https://www.engineeringtoolbox.com/carbon-dioxide-d_974.html

https://www.mathworks.com/help/matlab/ref/fgetl.html

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.