annotate examples/mystruct.c @ 16867:be41c30bcb44

Re-write documentation and all examples of dynamically linked functions. * doc/interpreter/dynamic.txi: deleted. * doc/interpreter/external.txi: Renamed from dynamic.txi. Rewrote or added much information about dynamically linked functions. * doc/interpreter/Makefile.am: Changed dynamic.txi to external.txi in build system. * doc/interpreter/data.txi, doc/interpreter/intro.txi, doc/interpreter/octave.texi, doc/interpreter/sparse.txi: Changed dynamic.txi to external.txi in cross-references. * doc/interpreter/doccheck/aspell-octave.en.pws: Added new words from external.txi to Octave dictionary. * examples/firstmexdemo.c: deleted. * examples/mex_demo.c: Renamed from firstmexdemo.c. Added many more comments to code. * examples/hello.cc: deleted. * examples/oct_demo.cc: Renamed from hello.cc. Added many more comments to code. * examples/Makefile.am: Changed build system to use mex_demo.c and oct_demo.cc. * examples/addtwomatrices.cc, examples/celldemo.cc, examples/embedded.cc, examples/fortdemo.cc, examples/funcdemo.cc, examples/globaldemo.cc, examples/helloworld.cc, examples/mycell.c, examples/myfeval.c, examples/myfunc.c, examples/myhello.c, examples/mypow2.c, examples/myprop.c, examples/myset.c, examples/mysparse.c, examples/mystring.c, examples/mystruct.c, examples/paramdemo.cc, examples/standalone.cc, examples/stringdemo.cc, examples/structdemo.cc, examples/unwinddemo.cc: Use Octave coding conventions for code. Fixed all compilation errors and warnings.
author Rik <rik@octave.org>
date Sat, 29 Jun 2013 18:08:24 -0700
parents 6cb30a539481
children 224e76250443
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
1 #include "mex.h"
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
2
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
3 void
16867
be41c30bcb44 Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents: 9932
diff changeset
4 mexFunction (int nlhs, mxArray* plhs[],
be41c30bcb44 Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents: 9932
diff changeset
5 int nrhs, const mxArray* prhs[])
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
6 {
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 6581
diff changeset
7 int i;
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 6581
diff changeset
8 mwIndex j;
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
9 mxArray *v;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
10 const char *keys[] = { "this", "that" };
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
11
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
12 if (nrhs != 1 || ! mxIsStruct (prhs[0]))
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
13 mexErrMsgTxt ("expects struct");
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
14
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
15 for (i = 0; i < mxGetNumberOfFields (prhs[0]); i++)
6581
1a414f670635 [project @ 2007-04-25 22:34:52 by jwe]
jwe
parents: 6580
diff changeset
16 for (j = 0; j < mxGetNumberOfElements (prhs[0]); j++)
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
17 {
6580
d2bb3b8a8d20 [project @ 2007-04-25 22:19:03 by dbateman]
dbateman
parents: 5864
diff changeset
18 mexPrintf ("field %s(%d) = ",
d2bb3b8a8d20 [project @ 2007-04-25 22:19:03 by dbateman]
dbateman
parents: 5864
diff changeset
19 mxGetFieldNameByNumber (prhs[0], i), j);
d2bb3b8a8d20 [project @ 2007-04-25 22:19:03 by dbateman]
dbateman
parents: 5864
diff changeset
20 v = mxGetFieldByNumber (prhs[0], j, i);
16867
be41c30bcb44 Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents: 9932
diff changeset
21 mexCallMATLAB (0, NULL, 1, &v, "disp");
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
22 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
23
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
24 v = mxCreateStructMatrix (2, 2, 2, keys);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
25
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
26 mxSetFieldByNumber (v, 0, 0, mxCreateString ("this1"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
27 mxSetFieldByNumber (v, 0, 1, mxCreateString ("that1"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
28 mxSetFieldByNumber (v, 1, 0, mxCreateString ("this2"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
29 mxSetFieldByNumber (v, 1, 1, mxCreateString ("that2"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
30 mxSetFieldByNumber (v, 2, 0, mxCreateString ("this3"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
31 mxSetFieldByNumber (v, 2, 1, mxCreateString ("that3"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
32 mxSetFieldByNumber (v, 3, 0, mxCreateString ("this4"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
33 mxSetFieldByNumber (v, 3, 1, mxCreateString ("that4"));
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
34
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
35 if (nlhs)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
36 plhs[0] = v;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents:
diff changeset
37 }