All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim :- Write a program for file parsing of NASA thermodynamics data using matlab. Objective :- Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file. Equations of Specific heat, Enthalpy(H) and Entropy(S)…
SIDDHESH PARAB
updated on 26 Aug 2021
Aim :- Write a program for file parsing of NASA thermodynamics data using matlab.
Objective :-
Equations of Specific heat, Enthalpy(H) and Entropy(S) are as under;
In this, The first 7 coefficients are HIGH-temperature coefficients and the second 7 coefficients are LOW-temperature coefficients. Also use the Local Temperature Ranges which is unique for each individual species, not the Global Temperature Range.
THEORY:-
FILE PARSING :-
Here in this project, we are going to split the NASA thermodynamic data which is having 53 gas species values. To perform the calculation for thermodynamic properties, we need some co-efficient values and temperature ranges which is available in the NASA file. So, we are going to parse the values which are all needed for our calculation from that particular file.
ENTHALPY :-
where p is pressure, and V is the volume of the system.
ENTROPY :-
ΔS=(Q/T)rev
where Q is the heat transfer, which is positive for heat transfer into and negative for heat transfer out of, and T is the absolute temperature at which the reversible process takes place.
SPECIFIC HEAT:-
UNIVERSAL GAS CONSTANT (R) :-
MOLECULAR WEIGHT :-
Code for function Specific Heat (Cp) :-
function [Cp]= specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,temp,temperature_range,R)
%a1 a2 a3 a4 a5 are high temperature coefficients
%a8 a9 a10 a11 a12 are low temperature coefficients
for i= 1:length(temperature_range)
if temperature_range(i)<=temp(2)
Cp(i)= R.*(a8 + (a9* temperature_range(i)) + (a10*(temperature_range(i).^2)) + (a11*(temperature_range(i).^3)) + (a12*(temperature_range(i).^4)));
else
Cp(i)= R.*(a1 + (a2*temperature_range(i)) + (a3*(temperature_range(i).^2)) + (a4*(temperature_range(i).^3)) + (a5*(temperature_range(i).^4)));
end
end
Explanation of function specific heat code :-
Code for function Enthalpy (H):-
function [H]= enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,temperature_range,R)
%a1 a2 a3 a4 a5 a6 are high temperature coefficients
%a8 a9 a10 a11 a12 a13 are low temperature coefficients
for i= 1:length(temperature_range)
if temperature_range(i)<=temp(2)
H(i)= R.*((a8.*temperature_range(i)) + (a9.*((temperature_range(i).^2)/2)) + (a10.*((temperature_range(i).^3)/3)) + (a11.*((temperature_range(i).^4)/4)) + (a12.*((temperature_range(i).^5)/5)) + a13);
else
H(i)= R.*((a1.*temperature_range(i)) + (a2.*((temperature_range(i).^2)/2)) + (a3.*((temperature_range(i).^3)/3)) + (a4.*((temperature_range(i).^4)/4)) + (a5.*((temperature_range(i).^5)/5)) + a6);
end
end
Explanation of function Enthalpy(H) code :-
Code for function Entropy (S) :-
function [S]= entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,temperature_range,R)
%a1 a2 a3 a4 a5 a7 are high temperature coefficients
%a8 a9 a10 a11 a12 a14 are low temperature coefficients
for i= 1:length(temperature_range)
if temperature_range(i)<=temp(2)
S(i)= R.*((a8.*log(temperature_range(i))) + (a9.*temperature_range(i)) + (a10.*((temperature_range(i).^2)/2)) + (a11.*((temperature_range(i).^3)/3)) + (a12.*((temperature_range(i).^4)/4)) + a14);
else
S(i)= R.*((a1.*log(temperature_range(i))) + (a2.*temperature_range(i)) + (a3.*((temperature_range(i).^2)/2)) + (a4*((temperature_range(i).^3)/3)) + (a5.*((temperature_range(i).^4)/4)) + a7);
end
end
Explanation of function Entropy (S) code :-
Code for function Molecular Weight:-
function[weight]= molecular_weight(name_of_species)
atomic_name= {'O','H','C','N','Ar'};
atomic_weight= [15.999 1.008 12.011 14.007 39.948]; % Atomic weight
% Molecular weight starting range
weight=0;
for i= 1:length(name_of_species)
for j= 1:length(atomic_name)
if strcmp(name_of_species(i),atomic_name(j))
weight= weight + atomic_weight(j);
x= j;
end
end
% Now we will find if there is more element in the species then incrementing
% atomic weight of the species
y= str2num(name_of_species(i));
if y>1
weight= weight + atomic_weight(x)*(y-1);
end
end
end
Explanation of function Molecular weight code :-
MAIN CODE :-
% Write a program for file parsing of NASA thermodynamics data
clear all;
close all;
clc;
f1 = fopen('THERMO.dat','r');
line1 =fgetl(f1); % For skipping first line
line2 =fgetl(f1);
% Since the values of global temperature values stored in single string,
% hence we have used string split command
global_temp_values =strsplit(line2,' ');
% For converting the values of string into numbers, we used str2num command
global_low_temperature = str2num(global_temp_values{2});
global_mid_temperature = str2num(global_temp_values{3});
global_high_temperature = str2num(global_temp_values{4});
% Defining the input value of universal gas constant in KJ/mol-K
R=8.314;
% Since line 3rd to line 5th contains comment hence we have skipped
line3 =fgetl(f1); % For skipping third line
line4 =fgetl(f1); % For skipping fourth line
line5 =fgetl(f1); % For skipping fifth line
for i=1:53
complete_string_of_species=fgetl(f1); % Reading sixth line
% Extracting the name of species
% Splitting of all values in a string into cell array
cellarray_of_entire_species=strsplit(complete_string_of_species,' ');
name_of_species=(cellarray_of_entire_species{1}); % To read the name of species
% Extracting local temperature values
local_low_temp=str2num(cellarray_of_entire_species{end-3});
local_mid_temp=str2num(cellarray_of_entire_species{end-1});
local_high_temp=str2num(cellarray_of_entire_species{end-2});
% Storing local temperature in a variable
temp = [local_low_temp local_mid_temp local_high_temp];
% Defining local temperature range
temperature_range=linspace(local_low_temp,local_high_temp,1000);
% Reading the 2nd line of species block
second_line_of_species_block=fgetl(f1);
a=findstr(second_line_of_species_block,'E'); %Finding string 'E'
% Extracting the higher and lower temperature coefficients
% Extracting higher temperature coefficients
a1=second_line_of_species_block(1:a(1)+3);
a1=str2num(a1);
a2=second_line_of_species_block(a(1)+4:a(2)+3);
a2=str2num(a2);
a3=second_line_of_species_block(a(2)+4:a(3)+3);
a3=str2num(a3);
a4=second_line_of_species_block(a(3)+4:a(4)+3);
a4=str2num(a4);
a5=second_line_of_species_block(a(4)+4:a(5)+3);
a5=str2num(a5);
% Reading third line of species block
third_line_of_species_block=fgetl(f1);
b=findstr(third_line_of_species_block,'E'); %Finding string 'E'
a6=third_line_of_species_block(1:b(1)+3);
a6=str2num(a6);
a7=third_line_of_species_block(b(1)+4:b(2)+3);
a7=str2num(a7);
% Finding lower temperature coefficients
a8=third_line_of_species_block(b(2)+4:b(3)+3);
a8=str2num(a8);
a9=third_line_of_species_block(b(3)+4:b(4)+3);
a9=str2num(a9);
a10=third_line_of_species_block(b(4)+4:b(5)+3);
a10=str2num(a10);
%Reading fourth line of species block
fourth_line_of_species_block=fgetl(f1);
c=findstr(fourth_line_of_species_block,'E');
a11=fourth_line_of_species_block(1:c(1)+3);
a11=str2num(a11);
a12=fourth_line_of_species_block(c(1)+4:c(2)+3);
a12=str2num(a12);
a13=fourth_line_of_species_block(c(2)+4:c(3)+3);
a13=str2num(a13);
a14=fourth_line_of_species_block(c(3)+4:c(4)+3);
a14=str2num(a14);
% Calculation of Specific Heat
Cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,temp,temperature_range,R);
% Calculation of Enthalpy
H = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,temperature_range,R);
% Calculation of Entropy
S = entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,temperature_range,R);
% Calculation of Molecular Weight
weight = molecular_weight(name_of_species);
% Saving molecular weight of each species in a file
molecular_weight_file = fopen('Molecular Weight.txt','a+');
fprintf(molecular_weight_file,'Molecular weight of %s is %f ',name_of_species,weight);
fclose(molecular_weight_file); % Closing the file
% Plots of Specific heat, Enthalpy and Entropy with temperature
% Making a new folder for each species
cd('C:/Users/parab/OneDrive/Documents/MATLAB/Species'); % Changing directory
mkdir(name_of_species);
cd(name_of_species);
% Plot1 - Specific Heat vs Temperature range
figure(1);
plot(temperature_range,Cp,'linewidth',3,'color','r');
xlabel('Temperature [K]');
ylabel('Specific Heat [KJ/Kg-K]');
title(sprintf('Specific Heat vs Temperature range of %s',['Species name = ',name_of_species,' & Molecular weight = ',num2str(weight)]));
grid on;
saveas(figure(1),'Specific Heat.jpg');
% Plot2 - Enthalpy vs Temperature range
figure(2);
plot(temperature_range,H,'linewidth',3,'color','k');
xlabel('Temperature [K]');
ylabel('Enthalpy [KJ]');
title(sprintf('Enthalpy vs Temperature range of %s',['Species name = ',name_of_species,' & Molecular weight = ',num2str(weight)]));
grid on;
saveas(figure(2),'Enthalpy.jpg');
% Plot3 - Entropy vs Temperature range
figure(3);
plot(temperature_range,S,'linewidth',3,'color','m');
xlabel('Temperature [K]');
ylabel('Entropy [KJ/K]');
title(sprintf('Entropy vs Temperature range of %s',['Species name = ',name_of_species,' & Molecular weight = ',num2str(weight)]));
grid on;
saveas(figure(3),'Entropy.jpg');
cd('C:/Users/parab/OneDrive/Documents/MATLAB'); %Changing directory to original path
% printing the Molecular Weight of species
sprintf('molecular weight of %s is %f',name_of_species,weight)
end
Explanation of main code:-
Error Faced during the challege :-
The below error has been corrected by deletion of one extra bracket. After deletion of extra bracket, program executed properly.
Output of Molecular Weight of all the species shown on the command window is as under;
Screenshot of folder containing all plots of species as under;
Screenshot of Enthalpy, Entropy and Specific heat plots of O2 saved in folder species:-
Output Plot of O2, N2 and CO2:-
1. O2
i) Entropy vs Temperature Plot
ii) Enthalpy vs Temperature Plot
iii) Specific Heat vs Temperature Plot
2) N2 :-
i) Entropy vs Temperature Plot
ii) Enthalpy vs Temperature Plot
iii) Specific Heat vs Temperature Plot
3) CO2
i) Entropy vs Temperature Plot
ii) Enthalpy vs Temperature Plot
iii) Specific Heat vs Temperature Plot
Drive folder link of all plots of 53 nos. of species :-
https://drive.google.com/drive/folders/1hbB0yaEsrDc4DL4YXILaGxwDdrxwGvC4?usp=sharing
Drive link of molecular weight of all species:-
https://drive.google.com/file/d/15BeLypbdgHHT1Fd9U2M7U9ovvi2UChLG/view?usp=sharing
Conclusion :-
1. Therefore, we have successfully parsed the given NASA thermodynamic data file and plotted the graphs of specific heat, enthalpy and entropy for the respective inputted species name.
2. Parsing is a very important part of many computer science disciplines. For example, compilers must parse source code to be able to translate it into object code. Likewise, any application that processes complex commands must be able to parse the commands. This includes virtually all end-user applications.
Reference :-
1. https://en.wikipedia.org/wiki/Parsing.
2. https://in.mathworks.com/matlabcentral/answers
3. https://www.mathworks.com/help/matlab/ref/cd.html
4. Textbook of Engineering Thermodynamics by P K Nag
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 2-Highway Assistant-Lane Changing Assistant
Aim :- Model Based Development of Highway Assistant – Lane Changing Assistant Objective :- To develop one specific requirement of Highway Assistant – Lane Changing Assistant algorithm. Please note that the whole Highway Assistant – Lane Changing Assistant is a very huge algorithm & only one small…
14 Feb 2022 04:19 PM IST
Project 1- Traffic Jam Assistant Feature
Aim :- Traffic Jam Assistant Feature Objective :- This model must be developed in MATLAB Simulink as per MBD guidelines according to the requirements given. Tag the requirements to the Simulink model, Requirements 1 & Requirement 2 are tagged into their corresponding subsystems. Creation of Simulink Data Dictionary…
05 Feb 2022 06:55 PM IST
Design of an Electric Vehicle
AIM:- Create a MATLAB model of an electric car that uses a battery and a DC motor. Choose suitable blocks from the Powertrain block set. Prepare a report about your model including the following: ABSTRACT:- In this project, we going to build the MATLAB model of ELECTRIC CAR by using a DC motor and a suitable battery for…
01 Feb 2022 06:47 AM IST
Project 2 Adaptive Cruise Control
Aim :- Develop a MATLAB Simulink Model for Adaptive Cruise Control feature used in Automotive Vehicle Objective:- To develop a Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink. While Developing the Adaptive Cruise Control Simulink Model, we have follow all the MBD related processes…
22 Jan 2022 08:13 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.