Challenge

Project 1 - Parsing NASA thermodynamic data

Aim : A function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.

Theory :

  • In this program using nasa thermodynamic file we reading the data of that file and calculating the enthalpy, entropy, specific heats and molecular weight

Code explanation :

main code explanation -

  • First we saving the data file in one folder in same folder we 'saveas' the written program
  • In program first open the file using fopen command followed by file name as shown in code attached below
  • after the file open to read the the file fgetl command used, By this we read the content in the data
  • when the fgetl command run first it gives the output of the first line similarly when second times run it gives second line similarly it goes on
  • so by this to read the the needed line we read the line by fgetl and stored in variable that variable stored lined is utilized

example : file_name = fgetl(file)

first_line = fgetl(file) likewise so on as shown in the code attached below

  • first_line variable as shown in the code attached below read the line which global temperature indicated line.
  • then using for loop next three waste line read

example : for i=1:3

a = fgetl(file)

end

  • after that using again for loop we extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file
  • how we extract the species, local temperatures, co-efficient is shown below

  • then after adding the co-efficient we calculating sepcific heat(CP), enthalpy(H), entropy(S) in sub program and calling that sub program to main program as shown in below

  • so after calling the sub program creating folder using cd command then each species graph folder add in that program using mkdir command
  • then we ploting each specific heat,enthalpy,entropy graph using figure 1,figure2, figure3 command
  • then we saveas the each figure using saveas command
  • then created folder calling to main folder then we calculating molecular weight of each species in sub program next we the sub program in main program

output of the code run in matlab is :

1. oxygen specific heat, enathaply, entropy graph

2. folders of the species

3.molecular weight of the species

4. workspace readings

error found when running the program:

code :

1.Main code

clear all
close all
clc
file = fopen('THERMO.dat','r');
file_name = fgetl(file);
TEMP_VALS = fgetl(file);
global_tempr_range = strsplit(TEMP_VALS,' ')
global_low_tempr = str2num(global_tempr_range{2});
global_mid_tempr = str2num(global_tempr_range{3});
global_high_tempr = str2num(global_tempr_range{4});

for i = 1:3
    a = fgetl(file)
end
for j = 1:53
    line_1 = fgetl(file);
    l1 = strsplit(line_1,' ')
    spieces = (l1{1});

    G = strfind(line_1,'G');
    lowtemp = str2num(line_1(G+3:G+10));
    hightemp = str2num(line_1(G+12:G+20));
    midtemp = str2num(line_1(G+22:G+30));
     t = linspace(lowtemp,hightemp,500);
   R = 8.314
   
    line_2 = fgetl(file);
    l2 = strfind(line_2,'E');
    A1 = str2num(line_2(1:l2(1)+3));
    A2 = str2num(line_2(l2(1)+4:l2(2)+3));
    A3 = str2num(line_2(l2(2)+4:l2(3)+3));
    A4 = str2num(line_2(l2(3)+4:l2(4)+3));
    A5 = str2num(line_2(l2(4)+4:l2(5)+3));
    line_3 = fgetl(file);
    l3 = strfind(line_3,'E');
    A6 = str2num(line_3(1:l3(1)+3));
    A7 = str2num(line_3(l3(1)+4:l3(2)+3));
    a1 = str2num(line_3(l3(2)+4:l3(3)+3));
    a2 = str2num(line_3(l3(3)+4:l3(4)+3));
    a3 = str2num(line_3(l3(4)+4:l3(5)+3));
    line_4 = fgetl(file);
    l4 = strfind(line_4,'E');
    a4 = str2num(line_4(1:l4(1)+3));
    a5 = str2num(line_4(l4(1)+4:l4(2)+3));
    a6 = str2num(line_4(l4(2)+4:l4(3)+3));
    a7 = str2num(line_4(l4(3)+4:l4(4)+3));
   
    [CP,H,S] = thermo_prop(A1,A2,A3,A4,A5,A6,A7,a1,a2,a3,a4,a5,a6,a7,global_mid_tempr,t)
  
      cd('D:\NASA_FILE')
      mkdir(spieces)
      cd(spieces)
    
  
    figure(1);
    plot(t,CP,'b','linewidth',4)
    grid on
    xlabel('local temp');
    ylabel('specific heat');
    title('specific(CP) VS Temperature(t)')
    m1 = 'specific heat of %s'
    m2 = spieces
    m3 = sprintf(m1,m2)
    
    figure(2);
    plot(t,H,'g','linewidth',4)
    grid on
    xlabel('local temp');
    ylabel('ENTHALPY');
    title('ENTHALPY(H) VS Temperature(t)')
    m4 = 'enthalpy of %s'
    m5 = spieces
    m6 = sprintf(m4,m5)
   
    figure(3);
    plot(t,S,'r','linewidth',4)
    grid on
    xlabel('local temp');
    ylabel('ENTROPY');
    title('ENTROPY(S) VS Temperature(t)')
    m7 = 'entropyof %s'
    m8 = spieces
    m9 = sprintf(m7,m8)
    
%     program = (['D:\NASA_FILE', spieces]);
    

    %saving plots
 saveas(figure(1),sprintf('%s.png',m3))
 saveas(figure(2),sprintf('%s.png',m6))
 saveas(figure(3),sprintf('%s.png',m9))

 cd('C:\Users\aprat\OneDrive\Desktop\nasa')

  
    MW = mol_wt(spieces);
    fprintf('%d molecular weight of %s is %d.',j,spieces,MW)
    fprintf('  ')
end

2.sub program for calculating the specific heat, enthalpy, entropy

function [CP,H,S] = thermo_prop(A1,A2,A3,A4,A5,A6,A7,a1,a2,a3,a4,a5,a6,a7,global_mid_tempr,t)
R = 8.314;

for q = 1:length(t)
   if (t(q) >= global_mid_tempr);
    
    CP = (A1 + (A2.*t) +(A3.*t.^2)+(A4.*t.^3)+(A5.*t.^4))*R;
    H = (A1+(A2.*(t./2))+(A3.*(t.^2)./3)+(A4.*(t.^3)./4)+(A5.*(t.^4)./5)+(A6./t)).*(t.*R);
    S = ((A1.*log(t))+(A2.*t)+(A3.*t.^2)+(A4.*t.^3)+(A5.*t.^4)+A7)*R;
   else
    CP = (a1 + (a2.*t) + (a3.*t.^2) + (a4.*t.^3) + (a5.*t.^4))*R;
    H = (a1+(a2.*(t./2))+(a3.*(t.^2)./3)+(a4.*(t.^3)./4)+(a5.*(t.^4)./5)+(a6./t)).*(t.*R);
    S = ((a1.*log(t))+(a2.*t)+(a3.*t.^2)+(a4.*t.^3)+(a5.*t.^4)+a7)*R;
   end
end

3.sub program for calculating the molecular weight

function MW = mol_wt(spieces)
atoms = {'H','C','N','O','A'};
atomic_weight = [1 12 14 16 40];
MW = 0;
for i = 1:length(spieces)
    for j= 1:length(atomic_weight)
        if(strcmp(spieces(i),atoms(j))==1)
            MW = MW + atomic_weight(j);
            rank = j;
        end
    end
    m = str2num(spieces(i));
    if m>1
        n = m-1;
        MW = MW + atomic_weight(rank)*(n);
    end
end
end

Reference :

https://skill-lync.com/student-projects/project-1-parsing-nasa-thermodynamic-data-990

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.