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 #include <localization.h>
11 /* ==================================================================== */
12 int sci_csub(char *fname)
17 int *piAddressVarOne = NULL;
18 double *pdVarOne = NULL;
22 int *piAddressVarTwo = NULL;
23 double *pdVarTwo = NULL;
26 int m_out = 0, n_out = 0;
29 /* --> result = csub(3,8)
30 /* check that we have only 2 input arguments */
31 /* check that we have only 1 output argument */
32 CheckInputArgument(pvApiCtx, 2, 2);
33 CheckOutputArgument(pvApiCtx, 1, 1);
35 /* get Address of inputs */
36 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
39 printError(&sciErr, 0);
43 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
46 printError(&sciErr, 0);
50 /* check input type */
51 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
54 printError(&sciErr, 0);
58 if ( iType1 != sci_matrix )
60 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 1);
64 sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
67 printError(&sciErr, 0);
71 if ( iType2 != sci_matrix )
73 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 2);
78 sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &m1, &n1, &pdVarOne);
81 printError(&sciErr, 0);
85 sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &m2, &n2, &pdVarTwo);
88 printError(&sciErr, 0);
93 if ( (m1 != n1) && (n1 != 1) )
95 Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 1);
98 if ( (m2 != n2) && (n2 != 1) )
100 Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 2);
104 /* call c function csub */
105 csub(&pdVarOne[0], &pdVarTwo[0], &dOut);
107 /* create result on stack */
110 createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m_out, n_out, &dOut);
112 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
114 ReturnArguments(pvApiCtx);
118 /* ==================================================================== */