example of a missing feature. Thanks sploving ;)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11867 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d8a371808a
commit
b585321009
6 changed files with 150 additions and 0 deletions
13
Examples/scilab/matrix2/README
Normal file
13
Examples/scilab/matrix2/README
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
Removes:
|
||||||
|
builder.sce => should be generated by swig
|
||||||
|
main.c => this only shows how the code can be used when matrixlib.c is a lib.
|
||||||
|
sci_sumitems.c => should be generated by swig
|
||||||
|
|
||||||
|
Missing:
|
||||||
|
matrixlib.i
|
||||||
|
Makefile
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
scilab -nwni -f builder.sce
|
||||||
|
exec loader.sce
|
||||||
|
exec runme.sci
|
||||||
6
Examples/scilab/matrix2/builder.sce
Normal file
6
Examples/scilab/matrix2/builder.sce
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
files=['matrixlib.c','sci_sumitems.c'];//,'sci_getValues.c'];
|
||||||
|
ilib_build('build_c',['sumitems','sci_sumitems';'generateValues','sci_getValues'],files,[]);
|
||||||
|
|
||||||
24
Examples/scilab/matrix2/main.c
Normal file
24
Examples/scilab/matrix2/main.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
double sumitems(double *first, int nbRow, int nbCol);
|
||||||
|
void main(){
|
||||||
|
/**
|
||||||
|
* --> myMatrix=[ 103 3 1 12;0 0 2043 1];
|
||||||
|
* --> sumitems(myMatrix);
|
||||||
|
* 32
|
||||||
|
*/
|
||||||
|
double B[] = {1,3,4,9,2,8,3,2}; /* Declare the matrix */
|
||||||
|
int rowB = 2, colB = 4;
|
||||||
|
printf("sumitems: %6.2f\n",sumitems(B, rowB, colB));
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --> myOtherMatrix=generateValues();
|
||||||
|
* --> size(myOtherMatrix);
|
||||||
|
*/
|
||||||
|
int numberRow, numberCol, i;
|
||||||
|
double * matrix=getValues(&numberRow, &numberCol);
|
||||||
|
printf("Matrix of size [%d,%d]",numberRow, numberCol);
|
||||||
|
for(i=0; i < numberRow*numberCol; i++)
|
||||||
|
{
|
||||||
|
printf("A[%d] = %5.2f\n",i,matrix[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Examples/scilab/matrix2/matrixlib.c
Normal file
19
Examples/scilab/matrix2/matrixlib.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
double sumitems(double *first, int nbRow, int nbCol) {
|
||||||
|
int i;
|
||||||
|
double total;
|
||||||
|
for (i=0; i<(nbRow*nbCol); i++) {
|
||||||
|
total+=first[i];
|
||||||
|
}
|
||||||
|
printf("plop: %6.2f\n",total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
double* getValues(int *numberOfRow, int *numberOfCol) {
|
||||||
|
*numberOfRow=23; *numberOfCol=3;
|
||||||
|
double *tempMatrix = (double*)malloc(sizeof(double) * *numberOfRow * *numberOfCol);
|
||||||
|
int i;
|
||||||
|
for (i=0; i<((*numberOfRow)*(*numberOfCol)); i++) {
|
||||||
|
tempMatrix[i]=i*2;
|
||||||
|
}
|
||||||
|
return tempMatrix;
|
||||||
|
}
|
||||||
6
Examples/scilab/matrix2/runme.sci
Normal file
6
Examples/scilab/matrix2/runme.sci
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
myMatrix=[ 103 3 1 12;0 0 2043 1];
|
||||||
|
sumitems(myMatrix);
|
||||||
|
|
||||||
|
myOtherMatrix=generateValues();
|
||||||
|
size(myOtherMatrix)
|
||||||
|
disp(myOtherMatrix);
|
||||||
82
Examples/scilab/matrix2/sci_sumitems.c
Normal file
82
Examples/scilab/matrix2/sci_sumitems.c
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
#include "api_scilab.h"
|
||||||
|
#include "stack-c.h"
|
||||||
|
double sumitems(double *first, int nbRow, int nbCol);
|
||||||
|
double* getValues(int *numberOfRow, int *numberOfCol);
|
||||||
|
|
||||||
|
int sci_sumitems(char *fname,unsigned long fname_len)
|
||||||
|
{
|
||||||
|
|
||||||
|
int iRows = 0;
|
||||||
|
int iCols = 0;
|
||||||
|
|
||||||
|
int *piAddr = NULL;
|
||||||
|
double* pdblReal = NULL;
|
||||||
|
|
||||||
|
CheckRhs(1,1);
|
||||||
|
CheckLhs(1,1);
|
||||||
|
|
||||||
|
SciErr sciErr;
|
||||||
|
|
||||||
|
//get variable address of the first input argument
|
||||||
|
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
|
||||||
|
if(sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
|
||||||
|
|
||||||
|
double plop = sumitems(pdblReal, iRows, iCols);
|
||||||
|
printf("plop: %6.2f\n",plop);
|
||||||
|
/*
|
||||||
|
* Here, it is a scalar but it could be also a matrix... don't assume it
|
||||||
|
* it will be always 1x1
|
||||||
|
*/
|
||||||
|
int iRowsReturn=1;
|
||||||
|
int iColReturn=1;
|
||||||
|
sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, iRowsReturn, iColReturn, &plop);
|
||||||
|
|
||||||
|
if(sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LhsVar(1) = Rhs + 1;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int sci_getValues(char *fname,unsigned long fname_len)
|
||||||
|
{
|
||||||
|
|
||||||
|
int iRows = 0;
|
||||||
|
int iCols = 0;
|
||||||
|
|
||||||
|
int *piAddr = NULL;
|
||||||
|
double* pdblReal = NULL;
|
||||||
|
|
||||||
|
CheckRhs(0,0);
|
||||||
|
CheckLhs(1,1);
|
||||||
|
|
||||||
|
SciErr sciErr;
|
||||||
|
|
||||||
|
|
||||||
|
int numberRow, numberCol, i;
|
||||||
|
double * matrix=getValues(&numberRow, &numberCol);
|
||||||
|
|
||||||
|
sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, numberRow, numberCol, matrix);
|
||||||
|
|
||||||
|
if(sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LhsVar(1) = Rhs + 1;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue