diff --git a/Examples/package.mo b/Examples/package.mo index 98b36a4..b627e76 100644 --- a/Examples/package.mo +++ b/Examples/package.mo @@ -1,13 +1,16 @@ within OMCallPythonAdvanced; -package Examples +package Examples + extends Modelica.Icons.ExamplesPackage; import OMCallPythonAdvanced.Py; model Test + extends Modelica.Icons.Example; Py.PythonHandle pyHandle = Py.PythonHandle() "Initialize Python"; - constant String pyProgram = + String pyProgram = "def multiply(x, y): print(\"Will compute\", x, \"times\", y) + print('Time: " + String(time) + "') return x * y "; parameter String pyModuleName = "__main__"; diff --git a/Resources/C-Sources/Makefile b/Resources/C-Sources/Makefile index 772e33e..f234db1 100644 --- a/Resources/C-Sources/Makefile +++ b/Resources/C-Sources/Makefile @@ -1,8 +1,13 @@ # change these to suit your platform! -PYTHON_INCLUDE_DIR=-I"e:/bin/py64/include" -PYTHON_LIBRARY_DIR=-L"e:/bin/py64" -PYTHON_LIBRARY=-lpython38 + +PYTHON_INCLUDE_DIR=-I"C:\Users\benjamins\AppData\Local\Programs\Python\Python39\include" + +PYTHON_LIBRARY_DIR=-L"C:\Users\benjamins\AppData\Local\Programs\Python\Python39" + + +PYTHON_LIBRARY=-lpython39 + CFLAGS=-g ${PYTHON_INCLUDE_DIR} LDFLAGS=${PYTHON_LIBRARY_DIR} ${PYTHON_LIBRARY} diff --git a/Resources/C-Sources/OMCallPythonAdvanced.c b/Resources/C-Sources/OMCallPythonAdvanced.c index 0ece5b6..f98b52a 100644 --- a/Resources/C-Sources/OMCallPythonAdvanced.c +++ b/Resources/C-Sources/OMCallPythonAdvanced.c @@ -130,3 +130,515 @@ int omc_PyRun_TwoArgumentsOneReturn(void* pyHandle, double x, double y, const ch } return 0; } + +int omc_PyRun_FourArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z) { + static int runDone = 0; + PyObject *pModule, *pFunc; + PyObject *pArgs, *pValue; + int i, status = -1; + /* set the output to zero first */ + *z = 0; + + if (!omc_PyIsInitialized) { + fprintf(stderr, "omc_PyRun_TwoArgumentsOneReturn: Python is not initialized!\n"); fflush(NULL); + return -1; + } + + /* only run this once! */ + if (!runDone) { + status = PyRun_SimpleString(pyProgram); + runDone = 1; + if (status != 0) { + fprintf(stderr, "Could not run program \n---- Program: ----\n%s\n----------------\n", pyProgram); fflush(NULL); + return -1; + } + } + + pModule = PyImport_ImportModule(pyModuleName); + + if (pModule != NULL) { + pFunc = PyObject_GetAttrString(pModule, pyFunctionName); + + if (pFunc && PyCallable_Check(pFunc)) { + pArgs = PyTuple_New(4); + /* first argument */ + pValue = PyFloat_FromDouble(x); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 0, pValue); + /* second argument */ + pValue = PyFloat_FromDouble(y); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument y: %g to Python float!\n", y); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 1, pValue); + /* third argument */ + pValue = PyFloat_FromDouble(a); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 2, pValue); + /* fourth argument */ + pValue = PyFloat_FromDouble(b); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 3, pValue); + + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (pValue != NULL) { + *z = PyFloat_AsDouble(pValue); + if (PyErr_Occurred()) { + PyErr_Print(); + fprintf(stderr, "Cannot convert return argument double z from Python float\n!"); fflush(NULL); + return -1; + } + fprintf(stdout, "Result of call: %s(%g, %g, %g, %g) -> %g\n", pyFunctionName, x, y, a, b, *z); fflush(NULL); + Py_DECREF(pValue); + } + else { + Py_DECREF(pFunc); + Py_DECREF(pModule); + PyErr_Print(); + fprintf(stderr,"Call to %s failed!\n", pyFunctionName); fflush(NULL); + return -1; + } + } + else { + if (PyErr_Occurred()) + PyErr_Print(); + fprintf(stderr, "Cannot find function \"%s\"\n", pyFunctionName); fflush(NULL); + return -1; + } + Py_XDECREF(pFunc); + Py_DECREF(pModule); + } + else { + PyErr_Print(); + fprintf(stderr, "Failed to load \"%s\"\n", pyModuleName); + return -1; + } + return 0; +} + +int omc_PyRun_FiveArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, double c, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z) { + static int runDone = 0; + PyObject *pModule, *pFunc; + PyObject *pArgs, *pValue; + int i, status = -1; + /* set the output to zero first */ + *z = 0; + + if (!omc_PyIsInitialized) { + fprintf(stderr, "omc_PyRun_TwoArgumentsOneReturn: Python is not initialized!\n"); fflush(NULL); + return -1; + } + + /* only run this once! */ + if (!runDone) { + status = PyRun_SimpleString(pyProgram); + runDone = 1; + if (status != 0) { + fprintf(stderr, "Could not run program \n---- Program: ----\n%s\n----------------\n", pyProgram); fflush(NULL); + return -1; + } + } + + pModule = PyImport_ImportModule(pyModuleName); + + if (pModule != NULL) { + pFunc = PyObject_GetAttrString(pModule, pyFunctionName); + + if (pFunc && PyCallable_Check(pFunc)) { + pArgs = PyTuple_New(5); + /* first argument */ + pValue = PyFloat_FromDouble(x); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 0, pValue); + /* second argument */ + pValue = PyFloat_FromDouble(y); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument y: %g to Python float!\n", y); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 1, pValue); + /* third argument */ + pValue = PyFloat_FromDouble(a); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 2, pValue); + /* fourth argument */ + pValue = PyFloat_FromDouble(b); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 3, pValue); + /* fifth argument */ + pValue = PyFloat_FromDouble(c); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 4, pValue); + + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (pValue != NULL) { + *z = PyFloat_AsDouble(pValue); + if (PyErr_Occurred()) { + PyErr_Print(); + fprintf(stderr, "Cannot convert return argument double z from Python float\n!"); fflush(NULL); + return -1; + } + fprintf(stdout, "Result of call: %s(%g, %g, %g, %g, %g) -> %g\n", pyFunctionName, x, y, a, b, c, *z); fflush(NULL); + Py_DECREF(pValue); + } + else { + Py_DECREF(pFunc); + Py_DECREF(pModule); + PyErr_Print(); + fprintf(stderr,"Call to %s failed!\n", pyFunctionName); fflush(NULL); + return -1; + } + } + else { + if (PyErr_Occurred()) + PyErr_Print(); + fprintf(stderr, "Cannot find function \"%s\"\n", pyFunctionName); fflush(NULL); + return -1; + } + Py_XDECREF(pFunc); + Py_DECREF(pModule); + } + else { + PyErr_Print(); + fprintf(stderr, "Failed to load \"%s\"\n", pyModuleName); + return -1; + } + return 0; +} + +int omc_PyRun_SixArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, double c, double d, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z) { + static int runDone = 0; + PyObject *pModule, *pFunc; + PyObject *pArgs, *pValue; + int i, status = -1; + /* set the output to zero first */ + *z = 0; + + if (!omc_PyIsInitialized) { + fprintf(stderr, "omc_PyRun_TwoArgumentsOneReturn: Python is not initialized!\n"); fflush(NULL); + return -1; + } + + /* only run this once! */ + if (!runDone) { + status = PyRun_SimpleString(pyProgram); + runDone = 1; + if (status != 0) { + fprintf(stderr, "Could not run program \n---- Program: ----\n%s\n----------------\n", pyProgram); fflush(NULL); + return -1; + } + } + + pModule = PyImport_ImportModule(pyModuleName); + + if (pModule != NULL) { + pFunc = PyObject_GetAttrString(pModule, pyFunctionName); + + if (pFunc && PyCallable_Check(pFunc)) { + pArgs = PyTuple_New(6); + /* first argument */ + pValue = PyFloat_FromDouble(x); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 0, pValue); + /* second argument */ + pValue = PyFloat_FromDouble(y); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument y: %g to Python float!\n", y); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 1, pValue); + /* third argument */ + pValue = PyFloat_FromDouble(a); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 2, pValue); + /* fourth argument */ + pValue = PyFloat_FromDouble(b); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 3, pValue); + /* fifth argument */ + pValue = PyFloat_FromDouble(c); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 4, pValue); + /* sixth argument */ + pValue = PyFloat_FromDouble(d); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 5, pValue); + + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (pValue != NULL) { + *z = PyFloat_AsDouble(pValue); + if (PyErr_Occurred()) { + PyErr_Print(); + fprintf(stderr, "Cannot convert return argument double z from Python float\n!"); fflush(NULL); + return -1; + } + fprintf(stdout, "Result of call: %s(%g, %g, %g, %g, %g, %g) -> %g\n", pyFunctionName, x, y, a, b, c, d, *z); fflush(NULL); + Py_DECREF(pValue); + } + else { + Py_DECREF(pFunc); + Py_DECREF(pModule); + PyErr_Print(); + fprintf(stderr,"Call to %s failed!\n", pyFunctionName); fflush(NULL); + return -1; + } + } + else { + if (PyErr_Occurred()) + PyErr_Print(); + fprintf(stderr, "Cannot find function \"%s\"\n", pyFunctionName); fflush(NULL); + return -1; + } + Py_XDECREF(pFunc); + Py_DECREF(pModule); + } + else { + PyErr_Print(); + fprintf(stderr, "Failed to load \"%s\"\n", pyModuleName); + return -1; + } + return 0; +} + +int omc_PyRun_NineArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, double c, double d, double e, double f, double g, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z) { + static int runDone = 0; + PyObject *pModule, *pFunc; + PyObject *pArgs, *pValue; + int i, status = -1; + /* set the output to zero first */ + *z = 0; + + if (!omc_PyIsInitialized) { + fprintf(stderr, "omc_PyRun_TwoArgumentsOneReturn: Python is not initialized!\n"); fflush(NULL); + return -1; + } + + /* only run this once! */ + if (!runDone) { + status = PyRun_SimpleString(pyProgram); + runDone = 1; + if (status != 0) { + fprintf(stderr, "Could not run program \n---- Program: ----\n%s\n----------------\n", pyProgram); fflush(NULL); + return -1; + } + } + + pModule = PyImport_ImportModule(pyModuleName); + + if (pModule != NULL) { + pFunc = PyObject_GetAttrString(pModule, pyFunctionName); + + if (pFunc && PyCallable_Check(pFunc)) { + pArgs = PyTuple_New(9); + /* first argument */ + pValue = PyFloat_FromDouble(x); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 0, pValue); + /* second argument */ + pValue = PyFloat_FromDouble(y); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument y: %g to Python float!\n", y); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 1, pValue); + /* third argument */ + pValue = PyFloat_FromDouble(a); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 2, pValue); + /* fourth argument */ + pValue = PyFloat_FromDouble(b); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 3, pValue); + /* fifth argument */ + pValue = PyFloat_FromDouble(c); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 4, pValue); + /* sixth argument */ + pValue = PyFloat_FromDouble(d); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 5, pValue); + /* seventh argument */ + pValue = PyFloat_FromDouble(e); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 6, pValue); + /* eight argument */ + pValue = PyFloat_FromDouble(f); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 7, pValue); + /* ninth argument */ + pValue = PyFloat_FromDouble(g); + if (!pValue) { + Py_DECREF(pArgs); + Py_DECREF(pModule); + fprintf(stderr, "Cannot convert argument x: %g to Python float!\n", x); fflush(NULL); + return -1; + } + /* store it in the tuple, pValue reference stolen here */ + PyTuple_SetItem(pArgs, 8, pValue); + + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (pValue != NULL) { + *z = PyFloat_AsDouble(pValue); + if (PyErr_Occurred()) { + PyErr_Print(); + fprintf(stderr, "Cannot convert return argument double z from Python float\n!"); fflush(NULL); + return -1; + } + fprintf(stdout, "Result of call: %s(%g, %g, %g, %g, %g, %g, %g, %g, %g) -> %g\n", pyFunctionName, x, y, a, b, c, d, e, f, g, *z); fflush(NULL); + Py_DECREF(pValue); + } + else { + Py_DECREF(pFunc); + Py_DECREF(pModule); + PyErr_Print(); + fprintf(stderr,"Call to %s failed!\n", pyFunctionName); fflush(NULL); + return -1; + } + } + else { + if (PyErr_Occurred()) + PyErr_Print(); + fprintf(stderr, "Cannot find function \"%s\"\n", pyFunctionName); fflush(NULL); + return -1; + } + Py_XDECREF(pFunc); + Py_DECREF(pModule); + } + else { + PyErr_Print(); + fprintf(stderr, "Failed to load \"%s\"\n", pyModuleName); + return -1; + } + return 0; +} \ No newline at end of file diff --git a/Resources/C-Sources/OMCallPythonAdvanced.h b/Resources/C-Sources/OMCallPythonAdvanced.h index 540c6ed..2cb9e2f 100644 --- a/Resources/C-Sources/OMCallPythonAdvanced.h +++ b/Resources/C-Sources/OMCallPythonAdvanced.h @@ -13,6 +13,10 @@ extern void omc_Py_Initialize(void* pyHandle); extern void omc_Py_Finalize(void* pyHandle); extern int omc_PyRun_SimpleString(void* pyHandle, const char* program); extern int omc_PyRun_TwoArgumentsOneReturn(void* pyHandle, double x, double y, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z); +extern int omc_PyRun_FourArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z); +extern int omc_PyRun_FiveArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, double c, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z); +extern int omc_PyRun_SixArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, double c, double d, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z); +extern int omc_PyRun_NineArgumentsOneReturn(void* pyHandle, double x, double y, double a, double b, double c, double d, double e, double f, double g, const char* pyProgram, const char* pyModuleName, const char* pyFunctionName, double *z); #endif /* #if !defined(__OMCallPythonAdvanced_H__) */ \ No newline at end of file diff --git a/Resources/Library/win64/libOMCallPythonAdvanced.a b/Resources/Library/win64/libOMCallPythonAdvanced.a index 4861300..1ee49bd 100644 Binary files a/Resources/Library/win64/libOMCallPythonAdvanced.a and b/Resources/Library/win64/libOMCallPythonAdvanced.a differ diff --git a/Resources/Library/win64/python3.dll b/Resources/Library/win64/python3.dll index a46eaa7..6f1b720 100644 Binary files a/Resources/Library/win64/python3.dll and b/Resources/Library/win64/python3.dll differ diff --git a/Resources/Library/win64/python38.dll b/Resources/Library/win64/python38.dll deleted file mode 100644 index 1e0b46c..0000000 Binary files a/Resources/Library/win64/python38.dll and /dev/null differ diff --git a/Resources/Library/win64/python39.dll b/Resources/Library/win64/python39.dll new file mode 100644 index 0000000..a7f081a Binary files /dev/null and b/Resources/Library/win64/python39.dll differ diff --git a/package.mo b/package.mo index dad5005..8254f16 100644 --- a/package.mo +++ b/package.mo @@ -1,21 +1,22 @@ package OMCallPythonAdvanced + extends Modelica.Icons.Package; package Py - + extends Modelica.Icons.FunctionsPackage; class PythonHandle extends ExternalObject; function constructor "External object constructor will intialized python" output PythonHandle pyHandle; - - external "C" pyHandle = omc_PyInit() annotation ( + + external "C" pyHandle = omc_PyInit() annotation( IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", Include = "#include \"OMCallPythonAdvanced.h\""); end constructor; function destructor "External object destructor that frees the python dll" input PythonHandle pyHandle; - - external "C" omc_PyEnd(pyHandle) annotation ( + + external "C" omc_PyEnd(pyHandle) annotation( IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", Include = "#include \"OMCallPythonAdvanced.h\""); end destructor; @@ -23,27 +24,26 @@ package OMCallPythonAdvanced function initialize input PythonHandle pyHandle; - external "C" omc_Py_Initialize(pyHandle) - annotation ( + + external "C" omc_Py_Initialize(pyHandle) annotation( IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", Include = "#include \"OMCallPythonAdvanced.h\"", LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", - Library = {"OMCallPythonAdvanced", "python38"}); + Library = {"OMCallPythonAdvanced", "python39"}); end initialize; function run input PythonHandle pyHandle; input String pyProgram; output Integer status "0 is OK, -1 is bad"; - - external "C" status = omc_PyRun_SimpleString(pyHandle, pyProgram) - annotation ( + + external "C" status = omc_PyRun_SimpleString(pyHandle, pyProgram) annotation( IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", Include = "#include \"OMCallPythonAdvanced.h\"", LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", - Library = {"OMCallPythonAdvanced", "python38"}); + Library = {"OMCallPythonAdvanced", "python39"}); end run; - + function twoRealArgumentsReturnReal input PythonHandle pyHandle; input Real x; @@ -53,24 +53,108 @@ package OMCallPythonAdvanced input String pyFunctionName "the function to call from the module"; output Real z; output Integer status "0 if OK, -1 if error"; - - external "C" status = omc_PyRun_TwoArgumentsOneReturn(pyHandle, x, y, pyProgram, pyModuleName, pyFunctionName, z) - annotation ( + + external "C" status = omc_PyRun_TwoArgumentsOneReturn(pyHandle, x, y, pyProgram, pyModuleName, pyFunctionName, z) annotation( IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", Include = "#include \"OMCallPythonAdvanced.h\"", LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", - Library = {"OMCallPythonAdvanced", "python38"}); + Library = {"OMCallPythonAdvanced", "python39"}); end twoRealArgumentsReturnReal; - function finalize + function fourRealArgumentsReturnReal input PythonHandle pyHandle; + input Real x; + input Real y; + input Real a; + input Real b; + input String pyProgram "python code"; + input String pyModuleName "the module to import"; + input String pyFunctionName "the function to call from the module"; + output Real z; + output Integer status "0 if OK, -1 if error"; + + external "C" status = omc_PyRun_FourArgumentsOneReturn(pyHandle, x, y, a, b, pyProgram, pyModuleName, pyFunctionName, z) annotation( + IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", + Include = "#include \"OMCallPythonAdvanced.h\"", + LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", + Library = {"OMCallPythonAdvanced", "python39"}); + end fourRealArgumentsReturnReal; - external "C" omc_Py_Finalize(pyHandle) - annotation ( + function fiveRealArgumentsReturnReal + input PythonHandle pyHandle; + input Real x; + input Real y; + input Real a; + input Real b; + input Real c; + input String pyProgram "python code"; + input String pyModuleName "the module to import"; + input String pyFunctionName "the function to call from the module"; + output Real z; + output Integer status "0 if OK, -1 if error"; + + external "C" status = omc_PyRun_FiveArgumentsOneReturn(pyHandle, x, y, a, b, c, pyProgram, pyModuleName, pyFunctionName, z) annotation( IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", Include = "#include \"OMCallPythonAdvanced.h\"", LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", - Library = {"OMCallPythonAdvanced", "python38"}); + Library = {"OMCallPythonAdvanced", "python39"}); + end fiveRealArgumentsReturnReal; + + function sixRealArgumentsReturnReal + input PythonHandle pyHandle; + input Real x; + input Real y; + input Real a; + input Real b; + input Real c; + input Real d; + input String pyProgram "python code"; + input String pyModuleName "the module to import"; + input String pyFunctionName "the function to call from the module"; + output Real z; + output Integer status "0 if OK, -1 if error"; + + external "C" status = omc_PyRun_SixArgumentsOneReturn(pyHandle, x, y, a, b, c, d, pyProgram, pyModuleName, pyFunctionName, z) annotation( + IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", + Include = "#include \"OMCallPythonAdvanced.h\"", + LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", + Library = {"OMCallPythonAdvanced", "python39"}); + end sixRealArgumentsReturnReal; + + function nineRealArgumentsReturnReal + input PythonHandle pyHandle; + input Real x; + input Real y; + input Real a; + input Real b; + input Real c; + input Real d; + input Real e; + input Real f; + input Real g; + input String pyProgram "python code"; + input String pyModuleName "the module to import"; + input String pyFunctionName "the function to call from the module"; + output Real z; + output Integer status "0 if OK, -1 if error"; + + external "C" status = omc_PyRun_NineArgumentsOneReturn(pyHandle, x, y, a, b, c, d, e, f, g, pyProgram, pyModuleName, pyFunctionName, z) annotation( + IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", + Include = "#include \"OMCallPythonAdvanced.h\"", + LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", + Library = {"OMCallPythonAdvanced", "python39"}); + end nineRealArgumentsReturnReal; + + function finalize + input PythonHandle pyHandle; + + external "C" omc_Py_Finalize(pyHandle) annotation( + IncludeDirectory = "modelica://OMCallPythonAdvanced/Resources/C-Sources", + Include = "#include \"OMCallPythonAdvanced.h\"", + LibraryDirectory = "modelica://OMCallPythonAdvanced/Resources/Library/", + Library = {"OMCallPythonAdvanced", "python39"}); end finalize; end Py; + +annotation(version="1.0.0"); end OMCallPythonAdvanced;