From 1cdc6b6d7e0b707984d830e75d25fc0de33fde54 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Sat, 29 Oct 2016 12:04:41 -0400 Subject: [PATCH] Add C-Lib and Matlab interface to getDataDirectories --- doc/SConscript | 2 +- include/cantera/clib/ct.h | 1 + interfaces/matlab/toolbox/getDataDirectories.m | 10 ++++++++++ src/clib/ct.cpp | 9 +++++++++ src/matlab/ctfunctions.cpp | 12 +++++++++++- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 interfaces/matlab/toolbox/getDataDirectories.m diff --git a/doc/SConscript b/doc/SConscript index 896b8ad65..0446e3845 100644 --- a/doc/SConscript +++ b/doc/SConscript @@ -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'] } # These files do not need to be documented in the MATLAB classes because they diff --git a/include/cantera/clib/ct.h b/include/cantera/clib/ct.h index 873632b18..81f7f92d6 100644 --- a/include/cantera/clib/ct.h +++ b/include/cantera/clib/ct.h @@ -156,6 +156,7 @@ extern "C" { CANTERA_CAPI int showCanteraErrors(); CANTERA_CAPI int setLogWriter(void* logger); CANTERA_CAPI int addCanteraDirectory(size_t buflen, const char* buf); + CANTERA_CAPI int ct_getDataDirectories(int buflen, char* buf, const char* sep); CANTERA_CAPI int clearStorage(); CANTERA_CAPI int ck_to_cti(const char* in_file, const char* db_file, diff --git a/interfaces/matlab/toolbox/getDataDirectories.m b/interfaces/matlab/toolbox/getDataDirectories.m new file mode 100644 index 000000000..836bd55a1 --- /dev/null +++ b/interfaces/matlab/toolbox/getDataDirectories.m @@ -0,0 +1,10 @@ +function d = getDataDirectories() +% GETDATADIRECTORIES Get a cell array of the directories searched for data files. +% getdatadirectories() +% Get a cell array of the directories Cantera searches for data files +% +% :return: +% Cell array with strings representing the data file search directories +% + +d = strsplit(ctmethods(0, 5, ';'), ';'); diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index 9a917d388..0f888cd7d 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -1420,6 +1420,15 @@ extern "C" { } } + int ct_getDataDirectories(int buflen, char* buf, const char* sep) + { + try { + return copyString(getDataDirectories(sep), buf, buflen); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int setLogWriter(void* logger) { try { diff --git a/src/matlab/ctfunctions.cpp b/src/matlab/ctfunctions.cpp index 552e8428d..5488cb44c 100644 --- a/src/matlab/ctfunctions.cpp +++ b/src/matlab/ctfunctions.cpp @@ -34,7 +34,7 @@ void ctfunctions(int nlhs, mxArray* plhs[], { int job = getInt(prhs[1]); int iok = 0, dbg, validate; - char* infile, *dbfile, *trfile, *idtag; + char* infile, *dbfile, *trfile, *idtag, *sep; int buflen = 0; char* output_buf = 0; @@ -81,6 +81,16 @@ void ctfunctions(int nlhs, mxArray* plhs[], iok = clear_rxnpath(); break; + // get string of data directories + case 5: + sep = getString(prhs[2]); + buflen = ct_getDataDirectories(0, 0, sep); + output_buf = (char*)mxCalloc(buflen, sizeof(char)); + iok = ct_getDataDirectories(buflen, output_buf, sep); + plhs[0] = mxCreateString(output_buf); + iok = 0; + return; + default: mexErrMsgTxt("ctfunctions: unknown job"); }