Challenge

Project 1 - Parsing NASA thermodynamic data

%FUNCTION OF THERMAL PROPERTISE.....
function [c_p,h,s]=thermal_properties(a1,a2,a3,a4,a5,a6,a7,T)
R=8.314

c_p=(a1+(a2*T)+(a3*T.^2)+(a4*T.^3)+(a5*T.^4))*R
h=(a1*T+(a2*(T.^2/2))+(a3*(T.^3/3))+(a4*(T.^4/4))+(a5*(T.^5/5))+a6./T)*R.*T
s=(a1*log(T)+(a2*T)+(a3*(T.^2/2))+(a4*(T.^3/3))+(a5*(T.^4/4))+a7)*R
end
% END OF FUNCTION CODE FOR THERMAL PROPERTIES
%function of calculation of molecular weight....
function [M]=molecular_weight(species_name)
atomic_mass=[15.999,1.008,12.011,14.007,39.948];
elements=['O','H','C','N','A'];
mol_wt=0
for i=1:length(species_name)
    for j=1:length(elements)
        if strcmpi(species_name(i),elements(j));
            mol_wt=mol_wt+atomic_mass(j);
            z=j;
        end
    end
    var=str2double(species_name(i));
    if (var>1)
        mol_wt=mol_wt+(atomic_mass(z)*(var-1));
    end
end
M=mol_wt
end

% END OF FUNCTION CODE FOR MOLECULAR WEIGHT

% FILE PARSING MAIN CODE



% main code to extract 14 coefficients from file

clear all
close all
clc
%opening file saved
b=fopen('THERMO.dat','r');
line1=fgetl(b)


%reading line where  global temperature available
line2=fgetl(b)
%spliting line into 'strings '
a=strsplit(line2,' ')
%converting string to numbers
global_low_temp=str2num(a{2});
global_mid_temp=str2num(a{3});
global_high_temp=str2num(a{4});

%skipping 3 lines 
fgetl(b);
fgetl(b);
fgetl(b);

%finding coeff values
%using for loop to limit the file
for i=1:inf
    line3=fgetl(b);
    B=strsplit(line3,' ')
%giving breat in the end of data
    if strcmp(line3,'END')
        break
    end
% finding species location
    species_name=(B{1});

%finding local temprature values
    local_low_temp=str2num(B{end-3});
    local_mid_temp=str2num(B{end-1});
    local_high_temp=str2num(B{end-2});
   %reading line 4 
    line4=fgetl(b);

%finding location of E
    C=strfind(line4,'E');
%finding coeff. according to the E locations
    
    a1=str2num(line4(1:C(1)+3))
    a2=str2num(line4((C(1)+4):(C(2)+3)));
    a3=str2num(line4((C(2)+4):(C(3)+3)));
    a4=str2num(line4((C(3)+4):(C(4)+3)));
    a5=str2num(line4((C(4)+4):(C(5)+3)));
  % repeating same for next 2 lines  
    line5=fgetl(b);
    D=strfind(line5,'E')
    a6=str2num(line5(1:D(1)+3))
    a7=str2num(line5((D(1)+4):(D(2)+3)));
    a8=str2num(line5((D(2)+4):(D(3)+3)));
    a9=str2num(line5((D(3)+4):(D(4)+3)));
    a10=str2num(line5((D(4)+4):(D(5)+3)));
    
    line6=fgetl(b);
    D=strfind(line6,'E')
    a11=str2num(line6(1:D(1)+3))
    a12=str2num(line6((D(1)+4):(D(2)+3)));
    a13=str2num(line6((D(2)+4):(D(3)+3)));
    a14=str2num(line6((D(3)+4):(D(4)+3)));


    
    T_low=linspace(local_low_temp,local_mid_temp,100);%low temp    T_high=linspace(local_mid_temp,local_high_temp,100);% high temp 
    % calling function and putting with low & high temperature values
    [c_ph,hh,sh]=thermal_properties(a1,a2,a3,a4,a5,a6,a7,T_high)% high temp coeffs
    [c_pl,hl,sl] =thermal_properties(a8,a9,a10,a11,a12,a13,a14,T_low)%low temp. coeffs
    %plotting 
    figure(1)
    plot(T_low,c_pl)
    hold on
    plot(T_high,c_ph)
    title('temperature vs specific heat ')
    xlabel('temperature')
    ylabel('specific heat')
    
    figure(2)
    plot(T_low,sl)
    hold on
    plot(T_high,sh)
    title('temperature vs entropy')
    xlabel('temperature')
    ylabel('entropy')
    
    figure(3)
    plot(T_low,hl)
    hold on
    plot(T_high,hh)
    title('temperature vs enthalpy')
    xlabel('temperature')
    ylabel('enthalpy')
    % creating file
    mkdir('species')
    cd('species')
%changing file directory
    mkdir(species_name)
    cd(species_name)
%saving files below
    saveas(1,'specific_heaT.jpg');
    saveas(3,'enthalpy.jpg');
    saveas(2,'entropy.jpg');
    close all
    cd ..
    cd ..
     % calculating molecular weight
    [M]=molecular_weight(species_name)
    k=sprintf('molecular weight of%s=%fu',species_name,M)
    disp(k)
end

AIM:

To write a code in MATLAB to parse nasa thermodynamic data file and then calculate thermodynamic properties of various gas species.

OBJECTIVE:

  • Write a function that extracts the 14 coefficients and calculates the enthalpy.entropy and specific heats for all the species
  • Calculating molecular weight of each species
  • Plotting the specific heat, enthalpy and entropy for the local temperature range.
  • Saving the plots as images with appropriate names and dumping them in seperate folders for each species.

THEORY:

File Parsing File parsing is a string or symbol either in natural language computer language or data structure conferming to the rules of the former grammer,

RESULT:

  • The code for file parsing is done
  • The graph for N2 O2 and CO2 is plotted
  • Molecular weight for every elements is found
  • files are created

GRAPH FOR SPECIES BELOW

FOR CO2:-

FOR N2:-

FOR O2:-

SEPARATE FOLDERS CREATED TO SAVE THE SPECIES PLOTS:-

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.