Project 1 - Parsing NASA thermodynamic data
Aim: To parse NASA thermodynamic data to extract the 14 coefficients to calculate the required properties like specific heat, enthalpy, entropy and molecular weight.
fopen: toopen a new file with the specified values.
fgetl: get a new line
str2num: convert the string to a number ('E' is to be taken into consideration)
file parsing: the coefficients 14 are to be taken into consideration. The text file .DAT file is to be used to extract both the high temperature coefficients and low temperature coefficients (the temperature range is to be known). local temperature range:global temperature range. Format specifier concept is observed in this assignment. The exponential form 'E' is to be extracted from the .DAT file.The coefficients are used according to the temperature range.These coefficients are then used judiciously to calculate the specific heat, enthalpy and gas constant of the species.
evaluation of gas constant: gas constant from the basic general physics point of view varies with the degrees of freedom of the molecule and depends on the degrees of freedom and varies for the monoatomic molecule and a diatomic molecule.
Modelling of Hydrodynamics and transfer phenomena in the case of a cross flow membrane filtration
concepts like getl and fopen
first fopen with normal numbers single with the correct format specifier %f floating point
str2num
strsplit are to be used properly
16.7 %f is to be used to represent the number of the required decimal places
for loop is to be used
/n command is to be used for the next line
fscanf('')
fprintf('')
writing a file
reading a file
header file: extract the global temperature range and local temperature range
then skip the lines and extract the subsequent lines to obtain the coefficients
calculate the enthalpy specific heat and gas constant with the coefficients for both the
like wise fscanf('format specifier',value) is chosen in the case of C programming language, file operations can be performed in the MATLAB using fprintf and fscanf by giving the appropriate format specifiers wherever necessary.in addition fgetl command is used to get the line in the input text file where the output is in the form of a 'String'. After extracting the line, it is required to get them as numerical values from the string which is required in the current operation.Here the strsplit(Line,' ').the use of delimiters(space/'E' etc) to get the appropriate numerals is of particular interest.
Parsing refers to file operation which contains input and output.To be specific, parsing refers to reading or extractig information from a file.The structure or the style of the lines in the header file is to be observed in order to deduce a logic or an algorithm to read the entire data from the file.Commands like fscanf(fileID,'format specifier',size) is used to extract the tests or comments or numbers from the file.
Usual structure of a file:
A file usually contains information as :
1) Header(general overview of the data in the file;what it is all about)
2) Comments (gives the extra information;can be omitted in most of the cases)
3) required data (numbers etc)(species data like Enthalpy, entropy, specific heat and temperature range)
Procedure for getting the data:
fgetl(file ID) command usually throws string as the output.
strsplit(line) gives the split string as the output.(in the form of an array )
To get the data which needs to be in numbers, the character 'E',is to be identified in the values as it is used to represent the exponent of 10^n where n is the number of digits after the 'E'.
findstr(file ID,'E') is usually where 'E' is applied as 'delimiter' in this case. Unnecessary comment lines can be skipped by using the fgetl command and the for loop which is used with the iterative variable,the number of comment lines present.
Finally the required values are required to be used for calculation of the properties supposed to be used for calculation of the properties required by storing them in the properties required by storing them in the varibles which can be the final coefficients /data required to analyse or calculate. But, the strings which were produced earlier are to be converted to numerical values to be stored in the variables.
str2num/str2double command is used to convert the string form to the alpha-numeric form.The same procedure is repeated to all the 53 species given in the NASA thermodynamic data file to get all the coefficients (7 high temperature and 7 low temperature) and accordingly the plots are obtained by using plot command.The local temperature ranges by extracting the local maxima and minima and mid range temperature can be obtained by judicious use of ' '(space) as the 'delimiter' while using the findstr() command which is (' ') present beween the temperature values stored/extracted as a string.
the final code can be written as follows:
clear all
close all
clc
% reading the header from THERMO.dat
k1 = fopen('THERMO.dat','r');
line1 = fgetl(k1);
disp(line1);
line2 = fgetl(k1);
disp(line2);
Header = strsplit(line2,' ');
R = 8.314;
global_low_temp = str2num(Header{2}) % 4x1 cell matrix is produced initially
global_mid_temp = str2num(Header{3})
global_high_temp = str2num(Header{4})
for i = 1:3
info_line = fgetl(k1)
disp(info_line)
end
% reading the species block from THERMO data file
for i = 1:53
Line1 = fgetl(k1);
species_desc = strsplit(Line1,' ')%
species_name = species_desc{1};
a = flip(species_desc)% used to get the required temperature values in the desired order to extract
local_low_temp = str2double(a{4});% obtained from variable 'a' obtained after flipping
local_high_temp = str2double(a{3});
local_mid_temp = str2num(a{2});
temp = linspace(local_low_temp,local_high_temp,500);
Line2 = fgetl(k1);
p = findstr(Line2,'E') % 'E' is the delimiter here
Line3 = fgetl(k1);
q = findstr(Line3,'E');
Line4 = fgetl(k1);
r = findstr(Line4,'E');
%High temperature coefficients
a1 = str2double(Line2(1:p(1)+3));
a2 = str2double(Line2(p(1)+4:p(2)+3));
a3 = str2double(Line2(p(2)+4:p(3)+3));
a4 = str2double(Line2(p(3)+4:p(4)+3));
a5 = str2double(Line3(p(4)+4:p(5)+3));
a6 = str2double(Line3(1:q(1)+3));
a7 = str2double(Line3(q(1)+4:q(2)+3));
%low temperature coefficients
b1 = str2double(Line3(q(2)+4:q(3)+3));
b2 = str2double(Line3(q(3)+4: q(4)+3));
b3 = str2double(Line3((q(4)+4:q(5)+3)));
b4 = str2double(Line4(1:r(1)+3));
b5 = str2double(Line4(r(1)+4:r(2)+3));
b6 = str2double(Line4(r(2)+4:r(3)+3));
b7 = str2double(Line4(r(3)+4:r(4)+3));
specific_heat = sp_heat_file_pa(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,temp,local_mid_temp);
enthalpy = enthalpy_file_pa(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,R,temp,local_mid_temp);
entropy = entropy_file_pa(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,R,temp,local_mid_temp);
Mw = molecular_weight_file_pa(species_name)
xlabel('temp')
ylabel('Entropy')
figure(1)
plot(temp,enthalpy,'linewidth','2','color','b')
title('temp vs enthalpy',species_name)
xlabel('temperature')
ylabel('Enthalpy')
grid on
end