Project

PROJECT ON PARSING OF NASA THERMODYNAMIC DATA

1. AIM

  1. To write the program that extracts the 14 co-efficient and to calculates the enthalpy, entropy and specific heats for all the species in the data file.
  2. To plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature: high temperature) specific for each species.
  3. To calculate the molecular weight of each species and display it in the command window.

2. GOVERNING EQUATION

`(CP)/R = a1 + a2.T + a3.T^2+ a4.T^3+ a5T^4`

`H/(R.T) = a1 + a2T/2 + a3T^2/3+ a4T^3/4+ a5T^4/5 + a6(1)/T`

`S/R = a1.lnT+ a2.T + a3.T^2/2+ a4.T^3/3+ a5.T^4/4 + a7`

3. BODY OF CONTENT

PARSING

Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural language, computer language or data structure, conforming to the rules of a formal grammer. The term parsing comes from Latin pars (orationis), meaning part (of speech).

GIVEN

NASA Thermodynamic data file ‘Thermo.dat’ is given for reference.

STEPS AND EXPLANATION

  1. Before starting the program make sure that the ‘Thermo.dat’ file should be in the same directory where the program is saved.
  2. First of all we need to read the NASA Thermodynamic Data file names as 'Thermo.dat'
  3. To read file we need to open ‘Thermo.dat’ file by using fopen command.
f1= fopen('THERMO.dat','r');
  1. Then to navigate the data fgetl command was used. The header line 'Thermo' was skipped by using fgetl command.
header = fgetl(f1);
  1. The temperature line '300 1000 5000' was stored as a single string in a variable.
Global_temp = fgetl(f1);
  1. To split the string into 3 strings strsplit command was used. Spaces between temperatures is used to give reference from where to split.
C = strsplit(Global_temp,' ');
  1. To convert the string values into numerical values str2num command was used. The three temperature values low, mid and high temperatures were stored in separate variables.
global_low_temp =str2num(C{2});

global_mid_temp =str2num(C{3});

global_high_temp =str2num(C{4});

8. After that the three comment lines as shown in figure below were skipped by using fgetl command.

comment1=fgetl(f1);
comment2=fgetl(f1);
comment3=fgetl(f1);
  1. the value of Universal gas constant R = 8.314J/mol-K was defined.
  1. The 14 coefficients for each species as given in the figure below were calculated by using for loop.

Within for loop we first get the next line after comment which is having a single string of species name and temperature. By using fgetl command we read the line which is stored in data_line.

data_line= fgetl(f1);

11. In order to read the species, we need to define from where to where the species name are. After that it stores in the z1. Which further define as species.

z1=data_line(1:6);
species=[z1]

12. After getting species we need to take the value of local temperature which is present after G in ‘Thermo.dat’ file by using strfind command.

Q = strfind(data_line,'G');
temp1=data_line([Q+3:55]);
temp2=data_line([Q+12:65]);
temp3=data_line([Q+22:75]);

13. After getting temp1, temp2, temp3 we need to define local temperature by using str2double command.

low_temperature = str2double(temp1);
mid_temperature = str2double(temp3);
high_temperature = str2double(temp2);

14. For each species contains 3 lines in which 14 coefficients are present. To distinguish the coefficients, the position of exponent are used to determined for each coefficient by using strfind command.

cofficient_line1= fgetl(f1);
place_of_E1 = strfind(cofficient_line1,'E');

15. after getting the position of E we define each coefficient of line 1 and store it into a1, a2, a3, a4, a5 by using str2double command.

a1 = cofficient_line1(1:place_of_E1(1)+3);
a1 = str2double(a1); %storing 1st coefficient
a2 = cofficient_line1(place_of_E1(1)+4:place_of_E1(2)+3);
a2 = str2double(a2); %storing 2nd coefficient
a3 = cofficient_line1(place_of_E1(2)+4:place_of_E1(3)+3);
a3 = str2double(a3); %storing 3rd coefficient
a4 = cofficient_line1(place_of_E1(3)+4:place_of_E1(4)+3);
a4 = str2double(a4); %storing 4th coefficient
a5 = cofficient_line1(place_of_E1(4)+4:place_of_E1(5)+3);
a5 = str2double(a5); %storing 5th coefficient

16. Similar steps were used in order to read and stores the coefficient of line 2

