-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get data directories function #375
Conversation
Yes, using Boost is definitely fine (and I was actually planning on starting to use the string algorithms to replace some of the functions defined in The question I have is whether this function should return a single string or whether it should just return a |
I chose that format, and the separator, assuming that most people would interact with the result as though it were something like the system |
I think Cython should understand how to translate For C or Matlab, returning a single string may indeed be an easier solution. |
Another option: what about having |
333e553
to
ffd9f4c
Compare
OK I added the argument and rebased onto master. I think returning the string makes the most sense, for easy interoperability with Clib and Matlab. |
@@ -31,6 +31,10 @@ def add_directory(directory): | |||
""" Add a directory to search for Cantera data files. """ | |||
CxxAddDirectory(stringify(directory)) | |||
|
|||
def get_data_directories(sep=':'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to use os.pathsep
instead of ':'
here, otherwise this will fail badly on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't matter, since the C++ returns just a string, and that's split into a list in Python, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows, if you call getDataDirectories
with :
as the separator, it will return a string like:
C:\src\anaconda\envs\py33\lib\site-packages\cantera\data:C:\Program Files\Cantera\data
Which Python will then split as:
['C',
'\\src\\anaconda\\envs\\py33\\lib\\site-packages\\cantera\\data',
'C',
'\\Program Files\\Cantera\\data']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And actually, given that the Python method returns a list, it shouldn't take the separator as an argument, it should just use os.pathsep
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I forgot about the drive letter... Thanks for the note
function getdatadirectories(sep) | ||
% GETDATADIRECTORIES Get a string of the directories searched for data files. | ||
% getdatadirectories(sep) | ||
% Get a string of the directores Cantera searches for data files, with each |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misspelled 'directories'
@@ -0,0 +1,11 @@ | |||
function getdatadirectories(sep) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we camelCase most of the most of the Matlab function names?
@@ -1420,6 +1420,17 @@ extern "C" { | |||
} | |||
} | |||
|
|||
int getDataDirectories(int buflen, char* buf, const char* sep) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function should be named ct_getDataDirectories
(some of the existing functions need to be updated to follow this convention). Also, I think you forgot to add ct.h
.
try { | ||
string d = getDataDirectories(sep); | ||
copyString(d, buf, buflen); | ||
return int(d.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyString
was recently modified so that you can simply write:
return copyString(getDataDirectories(sep), buf, buflen);
// get string of data directories | ||
case 5: | ||
sep = getString(prhs[2]); | ||
buflen = getDataDirectories(buflen, output_buf, sep); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is more clear to just put 0 in place of buflen
and output_buf
in this initial call.
@@ -212,7 +212,7 @@ if localenv['sphinx_docs']: | |||
'@Data': ['Air.m', 'constants.m', 'gasconstant.m', 'GRI30.m', | |||
'Hydrogen.m', 'Methane.m', 'Nitrogen.m', 'oneatm.m', | |||
'Oxygen.m', 'Water.m'], | |||
'@Utilities': ['adddir.m', 'ck2cti.m', 'cleanup.m', 'geterr.m',] | |||
'@Utilities': ['adddir.m', 'ck2cti.m', 'cleanup.m', 'geterr.m', 'getdatadirectories.m'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update case here as well.
157ebaa
to
75821c9
Compare
75821c9
to
9b9f578
Compare
I squashed a few of the revisions in preparation for merging this, and fixed two bugs:
However, I also noticed that the Matlab function does not work -- it currently does not return anything. |
Hmmm... I didn't get a chance to test the Matlab toolbox, I can do that when I get back to the office tomorrow. Thanks for fixing those bugs! |
9b9f578
to
7071bf6
Compare
OK I rebased this onto b01f9cd and fixed the Matlab bug. It returns a cell array of strings now, similar to the list in Python. |
Add a function to get the data directories that Cantera searches. Since we're using Boost in another spot now as a requirement, I thought it'd be OK to use that here as well. If not, we just need to implement our own string imploder to convert from
std::vector<string>
to astd::string
.