Parsing NASA Thermodynamic Data file using MATLAB
Objective:
- To read & extract 14 coefficients for each element from NASA thermodynamic data file and calculates the enthalpy, entropy & specific heats for all the species in the data file.
- To 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 suitable name. All these should be generated automatically.
-------------------------------------------------------------------------------------------------------------------
Abstract:
The purpose of this project was to parse NASA Thermodynamic Data File i.e. THERMO.dat given by NASA. The file contains the data in the raw form which needs to get separated, extracted and converted. The data extracted from the file is used to calculate specific heat, enthalpy, entropy and molecular mass of each element. Using these thermodynamic properties, relations are plotted between Specific Heat and Temperature, Enthalpy and Temperature & Entropy and Temperature for each element. All the plots for each element are stored in a separate folder under Result folder. All this is generated automatically. Plots for any element can be accessed as per the user demand.
-------------------------------------------------------------------------------------------------------------------
Contents:
1. Introduction
- File Parsing
- NASA Thermodynamic File
- List of 53 Elements contained in file THERMO.dat
- Specific Heat
- Enthalpy
- Entropy
- Temperature
- MATLAB Functions Used
2. MATLAB Programs with Methodology
- file_parsing.m : Main Program to call and perform all the task
- element_name_loc_temp.m : Function to extract element name & local temperatures of each element
- coefficient_calc.m : Function to extract coefficients of each element from the file
- specific_heat_calc.m : Function to calculate Specific Heat for 500 temperature values of each element
- enthalpy_calc.m : Function to calculate Enthalpy for 500 temperature values of each element
- entropy_calc.m :Function to calculate Entropy for 500 temperature values of each element
- molecular_weight.m : Function to calculate Molecular Weight of each element
- plot_func.m : Function to plot (Cp, H, S) Vs T for each element
3. Screenshots
- Molecular Weight of each species
- Screenshot of the window where all the folders are saved.
- Plots for O2 when asked by user (3 Plots)
- Plots for N2 when asked by user (3 Plots)
- Plots for CO2 when asked by user (3 Plots)
4. Errors Faced
5. Steps to Overcome Errors
6. Evaluation
7. Conclusion
8. Reference
-------------------------------------------------------------------------------------------------------------------
Introduction:
File Parsing
Parsing a file means reading in a data stream of some sort and building an in-memory model of the semantic content of that data. This aims at facilitating performing some kind of transformation on the data. It means, to a computer, about what “reading text” means to a human being. You scan it, from start to finish, and figure out what it means as you go - whether you’re a person reading text or a computer parsing a file.
NASA Thermodynamic File
THERMO.dat file is a data file containing 14 coefficients for 53 different elements given by NASA. These coefficients are utilized to calculate the specific heat, enthalpy & entropy for a particular element. Each element has its own range of local temperature. Below screenshot of THERMO.dat file is displayed.
List of 53 Elements contained in file THERMO.dat
AR C C2H C2H2 C2H3 C2H4
C2H5 C2H6 C3H7 C3H8 CH CH2
CH2(S) CH2CHO CH2CO CH2O CH2OH CH3
CH3CHO CH3O CH3OH CH4 CN CO
CO2 H H2 H2CN H2O H2O2
HCCO CCOH HCN HCNN HCNO HCO
HNCO HNO HO2 HOCN N N2
N2O NCO NH NH2 NH3 NNH
NO NO2 O O2 OH
Specific Heat
Specific heat, ratio of the quantity of heat required to raise the temperature of a body one degree to that required to raise the temperature of an equal mass of water one degree. The term is also used in a narrower sense to mean the amount of heat, in calories, required to raise the temperature of one gram of a substance by one Celsius degree.
The basic formula used for calculating Specific Heat is as follows-
Cp = (a1 + a2*T + a3*T^2 + a4*T^3 + a5*T^4) *R
Enthalpy
Enthalpy, the sum of the internal energy and the product of the pressure and volume of a thermodynamic system. Enthalpy is an energy-like property or state function—it has the dimensions of energy (joules or ergs), and its value is determined entirely by the temperature, pressure, and composition of the system. In symbols, the enthalpy, H, equals the sum of the internal energy, E, and the product of the pressure, P, and volume, V, of the system: H = E + PV.
The basic formula used for calculating Enthalpy is as follows-
H = (a1 + a2*T/2 + a3*T^2/3 + a4*T^3/4 + a5*T^4/5 + a6/T) *R*T
Entropy
Entropy, the measure of a system’s thermal energy per unit temperature that is unavailable for doing useful work. Because work is obtained from ordered molecular motion, the amount of entropy is also a measure of the molecular disorder, or randomness, of a system. The concept of entropy provides deep insight into the direction of spontaneous change for many everyday phenomena.
The basic formula used for calculating Entropy is as follows-
S = (a1*log T + a2*T + (a3*T^2)/2 + (a4*T^3)/3 + (a5*T^4)/4 + a7) *R
Temperature
Temperature is a physical property of matter that quantitatively expresses hot and cold. It is the manifestation of thermal energy, present in all matter, which is the source of the occurrence of heat, a flow of energy, when a body is in contact with another that is colder.
--------------------------------------------
MATLAB Functions Used:
fopen( ) : Open file, or obtain information about open files.
fclose( ) : Close one or all open files.
fgetl( ) : Read line from file, removing newline characters.
frewind( ) : Move file position indicator to beginning of open file.
strcmp( ) : Compare strings (case sensitive).
strcmpi( ) : Compare strings (case insensitive).
strsplit( ) : Split string or character vector at specified delimiter.
strcat( ) : Concatenate or join strings horizontally.
str2double( ) : Converts the string to double precision values.
strtok( ) : Parses str from left to right, using whitespace characters as delimiters, and returns part or all of the text in token.
strfind( ) : Searches a string or character in a string.
linspace( ) : Create a vector of n evenly spaced points in the interval [p,q].
fprintf( ) : File PRINT Formatted: use this for printing text to a file or the command window.
sprintf( ) : String PRINT Formatted: use this for creating a MATLAB string ( Character Vector).
disp( ) : Displays the value of variable X without printing the variable name.
input( ) : Displays the text in prompt and waits for the user to input a value and press the Return key.
imread( ) : Reads the image from the file specified by filename.
imshow( ) : Displays the grayscale image in a figure.
figure( ) : Creates a new figure window using default property values.
plot( ) : Creates a 2-D line plot of the data in Y versus the corresponding values in X.
xlabel( ), ylabel( ) : Labels the x-axis & y-axis of the chart returned by the gca command.
title( ) : Adds the specified title to the axes or chart returned by the gca command.
saveas( ) : Saves the figure specified by fig to file filename.
msgbox( ) : Create message dialog box.
questdlg( ) : Create question dialog box.
inputdlg( ) : Create dialog box to gather user input.
uiwait( ) : Block program execution and wait to resume.
------------------------------------------------------------------------------------------------------------
MATLAB Code:
1. file_parsing.m i.e. Main Program
Methodology:
First, open the data file, calculate the number of lines, then observe the pattern & number of lines of each element. To get number of total species, eliminate number of unnecessary lines from total number of lines & then divide by number of lines containing the element info. Now extract & store the low, mid & high global temperature.
Now to extract info of each element, a for loop is required which will run from 1 to total number of elements. Under the for loop, various functions will be called for executing their role for each element like element_name_loc_temp.m, coefficient_calc.m, specific_heat_calc.m, enthalpy_calc.m, entropy_calc.m, molecular_weight.m & plot_func.m
Now to ask user whether to show plots of any particular element or not, a do-while loop is required but MATLAB doesn’t support do-while loop. So, a while loop with test condition as 'ctrl==0' is used. The user enters the element name which is compared from the element name array one by one. As soon as the element matches, the name of the element is concatenated to the path of the result folder and is provided to imread function with the specific name of the plot. This way all the 3 plots can be accessed by the user. The loop will terminate only when the user enters no as a choice to exit the program.
% file_parsing.m
clear all
close all
clc
% Universal Gas Constant 'R' in J/(mol*K)
R = 8.314;
% Opening NASA thermodynamic data file 'THERMO.dat' in read mode
f1 = fopen('THERMO.dat','r');
% To find total number of species...
string=fgetl(f1);
i=1;
while strcmp(string,'END')==0
string=fgetl(f1);
i=i+1;
end
total_lines = i;
total_species = (total_lines-6)/4;
% total_lines-6 beacuase the last line and the first 5 lines are useless
% and divided by 4 because each element contains it's data in a set of 4 lines
% Extraction of Global Temperature
% Placing the file pointer in the beginning.
frewind(f1)
% Reading 1st line & skipping it as it's useless.
fgetl(f1);
% Reading & storing value from 2nd line.
global_temp_string = fgetl(f1);
global_temp = strsplit(global_temp_string, ' ');
global_low_temp = str2double(global_temp{2});
global_mid_temp = str2double(global_temp{3});
global_high_temp = str2double(global_temp{4});
% Next three fgetl commands to skip insignificant data
fgetl(f1);
fgetl(f1);
fgetl(f1);
% Calculating and ploting Cp, H, S for all species
for species = 1:total_species
% Extraction of Element Name & Local Temperature
[name, llt, lht, lmt] = element_name_loc_temp(f1);
ename{species} = name;
% Dividing local temperature range into 500 values
T = linspace(llt, lht, 500);
% Extraction of Co-effiicients
coeff = coefficient_calc(f1);
% Calculation of Specific Heat for 500 temperature values
Cp = specific_heat_calc(coeff, lmt, T, R);
% Calculation of Enthalpy for 500 temperature values
H = enthalpy_calc(coeff, lmt, T, R);
% Claculation of Entropy for 500 temperature values
S = entropy_calc(coeff, lmt, T, R);
% Calculation of Molecular Weight
Mol_Wt = molecular_weight(name);
fprintf( 'Molecular Weight of \t %s \t is \t %d \n', name, Mol_Wt)
% Plotting & Saving the plots: Cp vs T, H vs T and S vs T for all the elements
plot_func(Cp, H, S, T, name);
end
fclose(f1);
% Asking user whether to show plots of any particular element or not
ctrl = 0;
flag = 1;
while ctrl == 0
% Asking User Response
choice = questdlg('Do you want to view H-T, S-T, c-T plot of any element?','User Response', 'Yes', 'No', 'No');
% Execution will be controlled by user response using switch statement
switch choice
case 'Yes'
% To display the elements in a dialogue box
msgbox({'The elements present in the database are as follows:'...
'AR, C, C2H, C2H2, C2H3, C2H4, C2H5, C2H6, C3H7, C3H8'...
'CH, CH2, CH2(S), CH2CHO, CH2CO, CH2O, CH2OH, CH3, CH3CHO, CH3O'...
'CH3OH, CH4, CN, CO, CO2, H, H2, H2CN, H2O, H2O2'...
'HCCO, HCCOH, HCN, HCNN, HCNO, HCO, HNCO, HNO, HO2, HOCN'...
'N, N2, N2O, NCO, NH, NH2, NH3, NNH, NO, NO2'...
'O, O2, OH'});
% To ask element name in a dialogue box
user = inputdlg( 'Enter the element name: ');
% Loop to compare the user input with all the stored elements
% ename is the string array containing the element names
res = 0;
for n = 1:total_species
elname = ename(n)
% Comparing the user input & element name under case insensitive mode
res = strcmpi(elname, user);
if res == 1
% Storing the address of folder of the matched element
path = strcat('F:\Skill-Lync\Skill-Lync Practice Sheets\Matlab\Result\',ename{n});
% Storing address of the particular plot
filename1 = fullfile(path,'Enthalpy_Vs_Temperature_Plot.jpg');
% Reading the image & storing it's pixel info into matrix
image1 = imread(filename1);
figure(1)
% Displaying the image
imshow(image1);
filename2 = fullfile(path,'Entropy_Vs_Temperature_Plot.jpg');
image2 = imread(filename2);
figure(2)
imshow(image2);
filename3 = fullfile(path,'Specific_Heat_Vs_Temperature_Plot.jpg');
image3 = imread(filename3);
figure(3)
imshow(image3);
flag = 0;
end % End of if body
end % End of for loop
if flag == 1
uiwait(msgbox('Please enter a valid element name...!'));
end
case 'No'
ctrl = 1;
end % End of switch body
end
--------------------------------------------
2. element_name_loc_temp.m i.e. Function to extract element name & local temperatures
Methodology:
As input parameter, this function will only receive the file handle and will return name, low, mid & high local temperature for each element.
First, the line containing the name is stored using fgetl function. Then strtok function is used to give the first word from the line. Now for extracting the local temperature strfind function is used to find the position of ‘.’ in the line. Then by indexing method, the values are identified and further stored in respective variables but these values are still strings not number. So str2double function is used to convert the strings to number and then returned as output.
% element_name_loc_temp.m
% Function to extract element name & local temperatures.
function [name, llt,lht,lmt] = element_name_loc_temp(f1)
name_line = fgetl(f1);
% strtok()-Returns the first token in the text string
name = strtok(name_line);
% Finding & storing the position of '.' in variable ltline
ltline = strfind(name_line,'.');
% Storing the local low temperature
ltline1 = name_line( ltline(1)-3 : ltline(1)+3 );
ltline1 = str2double(ltline1);
% Storing the local high temperature
ltline2 = name_line( ltline(2)-4 : ltline(2)+3 );
ltline2 = str2double(ltline2);
% Storing the local mid temperature
ltline3 = name_line( ltline(3)-4 : ltline(3)+3 );
ltline3 = str2double(ltline3);
llt = ltline1; %local low temperature
lht = ltline2; %local high temperature
lmt = ltline3; %local mid temperature
end
--------------------------------------------
3. coefficient_calc.m i.e. Function to extract coefficients from the file
Methodology:
As input parameter, this function will only receive the file handle and will return coefficients for each element.
First, the line containing the name is stored using fgetl function. Using strfind function, the position of ‘E’ in the stored line is identified & stored in an array. Then using the position of ‘E’ in indexing method, the exact coefficient is stored in a variable. But it’s still a string. So require str2double function to convert the string into number. This method is repeated for all the coefficients. All the extracted coefficients are arranged into on array & returned by the function.
% coefficient_calc.m
% Function to extract coefficients from the file
function [coeff] = coefficient_calc(f1)
% Reading 1st line conataining coefficients
line_1 = fgetl(f1);
% Finding & storing the position of E in 1st line
% In E_pos_x : x represents the 1st line
E_pos_x = strfind(line_1,'E');
% Storing the required string
a1 = line_1( 1 : E_pos_x(1)+3);
% Converting the string into number of double type
a1 = str2double(a1);
a2 = line_1( E_pos_x(1)+4 : E_pos_x(2)+3);
a2 = str2double(a2);
a3 = line_1( E_pos_x(2)+4 : E_pos_x(3)+3);
a3 = str2double(a3);
a4 = line_1( E_pos_x(3)+4 : E_pos_x(4)+3);
a4 = str2double(a4);
a5 = line_1( E_pos_x(4)+4 : E_pos_x(5)+3);
a5 = str2double(a5);
% Reading 2nd line conataining coefficients
line_2 = fgetl(f1);
% Finding & storing the position of E in 2nd line
% In E_pos_y : y represents the 2nd line
E_pos_y = strfind(line_2,'E');
a6 = line_2( 1 : E_pos_y(1)+3);
a6 = str2double(a6);
a7 = line_2( E_pos_y(1)+4 : E_pos_y(2)+3);
a7 = str2double(a7);
b1 = line_2( E_pos_y(2)+4 : E_pos_y(3)+3);
b1 = str2double(b1);
b2 = line_2( E_pos_y(3)+4 : E_pos_y(4)+3);
b2 = str2double(b2);
b3 = line_2( E_pos_y(4)+4 : E_pos_y(5)+3);
b3 = str2double(b3);
% Reading 3rd line conataining coefficients
line_3 = fgetl(f1);
% Finding & storing the position of E in 3rd line
% In E_pos_z : z represents the 3rd line
E_pos_z = strfind(line_3,'E');
b4 = line_3(1 : E_pos_z(1)+3);
b4 = str2double(b4);
b5 = line_3( E_pos_z(1)+4 : E_pos_z(2)+3);
b5 = str2double(b5);
b6 = line_3( E_pos_z(2)+4 : E_pos_z(3)+3);
b6 = str2double(b6);
b7 = line_3( E_pos_z(3)+4 : E_pos_z(4)+3);
b7 = str2double(b7);
coeff = [ a1 a2 a3 a4 a5 a6 a7 b1 b2 b3 b4 b5 b6 b7];
--------------------------------------------
4. specific_heat_calc.m i.e. Function to calculate Specific Heat for 500
Methodology:
As input parameter, this function will receive the Coefficients, Local Mid Temperature, Temperature Matrix & Universal Gas Constant and will return Specific Heat Matrix for each element.
A for loop is used to calculate the value of specific heat for 500 temperature values. When the temperature values are greater or equal to local mid temperature then the first 7 coefficients will be used in the formula i.e. high temperature coefficient and when the temperature values are less than local mid temperature then the last 7 coefficients will be used in the formula i.e. low temperature coefficient. The specific heat for 500 temperature values will be stored in a matrix. This matrix will be returned by the function.
% specific_heat_calc.m
% Function to calculate Specific Heat for 500 temperature values
% Cp = (a1 + a2*T + a3*T^2 + a4*T^3 + a5*T^4)*R
function [Cp]= specific_heat_calc(coeff, lmt, T, R)
a = coeff;
for i = 1:length(T)
% if condition: checks temperature from local mid temperature
% to choose the particular formula for Cp
if T(i) >= lmt
% Here, Cp will be calculated using high temperature coefficient
% i.e. coeff[1:7]
Cp(i) = (a(1) + a(2)*T(i) + a(3)*T(i)^2 + a(4)*T(i)^3 + a(5)*T(i)^4) *R;
else
% Here, Cp will be calculated using low temperature coefficient
% i.e. coeff[7:14]
Cp(i) = (a(8) + a(9)*T(i) + a(10)*T(i)^2 + a(11)*T(i)^3 + a(12)*T(i)^4) *R;
end
end
end
--------------------------------------------
5. enthalpy_calc.m i.e. Function to calculate Enthalpy for 500 temperature
Methodology:
As input parameter, this function will receive the Coefficients, Local Mid Temperature, Temperature Matrix & Universal Gas Constant and will return Enthalpy Matrix for each element.
The choice between the coefficients will be similar to the above explanation in specific_heat_calc.m. (A for loop is used to calculate the value of Enthalpy for 500 temperature values. When the temperature values are greater or equal to local mid temperature then the first 7 coefficients will be used in the formula i.e. high temperature coefficient and when the temperature values are less than local mid temperature then the last 7 coefficients will be used in the formula i.e. low temperature coefficient.) The enthalpy for 500 temperature values will be stored in a matrix. This matrix will be returned by the function.
% enthalpy_calc.m
% Function to calculate Enthalpy for 500 temperature values
% H = (a1 + a2*T/2 + a3*T^2/3 + a4*T^3/4 + a5*T^4/5 + a6/T) *R*T
function [H] = enthalpy_calc(coeff, lmt, T, R)
a = coeff;
for i = 1:length(T)
% if condition: checks temperature from local mid temperature
% to choose particular formula for H
if T(i) >= lmt
% Here, H will be calculated using high temperature coefficient
% i.e. coeff[1:7] or a[1:7]
H(i) = (a(1) + (a(2)*T(i))/2 + (a(3)*T(i)^2)/3 + (a(4)*T(i)^3)/4 + (a(5)*T(i)^4)/5 + a(6)/T(i) )*R*T(i);
else
% Here, H will be calculated using low temperature coefficient
% i.e. coeff[7:14] or a[8-14]
H(i) = (a(8) + (a(9)*T(i))/2 + (a(10)*T(i)^2)/3 + (a(11)*T(i)^3)/4 + (a(12)*T(i)^4)/5 + a(13)/T(i) )*R*T(i);
end
end
end
--------------------------------------------
6. entropy_calc.m i.e. Function to calculate Entropy for 500 temperature
Methodology:
As input parameter, this function will receive the Coefficients, Local Mid Temperature, Temperature Matrix & Universal Gas Constant and will return Entropy Matrix for each element.
The choice between the coefficients will be similar to the above explanation in specific_heat_calc.m. (A for loop is used to calculate the value of Enthalpy for 500 temperature values. When the temperature values are greater or equal to local mid temperature then the first 7 coefficients will be used in the formula i.e. high temperature coefficient and when the temperature values are less than local mid temperature then the last 7 coefficients will be used in the formula i.e. low temperature coefficient.) The entropy for 500 temperature values will be stored in a matrix. This matrix will be returned by the function.
% entropy_calc.m
% Function to calculate Entropy for 500 temperature values
% S = (a1*log T + a2*T + (a3*T^2)/2 + (a4*T^3)/3 + (a5*T^4)/4 + a7) *R
function [S] = entropy_calc(coeff, lmt, T, R)
a = coeff;
for i = 1:length(T)
% if condition: checks temperature from local mid temperature
% to choose particular formula for S
if T(i) >= lmt
% Here, S will be calculated using high temperature coefficient
% i.e. coeff[1:7] or a[1:7]
S(i) = (a(1)*log(T(i)) + a(2)*T(i) + (a(3)*T(i)^2)/2 + (a(4)*T(i)^3)/3 + (a(5)*T(i)^4)/4 + a(7)) *R;
else
% Here, S will be calculated using low temperature coefficient
% i.e. coeff[7:14] or a[8:14]
S(i) = (a(8)*log(T(i)) + a(9)*T(i) + (a(10)*T(i)^2)/2 + (a(11)*T(i)^3)/3 + (a(12)*T(i)^4)/4 + a(14)) *R;
end
end
end
--------------------------------------------
7. molecular_weight.m i.e. Function to calculate Molecular Weight
Methodology:
As input parameter, this function will receive the Element Name and will return Molecular Weight for each element.
To calculate the molecular weight, a character string of all the letters appearing in the name of element and an array of the atomic weight corresponding to the letters is required. A nested for loop & if statement is used to compare each letter of the element name by the character string. The molecular weight is calculated letter by letter and if any numeric value came in between then it is first converted from string to number and the atomic weight of the preceding element is multiplied by one value less than numeric value which is further added to the molecular weight. This way the molecular weight of the element is calculated and is returned to the main function.
% molecular_weight.m
% Function to calculate Molecular Weight
function [Mol_Wt] = molecular_weight(name)
% Creating character vector of all letters appearing in the element name
std_element = {'C', 'H', 'O', 'N', 'A', 'S'};
% Creating atomic weight vector corresponding to the letters
atomic_wt = [12, 1, 16, 14, 40, 32];
Mol_Wt = 0;
for i = 1:length(name)
for j = 1:length(std_element)
% Comparing the element name with vector-standard element
if strcmp(name(i), std_element(j))
Mol_Wt = Mol_Wt + atomic_wt(j);
pos = j;
break
end
end
% Converting the number (but actually a string) in element name to number
num = str2double(name(i));
if num>1
Mol_Wt = Mol_Wt + (atomic_wt(pos).*(num-1));
end
end
end
--------------------------------------------
8. plot_func.m i.e. Function to plot (Cp, H, S) Vs T
Methodology:
As input parameter, this function will receive Specific Heat Matrix, Enthalpy Matrix, Entropy Matrix, Temperature Matrix & Element Name and will return nothing. This function will be plotting Specific Heat Vs Temperature, Enthalpy Vs Temperature, Entropy Vs Temperature Plot for each element. Additionally, it will create a Result folder under which a separate folder for each element with element name will be created. All 3 plots of an element will be stored in its corresponding folder. All these are generated automatically.
To create the main folder and sub folder, mkdir function is used. The path of each plot is concatenated with the appropriate main folder, sub-folder & the plot name. To save the plot at the desired path, saveas function is used. To plot and store each plot in a separate figure window, figure function is used separately for the 3 plots.
% plot_func.m
% Function to plot (Cp, H, S) Vs T
function [] = plot_func(Cp, H, S, T, name)
% Parent Folder = Result
% Sub Folder = Plots for particular element i.e. element name
%subfolder = strcat( 'Plots for - ', name);
mkdir( 'Result', name )
% Plotting Specific Heat Vs Temperature Plot
figure(1)
plot( T, Cp, 'color', 'r', 'linewidth', 3)
xlabel('Temperature T in K')
ylabel('Specific Heat Cp in kJ/K')
title( sprintf('Specific Heat Vs Temperature Plot for %s', name))
% Plotting Enthalpy Vs Temperature Plot
figure(2)
plot( T, H, 'color', 'm', 'linewidth',3)
xlabel('Temperature T in K')
ylabel('Enthalpy in kJ/kg')
title( sprintf('Enthalpy Vs Temperature Plot for %s', name))
% Plotting Entropy Vs Temperature Plot
figure(3)
plot( T, S, 'color', 'b', 'linewidth', 3)
xlabel('Temperature T in K')
ylabel('Entropy in kJ/K')
title( sprintf('Entropy Vs Temperature Plot for %s', name))
path = 'F:\Skill-Lync\Skill-Lync Practice Sheets\Matlab';
plot_1 = fullfile ( path, 'Result', name, 'Specific_Heat_Vs_Temperature_Plot.jpg');
plot_2 = fullfile ( path, 'Result', name, 'Enthalpy_Vs_Temperature_Plot.jpg');
plot_3 = fullfile ( path, 'Result', name, 'Entropy_Vs_Temperature_Plot.jpg');
saveas(figure(1), plot_1)
saveas(figure(2), plot_2)
saveas(figure(3), plot_3)
-------------------------------------------------------------------------------------------------------------------
Output:
1. Molecular Weight of each species
--------------------------------------------
2. Screenshot of the window where all the folders are saved.
--------------------------------------------
3. Plots for O2 when asked by user
----------------------------------
3.1 Specific Heat Vs Temperature Plot for O2
----------------------------------
3.2 Enthalpy Vs Temperature Plot for O2
----------------------------------
3.3 Entropy Vs Temperature Plot for O2
------------------------------------------------------------
4. Plots for N2 when asked by user
----------------------------------
4.1 Specific Heat Vs Temperature Plot for N2
----------------------------------
4.2 Enthalpy Vs Temperature Plot for N2
----------------------------------
4.3 Entropy Vs Temperature Plot for N2
-----------------------------------------------------------------
5. Plots for CO2 when asked by user
----------------------------------
5.1 Specific Heat Vs Temperature Plot for CO2
----------------------------------
5.2 Enthalpy Vs Temperature Plot for CO2
----------------------------------
5.3 Entropy Vs Temperature Plot for CO2
-------------------------------------------------------------------------------------------------------------------
Errors Faced:
- Error in imread funcion in main program
Steps to Overcome Errors:
- To rectify error 1; in line 108, ename(n) was replaced by ename{n}.
--------------------------------------------
- Error in Enthalpy Plot in enthalpy_calc function
Steps to Overcome Errors:
- To rectify error 2; line 23,
H(i) = (a(7) + (a(8)*T(i))/2 + (a(9)*T(i)^2)/3 + (a(10)*T(i)^3)/4 + (a(11)*T(i)^4)/5 + a(12)/T(i) )*R*T(i);
was replaced by
H(i) = (a(8) + (a(9)*T(i))/2 + (a(10)*T(i)^2)/3 + (a(11)*T(i)^3)/4 + (a(12)*T(i)^4)/5 + a(13)/T(i) )*R*T(i);
-------------------------------------------------------------------------------------------------------------------
Evaluation:
To parse NASA Thermodynamic file, the MATLAB code is developed by extensive research & development. The research includes the know-how of file parsing, various MATLAB functions for various tasks, alternatives to make the code easy and efficient. Comments have been added at all the required place in the code for the easy understanding. Various alternatives were tried to make the code much more efficient and reliable. At last errors were detected and various methodologies were practiced to resolve the errors. The different plots for each element show the relation and trend between the thermodynamic properties like specific heat, enthalpy & entropy with respect to temperature.
-------------------------------------------------------------------------------------------------------------------
Conclusion:
The file parsing project includes several modules from finding the correct information, converting it into useful form, plotting the relations to saving them automatically at the correct location. All these tasks led to great learning of various functions related to file handling in MATLAB and cleared confusions between some functions too. This project helps to enhance the thought process and logical thinking also. Overall, it was interesting and a bit challenging project to complete.
-------------------------------------------------------------------------------------------------------------------
Reference:
- https://in.mathworks.com/help/matlab/ref/mkdir.html
- https://in.mathworks.com/matlabcentral/answers/317006-create-new-folders-by-mkdir
- https://in.mathworks.com/help/matlab/ref/saveas.html
- https://in.mathworks.com/matlabcentral/answers/17580-how-to-define-a-path-in-saveas-command
- https://in.mathworks.com/help/matlab/referencelist.html?type=function&category=printing-and-exporting
- https://in.mathworks.com/help/matlab/ref/msgbox.html
- https://in.mathworks.com/matlabcentral/answers/151692-display-value-in-message-box
- https://in.mathworks.com/help/matlab/ref/fprintf.html
- https://in.mathworks.com/help/matlab/ref/sprintf.html
-------------------------------------------------------------------------------------------------------------------