cofficient_line2 = fgetl(f1);
place_of_E2 = strfind(cofficient_line2,'E');
a6 = cofficient_line2(1:place_of_E2(1)+3);
a6 = str2double(a6); %storing 6th coefficient
a7 = cofficient_line2(place_of_E2(1)+4:place_of_E2(2)+3);
a7 = str2double(a7); %storing 7th coefficient
a8 = cofficient_line2(place_of_E2(2)+4:place_of_E2(3)+3);
a8 = str2double(a8); %storing 8th coefficient
a9 = cofficient_line2(place_of_E2(3)+4:place_of_E2(4)+3);
a9 = str2double(a9); %storing 9th coefficient
a10 = cofficient_line2(place_of_E2(4)+4:place_of_E2(5)+3);
a10 = str2double(a10); %storing 10th coefficient
 

17. Similar steps were used in order to read and stores the coefficient of line 3

cofficient_line3 = fgetl(f1);
place_of_E3 = strfind(cofficient_line3,'E');
a11 = cofficient_line3(1:place_of_E3(1)+3);
a11 = str2double(a11); %storing 11th coefficient
a12 = cofficient_line3(place_of_E3(1)+4:place_of_E3(2)+3);
a12 = str2double(a12); %storing 12th coefficient
a13 = cofficient_line3(place_of_E3(2)+4:place_of_E3(3)+3);
a13 = str2double(a13); %storing 13th coefficient
a14 = cofficient_line3(place_of_E3(3)+4:place_of_E3(4)+3);
a14=str2double(a14); %storing 14th coefficient

18. Splitting of temperature is done by using linspace command which helps in plotting the graph.

T=linspace(low_temperature,high_temperature,500);

19. After that calculating the values of specific heat, enthalpy, and entropy were calculated by the help of separate function.

Cp=specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature);

S=entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature);

H=enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature);

20. The separate folders were created for each species to save the plots for each species in separate folders.

spec=char(species);
fd = sprintf('%s',spec);
cur_dir=pwd;
mkdir(spec);
cd(spec);

21. After that we need to plot specific heat VS temperature

%Plot 1, Specific heat (Cp) vs Temperature (T)

figure(1);
plot(T,Cp,'linewidth',3,'color','r');
xlabel('Temperature in K');
ylabel('Specific heat in kJ');
title('Specific heat vs Temperature');
  

22. After that we need to plot enthalpy VS temperature

%Plot 2, Enthalpy (H) vs Temperature (T)

figure(2);
plot(T,H,'linewidth',3,'color','b');
xlabel('Temperature in K');
ylabel('Enthalpy in kJ/(mol)');
title('Enthalpy vs Temperature');

23. After that we need to plot entropy VS temperature

%Plot 3, Entropy (S) vs Temperature (T)

figure(3);
plot(T,S,'linewidth',3,'color','g');
xlabel('Temperature in K');
ylabel('Entropy in kJ/(mol K)');
title('Entropy vs Temperature');

24. the plot generated should be stored in the separate species folder

% saving the plots that got generated

saveas(figure(1),'cp.png');
saveas(figure(2),'h.png');
saveas(figure(3),'s.png');
cd(cur_dir);

25. In order to calculate the molecular mass we need to call the molecular_mass function.

M= molecular_mass(species)
  1. After this the program is completed for one species as it is in the for will it will do similar step for all species.

FULL PROGRAM OF PARSING

clear all
close all
clc

%OPEN THE NASA THERMODYNAMICS FILE
f1= fopen('THERMO.dat','r');

%TO READ THE DATA FROM FILE WE USE fgetl
%STORING HEADER FILE
header = fgetl(f1);

%Reading Global Temperature Line
Global_temp = fgetl(f1);

%SPLITING OF GLOBAL TEMPERATURE STRING
C = strsplit(Global_temp,' ');

%STORING THE GLOBAL TEMPERATURE IN LOW, MID AND HIGH
%str2num USED TO CONVERT STRING INTO NUMERIC
global_low_temp =str2num(C{2});     %Global Low Temperature 
global_mid_temp =str2num(C{3});     %Global Mid Temperature 
global_high_temp =str2num(C{4});    %Global High Temperature 

%GETTING COMMENT IN ORDER TO SKIP THESE COMMNET FROM THE CALCULATION
comment1=fgetl(f1);
comment2=fgetl(f1);
comment3=fgetl(f1);

%DEFINING THE UNIVERSAL GAS CONSTANT VALUE
R=8.314;

