1 /* ============================================== */
2 #include "api_scilab.h"
3 #include "sciprint.h"
4 #include "Scierror.h"
5 /* ============================================== */
6 /* Interfaces for c fonctions */
7 /* ============================================== */
8 void c_sum(double *b, double *c, double *a);
9 void c_sub(double *b, double *c, double *a);
10 /* ============================================== */
c_intsum(char * fname,void * pvApiCtx)11 int c_intsum(char *fname, void * pvApiCtx)
12 {
13 int rows1 = 0, cols1 = 0, rows2 = 0, cols2 = 0, rows3 = 1, cols3 = 1;
14 int minlhs = 0, maxlhs = 1, minrhs = 2, maxrhs = 2;
15
16 double *pdbl1 = NULL, *pdbl2 = NULL, *pdblOut = NULL;
17 int* piAddr1 = NULL;
18 int* piAddr2 = NULL;
19 int* piAddr3 = NULL;
20
21 SciErr sciErr;
22
23 /* Check number of inputs (rhs=2) and outputs (lhs=1) */
24 CheckRhs(minrhs, maxrhs) ;
25 CheckLhs(minlhs, maxlhs) ;
26
27
28 /* Get Qdata (#1) and Param (#2) and create C (#3) as double ("d") matrices */
29 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
30 if (sciErr.iErr)
31 {
32 printError(&sciErr, 0);
33 return 0;
34 }
35 sciErr = getVarDimension(pvApiCtx, piAddr1, &rows1, &cols1);
36 if (sciErr.iErr)
37 {
38 printError(&sciErr, 0);
39 return 0;
40 }
41 sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &rows1, &cols1, &pdbl1);
42 if (sciErr.iErr)
43 {
44 printError(&sciErr, 0);
45 return 0;
46 }
47
48 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
49 if (sciErr.iErr)
50 {
51 printError(&sciErr, 0);
52 return 0;
53 }
54 sciErr = getVarDimension(pvApiCtx, piAddr2, &rows2, &cols2);
55 if (sciErr.iErr)
56 {
57 printError(&sciErr, 0);
58 return 0;
59 }
60 sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &rows2, &cols2, &pdbl2);
61 if (sciErr.iErr)
62 {
63 printError(&sciErr, 0);
64 return 0;
65 }
66
67
68
69 sciErr = allocMatrixOfDouble(pvApiCtx, Rhs + 1, rows3, cols3, &pdblOut);
70 if (sciErr.iErr)
71 {
72 printError(&sciErr, 0);
73 return 0;
74 }
75
76
77 /* Check dimensions */
78 if (!(rows1 == 1) | !(cols1 == 1))
79 {
80 sciprint("%s: Wrong inputs \r\n", "c_fun");
81 SciError(999);
82 return 0;
83 }
84 if (!(rows2 == 1) | !(cols2 == 1))
85 {
86 sciprint("%s: Wrong inputs \r\n", "c_fun");
87 SciError(999);
88 return 0;
89 }
90
91 /* Call c_fun */
92 c_sum(pdbl1, pdbl2, pdblOut);
93
94 /* Return result */
95 LhsVar(1) = Rhs + 1;
96 PutLhsVar();
97 return 0;
98 }
99 /* ============================================== */
c_intsub(char * fname,void * pvApiCtx)100 int c_intsub(char *fname, void * pvApiCtx)
101 {
102 int rows1 = 0, cols1 = 0, rows2 = 0, cols2 = 0, rows3 = 1, cols3 = 1;
103 int minlhs = 0, maxlhs = 1, minrhs = 2, maxrhs = 2;
104
105 double *pdbl1 = NULL, *pdbl2 = NULL, *pdblOut = NULL;
106 int* piAddr1 = NULL;
107 int* piAddr2 = NULL;
108 int* piAddr3 = NULL;
109
110 SciErr sciErr;
111 /* Check number of inputs (rhs=2) and outputs (lhs=1) */
112 CheckRhs(minrhs, maxrhs) ;
113 CheckLhs(minlhs, maxlhs) ;
114
115 /* Get Qdata (#1) and Param (#2) and create C (#3) as double ("d") matrices */
116 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
117 if (sciErr.iErr)
118 {
119 printError(&sciErr, 0);
120 return 0;
121 }
122 sciErr = getVarDimension(pvApiCtx, piAddr1, &rows1, &cols1);
123 if (sciErr.iErr)
124 {
125 printError(&sciErr, 0);
126 return 0;
127 }
128 sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &rows1, &cols1, &pdbl1);
129 if (sciErr.iErr)
130 {
131 printError(&sciErr, 0);
132 return 0;
133 }
134
135 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
136 if (sciErr.iErr)
137 {
138 printError(&sciErr, 0);
139 return 0;
140 }
141 sciErr = getVarDimension(pvApiCtx, piAddr2, &rows2, &cols2);
142 if (sciErr.iErr)
143 {
144 printError(&sciErr, 0);
145 return 0;
146 }
147 sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &rows2, &cols2, &pdbl2);
148 if (sciErr.iErr)
149 {
150 printError(&sciErr, 0);
151 return 0;
152 }
153
154 sciErr = allocMatrixOfDouble(pvApiCtx, Rhs + 1, rows3, cols3, &pdblOut);
155 if (sciErr.iErr)
156 {
157 printError(&sciErr, 0);
158 return 0;
159 }
160
161
162 /* Check dimensions */
163 if (!(rows1 == 1) | !(cols1 == 1))
164 {
165 sciprint("%s: Wrong inputs \r\n", "c_fun");
166 SciError(999);
167 return 0;
168 }
169 if (!(rows2 == 1) | !(cols2 == 1))
170 {
171 sciprint("%s: Wrong inputs \r\n", "c_fun");
172 SciError(999);
173 return 0;
174 }
175
176 /* Call c_fun */
177 c_sub(pdbl1, pdbl2, pdblOut);
178
179 /* Return result */
180 LhsVar(1) = Rhs + 1;
181 PutLhsVar();
182
183 return 0;
184 }
185 /* ============================================== */
c_sum(double * b,double * c,double * a)186 void c_sum(double *b, double *c, double *a)
187 {
188 *a = *b + *c;
189 }
190 /* ============================================== */
c_sub(double * b,double * c,double * a)191 void c_sub(double *b, double *c, double *a)
192 {
193 *a = *b - *c;
194 }
195 /* ============================================== */
196