Project

NASA THERMODYNAMIC FILE PARASING

FILE PARASING:

Whats FILE PARASING?

Parsing a file means reading in a data stream of some sort and building an in-memory model of the semantic content of that data. This aims at facilitating performing some kind of transformation on the data.

About The Project:

Write a function that extracts the 14 coefficients like the enthalpy, entropy, and specific heats and calculating or all the species in the data file.

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

AIM:

In order to write a function to extract and read the given THERMO.DAT file. In order to Calculate the values of the Specific Heat, Enthalpy, and Entropy using the given above equation for different temperature ranges. To plot and create a movie the Graphs of Cp vs T, H vs T, S vs T for all the 53 species in the files.

METHODOLOGY:

1) READING THE HEADER INFORMATION

Here basically the thermo.dat was read using fopen command. Further lines were also skipped using fgetl command( Skipping Line 1 to 5)

2)READING THE SPECIES BLOCKS ( LIKE OXYGEN, HYDROGEN, etc )

In total there are 53 such species, The coefficients are 14 in total they calculated using looping. The RHS and LHS sides of the Coefficients are sorted out using str2num command. The coefficient E is found using findstr command. The LINE1, LINE2, LINE3 are skipped. Each line further is taken as L1, L2, L3 inside species block.

3) CALCULATING VALUES OF ENTROPY ENTHALPY AND SPECIFIC HEAT USING THE EQUATIONS. FURTHER PLOTTING THE GRAPH FOR EACH SPECIES.

The graphs were plotted for Entropy, Enthalpy and Specific heat against Temperature. Further, a movie file is also created for all graphs plotted.

CODE:

clear all
close all
clc

%open the thremodynamic data file

file=fopen(\'Thermo.dat\',\'r\')
%skiping the Header
Line1=fgetl(file);
%Global temperature values 
line2=fgetl(file);

A=strsplit(line2,\' \');

Global_low_temp=str2num(A{2})
Global_med_temp=str2num(A{3})
Global_high_temp=str2num(A{4})



%Skipping comments
line3=fgetl(file);
line4=fgetl(file);
line5=fgetl(file);

%total number of species blocks 
ct=1
for i=1:53
    species=fgetl(file);
    species_terms = species(1:6);
    
    LINE1=fgetl(file);
    L1=strfind(LINE1,\'E\');
    Coe1=str2num(LINE1(1:(L1(1)+3)));
    Coe2=str2num(LINE1((L1(1)+4):(L1(2)+3)));
    Coe3=str2num(LINE1((L1(2)+4):(L1(3)+3)));
    Coe4=str2num(LINE1((L1(3)+4):(L1(4)+3)));
    Coe5=str2num(LINE1((L1(4)+4):(L1(5)+3)));
    
    
    LINE2=fgetl(file);
    L2=strfind(LINE2,\'E\');
    Coe6=str2num(LINE2(1:(L2(1)+3)));
    Coe7=str2num(LINE2((L2(1)+4):(L2(2)+3)));
    Coe8=str2num(LINE2((L2(2)+4):(L2(3)+3)));
    Coe9=str2num((LINE2((L2(3)+4):(L2(4)+3))));
    Coe10=str2num((LINE2((L2(4)+4):(L2(5)+3))));
    
    LINE3=fgetl(file);
    L3=strfind(LINE3,\'E\');
    Coe11=str2num(LINE3(1:(L3(1)+3)));
    Coe12=str2num(LINE3((L3(1)+4):(L3(2)+3)));
    Coe13=str2num(LINE3((L3(2)+4):(L3(3)+3)));
    Coe14=str2num(LINE3((L3(3)+4):(L3(4)+3)));
    
    %temperature
    T=linspace(300,5000,100);
    %Universal gas constant
    R=8.314;
    %calculations using equation
    for j=1:length(T)
        if T(j)<3000
            Cp=(Coe1+Coe2.*T+Coe3.*T.^2+Coe4.*T.^3+Coe5.*T.^4).*R;
            H=(Coe1+(Coe2.*T)./2+(Coe3.*T.^2)/2+(Coe4.*T.^3)/4+(Coe5.*T.^4/5)+Coe6./T).*T.*R;
            S=(Coe1.*log(T)+Coe2.*T+(Coe3.*T.^2)/2+(Coe4.*T.^3)/3+(Coe5.*T.^4)/4+Coe7).*R;
        else
            Cp=(Coe8+Coe9.*T+Coe10.*T.^2+Coe11.*T.^3+Coe12.*T.^4).*R;
            H=(Coe8+(Coe9.*T)/2+(Coe10.*T.^2)/2+(Coe11.*T.^3)/4+(Coe12.*T.^4/5)+Coe13./T).*T.*R;
            S=(Coe8.*log(T)+Coe9.*T+(Coe10.*T.^2)/2+(Coe11.*T.^3)/3+(Coe12.*T.^4)/4+Coe14).*R;
        end
       
    end
    



%plots
%plot T vs Cp
hold on


figure(1)
plot(T,Cp,\'linewidth\',3,\'color\',\'r\')
xlabel(\'temperature\')
ylabel(\'Specific Heat\')
title(species_terms)



%plot T vs H
figure(2)
plot(T,H,\'linewidth\',3,\'color\',\'b\')
xlabel(\'temperature\')
ylabel(\'Enthalpy\')
title(species_terms)


%plot T vs S
figure(3)
plot(T,S,\'linewidth\',3,\'color\',\'g\')
xlabel(\'temperature\')
ylabel(\'Entropy\')
title(species_terms)


pause(5)
M(ct)=getframe(gcf);
ct=ct+1;


end

movie(M)
videofile=VideoWriter(\'Plots\',\'Uncompressed AVI\');
open(videofile)
writeVideo(videofile,M)
close(videofile)

PLOTS

1) O

2)N2

3) CO2

REFERENCES:


1) https://in.mathworks.com/matlabcentral/answers/196582-best-way-to-parse-text-file

2) https://in.mathworks.com/matlabcentral/answers/270984-read-a-file-dat-from-matlab

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.