git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11868 626c5289-ae23-0410-ae9c-e8d60b6d4f22
81 lines
1.4 KiB
C
81 lines
1.4 KiB
C
#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);
|
|
/*
|
|
* 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;
|
|
|
|
}
|