%STARTING OF FOR LOOP FROM i=1 TO 53 
for i=1:53
 
%GETTING LINE WHICH IS HAVING SPECIES NAME AND LOCAL TEMPERATURE
data_line= fgetl(f1);              %Reading the line
z1=data_line(1:6);                 %SEPARATING SPECIES

%STORING THE SPECIES NAME INTO SPECIES
species=[z1]

%FIND THE POSITION OF LOCAL TEMPERATURE BY THE HELP OF G
Q = strfind(data_line,'G');

%STORING LOCAL TEMPERATURE
temp1=data_line([Q+3:55]);
temp2=data_line([Q+12:65]);
temp3=data_line([Q+22:75]);

%DEFINING OF LOCAL TEMPERATURE
low_temperature = str2double(temp1);         %Local Low Temperature
mid_temperature = str2double(temp3);         %Local mid Temperature
high_temperature = str2double(temp2);        %Local high Temperature 


%READING OF COEFFICIENT DATA FROM LINE 1

cofficient_line1= fgetl(f1);
place_of_E1 = strfind(cofficient_line1,'E');     %FINDING THE POSITION OF E
a1 = cofficient_line1(1:place_of_E1(1)+3);       %GETTING THE FIRST COEFFICIENT
a1 = str2double(a1);                             %STORING 1ST COEFFICIENT 
%SIMILARLY FOR OTHER COEFFICIENT OF LINE 1
a2 = cofficient_line1(place_of_E1(1)+4:place_of_E1(2)+3);
a2 = str2double(a2);                             %STORING 2ND COEFFICIENT  
a3 = cofficient_line1(place_of_E1(2)+4:place_of_E1(3)+3);
a3 = str2double(a3);                             %STORING 3RD COEFFICIENT 
a4 = cofficient_line1(place_of_E1(3)+4:place_of_E1(4)+3);
a4 = str2double(a4);                              %STORING 4TH COEFFICIENT  
a5 = cofficient_line1(place_of_E1(4)+4:place_of_E1(5)+3);
a5 = str2double(a5);                              %STORING 5TH COEFFICIENT 

%READING OF COEFFICIENT DATA FROM LINE 2

cofficient_line2 = fgetl(f1);
place_of_E2 = strfind(cofficient_line2,'E');
a6 = cofficient_line2(1:place_of_E2(1)+3);
a6 = str2double(a6);                                %STORING 6TH COEFFICIENT  
a7 = cofficient_line2(place_of_E2(1)+4:place_of_E2(2)+3);
a7 = str2double(a7);                                %STORING 7TH COEFFICIENT 
a8 = cofficient_line2(place_of_E2(2)+4:place_of_E2(3)+3);
a8 = str2double(a8);                                %STORING 8TH COEFFICIENT 
a9 = cofficient_line2(place_of_E2(3)+4:place_of_E2(4)+3);
a9 = str2double(a9);                                   %STORING 9TH COEFFICIENT 
a10 = cofficient_line2(place_of_E2(4)+4:place_of_E2(5)+3);
a10 = str2double(a10);                                  %STORING 10TH COEFFICIENT 

%READING OF COEFFICIENT DATA FROM LINE 3

cofficient_line3 = fgetl(f1);
place_of_E3 = strfind(cofficient_line3,'E');
a11 = cofficient_line3(1:place_of_E3(1)+3);
a11 = str2double(a11);                                  %STORING 11TH COEFFICIENT  
a12 = cofficient_line3(place_of_E3(1)+4:place_of_E3(2)+3);
a12 = str2double(a12);                                  %STORING 12TH COEFFICIENT 
a13 = cofficient_line3(place_of_E3(2)+4:place_of_E3(3)+3);
a13 = str2double(a13);                                  %STORING 13TH COEFFICIENT 
a14 = cofficient_line3(place_of_E3(3)+4:place_of_E3(4)+3);
a14=str2double(a14);                                    %STORING 14TH COEFFICIENT 

%SPLITTING THE TEMPERATURE FROM LOW TEMPERATURE TO HIGH TEMPERATURE

T=linspace(low_temperature,high_temperature,500);

%Specific Heat calculation

Cp=specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature);

%Entropy calculation

S=entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature);

%Enthaphy calculation

H=enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature);

