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 that extracts the 14 coefficients to perform the required operations for all the species in the given data file. OBJECTIVES: 1) To plot the specific heat (Cp), Enthalpy(H) and Entropy(S) for the specific local temperature range from low-temperature to high-temperature for each species. …
Jayesh Keche
updated on 22 Aug 2020
AIM: To write a code that extracts the 14 coefficients to perform the required operations for all the species in the given data file.
OBJECTIVES: 1) To plot the specific heat (Cp), Enthalpy(H) and Entropy(S) for the specific local temperature range from low-temperature to high-temperature for each species.
2) To save the plots as images with appropriate names and put them in separate folders for each species with a suitable name which will generate automatically.
3) To calculate the molecular weight of each species and to display it in the command window.
GOVERNING EQUATIONS:
The following equations will be used to calculate the values for Cp, H, and S.
Where,
R is the universal gas constant &
T is the temperature
The FIRST 7 coefficients from (a1 to a7) are HIGH-temperature coefficients and the SECOND 7 coefficients from (a8 to a14) are LOW-temperature coefficients. The above equations will be the same for low-temperature coefficients. Just replace the a1 to a7 coefficient with the a8 to a14.
THEORY:
To parse data or information means to break it down into component parts so that its syntax can be analyzed, categorized, and understood to perform the required operations. In this topic , coefficients of the different species will be read to calculate values of specific heat, enthalpy, and entropy with its molecular weight.
Here we are reading all the data from the ' THERMO.dat ' file which is NASA Thermodynamic Data.
CODE:
Programming language: MATLAB
clear all
close all
clc
DATA = fopen('THERMO.dat','r');
fgetl(DATA);
temperature_line = fgetl(DATA);
temp_split = strsplit(temperature_line,' ');
Global_low_temp = str2double(temp_split{2});
Global_med_temp = str2double(temp_split{3});
Global_high_temp = str2double(temp_split{4});
% Skipping the 3 lines
for s = 2:4
tline = fgetl(DATA);
end
for g = 1:53
first_ele_line = fgetl(DATA);
a = strsplit(first_ele_line,' ');
l = length(a); % length of string
element_name = (a{1});
loc_lo_temp = str2double(a{l-3});
loc_hi_temp = str2double(a{l-2});
loc_med_temp = str2double(a{l-1});
t1 = loc_lo_temp;
t2 = loc_hi_temp;
t3 = loc_med_temp;
first_line = fgetl(DATA); % 1st line of coefficient for O
% For first line
location_E = strfind(first_line,'E'); % Locating the E in co efficient of 1st line
E1 = location_E;
E1(1); % Individual positiion number
% Getting whole value of co efficient
a1 = first_line(1:E1(1)+3);
a1 = str2double(a1);
a2 = first_line(E1(1)+4:E1(2)+3);
a2 = str2double(a2);
a3 = first_line(E1(2)+4:E1(3)+3);
a3 = str2double(a3);
a4 = first_line(E1(3)+4:E1(4)+3);
a4 = str2double(a4);
a5 = first_line(E1(4)+4:E1(5)+3);
a5 = str2double(a5);
% For second line
second_line = fgetl(DATA); % 2nd line of coefficient for O
location_E2 = strfind(second_line,'E'); % Locating the E in co efficient of 1st line
E2 = location_E2;
E2(1); % Individual positiion number
% Getting whole value of co efficient
a6 = second_line(1:E2(1)+3);
a6 = str2double(a6);
a7 = second_line(E2(1)+4:E2(2)+3);
a7 = str2double(a7);
a8 = second_line(E2(2)+4:E2(3)+3);
a8 = str2double(a8);
a9 = second_line(E2(3)+4:E2(4)+3);
a9 = str2double(a9);
a10 = second_line(E2(4)+4:E2(5)+3);
a10 = str2double(a10);
% For third line
third_line = fgetl(DATA); % 3rd line of coefficient for O
location_E3 = findstr(third_line,'E'); % Locating the E in co efficient of 1st line
E3 = location_E3;
E3(1); % Individual positiion number
% Getting whole value of co efficient
a11 = third_line(1:E2(1)+3);
a11 = str2double(a11);
a12 = third_line(E2(1)+4:E2(2)+3);
a12 = str2double(a12);
a13 = third_line(E2(2)+4:E2(3)+3);
a13 = str2double(a13);
a14 = third_line(E2(3)+4:E2(4)+3);
a14 = str2double(a14);
% Enthalpy
T = linspace(t1,t2,1000);
R = 8.314 ;
for m = 1:length(T)
if T(m) > t3
Cp(m) = (a1 + a2*T(m) + a3*T(m)^2 + a4*T(m)^3 + a5*T(m)^4)*R;
H(m) = (a1 + a2*T(m)/2 + a3*T(m)^2/3 + a4*T(m)^3/4 + a5*T(m)^4/5 + a6/T(m))*R*T(m);
S(m) = (a1*log(T(m)) + a2*T(m) + a3*T(m)^2/2 + a4*T(m)^3/3 + a5*T(m)^4/4 + a7)*R;
else
Cp(m) = (a8 + a9*T(m) + a10*T(m)^2 + a11*T(m)^3 + a12*T(m)^4)*R;
H(m) = (a8 + a9*T(m)/2 + a10*T(m)^2/3 + a11*T(m)^3/4 + a12*T(m)^4/5 + a13/T(m))*R*T(m);
S(m) = (a8*log(T(m)) + a9*T(m) + a10*T(m)^2/2 + a11*T(m)^3/3 + a12*T(m)^4/4 + a14)*R;
end
end
% Creating
mkdir('I:\JACK\SKILL-Lync\Matlab for Mechanical\',element_name)
cd(['I:\JACK\SKILL-Lync\Matlab for Mechanical\',element_name])
% plotting
figure(1)
plot(T,Cp,'linewidth',2)
xlabel('Temperature');
ylabel('Specific Heat (Cp)');
title(element_name)
saveas(1,'Cpval.jpg')
figure(2)
plot(T,H,'linewidth',2)
xlabel('Temperature');
ylabel('Enthalpy (H)');
title(element_name)
saveas(2,'Hval.jpg')
figure(3)
plot(T,S,'linewidth',2)
xlabel('Temperature');
ylabel('Entropy (S)');
title(element_name)
saveas(3,'Sval.jpg')
% Finding molecular weight
element = ['H','O','C','N','A','S'];
atomic_weight = [1 16 12 14 40 32];
Mo_wt = 0;
for i = 1:length(element_name);
for j = 1:length(element);
if strcmp(element_name(i),element(j));
Mo_wt = Mo_wt + atomic_weight(j);
position = j;
end
end
n = str2double(element_name(i));
if n >1
Mo_wt = Mo_wt + atomic_weight(position);
end
end
sprintf('Molecular weight of %s is %f u',element_name,Mo_wt)
end
fclose(DATA);
CODE EXPLANATION:
1) fopen command is used to open and read the dat file which is stored in DATA
2) fgetl command is used to extract the 1st line of DATA as it contains global temp .The data we get here in terms of combine string ,so we use strsplit command to split the long sring in the string for individual purpose. Now str2double command is used to get integer value from string. This command will give digit converting character property. (Now from here onwards fgetl, strsplit, str2double commands will be used for respe purpose in the code.)
3) for loop is use to skip further 3 comment lines.
4) Now for loop is stated for number of iteration from 1 to 53 as there are 53 elements in THERMO,dat file ,which will end after all the executions are done with respective data for every element.
5) After the start of the above for loop :-1st line for each element is called using fgetl command and splitted them with separate string using strsplit command .Length of whole string is defined which will help to locate local temperature values automatically with use of str2double
6) Again fgetl command is used to to get 1st line of coefficient for respective elements and located the position of E. The purpose of locating the position of E is that with the help of defined position of E, all the coefficient can be extracted using simple formulation. So in the first line of coefficient all 5 coefficient will be called. Now same concept will be use for second coefficient line to extract 5 values an for 3rd line to extract remaining 4 values. In this way all 14 Coefficients will be extracted for each specie.
7) Now to calculate Cp, H & S , all formulas are specified in the separate for loop , in which if-else command is used according to situation mention in the problem about the local temperature. If T(m)>t3 (local medium temperature) them ‘if’ condition will execute or condition is not satisfy then ‘else’ command will execute automatically in loop for each temperature value for every element.
8) Now ‘mkdir’ command is used to create the folder in the current directory.Next to that cd command is used to change current folder to new folder to store the plots of graph of every element in separate folder. There will separate folder for every
9) To find the molecular weight of the elements for loop is executed in which strcmp command is used to compare the logic of strings mention in the i and j. If value is match then it returns the values of atomic weight of that particular element will be added. Sprintf command is used to display the molecular weight of each element and fclose command is used to close the file.
OUTPUTS:
1) Screenshot of Location where folders are saved:-
2) Plots of Cp,H, and S for O2:-
3) Plots of Cp,H, and S for N2
4) Plots of Cp,H, and S for CO2:-
5) Display of 'Molecular Weights' of elements in the 'Command Window':-
CONCLUSION:
Here the data is read and extracted successfully from NASA Thermodynamic Data file for different species and all the values of Cp, H, and S are calculated along with plots which are stored in a separate respective folder for each element. From this, we can conclude that the file can parse in MATLAB to perform the various required operations using the data contained in the files.
REFERENCES:
https://in.mathworks.com/help/matlab/ref/strcmp.html
https://in.mathworks.com/help/matlab/ref/mkdir.html#d120e796763
https://in.mathworks.com/help/matlab/ref/saveas.html#d120e1105108
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...
Roof challenge
Design of Roof Objectives- 1. For the Given Roof styling, Develop the essential flanges and reinforcements, provide appropriate dimensions and check forDraft analysis and also submit your section modulus report on the 0-Y section.2. Start with the creation of a roof ditch area the tool opening angle is only 3 degrees.3.…
30 Jul 2021 04:51 PM IST
Section Modulus calculation and optimization
AIM: Section modulus calculation and optimization OBJECTIVE: Use section of the Hood and calculate the section modulus.Vary the section in such a way that new section is an improved version of previous section. THEORY:Section modulus is to find the geometric property for a given cross-section used in the design.Calculate…
30 Jul 2021 04:51 PM IST
Fender Design Challenge
FENDER: The fender is the car body part that frames the wheel. Its purpose is to prevent sand, dirt, rocks, and other roads spray from beinthrown into the air by the rotating tire and close the engine component. When a vehicle is moving, tires pick up stones and otherand hurl them in all directions. Fenders are basically…
30 Jul 2021 04:51 PM IST
Hood design-Week 2
DESIGNING OF HOOD ASSEMBLY Objective To understand and study the design methodology and mechanisms that goes under designing and developing an AutomotivHood to achieve maximum safety for everyone in and around vehicle. HOOD DESIGN- CHALLANGE Introduction:- Hood is main component of a car at the front portion. It is used…
30 Jul 2021 04:50 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.