summaryrefslogtreecommitdiff
path: root/modules/mexlib/examples/mexglx
diff options
context:
space:
mode:
authorShashank2017-05-29 12:40:26 +0530
committerShashank2017-05-29 12:40:26 +0530
commit0345245e860375a32c9a437c4a9d9cae807134e9 (patch)
treead51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/mexlib/examples/mexglx
downloadscilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip
CMSCOPE changed
Diffstat (limited to 'modules/mexlib/examples/mexglx')
-rwxr-xr-xmodules/mexlib/examples/mexglx/README85
-rwxr-xr-xmodules/mexlib/examples/mexglx/foo.c70
-rwxr-xr-xmodules/mexlib/examples/mexglx/libtst.c25
-rwxr-xr-xmodules/mexlib/examples/mexglx/test.dia.ref102
-rwxr-xr-xmodules/mexlib/examples/mexglx/test.sce53
-rwxr-xr-xmodules/mexlib/examples/mexglx/test1.sce45
6 files changed, 380 insertions, 0 deletions
diff --git a/modules/mexlib/examples/mexglx/README b/modules/mexlib/examples/mexglx/README
new file mode 100755
index 000000000..320fab67e
--- /dev/null
+++ b/modules/mexlib/examples/mexglx/README
@@ -0,0 +1,85 @@
+Linking a .mexglx, say foo.mexglx, file with Scilab.
+(Assuming foo.mexglx has been created by the Matlab's mex script).
+
+0/ Here I create the file foo.mexglx using Scilab, just to have a
+ proper foo.mexglx for testing (note that I copy libfoo.so to foo.mexglx
+ but internally the name libfoo.so is contained in foo.mexglx and
+ the dynamic loader will search libfoo.so (see below)).
+
+-->ilib_for_link("foo",['foo.o'],[],"c");
+-->host('cp libfoo.so foo.mexglx');
+
+ If I have matlab
+
+-->host('mex -V4 foo.c');
+
+1/ If necessary, create empty libmx.so libmex.so and libmat.so which
+ could be required by the .mexglx file.
+ (If "ldd foo.mexglx" shows a dependency).
+
+This is done by the following commands:
+
+-->ilib_for_link("mx",[],[],"c");
+-->ilib_for_link("mex",[],[],"c");
+-->ilib_for_link("mat",[],[],"c");
+
+2/link the (almost empty) .so files with Scilab
+
+// Note that this is not really usefull
+//-->link ./libmx.so;
+//-->link ./libmex.so;
+//-->link ./libmat.so;
+
+3/link foo.mexglx with Scilab
+-->link ./foo.mexglx;
+
+4/ Make a dynamic library with the provided C routine (libtst.c file).
+ Note that you can use libtst.c file as is and that the entrypoint
+ MUST BE mexFunction. If you have more than one mexglx files you
+ will need to copy libtst.c and change only the function name
+ (this is described below)
+
+-->ilib_for_link("tst",['libtst.o'],[],"c");
+
+5/At Scilab prompt enter:
+
+-->addinter('./libtst.so','libtst','foo');
+OR addinter ./libtst.so libtst foo to link libtst.so with Scilab.
+Note that foo is the name of the Scilab function.
+
+6/call the mexfunction:
+-->foo(5,'foo')
+
+Note that the mexfunction is called through the libtst function
+using the entrypoint 'libtst' (not mexFunction!).
+If several mexFunction are used, one should build several
+libtst.c file, one for each mexfunction, using a different name
+e.g. libtst1.c libtst2.c ... Each mexFunction must be called through a
+different entrypoint.
+
+Here Makelib and libtst.c are generic files while
+Makextimesy and libxtimesy.c are adapted to xtimesy.mexglx.
+
+*********************************************
+
+OR ...
+ld -shared -o foo.so libtst.so foo.mexglx -rpath `pwd`
+addinter('./foo.so','libtst','foo');
+
+EXAMPLE:
+mexname='xtimesy';
+mputl(strsubst(mgetl('libtst.c'),'libtst',mexname),'lib'+mexname+'.c');
+mputl(strsubst(mgetl('Makelib'),'libtst','lib'+mexname),'Make'+mexname);
+//make -f Makextimesy
+// ld -shared -o xtimesy.so libxtimesy.o xtimesy.mexglx -rpath `pwd`
+//OR :
+link ./libmx.so;
+link ./libmex.so;
+link ./libmat.so;
+link ./xtimesy.mexglx;
+addinter('./libxtimesy.so','xtimesy','xtimesy')
+xtimesy(2,3)
+
+
+
+
diff --git a/modules/mexlib/examples/mexglx/foo.c b/modules/mexlib/examples/mexglx/foo.c
new file mode 100755
index 000000000..025b29557
--- /dev/null
+++ b/modules/mexlib/examples/mexglx/foo.c
@@ -0,0 +1,70 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) INRIA
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+#include <stdio.h>
+#include "mex.h"
+
+#define STRING "hello world"
+
+void ABcopy (double *a, double *b, int mn);
+
+void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+{
+ mxArray *ptrB;
+ double *A, *B;
+ int m, n, it, strl;
+ char *str;
+ if (nrhs != 2)
+ {
+ mexErrMsgTxt("This function requires 2 inputs!");
+ }
+ if (nlhs > 3)
+ {
+ mexErrMsgTxt("This function requires at most 3 outputs!");
+ }
+ if (! mxIsNumeric(prhs[0]))
+ {
+ mexErrMsgTxt("First argument must be numeric matrix.");
+ }
+ if (! mxIsChar(prhs[1]))
+ {
+ mexErrMsgTxt("Second argument must be a string.");
+ }
+ m = mxGetM(prhs[0]);
+ n = mxGetN(prhs[0]);
+ A = mxGetPr(prhs[0]);
+ it = 0;
+ ptrB = mxCreateDoubleMatrix(n, m, it);
+ m = mxGetM(ptrB);
+ n = mxGetN(ptrB);
+ B = mxGetPr(ptrB);
+ ABcopy(A, B, m * n);
+ plhs[0] = prhs[0];
+ plhs[1] = ptrB;
+ m = mxGetM(prhs[1]);
+ strl = mxGetN(prhs[1]);
+ str = mxCalloc(m * strl + 1, sizeof(char));
+ mxGetString(prhs[1], str, m * strl);
+ plhs[2] = mxCreateString(str);
+}
+
+void ABcopy(a, b, mn)
+double *a;
+double *b;
+int mn;
+{
+ int i;
+ for ( i = 0 ; i < mn ; i++)
+ {
+ b[i] = a[i] + 33.0 + i;
+ }
+}
diff --git a/modules/mexlib/examples/mexglx/libtst.c b/modules/mexlib/examples/mexglx/libtst.c
new file mode 100755
index 000000000..0a19c7a38
--- /dev/null
+++ b/modules/mexlib/examples/mexglx/libtst.c
@@ -0,0 +1,25 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) INRIA
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+#include <mex.h>
+extern Gatefunc mexFunction;
+static GenericTable Tab[] =
+{
+ {mex_gateway, mexFunction, "errmsg"},
+};
+
+int C2F(libtst)()
+{
+ Rhs = Max(0, Rhs);
+ (*(Tab[Fin - 1].f))(Tab[Fin - 1].name, Tab[Fin - 1].F);
+ return 0;
+}
diff --git a/modules/mexlib/examples/mexglx/test.dia.ref b/modules/mexlib/examples/mexglx/test.dia.ref
new file mode 100755
index 000000000..3b4cd1e7c
--- /dev/null
+++ b/modules/mexlib/examples/mexglx/test.dia.ref
@@ -0,0 +1,102 @@
+
+// Linking a0.mexglx, say foo.mexglx, file with Scilab.
+
+// (Assuming foo.mexglx has been created by the Matlab's mex script).
+
+// 0/ Here I create the file foo.mexglx using Scilab, just to have a
+
+// proper foo.mexglx for testing
+
+
+ilib_for_link("foo",['foo.o'],[],"c");
+ generate a loader file
+ generate a Makefile
+ running the makefile
+ compilation of foo
+ building shared library (be patient)
+
+host('cp libfoo.so foo.mexglx');
+
+
+// 1/ If necessary, create empty libmx.so libmex.so and libmat.so which
+
+// could be required by the0.mexglx file.
+
+// (If "ldd foo.mexglx" shows a dependency).
+
+// This is done by the following commands:
+
+
+ilib_for_link("mx",[],[],"c");
+ generate a loader file
+ generate a Makefile
+ running the makefile
+ building shared library (be patient)
+
+ilib_for_link("mex",[],[],"c");
+ generate a loader file
+ generate a Makefile
+ running the makefile
+ building shared library (be patient)
+
+ilib_for_link("mat",[],[],"c");
+ generate a loader file
+ generate a Makefile
+ running the makefile
+ building shared library (be patient)
+
+
+// 2/link the (almost empty)0.so files with Scilab
+
+// Note that this is not really usefull
+
+
+//link0./libmx.so;
+
+//link0./libmex.so;
+
+//link0./libmat.so;
+
+
+// 3/link foo.mexglx with Scilab
+
+link0./foo.mexglx;
+shared archive loaded
+Link done
+
+
+// 4/ Make a dynamic library with the provided C routine (libtst.c file).
+
+// Note that you can use libtst.c file as is and that the entrypoint
+
+// MUST BE mexFunction. If you have more than one mexglx files you
+
+// will need to copy libtst.c and change only the function name
+
+// (this is described below)
+
+
+ilib_for_link("tst",['libtst.o'],[],"c");
+ generate a loader file
+ generate a Makefile
+ running the makefile
+ compilation of libtst
+ building shared library (be patient)
+
+
+//5/At Scilab prompt enter:
+
+
+addinter('./libtst.so','libtst','foo');
+shared archive loaded
+
+
+// 6/call the mexfunction:
+
+
+foo(5,'test string')
+ ans =
+
+ 5.
+
+
diff --git a/modules/mexlib/examples/mexglx/test.sce b/modules/mexlib/examples/mexglx/test.sce
new file mode 100755
index 000000000..2a81e22e0
--- /dev/null
+++ b/modules/mexlib/examples/mexglx/test.sce
@@ -0,0 +1,53 @@
+
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+// Linking a .mexglx, say foo.mexglx, file with Scilab.
+// (Assuming foo.mexglx has been created by the Matlab's mex script).
+// 0/ Here I create the file foo.mexglx using Scilab, just to have a
+// proper foo.mexglx for testing
+
+ilib_for_link("foo",["foo.o"],[],"c");
+host("cp libfoo.so foo.mexglx");
+
+// 1/ If necessary, create empty libmx.so libmex.so and libmat.so which
+// could be required by the .mexglx file.
+// (If "ldd foo.mexglx" shows a dependency).
+// This is done by the following commands:
+
+ilib_for_link("mx",[],[],"c");
+ilib_for_link("mex",[],[],"c");
+ilib_for_link("mat",[],[],"c");
+
+// 2/link the (almost empty) .so files with Scilab
+// Note that this is not really usefull
+
+//link ./libmx.so;
+//link ./libmex.so;
+//link ./libmat.so;
+
+// 3/link foo.mexglx with Scilab
+link ./foo.mexglx;
+
+// 4/ Make a dynamic library with the provided C routine (libtst.c file).
+// Note that you can use libtst.c file as is and that the entrypoint
+// MUST BE mexFunction. If you have more than one mexglx files you
+// will need to copy libtst.c and change only the function name
+// (this is described below)
+
+ilib_for_link("tst",["libtst.o"],[],"c");
+
+//5/At Scilab prompt enter:
+
+addinter("./libtst.so","libtst","foo");
+
+// 6/call the mexfunction:
+
+foo(5,"test string")
+
diff --git a/modules/mexlib/examples/mexglx/test1.sce b/modules/mexlib/examples/mexglx/test1.sce
new file mode 100755
index 000000000..41c2eb46f
--- /dev/null
+++ b/modules/mexlib/examples/mexglx/test1.sce
@@ -0,0 +1,45 @@
+
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+// Linking a .mexglx, say foo.mexglx, file with Scilab.
+// (Assuming foo.mexglx has been created by the Matlab's mex script).
+// 0/ Here I create the file foo.mexglx using Scilab, just to have a
+// proper foo.mexglx for testing
+
+ilib_for_link("foo",["foo.o"],[],"c");
+host("cp libfoo.so foo.mexglx");
+
+// 1/ If necessary, create empty libmx.so libmex.so and libmat.so which
+// could be required by the .mexglx file.
+// (If "ldd foo.mexglx" shows a dependency).
+// This is done by the following commands:
+
+ilib_for_link("mx",[],[],"c");
+ilib_for_link("mex",[],[],"c");
+ilib_for_link("mat",[],[],"c");
+
+// 4/ Make a dynamic library with the provided C routine (libtst.c file).
+// Note that you can use libtst.c file as is and that the entrypoint
+// MUST BE mexFunction. If you have more than one mexglx files you
+// will need to copy libtst.c and change only the function name
+// (this is described below)
+
+// just make a lib*.so from ./foo.mexglx or else libtool will ignore ./foo.mexglx
+
+host("cp ./foo.mexglx libfoo_mex.so")
+ilib_for_link("tst",["libtst.o"]," -R`pwd` -L`pwd` -lfoo_mex -lmx -lmex -lmat","c");
+
+//5/At Scilab prompt enter:
+
+addinter("./libtst.so","libtst","foo");
+
+// 6/call the mexfunction:
+
+foo(5,"test string")