Project

Parsing NASA thermodynamic data

Data parsing - Data parsing is a method where one string of data gets converted into a different type of data. So let’s say you receive your data in raw HTML, a parser will take the said HTML and transform it into a more readable data format that can be easily read and understood.

In short, Data parsing is a process of extracting the required information from the given file and making it readable.

Here in this project we need to data parsing for NASA thermodynamic data i.e. we have to extract the information and do the plotting accordingly to make the data readable.

In this project, we have NASA thermodynamis data which contains information regarding polynomials that can be used to evaluate thermodynamic properties such as Cp, H and S. They have also documented the co-efficients that are required to evaluate these polynomials for 1000+ species.

Data is stored in a THERMO.dat file which is opnened using a' fopen' function

The first line of the file indicates global temperatures for the species which are extracted and since the temperatures are inside a string we use string split function (strsplit) to split strings in the specified delimiter,here space(' ')is the delimiter '

Command str2double is used to convert the string values to numerical values(double is a data type)'

A temperature range with 500 values between global high temperatute and global low temperature is made by using linspace command

Species data has 14 coefficients in which first seven coefficients are for high temperature and the remaining are for low temperature.

Functions are made to calculate specific heat, enthalpy,entropy and molecular mass for all species.

For loop isused for the program to calculate the specific heat, entropy and enthalpy for all 53 species using the local temperature ranges given uniquely for each species and then they are represented by plotting cp,H and S against the local temperature ranges.

Directory is changed and a new folder is made to save the plots .

Formula used to calculate specific heat,enthalpy and entropy:

`(cp)/R=a1+a2T+a3T^2+a4T^3+a5T^4`

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

`S/R=a1logT+a2T+a3T^2/2+a4T^3/3+a5T^4/4+a7`

Main code:

clear all
close all
clc

R = 8.314;

f1 = fopen('THERMO.dat','r')
line1 = fgetl(f1);
Global_temp = fgetl(f1);
C= strsplit(Global_temp,' ');

global_low_temp = str2double(C{2});
global_mid_temp = str2double(C{3});
global_high_temp = str2double(C{4});

fgetl(f1);
fgetl(f1);
fgetl(f1);
for i = 1:53
  line = fgetl(f1);
  A= strsplit(line,' ')
  species= A(1)
  Q= strfind(line,'G');
  local_low_temp = line(Q+3:55);
local_mid_temp = line(Q+13:65);
local_high_temp = line(Q+23:75);
lt = str2double(local_low_temp);
mt = str2double(local_mid_temp);
ht = str2double(local_high_temp);

cfline1= fgetl(f1)
X = strfind(cfline1,'E');
a1 = cfline1(1:X(1)+3);
a1 = str2double(a1);
a2 = cfline1(X(1)+4:X(2)+3);
a2 = str2double(a2);
a3 = cfline1(X(2)+4:X(3)+3);
a3 = str2double(a3);
a4 = cfline1(X(3)+4:X(4)+3);
a4 = str2double(a4);
a5 = cfline1(X(4)+4:X(5)+3);
a5 = str2double(a5);

cfline2= fgetl(f1)
Y = strfind(cfline2,'E');
a6 = cfline2(1:Y(1)+3);
a6 = str2double(a6);
a7 = cfline2(Y(1)+4:Y(2)+3);
a7 = str2double(a7);
a8 = cfline2(Y(2)+4:Y(3)+3);
a8 = str2double(a8);
a9 = cfline2(Y(3)+4:Y(4)+3);
a9 = str2double(a9);
a10 = cfline2(Y(4)+4:Y(5)+3);
a10= str2double(a10);


cfline3= fgetl(f1)
Z = strfind(cfline3,'E');
a11 = cfline3(1:Z(1)+3);
a11= str2double(a11);
a12= cfline3(Z(1)+4:Z(2)+3);
a12= str2double(a12);
a13= cfline3(Z(2)+4:Z(3)+3);
a13= str2double(a13);
a14= cfline3(Z(3)+4:Z(4)+3);
a14= str2double(a14);

T = linspace(lt,ht,500)
cp = specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,lt,ht,mt);
S = entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,lt,ht,mt);
H = enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,lt,ht,mt);


mkdir('C:/Users/Rajat/species')
cd('C:/Users/Rajat/species')


figure(1)
plot(T,cp,'linewidth',2,'color','r')
xlabel('Temperature in kelvin')
ylabel('specific heat in kj')
title('specific heat vs temperature')

figure(2)
plot(T,H,'linewidth',2,'color','b')
xlabel('Temperature in kelvin')
ylabel('Enthalpy in kj/(mol)')
title('Enthalpy vs temperature')

figure(3)
plot(T,S,'linewidth',2,'color','g')
xlabel('Temperature in kelvin')
ylabel('Entropy in kj/(mol k)')
title('entropy vs temperature')

directory =('C:/Users/Rajat/species')
cd(directory)

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

cd('C:/Users/Rajat/species');



end
fclose

Function for specific heat:

function cp = specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,lt,ht,mt);
  if T >=mt;
    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

Function for enthalpy:

function H = enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,lt,ht,mt);
  if T >=mt;
    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

Function for entropy:

function S = entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,lt,ht,mt);
  if T >=mt;
    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

Function for molecular mass:

function M  = molecular_mass(species)
 
  Constituents ={'H','C','N','O','A'}
  Atomic_weight = [1.00794 12.0107 14.0067 15.9994 39.948]
  M = 0;
  
  for i = 1:length(species)
       for j= 1:length(Constituents)
          if (strcmp(species(i),Constituents(j))==1)
             M = M+ Atomic_weight(j);
             g=j;
           end
        end
        n = str2double(species(i));
        if n>1
            M = M+ Atomic_weight(p)*(n-1);
        end
end
end

Attachements:

Plots for O2:

Plots for N2:

Plots for CO2:

Screenshot of the folder where plots are saved:

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.