%Saving in a folder for each species
spec=char(species); 
fd = sprintf('%s',spec);
cur_dir=pwd;
mkdir(spec);
cd(spec);
  
  
%Plot 1, Specific heat (Cp) vs Temperature (T)
%figure 1 for defining plot
figure(1);
%plot of Cp and T
plot(T,Cp,'linewidth',3,'color','r');
%defining the x and y axis
xlabel('Temperature in K');
ylabel('Specific heat in kJ');
%giving tittle for the figure 1
title('Specific heat vs Temperature');
  
%Plot 2, Enthalpy (H) vs Temperature (T)
%figure 2 for defining plot  
figure(2);
%plot of Cp and T
plot(T,H,'linewidth',3,'color','b');
%defining the x and y axis
xlabel('Temperature in K');
ylabel('Enthalpy in kJ/(mol)');
%giving tittle for the figure 2
title('Enthalpy vs Temperature');
  
%Plot 3, Entropy (S) vs Temperature (T)
%figure 2 for defining plot
figure(3);
%plot of Cp and T
plot(T,S,'linewidth',3,'color','g');
%defining the x and y axis
xlabel('Temperature in K');
ylabel('Entropy in kJ/(mol K)');
%giving tittle for the figure 3
title('Entropy vs Temperature');

% saving the plots for the species in the species folder
saveas(figure(1),'cp.png');
saveas(figure(2),'h.png');
saveas(figure(3),'s.png');
cd(cur_dir);

%Molecular mass calcuation
M= molecular_mass(species)


end

fclose(f1);

FUNCTION USED

  1. SPECIFIC HEAT FUNCTION
%function of specific heat by taking input such as coefficeint and R
function Cp=specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature)
if T>=mid_temperature
    Cp=(a1+a2.*(T)+a3.*(T.^2)+a4.*(T.^3)+a5.*(T.^4))*R;
else
    Cp=(a8+a9.*(T)+a10.*(T.^2)+a11.*(T.^3)+a12.*(T.^4))*R;
end
  1. ENTHALPY FUNCTION
%function of ENTHALPY by taking input such as coefficeint and R

function H=enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature)
if T>=mid_temperature
    H=(a1.*T+a2.*(T.^2)./2+a3.*(T.^3)./3+a4.*(T.^4)./4+a5.*(T.^5)./5+a6)*R;
else
    H=(a8.*T+a9.*(T.^2)./2+a10.*(T.^3)./3+a11.*(T.^4)./4+a12.*(T.^5)./5+a13)*R;
end
  1. ENTROPY FUNCTION
%function of ENTROPY by taking input such as coefficeint and R
function S=entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,low_temperature,high_temperature,mid_temperature)
if T>=mid_temperature
    S=(a1.*log(T)+a2.*T+a3.*(T.^2)./2+a4.*(T.^3)./3+a5.*(T.^4)./4+a7)*R;
else
    S=(a8.*log(T)+a9.*T+a10.*(T.^2)./2+a11.*(T.^3)./3+a12.*(T.^4)./4+a14)*R;
end
  1. MOLECULAR MASS FUNCTION
%Function_for_Molecular_Weight%

function M= molecular_mass(species)
%DEFINING ATOMS
        atoms={'H','C','N','O','A'};
        %DEFINING ATOMIS MASS
        AtomicWeight=[1 12 14 16 40];
        %INITIAL VALUE OF M
               M=0;
        for i=1:length(species)
            for j=1:length(AtomicWeight)
                if (strcmp(species(i),atoms(j))==1)
                    M=M+AtomicWeight(j);
                    g=j;
                end
            end
         % Adding the weights of the repeating atoms
                n=str2double(species(i));
                if n>1
                    %p=(n-1);
                    M=M+AtomicWeight(g)*(n-1);
                end
                         
      end
end
  1. RESULT
  1. The plots are saved for all species in their species folder.
  2. Molecular weight are calculated in the command window.
  1. plots for oxygen ‘O’
  1. plots for oxygen molecules ‘O2’
  1. plots for ‘CH3’

MOLECULAR MASS IN COMMAND WINDOW

ERROR

By writing wrong spelling it was not working

GOOGLE DRIVE LINK

For rest of the image

https://drive.google.com/drive/folders/10RKnFgyBATJQH5n0melGCcs_h7CeKtEB?usp=sharing

Link for NASA THERMODYNAMICS FILE

https://drive.google.com/file/d/1CzYP18svIkI1fv7rSlL7-SLaKuLF6hga/view?usp=sharing

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.