comparison examples/mypow2.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
comparison
equal deleted inserted replaced
16866:a472bfc67b6c 16867:be41c30bcb44
1 #include "mex.h" 1 #include "mex.h"
2 2
3 void 3 void
4 mexFunction (int nlhs, mxArray* plhs[], int nrhs, 4 mexFunction (int nlhs, mxArray* plhs[],
5 const mxArray* prhs[]) 5 int nrhs, const mxArray* prhs[])
6 { 6 {
7 mwSize n;
7 mwIndex i; 8 mwIndex i;
8 mwSize n;
9 double *vri, *vro; 9 double *vri, *vro;
10 10
11 if (nrhs != 1 || ! mxIsNumeric (prhs[0])) 11 if (nrhs != 1 || ! mxIsNumeric (prhs[0]))
12 mexErrMsgTxt ("expects matrix"); 12 mexErrMsgTxt ("ARG1 must be a matrix");
13 13
14 n = mxGetNumberOfElements (prhs[0]); 14 n = mxGetNumberOfElements (prhs[0]);
15 plhs[0] = (mxArray *) mxCreateNumericArray 15 plhs[0] = mxCreateNumericArray
16 (mxGetNumberOfDimensions (prhs[0]), 16 (mxGetNumberOfDimensions (prhs[0]), mxGetDimensions (prhs[0]),
17 mxGetDimensions (prhs[0]), mxGetClassID (prhs[0]), 17 mxGetClassID (prhs[0]), mxIsComplex (prhs[0]));
18 mxIsComplex (prhs[0]));
19 vri = mxGetPr (prhs[0]); 18 vri = mxGetPr (prhs[0]);
20 vro = mxGetPr (plhs[0]); 19 vro = mxGetPr (plhs[0]);
21 20
22 if (mxIsComplex (prhs[0])) 21 if (mxIsComplex (prhs[0]))
23 { 22 {
25 vii = mxGetPi (prhs[0]); 24 vii = mxGetPi (prhs[0]);
26 vio = mxGetPi (plhs[0]); 25 vio = mxGetPi (plhs[0]);
27 26
28 for (i = 0; i < n; i++) 27 for (i = 0; i < n; i++)
29 { 28 {
30 vro [i] = vri [i] * vri [i] - vii [i] * vii [i]; 29 vro[i] = vri[i] * vri[i] - vii[i] * vii[i];
31 vio [i] = 2 * vri [i] * vii [i]; 30 vio[i] = 2 * vri[i] * vii[i];
32 } 31 }
33 } 32 }
34 else 33 else
35 { 34 {
36 for (i = 0; i < n; i++) 35 for (i = 0; i < n; i++)
37 vro [i] = vri [i] * vri [i]; 36 vro[i] = vri[i] * vri[i];
38 } 37 }
39 } 38 }