1 /* Copyright Inria/Enpc *//*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) INRIA/ENPC
4 *
5 * This file is released under the 3-clause BSD license. See COPYING-BSD.
6 *
7 */
8
9 /************************************
10 * (very) simple example 1
11 * with a C wrapper
12 * -->link('ext1c.o','ext1cI','C');
13 * -->a=[1,2,3];b=[4,5,6];n=3;
14 * -->c=call('ext1cI',n,a,b)
15 * c=a+b
16 ************************************/
17
18 #include "stack-c.h"
19
ext14cI(char * fname)20 int ext14cI(char *fname)
21 {
22 int m1, n1, l1, m2, n2, l2, m3, n3, l3, n, l4;
23 int minlhs = 0, minrhs = 3, maxlhs = 1, maxrhs = 3;
24 Nbvars = 0;
25 CheckRhs(minrhs, maxrhs) ;
26 CheckLhs(minlhs, maxlhs) ;
27 GetRhsVar( 1, STRING_DATATYPE, &m1, &n1, &l1);
28 GetRhsVar( 2, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2);
29 GetRhsVar( 3, MATRIX_OF_DOUBLE_DATATYPE, &m3, &n3, &l3);
30 if ( m3 * n3 != m2 * n2)
31 {
32 sciprint("%s :Incompatible dimensions\n", fname);
33 SciError(999);
34 return (0);
35 }
36 CreateVar( 4, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l4);
37 n = m3 * n3;
38 ext14c(&n, stk(l2), stk(l3), stk(l4));
39 LhsVar(1) = 4;
40 PutLhsVar();
41 return (0);
42 }
43
44
ext14c(n,a,b,c)45 int ext14c(n, a, b, c)
46 int *n;
47 double *a, *b, *c;
48 {
49 int k;
50 for (k = 0; k < *n; ++k)
51 {
52 c[k] = a[k] + b[k];
53 }
54 return (0);
55 }
56
57