From 5641fa83e9c1e39bf373a47330e76b3dfd5943b9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 8 Nov 2016 13:34:48 -0500 Subject: [PATCH] [clib/Matlab] Add function for getting Cantera version --- doc/SConscript | 3 ++- include/cantera/clib/ct.h | 1 + interfaces/matlab/toolbox/canteraVersion.m | 10 ++++++++++ src/clib/ct.cpp | 9 +++++++++ src/matlab/ctfunctions.cpp | 8 ++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 interfaces/matlab/toolbox/canteraVersion.m diff --git a/doc/SConscript b/doc/SConscript index 0446e3845..b273ca3e0 100644 --- a/doc/SConscript +++ b/doc/SConscript @@ -212,7 +212,8 @@ 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', 'getDataDirectories.m'] + '@Utilities': ['adddir.m', 'ck2cti.m', 'cleanup.m', 'geterr.m', + 'getDataDirectories.m', 'canteraVersion.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 e073cf807..12cd51390 100644 --- a/include/cantera/clib/ct.h +++ b/include/cantera/clib/ct.h @@ -156,6 +156,7 @@ extern "C" { CANTERA_CAPI int ct_setLogWriter(void* logger); CANTERA_CAPI int ct_addCanteraDirectory(size_t buflen, const char* buf); CANTERA_CAPI int ct_getDataDirectories(int buflen, char* buf, const char* sep); + CANTERA_CAPI int ct_getCanteraVersion(int buflen, char* buf); CANTERA_CAPI int ct_clearStorage(); CANTERA_CAPI int ct_ck2cti(const char* in_file, const char* db_file, diff --git a/interfaces/matlab/toolbox/canteraVersion.m b/interfaces/matlab/toolbox/canteraVersion.m new file mode 100644 index 000000000..873b08d11 --- /dev/null +++ b/interfaces/matlab/toolbox/canteraVersion.m @@ -0,0 +1,10 @@ +function v = canteraVersion() +% CANTERAVERSION Get Cantera version information +% canteraVersion() +% +% :return: +% A string containing the Cantera version +% + +v = ctmethods(0, 6); + diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index 8ee3c5ed9..cf6d48222 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -1419,6 +1419,15 @@ extern "C" { } } + int ct_getCanteraVersion(int buflen, char* buf) + { + try { + return copyString(CANTERA_VERSION, buf, buflen); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int ct_setLogWriter(void* logger) { try { diff --git a/src/matlab/ctfunctions.cpp b/src/matlab/ctfunctions.cpp index 598fbc1cc..6efe14d88 100644 --- a/src/matlab/ctfunctions.cpp +++ b/src/matlab/ctfunctions.cpp @@ -90,6 +90,14 @@ void ctfunctions(int nlhs, mxArray* plhs[], iok = 0; return; + // get cantera version string + case 6: + buflen = ct_getCanteraVersion(0, 0); + output_buf = (char*)mxCalloc(buflen, sizeof(char)); + iok = ct_getCanteraVersion(buflen, output_buf); + plhs[0] = mxCreateString(output_buf); + return; + default: mexErrMsgTxt("ctfunctions: unknown job"); }