Challenge

Project 1 - Parsing NASA thermodynamic data

Aim:

1)Extract coefficient data for various species from NASA thermodynamic data file.

2)Calculate Entrophy,Enthapy,Specific heat for these species over given temperature range.

3)Plot the nature of Enthalpy,Entropy,Specific Heat with respect to time for each species.

4)Export plots to specified folder in directory.

5)Calculate molecular weight of each species.

Based on the experiments performed on various species NASA has found values of constants for the function of Entropy,Enthalpy,Specific heat and Temperature.these constant can be accesed from data base.

(THERMO.dat file) .the equations are-

`Cp/(R )=a1+a2*T+a3*T^2+a4*T^3+a5*T^4`

`H/(RT)=a1+(a2*T)/2+a3*T^2/3+a4*T^3/4+a5*T^4/5+a6*(1/T)`

`S/R=a1*lnT+a2*T+a3*T^2/2+a4*T^3/3+a5*T^4/4+a7`

values of constants varies from species to species and can be found in THERMO.dat file. If you open the file you will get following-

as you can see data needs to be procesed and sort in order to use it.this is where file parsing came into picture.after sorting data required operations can be performed on data to study behaviour of given properties with temperature.

MATLAB CODE -

main code-

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

%heading
line1 = fgetl(f)

%global temperature values
line2 = fgetl(f)

%next three lines are comments
com1 = fgetl(f)
com2 = fgetl(f)
com3 = fgetl(f)
A = strsplit(line2,' ');
global_low_temp = str2num(A{2})
global_mid_temp = str2num(A{3})
global_high_temp = str2num(A{4})

%species information
for  i =1:53
    species = fgetl(f);
    species_name = species(1:7)
    t1 = fgetl(f);
    l1 = strfind(t1,'E');
    c1 = str2num(t1(1:(l1(1)+3)));
    c2 = str2num(t1((l1(1)+4):(l1(2)+3)));
    c3 = str2num(t1((l1(2)+4):(l1(3)+3)));
    c4 = str2num(t1((l1(3)+4):(l1(4)+3)));
    c5 = str2num(t1((l1(4)+4):(l1(5)+3)));
    
    t2 = fgetl(f);
    l2 = strfind(t2,'E')
    
    c6 = str2num(t2(1:(l2(1)+3)));
    c7 = str2num(t2((l2(1)+4):(l2(2)+3)));
    c8 = str2num(t2((l2(2)+4):(l2(3)+3)));
    c9 = str2num(t2((l2(3)+4):(l2(4)+3)));
    c10 = str2num(t2((l2(4)+4):(l2(5)+3)));
    
    t3 = fgetl(f);
    l3 = strfind(t3,'E');
    
    c11 = str2num(t3(1:(l3(1)+3)));
    c12 = str2num(t3((l3(1)+4):(l3(2)+3)));
    c13 = str2num(t3((l3(2)+4):(l3(3)+3)));
    c14 = str2num(t3((l3(3)+4):(l3(4)+3)));
    
    %creating folder for each species
    mkdir(['C:\Users\srushti jagdale\Documents\MATLAB\species\',species_name]);
    
    %Temperature ranges assumed for calculation perpose
    temp = linspace(300,5000,100);
    
    %Universal gas constant
    R = 8.314;
    
    %calculation of properties based on lower and upper temperature
    for j = 1:length(temp)
        if temp(j)<3000
            Cp = (c1+c2.*temp+c3.*temp.^2+c4.*temp.^3+c5.*temp.^4).*R;
            H = (c1+(c2.*temp)./2+(c3.*temp.^2)./3+(c4.*temp.^3)./4+(c5.*temp.^4)./5+(c6./temp)).*R.*temp;
            S = (c1.*log(temp)+c2.*temp+(c3.*temp.^2)./2+(c4.*temp.^3)./3+(c5.*temp.^4)./4+c7).*R;
        else
            Cp = (c8+c9.*temp+c10.*temp.^2+c11.*temp.^3+c12.*temp.^4).*R;
            H = (c8+(c9.*temp)./2+(c10.*temp.^2)./3+(c11.*temp.^3)./4+(c12.*temp.^4)./5+(c13./temp)).*R.*temp;
            S = (c8.*log(temp)+c9.*temp+(c10.*temp.^2)./2+(c11.*temp.^3)./3+(c12.*temp.^4)./4+c14).*R;
        end
    end
    
    %plotting
    
    %temperature vs Entropy
    figure(1)
    plot(temp,S,'linewidth',4,'color','b')
    title(species_name)
    xlabel('Temperature')
    ylabel('Entropy')
    
    %temperature vs Enthalpy
    figure(2)
    plot(temp,H,'linewidth',4,'color','k')
    title(species_name)
    xlabel('Temperature')
    ylabel('Enthalpy')
    
    %temperature vs Specific heat
    figure(3)
    plot(temp,Cp,'linewidth',4,'color','y')
    title(species_name)
    xlabel('Temperature')
    ylabel('Specific heat')
    
    directory =(['C:\Users\srushti jagdale\Documents\MATLAB\species\',species_name]);
    %changing the directory
    cd(directory)
    
    %saving the plots
    
    saveas(1,'Entropy.jpg');
    saveas(2,'Enthalpy.jpg');
    saveas(3,'Specific heat.jpg');
    
    %switching back to orignal directory
    cd('C:\Users\srushti jagdale\Documents\MATLAB\')
    M = molecular_mass(species_name)
end
fclose(f)
    

code for molecular mass -

function M = molecular_mass(species_name)
species = upper(species_name)
constituents = ['H','C','N','O','A'];
atomic_weight = [1.00749 12.0107 14.0067 15.9994 39.948];
M = 0;
for i=1:length(species)
    for j=1:length(constituents)
        if strcmp(species(i),constituents(j))
            M = M+atomic_weight(j);
            u=j;
        end
    end
    n =str2num(species(i));
    if n>1
     M = M + atomic_weight(u)*(n-1);
    end
end
end

Explaination of code -

clear all ,close all ,clc for clearing previous variables and command window.

fopen to open the THERMO.DAT file also specified the permission needed i.e. to read the file (r)

fgetl to next line each time executed.it is used to get header comments and global temperature data and stored in different variables.

strsplit to split global temperature combined data .

str2num to convert string to numbers.in this way combined temerature data is extracted and stored in different variable.

for loop ,to extract information of each species by repeating extraction algorithm.

extarction algorithm -

strfind to find seperater between constants and combine exponential part.

store constants into different variable.

mkdir to create folder for each species in required directory.

temparture range is created using linspace command.

data file contains 14 constants values first seven are for low temperature range and remaining are for higher temperature range

if-else is used to solve for low temp and high temp seperately based on value of temp.

plot to plot properties Vs temperature data.

cd to change orignal directory to required one

saveas to save data in that directory.

cd to switch back to orignal directory.

molecular_mass function is created to calculate molecular mass.

Output-

1.created folder for individual species

2.plots for O2,N2 and Co2 -

1)O2

A)Entropy behaviour

B)Enthapy behaviour

C)Specific heat behaviour

2)N2

A)Entropy behaviour

B)Enthapy behaviour

C)Specific heat behaviour

3) Co2

A)Entropy behaviour

B)Enthapy behaviour

C)Specific heat behaviour

3.molecular masses-

References -

https://www.grc.nasa.gov/www/k-12/airplane/thermo.html

https://in.mathworks.com/matlabcentral/answers/196582-best-way-to-parse-text-file

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.