User`s guide

4 Guidelines for Writing C MEX S-Functions
4-30
/*
* Verify we have a valid XDataEvenlySpaced parameter.
*/
if (!mxIsNumeric(XDATAEVENLYSPACED(S)) ||
!(mxIsDouble(XDATAEVENLYSPACED(S)) ||
mxIsLogical(XDATAEVENLYSPACED(S))) ||
mxIsComplex(XDATAEVENLYSPACED(S)) ||
mxGetNumberOfElements(XDATAEVENLYSPACED(S)) != 1) {
ssSetErrorStatus(S,”3rd, X-evenly-spaced parameter must be scalar
“(0.0=false, 1.0=true)”);
return;
}
/*
* Verify x-data is correctly spaced.
*/
{
int_T i;
boolean_T spacingEqual;
real_T *xData = mxGetPr(XVECT(S));
int_T numEl = mxGetNumberOfElements(XVECT(S));
/*
* spacingEqual is TRUE if user XDataEvenlySpaced
*/
spacingEqual = (mxGetScalar(XDATAEVENLYSPACED(S)) != 0.0);
if (spacingEqual) { /* XData is ‘evenly-spaced’ */
boolean_T badSpacing = FALSE;
real_T spacing = xData[1] - xData[0];
real_T space;
if (spacing <= 0.0) {
badSpacing = TRUE;
} else {
real_T eps = DBL_EPSILON;
for (i = 2; i < numEl; i++) {
space = xData[i] - xData[i-1];
if (space <= 0.0 ||
fabs(space-spacing) >= 128.0*eps*spacing ){
badSpacing = TRUE;
break;
}
}
}
if (badSpacing) {
ssSetErrorStatus(S,”X-vector must be an evenly spaced “
“strictly monotonically increasing vector”);
return;
}