All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim: To write a code to parse the thermodynamic data file provided and then calculate the thermodynamic properties of various gas species Objective: 1)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. 2. Calculate the…
Asad Ali Baig Mirza
updated on 01 Apr 2022
Aim: To write a code to parse the thermodynamic data file provided and then calculate the thermodynamic properties of various gas species
Objective:
1)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.
2. Calculate the molecular weight of each species.
3. Plot the Cp, Enthalpy and Entropy for the local temperature range
4. Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name.
Theory:
File parsing is a string or symbol either in a natural language,computer language conferning to the rules of former grammer
Mathematical equations:
For specific heat
For enthalpy
For entropy
Where
T=Local temperature
b1-b7 =High temperature coefficient
b8-b14=low temperature coefficient
R=Gas constant =8.314
Program:
The Program for File parsing is as follows
%NASA thermodynamic data file parsing
clear all
close all
clc
%universal gas constant
R=8.314;
%reader header information
f1=fopen('THERMO.dat','r');
tline1=fgetl(f1);
tline2=fgetl(f1);
temp=strsplit(tline2,' ');
global_low_temp=str2num(temp{2});
global_mid_temp=str2num(temp{3});
global_high_temp=str2num(temp{4});
%skipping next three lines
for i=3
skippedlines=fgetl(f1);
end
for i=1:53
tline3=fgetl(f1)
S=strsplit(tline3,' ');
species_name=S{1};
A=strfind(tline3,'G');
temp_values=tline3(A+4:length(tline3));
B=strsplit(temp_values,' ');
local_low_temp=str2double(B{1});
local_mid_temp=str2double(B{3});
local_high_temp=str2double(B{2});
tline4=fgetl(f1);
f=strfind(tline4,'E');
a1=str2double(tline4(1:(f(1)+3)));
a2=str2double(tline4(f(1)+4:f(2)+3));
a2=str2double(tline4(f(2)+4:f(3)+3));
a2=str2double(tline4(f(3)+4:f(4)+3));
a2=str2double(tline4(f(4)+4:f(5)+3));
tline5=fgetl(f1);
a6=str2double(tline5(1:(f(1)+3)));
a7=str2double(tline5(f(1)+4:f(2)+3));
a8=str2double(tline5(f(2)+4:f(3)+3));
a9=str2double(tline5(f(3)+4:f(4)+3));
a10=str2double(tline5(f(4)+4:f(5)+3));
tline6=fgetl(f1);
a11=str2double(tline6(1:(f(1)+3)));
a12=str2double(tline6(f(1)+4:f(2)+3));
a13=str2double(tline6(f(2)+4:f(3)+3));
a14=str2double(tline6(f(3)+4:f(4)+3));
t=linspace(local_low_temp,local_high_temp,100)
%to calculate specific heat using function
C_p=R*specific_heat_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
s=R*entropy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
h=R*enthalpy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
%Creating a folder
mkdir(['G:',species_name])
cd(species_name)
%Plotting for
%temperature vs specific heat
figure(1)
plot(t,c_p)
xlabel('temperature')
ylabel('specific heat')
title('temperature vs specific heat')
image=getframe(gcf);
imwrite(image.cdata,'t vs cp.png')
saveas(1,'specific heat','jpg')
%temperature vs enthalpy
figure(2)
plot(t,H)
xlabel('temperature')
ylabel('enthalpy')
title('temperature vs enthalpy')
image=getframe(gcf);
imwrite(image.cdata,'t vs H.png')
saveas(2,'enthalpy','jpg')
%temperature vs entropy
figure(3)
plot(t,S)
xlabel('temperature')
ylabel('entropy')
title('temperature vs entropy')
image=getframe(gcf);
imwrite(image.cdata,'t vs S.png')
saveas(2,'entropy','jpg')
cd..
%calculating molecular mass
[M]=molecular_wt(species_name);
K=sprintf('%s mol_wt=%f',species_name,M);
disp(K)
end
specific heat function code
Function[C_p]=specific_heat_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
if (T>local_mid_temp)
C_p=(a1+(a2*t)+(a3*(t.^2))+(a4*(t.^3))+(a5*(t.^4)));
else
C_p=(a8+(a9*t)+(a10*(t.^2))+(a11*(t.^3))+(a12*(t.^4)))
end
Enthalpy function code
Function[H]=enthalpy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
if (T>local_mid_temp)
H=(a1*t+(a2*(t.^2)/2)+(a3*(t.^3)/3)+(a4*(t.^4)/4)+(a5*(t.^5)/5)+a6);
else
H=(a8*t+(a9*(t.^2)/2)+(a10*(t.^3)/3)+(a11*(t.^4)/4)+(a12*(t.^5)/5)+a13);
end
Entropy Function code
Function[S]=entropy_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,T,R);
if (T>local_mid_temp)
S=(a1*log(t)+(a2*t)+(a3*(t.^2)/2)+(a4*(t.^3)/3)+(a5*(t.^4)/4)+a7);
else
S=(a8*log(t)+(a9*t)+(a10*(t.^2)/2)+(a11*(t.^3)/3)+(a12*(t.^4)/4)+a14);
end
Plots:
Plots we got from element O2
Plots we got from element N2
plots we got from CO2 Element
Molecular weight of O2=31.9980
Molecular weight of N2=28.0140
Molecular weight of CO2=44.0090
Folders:
Issues faced during the challenge:
during the challenge i faced issue in understanding in the concept and i had a one on one session with support engineer and i am very clear with the concept
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...
Radar Mast & Final Assembly of Yacht
Radar mast: Front view Side view Top view Expanded feature tree of Radarmast …
08 Mar 2023 06:59 PM IST
Week - 4
Implement control logic of a “washing machine” using Stateflow as per given sequence: If the power supply is available, the system gets activated If the Water supply is not available, stop the process & indicate through LED Soaking time should be 200s followed by Washing time of 100s. Then rinsing…
06 Apr 2022 07:06 PM IST
Week -2
Aim: 1)Make a Simulink model of Doorbell using solenoid block. 2)Use a thermistor to sense the temperature of a heater & turn on or turn off the fan. Solenoid: A solenoid is a type of electromagnet formed by a helical coil of wire whose length…
06 Apr 2022 04:28 PM IST
Project 1 - Parsing NASA thermodynamic data
Aim: To write a code to parse the thermodynamic data file provided and then calculate the thermodynamic properties of various gas species Objective: 1)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. 2. Calculate the…
01 Apr 2022 05:25 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.