Let me preface this by saying I have minimal experience with MATLAB, and am largely using existing scripts. It’s possible that the bug I’m dealing with is extremely simple and I just don’t know enough to recognize the source of the problem.
With that said, here’s the situation. I’m using a script to read in a database of chemical properties, which looks like this:
Ar 150.86 4.898 0
Br2 584.15 10.3 0.129
CCl4 556.35 4.56 0.1926
CF4 227.51 3.745 0.179
CHCl3 536.4 5.472 0.2219
CHN 456.65 5.39 0.4099
CH2Br2 611 7.17 0.2095
CH2Cl2 510 6.08 0.1986
CH2F2 351.255 5.784 0.2771
CH2O 408 6.59 0.2818
CH2O2 588 5.81 0.3173
CH3Br 467 8 0.1922
CH3CN 545.5 4.833 .338
CH3Cl 416.25 6.68 0.1531
CH3F 317.42 5.875 0.198
CH3NO 771 7.8 0.4124
CH3NO2 588.15 6.31 0.348
CH4 190.564 4.599 0.0115
...
N2 126.2 3.4 0.0377
N2O 309.57 7.245 0.1409
Ne 44.4 2.653 -0.0396
O2 154.58 5.043 0.0222
O2S 430.75 7.884 0.2454
SO2 430.75 7.884 0.2454
O3 261 5.57 0.2119
O3S 490.85 8.21 0.424
SO3 490.85 8.21 0.424
OCS 378.8 6.349 .0970119
Kr 209.35 5.50195 0
S 1313 18.2081 .246346
Xe 289.74 5.84037 0
The script used to read in this database is as follows:
% This program loads the SECOND database in the file 'F' into the matrix 'databaseB'.
F = 'fugacityCoefficientVariables.txt'; % The name of the file holding the data
fid = fopen(F); % Opens the data file and stores the I/O id number
global databaseB
databaseB = cell(0,4);
line = fgetl(fid); % Delete the Trash Line
line = fgetl(fid); % Check the first line.
while ischar(line) % While there are more lines to read. . .
while length(line)<5 % Discard any lines without any information
line=fgetl(fid); % ==0 would also work, but this handled
end % an odd space which stopped the program
line = regexprep(line,line(1),''); % Removes an unidentified character from the string
databaseB = [databaseB ;regexp(line,'t','split')]; % Place the species name in the first column of the database
line = fgetl(fid); % Get the next line to prepare for the while loop above.
end
clear('F','fid','x','trash','line');
% Clear all variables associated with the program except the database and
% the total number of species in the database.
The global variable databaseB is then called by another script, which uses it to look up these chemical properties by molecule.
However, when I run that script, I get an error message that none of the molecules it’s looking for can be found, e.g. Error using fugCoef (line 32) Species N2 is missing from the database.
With some experimentation, I’ve found this is true for every molecule listed in the database–none of them are being read in properly, even though the databaseB object is successfully being created.
Any idea where the problem might be found, and how it might be fixed?
Thanks!