Challenge

Parsing NASA thermodynamic data

AIM:

Make function that extracts the 14 coefficients and calculates the enthalpy, entropy and specific heats for all the species in the data file

GOVERNING EQUATIONS :

OBJECTIVES OF THE PROJECT:

  • Write a function that extracts the 14 coefficients and calculates the enthalpy, entropy, and specific heats for all the species in the data file. By reading this file NASA thermodynamic data.
  • Calculate the molecular weight of each species and display it in the command window.
  • Plot the Cp, Enthalpy, and Entropy for the local temperature range (low temperature: high temperature) specific for each species.
  • Save the plots as images with appropriate names and dump them in separate folders for each species with a suitable name. All of these should be generated automatically.

Explanation of coding logic:

  • Initially opening the given thermodynamic data file and read the data.
  • reading the header file of thermodynamic data and calculate the global low, mid, and high temperatures.
  • Then calculating the 14 coefficients for all the species.
  • By using the while loop, calculating the 14 coefficients for all the species.
  • By using strfind() command, finding out the number of exponentials.
  • Once we have fond out, then converting the coefficient from string form to number form by using str2num() command.
  • By doing the above steps for lines two and three, we are calculating the 14 coefficients for all the species.
  • Once we have find out the coefficients for a species, then calculating the entropy, enthalpy, and specific heat.
  • Assuming universal gas constant R=8.314 J/mol-k and assuming temperature range from 100 to 5000 takeing 100 values by linspace() command.
  • Once you calculated the entropy, enthalpy, and specific heat for all the species, ploting the graph between Temperature vs Entropy, Temperature vs Enthalpy, and Temperature vs Specific heat.
  • Finally calculating the molecular weight for all the species and displaying it in the command window.

MATLAB Code:

clc 
clear all 
close all

%exploring THERMO.dat

file=fopen('THERMO.dat','r');
f2=fgetl(file);
f2=fgetl(file);
a=split(f2,'  ');
gtmax=str2num(a{4});
gtmid=str2num(a{3});
gtmin=str2num(a{2});
f2=fgetl(file);
f2=fgetl(file);
f2=fgetl(file);
s=0;
while(s==0)
    format long 
    f2=fgetl(file);
    species=strtrim(f2(1:10))
    f2=strtrim(fgetl(file));
    a=strfind(f2,'.');
    b=strfind(f2,'E');
%calculating co-efficients.
    c1=str2double(f2((a(1)-1):(b(1)+3)));
    c2=str2double(f2((a(2)-1):(b(2)+3)));
    c3=str2double(f2((a(3)-1):(b(3)+3)));
    c4=str2double(f2((a(4)-1):(b(4)+3))) ;   
    c5=str2double(f2((a(5)-1):(b(5)+3)));
    
    f2=strtrim(fgetl(file));
    a=strfind(f2,'.');
    b=strfind(f2,'E');
    c6=str2double(f2((a(1)-1):(b(1)+3)));
    c7=str2double(f2((a(2)-1):(b(2)+3)));
    c8=str2double(f2((a(3)-1):(b(3)+3)));
    c9=str2double(f2((a(4)-1):(b(4)+3))) ;   
    c10=str2double(f2((a(5)-1):(b(5)+3)));
    
    f2=strtrim(fgetl(file));
    a=strfind(f2,'.');
    b=strfind(f2,'E');
    c11=str2double(f2((a(1)-1):(b(1)+3)));
    c12=str2double(f2((a(2)-1):(b(2)+3)));
    c13=str2double(f2((a(3)-1):(b(3)+3)));
    c14=str2double(f2((a(4)-1):(b(4)+3))) ;   
    
    
%Temperature ranges assumed for calculation purpose
Temperature = linspace(gtmin,gtmax,100); 

%Universal gas constant
R =8.314;                            

%calculation of properties based on the lower and upper temperature
for j = 1:length(Temperature)
    if Temperature(j)1
        MM = MM + Atomic_weight(u)*(n-1);
    end
end
disp(MM)


%plotting

%Temperature vs Entropy
figure(1)
plot(Temperature,S,'linewidth',4,'color','b')
title(species)
xlabel('Temperature')
ylabel('Entropy')
str=['Mol Wt:' num2str(MM)];
text(3500,1000,str)

%Temperature vs Enthalpy
figure(2)
plot(Temperature,H,'linewidth',4,'color','k')
title(species)
xlabel('Temperature')
ylabel('Enthalpy')
str=['Mol Wt:' num2str(MM)];

%Temperature vs Specific heat
figure(3)
plot(Temperature,Cp,'linewidth',4,'color','g')
title(species)
xlabel('Temperature')
ylabel('Specific heat')
str=['Mol Wt:' num2str(MM)];
s1=[species '  -  1.jpg'];
s2=[species '  -  2.jpg'];
s3=[species '  -  3.jpg'];

%creating folder for each species
mkdir(['C:\Users\ASUS\Desktop\matlab\data parse\',species]);
cd(['C:\Users\ASUS\Desktop\matlab\data parse\',species])
saveas(1,s1);
saveas(2,s2);
saveas(3,s3);
close all


    if(strfind(f2,'END'))
        s=1
    end
    
end




Results:

  • Figures being saved in Directories.
  • Command window showing Molecular weight:

Plots :

Errors & remedies:

  • array limits were provided wrong,solved by giving values again.
  • typing mistakes were also observed.
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.