1 /* ==================================================================== */
2 /* Template toolbox_skeleton */
3 /* This file is released under the 3-clause BSD license. See COPYING-BSD. */
4 /* ==================================================================== */
5 #include "api_scilab.h"
9 /* ==================================================================== */
10 int sci_csub(char *fname)
15 int *piAddressVarOne = NULL;
16 double *pdVarOne = NULL;
20 int *piAddressVarTwo = NULL;
21 double *pdVarTwo = NULL;
24 int m_out = 0, n_out = 0;
27 /* --> result = csub(3,8)
28 /* check that we have only 2 input arguments */
29 /* check that we have only 1 output argument */
30 CheckInputArgument(pvApiCtx, 2, 2);
31 CheckOutputArgument(pvApiCtx, 1, 1);
33 /* get Address of inputs */
34 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
37 printError(&sciErr, 0);
41 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
44 printError(&sciErr, 0);
48 /* check input type */
49 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
52 printError(&sciErr, 0);
56 if ( iType1 != sci_matrix )
58 Scierror(999, "%s: Wrong type for input argument #%d: A scalar expected.\n", fname, 1);
62 sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
65 printError(&sciErr, 0);
69 if ( iType2 != sci_matrix )
71 Scierror(999, "%s: Wrong type for input argument #%d: A scalar expected.\n", fname, 2);
76 sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &m1, &n1, &pdVarOne);
79 printError(&sciErr, 0);
83 sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &m2, &n2, &pdVarTwo);
86 printError(&sciErr, 0);
91 if ( (m1 != n1) && (n1 != 1) )
93 Scierror(999, "%s: Wrong size for input argument #%d: A scalar expected.\n", fname, 1);
96 if ( (m2 != n2) && (n2 != 1) )
98 Scierror(999, "%s: Wrong size for input argument #%d: A scalar expected.\n", fname, 2);
102 /* call c function csub */
103 csub(&pdVarOne[0], &pdVarTwo[0], &dOut);
105 /* create result on stack */
108 createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m_out, n_out, &dOut);
110 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
112 ReturnArguments(pvApiCtx);
116 /* ==================================================================== */