Project

Parsing NASA thermodynamic data

Aim : write a code in Matlab / to parse the NASA thermodynamic data file and then calculate thermodynamic properties of various gas species.

Objective :

  • Write a programme that extracts the 14 co-efficients of the species from the given file
  • Write a programme that calculates the enthalpy, entropy and specific heats for all the species in the data file.
  • To write a programme that Calculates the molecular weight of each species.
  • To write a programme that plots the specific heat, enthalpy and entropy of a given species.

Procedure :

  1. Initially open the given thermodynamic data file and read the data in the file and store the data to a variable f1.
  2. Then read the headder file of thermodynamic data and calculate the global low,mid and high temperatures from the second line of the header file.
  3. By using fgel() , strplit() and str2num() command fidn out the global low,mid and high temperature in the second line.
  4. Then calculate the 14 co-efficients for all the species in the given thermodynamic data file.
  5. In data file each species has three lines in which 14 co-efficients are there.
  6. by using for loop, calculate the 14 coefficients for all the species.
  7. By using strfind() command, find out the number of the exponentials in the first line and locate the co-efficients.
  8. once we find out the position of co-efficients we can use str2num() to convert them from string form to number form and assign them a variable
  9. By doing the above steps for line two and three, we can calculate the 14 co-efficient for all the species.
  10. once you find out the co-efficients for a species,tehn calculate the entropy,enthalpy and specific heat.
  11. First 7 coefficients are high range temperature co-efficients and next 7 co-efficients are low range temperatures.
  12. Now we calculate the entropy ,enthalpy and specific heat for 7 high tempetaures and 7 low temperatures.
  13. Assuming universal gas constant R=8.314 j/mol-k and assuming temperature range from 100 to 5000 amd take 100 values with help of linspace() command.
  14. Once you calculate the entropy,enthalpy and specific heat for all species, plot graph between:Temperature vs enthalpy, Temperature vs entropy and Temperature vs specific heat.
  15. store all the three plots for all species in the file.The stored file is the picture below.
  16. Molecular weight is calculated by calling the molecular weight function.

CODE :

1. Primary code :

clear all
close all
clc

f1=fopen('THERMO.dat','r')


heading =fgetl(f1) %thermo %line 1

global_T=fgetl(f1) %global Tratures %line 2 %string type

a=strsplit(global_T,' ') %global_T is the line to split %space is the d-limiter

%converting string to number
%cell array can  store anything and need to be put in curly braces

global_low_T=str2num(a{2})
global_med_T=str2num(a{3})
global_high_T=str2num(a{4})

%skipping next 3 lines with getl

for i=1:3
    fgetl(f1);
end

%CREATING DIR FOLDER
   mkdir('D:\result')


  for i=1:53  
      
  element=fgetl(f1);
  element_n=element(1:6)
  
  local=strsplit(element,' ')
  l=length(local)
  local_T1=str2num(local{l-3})
  local_T2=str2num(local{l-2})
  local_T3=str2num(local{l-1})
  


  % accessing line 1
  
  line1=fgetl(f1);
  
  %finding the location of E in line 1
  
  l1 = findstr(line1,'E');
  
  % 5 coff of the first line
  % the values of E is stored in l1 
  % 14 coeff of the first element
  
  a1=str2num(line1(1:l1(1)+3)); %starting point of first coeff
  
  %+4 is to get to the starting point of 2nd coff : 
  
  a2=str2num(line1((l1(1)+4):(l1(2)+3)));
  a3=str2num(line1((l1(2)+4):(l1(3)+3)));
  a4=str2num(line1((l1(3)+4):(l1(4)+3)));
  a5=str2num(line1((l1(4)+4):(l1(5)+3)));
  
 line2=fgetl(f1);
 
 l2= findstr(line2,'E');
 
  a6=str2num(line2(1:l1(1)+3));
  a7=str2num(line2((l1(1)+4):(l1(2)+3)));
  b1=str2num(line2((l1(2)+4):(l1(3)+3)));
  b2=str2num(line2((l1(3)+4):(l1(4)+3)));
  b3=str2num(line2((l1(4)+4):(l1(5)+3)));
  
  line3=fgetl(f1);
 
 l3= findstr(line3,'E');
 
  b4=str2num(line3(1:l1(1)+3));
  b5=str2num(line3((l1(1)+4):(l1(2)+3)));
  b6=str2num(line3((l1(2)+4):(l1(3)+3)));
  b7=str2num(line3((l1(3)+4):(l1(4)+3)));
  
  R=8.3145; %gas constant

 t=linspace(local_T1,local_T2,500);

  for j=1:500
    
if t>local_T3
    
    cp=(a1+a2.*t+(a3.*t.^2)+(a4.*t.^3)+(a5.*t.^4)).*R;
    h=(a1+(a2.*t./2)+(a3.*(t.^2)./3)+(a4.*(t.^3)./4)+(a5.*(t.^4)./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;
else 
% IF low Temp
    cp=(b1+b2.*t+(b3.*t.^2)+(b4.*t.^3)+(b5.*t.^4)).*R;
    h=(b1+(b2.*t./2)+(b3.*(t.^2)./3)+(b4.*(t.^3)./4)+(b5.*(t.^4)./5)+(b6./t)).*R.*t;
    s=(b1*log(t)+b2.*t+(b3.*(t.^2)./2)+(b4.*(t.^3)./3)+(b5.*(t.^4)./4)+b7).*R;
  end
  
end
M=molecular_mass(element)
fprintf('molecular weight of:')
disp(element_n)
fprintf('is')
disp(M)

figure(1)
plot(t,cp,'linewidth',4,'color','r');
title(element_n)
xlabel('temperature in k')
ylabel('specific heat in kj')

figure (2)
plot(t,h,'linewidth',4,'color','b');
title(element_n)
xlabel('temperature in k')
ylabel('enthalpy in kj/(mol)')

figure(3)
plot(t,s,'linewidth',4,'color','g');
title(element_n)
xlabel('temperature in k')
ylabel('entropy in kj/(mol k)')

%creating directory
mkdir('D:\result\',element_n)
directory=(['D:\result\',element_n]);

cd(directory);

%saving plots
saveas(1,'specific heat.jpg');
saveas(2,'Enthalpy.jpg');
saveas(3,'entropy.jpg');

directory2=(['D:\'])
cd(directory2);



  end


fclose(f1)

2.function code to calculate teh molecular mass:

function M = molecular_mass(element)
element = 'O2'
name=['H','C','N','O','AR'];
atomic_weight=[1,12,14,16,40];
 M=0;
for i=1:length(element)
   for j=1:length(atomic_weight)
        if (strcmp(element(i),name(j))==1)
        
            
         M=M+atomic_weight(j);
         g=j;
        
        end

   end
  if  isempty(str2num(element(i))) == 0
      M=M+(str2num(element(i))-1)*atomic_weight(g);
  end

  
end
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.