Beispiel #1
0
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);
}
Beispiel #2
0
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);
}