void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { LcaError theErr; lcaErrorInit(&theErr); LHSCHECK(nlhs, plhs); if ( 1 < nlhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Need one output arg"); goto cleanup; } if ( 0 != nrhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Expected no rhs argument"); goto cleanup; } ezcaDebugOn(); nlhs = 0; cleanup: ERR_CHECK(nlhs, plhs, &theErr); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { LcaError theErr; lcaErrorInit(&theErr); LHSCHECK(nlhs, plhs); if ( 1 < nlhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Need one output arg"); goto cleanup; } if ( 0 != nrhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Expected no rhs argument"); goto cleanup; } if ( ! (plhs[0] = mxCreateDoubleMatrix( 1, 1, mxREAL )) ) { lcaSetError(&theErr, EZCA_FAILEDMALLOC, "Not enough memory"); goto cleanup; } *mxGetPr(plhs[0]) = ezcaGetTimeout(); nlhs = 0; cleanup: ERR_CHECK(nlhs, plhs, &theErr); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { PVs pvs = { {0} }; MultiArgRec args[]={ { sizeof(double), 0, (void**)0 }, { sizeof(double), 0, (void**)0 } }; void *pres[NumberOf(args)]; int i; LcaError theErr; lcaErrorInit(&theErr); LHSCHECK(nlhs, plhs); if ( NumberOf(args) < nlhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Too many output args"); goto cleanup; } if ( 1 != nrhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Expected one rhs argument"); goto cleanup; } for ( i=0; i<NumberOf(args); i++) { args[i].pres = &pres[i]; plhs[i]=0; } if ( buildPVs(prhs[0], &pvs, &theErr) ) goto cleanup; if ( !multi_ezca_get_misc(pvs.names, pvs.m, (MultiEzcaFunc)ezcaGetAlarmLimits, NumberOf(args), args, &theErr) ) goto cleanup; for ( i=0; i<nlhs; i++ ) { if ( !(plhs[i]=mxCreateDoubleMatrix(pvs.m, 1, mxREAL)) ) { lcaSetError(&theErr, EZCA_FAILEDMALLOC, "Not enough memory"); goto cleanup; } memcpy(mxGetPr(plhs[i]), *args[i].pres, pvs.m * args[i].size); } nlhs = 0; /* prevent array destruction if everything is OK */ cleanup: for ( i=0; i<nlhs; i++ ) { if ( plhs[i] ) { mxDestroyArray(plhs[i]); plhs[i] = 0; } } for ( i=0; i<NumberOf(args); i++ ) { if ( args[i].pres ) lcaFree(*args[i].pres); } releasePVs(&pvs); /* do this LAST (in case mexErrMsgTxt is called) */ ERR_CHECK(nlhs, plhs, &theErr); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { PVs pvs = { {0} }; int i,j; LcaError theErr; MultiArgRec args[1]; units_string *strbuf MAY_ALIAS = 0; mxArray *tmp; lcaErrorInit(&theErr); LHSCHECK(nlhs, plhs); if ( nlhs > 1 ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Too many output args"); goto cleanup; } if ( nrhs < 1 || nrhs > 1 ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Expected 1 rhs argument"); goto cleanup; } if ( buildPVs(prhs[0], &pvs, &theErr) ) goto cleanup; MSetArg(args[0], sizeof(units_string), 0, &strbuf); if ( !multi_ezca_get_misc(pvs.names, pvs.m, (MultiEzcaFunc)ezcaGetUnits, NumberOf(args), args, &theErr) ) goto cleanup; /* convert string array to a matlab cell array of matlab strings */ if ( !(plhs[0] = mxCreateCellMatrix(pvs.m, 1)) ) { lcaSetError(&theErr, EZCA_FAILEDMALLOC, "Not enough memory"); goto cleanup; } for ( i = 0; i < pvs.m; i++ ) { if ( !(tmp = mxCreateString((char*)&strbuf[i])) ) { for ( j=0; j<i; j++ ) { mxDestroyArray(mxGetCell(plhs[0],i)); } mxDestroyArray(plhs[0]); plhs[0] = 0; lcaSetError(&theErr, EZCA_FAILEDMALLOC, "Not enough memory"); goto cleanup; } mxSetCell(plhs[0], i, (mxArray*)tmp); } nlhs = 0; cleanup: if ( strbuf ) lcaFree( strbuf ); releasePVs(&pvs); /* do this LAST (in case mexErrMsgTxt is called) */ ERR_CHECK(nlhs, plhs, &theErr); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i,n = 0; const mxArray *tmp; PVs pvs = { {0} }; char type = ezcaNative; LcaError theErr; lcaErrorInit(&theErr); LHSCHECK(nlhs, plhs); if ( nlhs > 1 ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Too many output args"); goto cleanup; } if ( nrhs < 1 || nrhs > 3 ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Expected 1..3 rhs argument"); goto cleanup; } /* check for an optional 'column dimension' argument */ if ( nrhs > 1 ) { if ( ! mxIsNumeric(tmp = prhs[1]) || 1 != mxGetM(tmp) || 1 != mxGetN(tmp) ) { lcaSetError(&theErr, EZCA_INVALIDARG, "2nd argument must be a numeric scalar"); goto cleanup; } n = (int)mxGetScalar( tmp ); } /* check for an optional data type argument */ if ( nrhs > 2 ) { if ( ezcaInvalid == (type = marg2ezcaType( prhs[2], &theErr )) ) { goto cleanup; } } if ( buildPVs(prhs[0], &pvs, &theErr) ) goto cleanup; if ( 0 == multi_ezca_set_mon( pvs.names, pvs.m, type, n, &theErr ) ) { nlhs = 0; } cleanup: releasePVs(&pvs); /* do this LAST (in case mexErrMsgTxt is called) */ ERR_CHECK(nlhs, plhs, &theErr); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i; int *src; int *dst; LcaError *ptheErr = lcaGetLastError(); LcaError theErr; lcaErrorInit(&theErr); LHSCHECK(nlhs, plhs); if ( nlhs > 1 ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Too many output args"); goto cleanup; } if ( nrhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Expected no rhs argument"); goto cleanup; } if ( (i=ptheErr->nerrs) ) { src = ptheErr->errs; } else { i = 1; src = &ptheErr->err; } if ( ! (plhs[0] = mxCreateNumericMatrix( i, 1, mxINT32_CLASS, mxREAL )) ) { lcaSetError(&theErr, EZCA_FAILEDMALLOC, "Not enough memory"); goto cleanup; } dst = (int*)mxGetData(plhs[0]); while ( i-- ) { *dst++ = *src++; } nlhs = 0; cleanup: /* do this LAST (in case mexErrMsgTxt is called) */ ERR_CHECK(nlhs, plhs, &theErr); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { LcaError theErr; float timeout; lcaErrorInit(&theErr); LHSCHECK(nlhs, plhs); if ( 1 < nlhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Need one output arg"); goto cleanup; } if ( 1 != nrhs ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Expected one rhs argument"); goto cleanup; } if ( !mxIsDouble(prhs[0]) || 1 != mxGetM(prhs[0]) || 1 != mxGetN(prhs[0]) ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Need a single numeric argument"); goto cleanup; } timeout = mxGetScalar(prhs[0]); if ( timeout < 0.001 ) { lcaSetError(&theErr, EZCA_INVALIDARG, "Timeout arg must be >= 0.001"); goto cleanup; } ezcaSetTimeout(timeout); nlhs = 0; cleanup: ERR_CHECK(nlhs, plhs, &theErr); }