// are also available at␊ |
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt␊ |
␊ |
/* -------------------------------------------------------------------------- */␊ |
/* This gateway uses the new scilab api␊ |
/* -------------------------------------------------------------------------- */␊ |
␊ |
#include "machine.h"␊ |
#include "Scierror.h"␊ |
#include "api_scilab.h"␊ |
|
␊ |
#include "accsum.h"␊ |
␊ |
// s = accsum_fcompsum(x) ␊ |
// [s,e] = accsum_fcompsum(x) ␊ |
// s = accsum_fcompsum(x)␊ |
// [s,e] = accsum_fcompsum(x)␊ |
// returns the sum of x, with a compensated summation.␊ |
int sci_accsum_fcompsum (char * fname, void* pvApiCtx) {␊ |
#if SCI_VERSION_MAJOR < 6␊ |
int sci_accsum_fcompsum(char * fname)␊ |
#else␊ |
int sci_accsum_fcompsum(char * fname, void * pvApiCtx)␊ |
#endif␊ |
{␊ |
␊ |
␉SciErr sciErr;␊ |
␉int *piAddr = NULL;␊ |
␉int iType = 0;␊ |
␉int rowsX,colsX;␊ |
␉double* lX = NULL;␊ |
␉int iComplex = 0;␊ |
␉int i;␊ |
double s;␊ |
double e;␊ |
SciErr sciErr;␊ |
int * piAddr = NULL;␊ |
int iType = 0;␊ |
int rowsX;␊ |
int colsX;␊ |
double * lX = NULL;␊ |
int iComplex = 0;␊ |
int i;␊ |
double s;␊ |
double e;␊ |
␊ |
␉int minlhs=1, minrhs=1, maxlhs=2, maxrhs=1;␊ |
int minlhs = 1;␊ |
int minrhs = 1;␊ |
int maxlhs = 2;␊ |
int maxrhs = 1;␊ |
␊ |
␉CheckRhs(minrhs,maxrhs) ;␊ |
␉CheckLhs(minlhs,maxlhs) ;␊ |
CheckRhs(minrhs, maxrhs) ;␊ |
CheckLhs(minlhs, maxlhs) ;␊ |
␊ |
␉//␊ |
␉// Read X␊ |
␉//␊ |
␉sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);␊ |
␉if(sciErr.iErr)␊ |
␉{␊ |
␉␉printError(&sciErr, 0);␊ |
␉␉return 0;␊ |
␉}␊ |
␉sciErr = getVarType(pvApiCtx, piAddr, &iType);␊ |
␉if(sciErr.iErr)␊ |
␉{␊ |
␉␉printError(&sciErr, 0);␊ |
␉␉return 0;␊ |
␉}␊ |
␉if ( iType != sci_matrix ) ␊ |
␉{␊ |
␉␉Scierror(999,_("%s: Wrong type for input argument #%d. Matrix expected.\n"),fname,1);␊ |
␉␉return 0;␊ |
␉}␊ |
␉iComplex␉= isVarComplex(pvApiCtx, piAddr);␊ |
␉if ( iComplex == 1 ) ␊ |
␉{␊ |
␉␉Scierror(999,_("%s: Wrong content for input argument #%d. Real matrix expected.\n"),fname,1);␊ |
␉␉return 0;␊ |
␉}␊ |
␉sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsX, &colsX, &lX);␊ |
␉if(sciErr.iErr)␊ |
␉{␊ |
␉␉printError(&sciErr, 0);␊ |
␉␉return 0;␊ |
␉}␊ |
␉//␊ |
␉// Perform the sum␊ |
␉//␊ |
//␊ |
// Read X␊ |
//␊ |
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);␊ |
if(sciErr.iErr)␊ |
{␊ |
printError(&sciErr, 0);␊ |
return 1;␊ |
}␊ |
sciErr = getVarType(pvApiCtx, piAddr, &iType);␊ |
if(sciErr.iErr)␊ |
{␊ |
printError(&sciErr, 0);␊ |
return 1;␊ |
}␊ |
if ( iType != sci_matrix )␊ |
{␊ |
Scierror(999, _("%s: Wrong type for input argument #%d. "␊ |
"Matrix expected.\n"),␊ |
fname, 1);␊ |
return 1;␊ |
}␊ |
iComplex = isVarComplex(pvApiCtx, piAddr);␊ |
if ( iComplex == 1 )␊ |
{␊ |
Scierror(999, _("%s: Wrong content for input argument #%d. "␊ |
"Real matrix expected.\n"),␊ |
fname, 1);␊ |
return 1;␊ |
}␊ |
sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsX, &colsX, &lX);␊ |
if(sciErr.iErr)␊ |
{␊ |
printError(&sciErr, 0);␊ |
return 1;␊ |
}␊ |
//␊ |
// Perform the sum␊ |
//␊ |
accsum_fcompsum(lX, rowsX*colsX, &s, &e);␊ |
//␊ |
// Set LHS␊ |
|
if(sciErr.iErr)␊ |
{␊ |
printError(&sciErr, 0);␊ |
return 0;␊ |
return 1;␊ |
}␊ |
LhsVar(1) = Rhs+1;␊ |
} ␊ |
}␊ |
if ( Lhs==2 )␊ |
{␊ |
//␊ |
|
if(sciErr.iErr)␊ |
{␊ |
printError(&sciErr, 0);␊ |
return 0;␊ |
return 1;␊ |
}␊ |
LhsVar(2) = Rhs+2;␊ |
}␊ |
␉return(0);␊ |
return 0;␊ |
}␊ |
␊ |