root/MGET/Trunk/PythonPackage/src/GeoEco/MatlabUtils.cpp
| Revision 163, 1.8 kB (checked in by jjr8, 2 years ago) |
|---|
| Line | |
|---|---|
| 1 | // MatlabUtils.cpp - Implements C utility functions used by Matlab.py. Not |
| 2 | // intended to be called from any code outside of Matlab.py. |
| 3 | // |
| 4 | // Copyright (C) 2008 Jason J. Roberts |
| 5 | // |
| 6 | // This program is free software; you can redistribute it and/or |
| 7 | // modify it under the terms of the GNU General Public License |
| 8 | // as published by the Free Software Foundation; either version 2 |
| 9 | // of the License, or (at your option) any later version. |
| 10 | // |
| 11 | // This program is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License (available in the file LICENSE.TXT) |
| 15 | // for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | |
| 21 | #include "mclmcr.h" |
| 22 | #include "mclcppclass.h" |
| 23 | #include "python.h" |
| 24 | |
| 25 | static PyObject *InitializeMCR(PyObject *self) |
| 26 | { |
| 27 | static int initializedMCR = 0; |
| 28 | |
| 29 | // If we haven't initialized the MCR yet, do it now. |
| 30 | |
| 31 | if (!initializedMCR) |
| 32 | { |
| 33 | const char *pszOptions[] = {"-nojvm", "-nojit"}; |
| 34 | if (!mclInitializeApplication(pszOptions, 2)) |
| 35 | { |
| 36 | PyErr_SetString(PyExc_RuntimeError, "Failed to initialize the Matlab Component Runtime (MCR)."); |
| 37 | return NULL; |
| 38 | } |
| 39 | initializedMCR = 1; |
| 40 | } |
| 41 | |
| 42 | // Return successfully. |
| 43 | |
| 44 | Py_INCREF(Py_None); |
| 45 | return Py_None; |
| 46 | } |
| 47 | |
| 48 | static PyMethodDef MatlabUtilsMethods[] = |
| 49 | { |
| 50 | {"InitializeMCR", (PyCFunction) InitializeMCR, METH_NOARGS, "Initialize the Matlab Component Runtime for the current process."}, |
| 51 | {NULL, NULL, 0, NULL} |
| 52 | }; |
| 53 | |
| 54 | PyMODINIT_FUNC initMatlabUtils(void) |
| 55 | { |
| 56 | Py_InitModule("MatlabUtils", MatlabUtilsMethods); |
| 57 | } |
Note: See TracBrowser for help on using the browser.
