Skip to content

Commit c19b8be

Browse files
committed
[MATLAB] Added utility function to add data directories
to Cantera's search path. Pass Cantera error text as a format argument instead of a format string to avoid issues with percent signs and backslashes in error messages.
1 parent 11a2381 commit c19b8be

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

interfaces/matlab/+ct/+impl/call.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
output = double(output);
88

99
if ismember(output, ct.impl.errorCode)
10-
error('Cantera:ctError', ct.impl.getError());
10+
error('Cantera:ctError', '%s', ct.impl.getError());
1111
end
1212

1313
end

interfaces/matlab/+ct/+impl/getArray.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
iok = double(iok);
1919
if ismember(iok, ct.impl.errorCode)
20-
error('Cantera:ctError', ct.impl.getError());
20+
error('Cantera:ctError', '%s', ct.impl.getError());
2121
end
2222

2323
% Convert output to double for better data compatibility

interfaces/matlab/+ct/+impl/getString.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
error('not implemented - argument list contains more than one char array.')
1616
end
1717
else
18-
error('Cantera:ctError', ct.impl.getError());
18+
error('Cantera:ctError', '%s', ct.impl.getError());
1919
end
2020

2121
iok = double(iok);
2222
if ismember(iok, ct.impl.errorCode)
23-
error('Cantera:ctError', ct.impl.getError());
23+
error('Cantera:ctError', '%s', ct.impl.getError());
2424
end
2525

2626
% Discard the last character
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function addDataDirectories(dirs)
2+
% Add one or more directories to the data file search path. ::
3+
%
4+
% >> ct.addDataDirectories('/path/to/data')
5+
% >> ct.addDataDirectories(["/path/one", "/path/two"])
6+
%
7+
% Directories are added to the front of the Cantera data file search path,
8+
% so the most recently added directory is searched first. Use
9+
% :mat:func:`dataDirectories` to inspect the current search path.
10+
%
11+
% :param dirs:
12+
% A string, char array, or string array of directories to add to the
13+
% Cantera data file search path.
14+
arguments
15+
dirs (1,:) string
16+
end
17+
18+
ct.isLoaded(true);
19+
for d = dirs
20+
ct.impl.call('mCt_addDataDirectory', char(d));
21+
end
22+
end

0 commit comments

Comments
 (0)