Challenge

Project 1 - Parsing NASA thermodynamic data

Objective

1. Write a function that extracts the 14 co-efficients and calculates the enthalpy(H), entropy(S) and specific heats(Cp) for all the species in the data file. You will be reading this file NASA thermodynamic data (https://drive.google.com/file/d/1AikCHDlz9s_fu8whE81qee_GD4AyYpCP/view?usp=sharing) . The formulae are shown below.

Here R is the universal gas constant, T is the temeprature

The first 7 coefficients are high-temperature coefficients and the second 7 coefficients are low-temperature coefficients.

Also use the local temperature ranges which is unique for each individual species, not the global temperature range.

2. Calculate the molecular weight of each species and display it in the command window.

3. Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.

4. Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name. All these should be generated automatically.

5. The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H and S plots.

6. Please write a detailed report to describe your logic.

objective 1 (create code for run all the requirements)

Code

clear 
close all
clc

R = 8.314;
fprintf('universal gas constant = %1.3f\n',R);

filename = 'J:\matlab installation\bin\THERMO.dat';
fileID = fopen('J:\matlab installation\bin\THERMO.dat','r');
skip_1 = fgetl(fileID);
Gtemp = fgetl(fileID);
A = strfind(Gtemp,'.');

% To calculate global minimum temperature
Gmin_str = Gtemp(A(1)-3:A(1)+3);
Gmin = str2double(Gmin_str);
fprintf('global minimum temperature = %d\n',Gmin);

% To calculate global mid temperature
Gmid_str = Gtemp(A(2)-4:A(2)+3);
Gmid = str2double(Gmid_str);
fprintf('global mid temperature = %d\n',Gmid);

% To calculate global max temperature
Gmax_str = Gtemp(A(3)-4:A(3)+3);
Gmax = str2double(Gmax_str);
fprintf('global maximum temperature = %d\n',Gmax);


skip_2 = fgetl(fileID);
skip_3 = fgetl(fileID);
skip_4 = fgetl(fileID);


for i=1:53    
    
    s1 = fgetl(fileID);
    
            n = strsplit(s1);
            
                    m = n{1}; I = i; fprintf('molicule(%d) = %s\n',I,m);
                    
                    W = Molicular_weight(m); fprintf('molicular weight = %1.4f\n',W);

                    Lmin = str2double(n{end-3});
                    
                    Lmid = str2double(n{end-1});
                    
                    Lmax = str2double(n{end-2});
                    
                    T = linspace(Lmin,Lmax,60);
                    
    s2 = fgetl(fileID);
    
            a = strfind(s2, 'E');

                    aal = s2(1:a(1)+3);

                    a1 = str2double(aal);

                    aa2 = s2 (a(1)+4:a(2)+3);

                    a2 = str2double(aa2);

                    aa3 = s2(a(2)+4:a(3)+3);

                    a3 = str2double(aa3);

                    aa4 = s2(a(3)+4:a(4)+3);

                    a4 = str2double(aa4);

                    aa5 = s2(a(4)+4:a(5)+3);

                    a5 = str2double(aa5);
    
    s3 = fgetl(fileID);
    
           b = strfind(s3, 'E');
           
                    aa6 = s3(1:b(1)+3);

                    a6 = str2double(aa6);

                    aa7 = s3(b(1)+4:b(2)+3);

                    a7 = str2double(aa7);

                    AA1 = s3(b(2)+4:b(3)+3);

                    A1 = str2double(AA1);

                    AA2 = s3(b(3)+4:b(4)+3);

                    A2 = str2double(AA2);

                    AA3 = s3(b(4)+4:b(5)+3);

                    A3 = str2double(AA3);
    
    s4 = fgetl(fileID);
    
           c = strfind(s4, 'E');
           
                    AA4 = s4(1:c(1)+3);

                    A4 = str2double(AA4);

                    AA5 = s4(c(1)+4:c(2)+3);

                    A5 = str2double(AA5);

                    AA6 = s4(c(2)+4:c(3)+3);

                    A6 = str2double(AA6);

                    AA7 = s4(c(3)+4:c(4)+3);

                    A7 = str2double(AA7);
                    
                    
[Cp,En,E] = fun(a1,a2,a3,a4,a5,a6,a7,A1,A2,A3,A4,A5,A6,A7,R,T,Lmid);
          

name='out graphs';
mkdir(name)
cd(name)
mkdir(m);
cd(m);
  

figure (1)

    plot (T,Cp);

    xlabel('Temperature [K]');

    ylabel('Specific Heat [k]]');

    title(sprintf('T Vs Cp graph of %s',m));

    saveas (1,'Specific Heat.jpg');

figure (2)

    plot (T,E);

    xlabel('Temperature [K]');

    ylabel('Enthalpy in [k]/(mol)]');

    title(sprintf('T Vs H graph of %s',m));

    saveas(2,'Ethalpy.jpg');

figure(3)

    plot (T,En);

    xlabel('Temperature [K]');

    ylabel('Entropy in [kJ/(mol-K)]');

    title(sprintf('T Vs H graph of %s',m));

    saveas (3, 'Entropy.jpg');

cd('J:\matlab installation\bin');
  
end










function[Cp,En,E] = fun(a1,a2,a3,a4,a5,a6,a7,A1,A2,A3,A4,A5,A6,A7,R,T,Lmid)

            Cp = ones(1);
            En = ones(1);
            E = ones(1);
            
for j = 1:length(T)
    
    if T(j)>Lmid
        
        Cp(j) = (a1 + a2*T(j) + a3*(T(j)^2) + a4*(T(j)^3) + a5*(T(j)^4))*R;
        
        E(j)  = (a1 + a2*(T(j)/2) + a3*(T(j)^2)/3 + a4*(T(j)^3)/4 + a5*(T(j)^4)/5 + a6/T(j))*R*T(j);
        
        En(j)  = (a1*log(T(j)) + a2*T(j) + a3*(T(j)^2)/2 + a4*(T(j)^3)/3 + a5*(T(j)^4)/4 + a7)*R;
        
    else
        Cp(j) = (A1 + A2*T(j) + A3*(T(j)^2) + A4*(T(j)^3) + A5*T(j)^4)*R;
        
        E(j)  = (A1 + A2*(T(j)/2) + A3*(T(j)^2)/3 + A4*(T(j)^3)/4 + A5*(T(j)^4)/5 + A6/T(j))*R*T(j);
        
        En(j)  = (A1*log(T(j)) + A2*T(j) + A3*(T(j)^2)/2 + A4*(T(j)^3)/3 + A5*(T(j)^4)/4 + A7)*R;
        
    end
    
end

end

function [W] = Molicular_weight(m)

 atomic_name = ['H', 'C', 'O', 'N', 'A', 'S'];

 atomic_weight = [1.00794, 12.011, 15.9994, 14.00674, 39.948, 32.066];

 num = str2double (m);

 W=0;

    for i = 1:length(m) % Loop runs to the length of the species 

        for j = 1: length (atomic_name)
            
            if strcmp(m(i), atomic_name (j)) 
                
                W = W+ atomic_weight (j);
                
                pos = j;
                
            end
            
        end

        if num>1

            W = W + atomic_weight (pos)*(num-1);

        end
    end
end

Code Explanation

  1. Use clear, close, clc to clear all history
  2. then using "fopen" opens that given data
  3. For each "fgetl" comand we can open consiquent rows it's start's from first row.
  4. next find each of the global temperatures like lowest global temperature to high value
  5. after that skip 3 rows that only contain comments and subsequently made a for loop to find all the coefficients, molicular weight, molicule name and create graphs for each and every substances and save it in the current directery
  6. then write a function for Specific heat, Enthalpy, Entropy and Molicular weight

Output

graphs-:

this given drive link contain all the saved graphs

https://drive.google.com/drive/folders/1VtQVyDg7dphET7X0ycFprgMhuoT_QcJ1?usp=sharing

commends-:

universal gas constant = 8.314
global minimum temperature = 300
global mid temperature = 1000
global maximum temperature = 5000

molicule(1) = O
molicular weight = 15.9994

molicule(2) = O2
molicular weight = 15.9994
Warning: Directory already exists.
> In trial (line 126)

molicule(3) = H
molicular weight = 1.0079
Warning: Directory already exists.
> In trial (line 126)

molicule(4) = H2
molicular weight = 1.0079
Warning: Directory already exists.
> In trial (line 126)

molicule(5) = OH
molicular weight = 17.0073
Warning: Directory already exists.
> In trial (line 126)

molicule(6) = H2O
molicular weight = 17.0073
Warning: Directory already exists.
> In trial (line 126)

molicule(7) = HO2
molicular weight = 17.0073
Warning: Directory already exists.
> In trial (line 126)

molicule(8) = H2O2
molicular weight = 17.0073
Warning: Directory already exists.
> In trial (line 126)

molicule(9) = C
molicular weight = 12.0110
Warning: Directory already exists.
> In trial (line 126)

molicule(10) = CH
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(11) = CH2
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(12) = CH2(S)
molicular weight = 45.0849
Warning: Directory already exists.
> In trial (line 126)

molicule(13) = CH3
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(14) = CH4
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(15) = CO
molicular weight = 28.0104
Warning: Directory already exists.
> In trial (line 126)

molicule(16) = CO2
molicular weight = 28.0104
Warning: Directory already exists.
> In trial (line 126)

molicule(17) = HCO
molicular weight = 29.0183
Warning: Directory already exists.
> In trial (line 126)

molicule(18) = CH2O
molicular weight = 29.0183
Warning: Directory already exists.
> In trial (line 126)

molicule(19) = CH2OH
molicular weight = 30.0263
Warning: Directory already exists.
> In trial (line 126)

molicule(20) = CH3O
molicular weight = 29.0183
Warning: Directory already exists.
> In trial (line 126)

molicule(21) = CH3OH
molicular weight = 30.0263
Warning: Directory already exists.
> In trial (line 126)

molicule(22) = C2H
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(23) = C2H2
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(24) = C2H3
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(25) = C2H4
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(26) = C2H5
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(27) = C2H6
molicular weight = 13.0189
Warning: Directory already exists.
> In trial (line 126)

molicule(28) = CH2CO
molicular weight = 41.0293
Warning: Directory already exists.
> In trial (line 126)

molicule(29) = HCCO
molicular weight = 41.0293
Warning: Directory already exists.
> In trial (line 126)

molicule(30) = HCCOH
molicular weight = 42.0373
Warning: Directory already exists.
> In trial (line 126)

molicule(31) = H2CN
molicular weight = 27.0257
Warning: Directory already exists.
> In trial (line 126)

Output Explained

  1. All the graphs are automatically saved into current directory as the name of "out graphs"
  2. commend section shows the name of each molicules and molicular weight of them
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.