All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective - To write a code in MATLAB to parse the NASA Thermodynamic file and to calculate the various thermodynamic properties(Cp,H,S) What to do & find - \"Parse\" is the break down the given set of data or sentence into its component parts and describe there syntactic roles. In this dataset we have stream…
Aditya Bhirdikar
updated on 08 Apr 2020
Objective - To write a code in MATLAB to parse the NASA Thermodynamic file and to calculate the various thermodynamic properties(Cp,H,S)
What to do & find - \"Parse\" is the break down the given set of data or sentence into its component parts and describe there syntactic roles.
In this dataset we have stream of various 53 species(molecule) with co-effecient properties varing from low temperature range to higher temperature range. We have to parse the data to plot the graph of various thermodynamic properties v/s temperature and to calculate the molecular mass of each species.
Steps Involved -
Formulae to calculate the Specific heat(Cp), Enthalpy(H), Entropy(S)
Syntax uses -
1. fgetl - to read the lines present in data sequentially.
2. fopen - to load the data which is given & to perform the read operation by \'r\'
3. strsplit - to split the given string data line to different each string type.
4. str2num - to convert the data of string to number .
5. strfind - to find the the character or symbol in string when defined.
6. linspace - to create set of defined partitions when specified the range.
7. mkdir - to create a new file directory.
8. cd - to change the path of directory from old to new file.
9. strcmp - to compare two strings .
10. fprintf - writes a new line of what command is to be printed.
11. fclose - used to close the current file
Detailed Program of file parsing is given below with explanation
% To parse the given NASA Thermodynamic file, to caluculate molecular mass
% & plot graph of temperature v/s thermodynamic properties
clear all
close all
clc
% reading the given file
f1 = fopen(\'THERMO.dat\',\'r\');
% reading the subsequent lines present in the file
l1 = fgetl(f1); % reading the header prt of file i.e line1
l2 = fgetl(f1); % reading the header prt of file i.e line2
temp = strsplit(l2,\' \'); % using strsplit to give spaces between the datas present in the line which are of
% string type
global_low_temp = str2double(temp{1}); % converting the temperature to number &
assigning it to global_low_temp
global_mid_temp = str2double(temp{2}); % converting the temperature to number &
assigning it to global_mid_temp
global_high_temp = str2double(temp{3}); % converting the temperature to number &
assigning it to global_low_temp
for l =3:5 % reading the next continous 3 line using for loop .ie.
line3,4,5
lines_skipped = fgetl(f1); % skipping the header files
end
% to read all the 53 species name and store it in \'species_name\'
for i= 1:53 % main for loop iteration for the 53 species in this loop all the commands are executed
l6 = fgetl(f1); % read the line by sequence this fgetl command is used
a = strsplit(l6,\' \'); % assigning the species name
species_name = a(1); % at this point \'O\' is considered as a(1) same for all other species
% to find the local temp for species name
b =strfind(l6,\'.\'); % to find the \'.\' operator in the
line
local_temp_range = l6(b(1)-3:b(1)+23); % taking the length of the the
temperature range
local_temperature = strsplit(local_temp_range,\' \') ; % splitting the temp range with \'\'
% to convert from cell array to number
local_low_temp = str2num(local_temperature{1}); %200 converting the data from string to
number
local_high_temp = str2num(local_temperature{2}); %3500 converting the data from string
to number
local_mid_temp = str2num(local_temperature{3}); %1000 converting the data from string
to number
% assigning the above temperatures as temp1,temp2, temp3
temp1 = local_low_temp; %200 assigning the values to the temp1
temp2 = local_mid_temp ; %1000 assigning the values to the temp2
temp3 = local_high_temp; %3500 assigning the values to the temp3
% to find the co-effs of O in line 7 and the same is considered for other species
% co-effs of high temperature
l7 = fgetl(f1);
c = strfind(l7,\'E\'); % reading line 7 to find position where \"E\" is present
cf1 = l7(1:c(1)+3); % selecting the range & taking it as c(1)
co_eff1_ht = str2num(cf1); % converting from string to num
a1 = co_eff1_ht; % assigning the value in a1
cf2 = l7(c(1)+4:c(2)+3); % selecting the range & taking it as c(1) & c(2)
co_eff2_ht = str2num(cf2); % converting from string to num
a2 = co_eff2_ht; % assigning the value in a2
cf3 = l7(c(2)+4:c(3)+3); % selecting the range & taking it as c(2) & c(3)
co_eff3_ht = str2num(cf3); % converting from string to num
a3 = co_eff3_ht; % assigning the value in a3
cf4 = l7(c(3)+4:c(4)+3); %selecting the range & taking it as c(3) & c(4)
co_eff4_ht = str2num(cf4); % converting from string to num
a4 = co_eff4_ht; % assigning the value in a4
cf5 = l7(c(4)+4:c(5)+3); %selecting the range & taking it as c(4) & c(5)
co_eff5_ht = str2num(cf5); % converting from string to num
a5 =co_eff5_ht; % assigning the value in a4
% to find the co-effs of O in line 8
l8 = fgetl(f1);
d = strfind(l8,\'E\'); %reading line 8 to find position where \"E\" is present
df1 = l8(1:d(1)+3); %selecting the range & taking it as d(1)
co_eff6_ht = str2num(df1);% converting from string to num
a6 = co_eff6_ht; % assigning the value in a6
df2 = l8(d(1)+4:d(2)+3); %selecting the range & taking it as d(1) & d(2)
co_eff7_ht = str2num(df2);% converting from string to num
a7 = co_eff7_ht; % assigning the value in a7
% co-effs of low tempearture
df3 = l8(d(2)+4:d(3)+3); %selecting the range & taking it as d(2) & d(3)
co_eff8_lt = str2num(df3);% converting from string to num
b1 = co_eff8_lt; % assigning the value in b1
df4 = l8(d(3)+4:d(4)+3); %selecting the range & taking it as d(3) & d(4)
co_eff9_lt = str2num(df4);% converting from string to num
b2 = co_eff9_lt; % assigning the value in b2
df5 = l8(d(4)+4:d(5)+3); %selecting the range & taking it as d(4) & d(5)
co_eff10_lt = str2num(df5);% converting from string to num
b3 = co_eff10_lt; % assigning the value in b2
% to find the co-effs of O in line 9
l9 = fgetl(f1);
e = strfind(l9,\'E\'); %reading line 9 to find position where \"E\" is present
ef1 = l9(1:e(1)+3); %selecting the range & taking it as e(1)
co_eff11_lt = str2num(ef1);% converting from string to num
b4 = co_eff11_lt; % assigning the value in b4
ef2 = l8(e(1)+4:e(2)+3); %selecting the range & taking it as e(1) & e(2)
co_eff12_lt = str2num(ef2);% converting from string to num
b5 = co_eff12_lt; % assigning the value in b5
ef3 = l8(e(2)+4:d(3)+3); %selecting the range & taking it as e(2) & e(3)
co_eff13_lt = str2num(ef3);% converting from string to num
b6 = co_eff13_lt; % assigning the value in b5
ef4 = l8(e(3)+4:e(4)+3); %selecting the range & taking it as e(3) & e(4)
co_eff14_lt = str2num(ef4);% converting from string to num
b7 = co_eff14_lt; % assigning the value in b5
% changing the species name to char & assigning it to molecule_name this done
% to create mkdir command to create the directory as it accepts the char data
molecule_name = char(species_name);
% calculating specific heat, enthalpy, entropy for co-effs for high temperature and
% low temperature
temp = linspace(temp1,temp3,100);% temp range from 200 - 3500
R =8.314; % universal gas constant
y = 1:length(temp); % range from 200 - 3500
for z = 1:length(y) % elemnts present in the range 200 -3500
if(temp(z)<=1000) % selecting the if condition taking mid_temp condition
% equations at low temperature
cp = R*(b1 + b2.*(temp) + b3.*(temp.^2) + b4.*(temp.^3) + b5.*(temp.^4));
H =(R.*temp).*(b1 + b2.*((temp)/2) + b3.*((temp.^2)/3) + b4.*((temp.^3)/4) + b5.*((temp.^4)/5) + (b6)./temp(z));
S = R*(b1.*(log(temp)) + b2.*(temp) + b3.*((temp.^2)/2) + b4.*((temp.^3)/3) + b5.*((temp.^4)/4) + b7);
else
% equations for high temperature
cp = R*(a1 + a2.*(temp) + a3.*(temp.^2) + a4.*(temp.^3) + a5.*(temp.^4));
H =(R.*temp).*(a1 + a2.*((temp)/2) + a3.*((temp.^2)/3) + a4.*((temp.^3)/4) + a5.*((temp.^4)/5) + (a6)./temp(z));
S = R*(a1.*(log(temp)) + a2.*(temp) + a3.*((temp.^2)/2) + a4.*((temp.^3)/3) + a5.*((temp.^4)/4) + a7);
end
end
figure(1) % storing in figure 1 the output
plot(temp,cp,\'linewidth\',3,\'color\',\'r\') % plotting temp v/s specific heat
xlabel(\'temperature\') % label along x-axis
ylabel(\'specific heat\') % label along y-axis
title(\'temperature v/s specific heat\')
figure(2) % storing in figure 2 the output
plot(temp,H,\'linewidth\',3,\'color\',\'g\') % plotting temp v/s enthalpy
xlabel(\'temperature\') % label along x-axis
ylabel(\'enthalpy\') % label along y-axis
title(\'temperature v/s enthalpy\')
figure(3) % storing in figure 3 the output
plot(temp,S,\'linewidth\',3,\'color\',\'b\') % plotting temp v/s entropy
xlabel(\'temperature\') % label along x-axis
ylabel(\'entropy\') % label along y-axis
title(\'temperature v/s entropy\')
% current working directory is C:\\Users\\ADITYA N\\Desktop\\skill_lync,challange
% it can be known by pwd, changing the file directory to H:\\fileparse_species
% creates the file name as fileparse_species in H drive & gives molecule_name
mkdir([\'H:\\fileparse_species_\',molecule_name])
% changes the directory from C drive to H drive
directory = ([\'H:\\fileparse_species_\',molecule_name]);
cd(directory)
% saves the figure in the particular folder with respective images in.jpg extension
saveas(figure(1),\'specific heat.jpg\')
saveas(figure(2),\'enthalpy.jpg\')
saveas(figure(3),\'entropy.jpg\')
% To calculate the molecular weight
fprintf(\'\\n\') % prints the command in new line
fprintf(\'molecular weight of \') % prints this sentence in command window
fprintf(molecule_name) % prints the molecule name in command window
fprintf(\' : \') % prints the semi-colon in the commamd window
elements = [\'O\',\'H\',\'N\',\'C\',\'A\']; % these are the atoms which are used to form a molecule
element_weight = [16 1 14 12 40]; % these ate the atomic weight of the above atoms
m = 0; % considering the molecular mass as 0 initially
% considering the values of each molecule
for i = 1:length(molecule_name) % here the molecules are selected in the data file sequnce wise(O,O2,H2O,CO,CO2...)
for j = 1:length(elements) % here the each atoms are compared with molecules present in data = [\'O\',\'H\',\'N\',\'C\',\'A\']
if strcmp(molecule_name(i),elements(j)) % here the each molecule is compared with each atom
% i.e. in case-1: the oxygen molecule is compared with all the elements prsesnt
m = m+element_weight(j);% it is added here ant the o/p is stored in m
position = j; % the positon of the atom is captured here
% i.e.the postion of the molecule(O) is matched with elements here it is 1
end
end
% this command is executed when molecules like H2O,CO2,CH3 etc.. comes into picture here the numeric 2 is taken
%in case of H2O and 2>1 converted to string to number the abobe calculated atom weight is taken in m & that positon of the
% atom present in elements = [\'O\',\'H\',\'N\',\'C\',\'A\'] is considered and the atomic wight w.rt. this positon is added.
%(n-1) is considered here because of in H2O O is calculated once in the first if condition here n=2-1 so that O should not
% be added here again.
n =str2num(molecule_name(i));
if n>1
m = m + element_weight(position)*(n-1);
end
end
fprintf(\'%d\',m); %d is for digit
end
fclose(f1); % it is used to close the file.
Plot for CO2 -
Plot for H2O -
The folder cobtaining the vatous plots of differnt species is shown below
Below screen shot of calculated molecular mass of the species in command window
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...
Week 12- Final project
Final project - Door trim Inner Panel Role of plastic in the automobile industry: The use of polymers as plastics in the construction of automobiles has continued to grow over the last decades. Nowadays they are the second most commonly found in cars. Here are four reasons why plastic is used in car manufacturing:…
27 Mar 2023 10:20 AM IST
Week 10- Assembly Workbench
1. All the individual parts are modeled in the part design workbench with appropriate dimensions. 2. They are put in one assembly. 3. Applied with necessary constraints on it.
24 Feb 2023 11:41 PM IST
Week 9 - Project - A pillar Design with Master Section
1. For the given Class A surface dessign. 2. The Class B surface is created . 3. Class C surface is also created. 4. Finally the dog is created using the master section. 5.At last it is draft analysed.
24 Feb 2023 11:29 PM IST
Week 9 - Project 1 - Door Trim Lower with Engineering Features
1. For the Given Class A surface draft analysis is done on it. 2. By offsetting the Class B surface, the fillets which were failing were recreated. 3. Finally by using the reference to the surface of method/ by draft direction method there is a class C surface creation done. 4. Wherever required the heat stakes and locator…
24 Feb 2023 11:17 PM 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.