Project

nasa project

FILE PARSING OF NASA THERMODYNAMIC DATA:

FILE PARSING: It is the process of reading data from data structures(text file in this case) and storing/using it again in some other forms(graphs and text files in this case)

FILE FORMATS: .txt,.docx,.dat

How the program works:

  • \"fopen\" command - To open perticular text file
  • \"fgetl\" command - To read a line
  • \"strfind\" command - To sperate out the coefficeints
  • \"str2num\" command - coefficients are converted from \'string\' to \'number\'
  • \"mkdir\" command - To create folders for each species
  • Specific Heat, Enthalpy & Entropy are calculated using the above formulae
  • \"plot\" command - Graphs are plotted using this command
  • \"xlabel\",\"ylabel\",\"linewidth\",\"color\"&\"title\" - name the sides and size of line in a Graphs
  • \"cd\" command - To change the directory for graphs
  • To calculate molecular mass, another function was called
  • \"fprintf\" command - To write inside a text file
  • \"fclose\" command - To close any text file
clear all
close all
clc
% Defining constants
%real gas constant
R = 8.314; 
% Reading header info from nasa_thermo.txt
fid = fopen(\'therm.dat\',\'rt\');
TITLE = fgetl(fid);
A = fscanf(fid,\'%f \\n\',[1 3]);
% Reading temp limits
low_temp_limit = A(1);
mid_temp_limit = A(2);
high_temp_limit = A(3);
% Skipping 3 lines of comments
skip1 = fgetl(fid);
skip2 = fgetl(fid);
skip3 = fgetl(fid);

for i = 1:53  
name_line = fgetl(fid)
% Reading a line and seperating the name of species 
species = name_line(1:6); 
% Line 23 to line58- reading coefficients using \'for\' loop for all species
tline1 = fgetl(fid)
% Using \'E\' as seperator, we can seperate all the coefficients.
y1 = strfind(tline1,\'E\');
% Converting coefficients from string to numbers.         
h1 = tline1( 1: (y1(1)+3) );
h1 = str2num(h1);           
h2 = tline1( (y1(1)+4): (y1(2)+3));
h2 = str2num(h2);
h3 = tline1( (y1(2)+4): (y1(3)+3) );
h3 = str2num(h3);
h4 = tline1( (y1(3)+4): (y1(4)+3) );
h4 = str2num(h4);
h5 = tline1( (y1(4)+4): (y1(5)+3) );
h5= str2num(h5);

tline2 = fgetl(fid)
y2 = strfind(tline2,\'E\');
h6 = tline2( 1: (y2(1)+3) );
h6 = str2num(h6);
h7 = tline2( (y2(1)+4): (y2(2)+3) );
h7 = str2num(h7);
h8 = tline2( (y2(2)+4): (y2(3)+3) );
h8 = str2num(h8);
h9 = tline2( (y2(3)+4): (y2(4)+3) );
h9 = str2num(h9);
h10 = tline2( (y2(4)+4): (y2(5)+3) );
h10 = str2num(h10);

tline3 = fgetl(fid)
y3 = strfind(tline3,\'E\');
h11 = tline3( 1: (y3(1)+3) );
h11 = str2num(h11);
h12 = tline3( (y3(1)+4): (y3(2)+3) );
h12 = str2num(h12);
h13 = tline3( (y3(2)+4): (y3(3)+3) );
h13 = str2num(h13);
h14 = tline3( (y3(3)+4): (y3(4)+3) );
h14 = str2num(h14);

% Creating folder with different species name
subfolder_name = species
mkdir([\'C:\\USERS\\KABILAN\\nasa\\\',subfolder_name])

T= linspace(1,5000,50);

for j=1:length(T)
    if T(j)< 2500 %Different coefficients are used based on temperature rannge.
        %Since the transition temperature was not given, 2500k has been
        %used for simplicity
    Cp = R*(h1+h2.*T+h3.*T.^2+h4.*T.^3+h5.*T.^4);
    H = R.*T.*(h1+(h2.*T)./2+(h3.*T.^2)/3+(h4.*T.^3)/4+(h5.*T.^4/5)+h6./T);
    S = R.*(h1*log(T)+h2.*T+(h3.*T.^2)/2+(h4.*T.^3)/3+(h5.*T.^4)/4+h7);
    else
    Cp = R.*(h8+h9.*T+h10.*T.^2+h11.*T.^3+h12.*T.^4);
    H = R.*T.*(h8+(h9.*T)/2+(h10.*T.^2)/3+(h11.*T.^3)/4+(h12.*T.^4/5)+h13./T);
    S = R.*(h8.*log(T)+h9.*T+(h10.*T.^2)/2+(h11.*T.^3)/3+(h12.*T.^4)/4+h14);
    end
end
%Plotting the required graphs
figure(1)
plot(T,Cp,\'linewidth\',2,\'color\',\'r\') %Temperature VS Specific Heat
title(subfolder_name)
xlabel(\'Temperature\')
ylabel(\'Specific Heat\')
figure(2)
plot(T,H,\'linewidth\',2,\'color\',\'g\')  %Temperature VS Enthalpy
title(species)
xlabel(\'Temperature\')
ylabel(\'Enthalpy\')
figure(3)
plot(T,S,\'linewidth\',2,\'color\',\'b\')  % Temperature VS Entropy
title(species)
xlabel(\'Temperature\')
ylabel(\'Entropy\')

% To make the directory for function call same, we will change the current directory
cd(\'C:\\USERS\\KABILAN\')

% Calling function for molecular maa
molar_mass = molecular_mass(species);

% Changing the directory to dump the graphs in respective species folder.
filepath = ([\'C:\\USERS\\KABILAN\\nasa\\\',subfolder_name])
cd(filepath)
% Saving the graphs with names.
saveas(1,\'Specific Heat.jpg\')  
saveas(2,\'Enthalpy.jpg\')
saveas(3,\'Entropy.jpg\')

% Saving the molecular mass in .txt file.
f1 = fopen(\'Molecular mass.txt\', \'wt\')
fprintf(f1,\'%s \\n %s %f \\n\',species, \'Molecular mass\', molar_mass);
fclose(f1);

end

fclose(fid)


function for molecular mass
function[mm] = molecular_mass(species)
% This function takes species name as input and returns mm value to main Program

% The way this function works is, it will compare the alphabets in \\\'atoms\\\'.
% If program find a match it will add up the weight of that perticular atom.

atoms = \'CHON\';
aw = [12 1 16 14];  % Assigning correponding weights.
mm =0; % Assigning initaial value equal to zero. 

%loop will add weight of all the present atoms once
for i= 1:length(species)
    for j= 1:4
    if strcmp(species(i),atoms(j))
        mm = mm + aw(j);
    end
    end
end

%loop for adding weight if atoms are repeting
for g = 1:length(species)
    n = str2num(species(g));
    if n > 1
        p = (g-1);
        mm = mm + aw(p)*(n-1)
    end
end

%loop seperately for Argon
for l= 1:length(species)
    if strcmp(species(l),\'R\')
        mm = mm + 38.8
    end
end

1)I have got 54 folders for each file in a thermodynamic data file and each folder i got 3 plots and one molecular mass text file

2)I have attached my plots for O2,N2,CO2 below,

O2:

Enthalpy:

entropy:

Specific Heat:

CO2:

Enthalpy:

Entropy:

Specific Heat:

N2:

Enthalpy:

Entropy:

Specific Heat:

Molecular mass for O2:28.000000

Molecular mass for CO2:29.000000

Molecular mass for N2:26.000000

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.