Challenge

Project 1 - Parsing NASA thermodynamic data

Report on Project 1 - Parsing NASA thermodynamic data

AIM:

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

GOVERNING EQUATIONS:

Making folder for each species

mkdir(['C:\Users\IHTHISHAMUL-HAQ\Documents\MATLAB\NASA'],sp_name)

OBJECTIVES:

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

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

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.

REPORT:

This program was done using MATLAB language.

Supplementary code: (Low temperature function)

function n = low_temp(L2,L3,R,tl)
b = findstr(L2,'E');
a8 = L2(b(2)+4:b(3)+3);
a8 = str2num(a8);
a9 = L2(b(3)+4:b(4)+3);
a9 = str2num(a9);
a10 = L2(b(4)+4:b(5)+3);
a10 = str2num(a10);
c = findstr(L3,'E');
a11 = L3(1:c(1)+3);
a11 = str2num(a11);
a12 = L3(c(1)+4:c(2)+3);
a12 = str2num(a12);
a13 = L3(c(2)+4:c(3)+3);
a13 = str2num(a13);
a14 = L3(c(3)+4:c(4)+3);
a14 = str2num(a14);
spe_heat= R*(a8+(tl.*a9)+(a10*(tl.^2))+(a11*(tl.^3))+(a12*(tl.^4)));
enthalpy = R*tl.*(a8+(a9*tl./2)+(a10*tl.^2/3)+(a11*tl.^3/4)+(a12*tl.^4/5)+(tl.^-1/a13));
entropy =((a8*log(tl))+(a9*tl)+((a10*(tl.^2)/2))+((a11*(tl.^3)/3))+((a12*(tl.^4)/4))+a14);
n = {spe_heat,enthalpy,entropy};
end

Supplementary code: (High temperature function)

function m = high_temp(L1,L2,R,th)
 a = findstr(L1,'E');
        a1 = L1(1:a(1)+3);
        a1 = str2num(a1);
        a2 = L1(a(1)+4:a(2)+3);
        a2 = str2num(a2);
        a3 = L1(a(2)+4:a(3)+3);
        a3 = str2num(a3);
        a4 = L1(a(3)+4:a(4)+3);
        a4 = str2num(a4);
        a5 = L1(a(4)+4:a(5)+3);
        a5 = str2num(a5);
        b = findstr(L2,'E');
        a6 = L2(1:b(1)+3);
        a6 = str2num(a6);
        a7 = L2(b(1)+4:b(2)+3);
        a7 = str2num(a7);
spe_heat = R*(a1+(th.*a2)+(a3*th.^2)+(a4*th.^3)+(a5*th.^4));
enthalpy = R*th.*(a1+(a2*th./2)+(a3*th.^2/3)+(a4*th.^3/4)+(a5*th.^4/5)+(th.^-1/a6));
entropy = (a1*log(th)+(a2*th)+(a3*(th.^2)/2)+(a4*(th.^3)/3)+(a5*(th.^4)/4)+a7);
m = {spe_heat,enthalpy,entropy};
end

Main code:q

close all
clear all
clc
% A program on parsing of Thermo.dat file
% For opening thermo file
f = fopen('thermo.txt','r');
% Skipping of heading lines
for i=1:5
fgetl(f);
end
% Defining number of species
num_species = 53;
% Using loop for all species
for j = 1:num_species
% Let L be the first line of species
    L = fgetl(f);
% Let L1 be second line    
    L1=fgetl(f);
% For taking co-efficient values from line 1    
    a = findstr(L1,'E');
% Let L2 be third line     
    L2=fgetl(f);
% For taking co-efficient values from line 2    
    b = findstr(L2,'E');
% Let L3 be fourth line
    L3=fgetl(f);
% For taking co-efficient values from line 3    
    c = findstr(L3,'E');
% To display END of the file    
    if strcmp(L,'END')
        disp('File end')
        break
    end
% Making a cell array of first line to extract local temperature and species name    
    l = strsplit(L,' ');
% Exracting species name    
    sp_name = l{1};
% Exracting high temperature    
    T = l{end-2};
    T = str2num(T);
% Exracting Mid temperature    
    Tmid = l{end-1};
    Tmid = str2num(Tmid);  
    th = linspace(Tmid,T,100);
% Exracting Low temperature    
    t = l{end-3};
    t = str2num(t);
    tl = linspace(t,Tmid,100);
    Total_temp = [tl:th];
% Giving Universal gas constant    
    R = 8.3144598;
% Calling high_temp function    
    m = high_temp(L1,L2,R,th);
    th_Cp = m{1};
    th_H = m{2};
    th_S = m{3};
% Calling low_temp function        
    n = low_temp(L2,L3,R,tl);
    tl_Cp = n{1};
    tl_H = n{2};
    tl_S = n{3};
% Clubbing the high temp and low temp values to get a plot    
    Cp = [tl_Cp:th_Cp];
    H = [tl_H:th_H];
    S = [tl_S:th_S];
    
    mkdir(['C:\Users\IHTHISHAMUL-HAQ\Documents\MATLAB\NASA'],sp_name)
  
    % PLOTTING
    figure(1)
    plot(Cp,'color','r')
    figure(2)
    plot(H,'color','b')
    figure(3)
    plot(S,'color','g')
    cd('C:\Users\IHTHISHAMUL-HAQ\Documents\MATLAB\NASA')
    cd(sp_name)
    saveas(figure(1),'Cp.jpg')
    saveas(figure(2),'Enthalpy.jpg')
    saveas(figure(3),'Entropy.jpg')
    cd ..
end

CONCLUSION:

Thus a function that extracts the 14 co-efficient and calculates the enthalpy, entropy and specific heats for all the species in the data file is done.

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.