SWZ: make mex files return error code

time-shift
Houtan Bastani 2011-05-16 16:39:13 +02:00
parent 5fa666e448
commit cd021d33f6
4 changed files with 44 additions and 44 deletions

View File

@ -53,8 +53,8 @@ mexFunction(int nlhs, mxArray *plhs[],
if (!mxIsDouble(prhs[1])) if (!mxIsDouble(prhs[1]))
DYN_MEX_FUNC_ERR_MSG_TXT("Second argument is a vector of free parameters"); DYN_MEX_FUNC_ERR_MSG_TXT("Second argument is a vector of free parameters");
if (nlhs < 3) if (nlhs < 4)
DYN_MEX_FUNC_ERR_MSG_TXT("You must specify at least three output arguments [A0,Aplus,Zeta]"); DYN_MEX_FUNC_ERR_MSG_TXT("You must specify at least four output arguments [err,A0,Aplus,Zeta]");
// copy the string data from prhs[0] into a C string input_ buf. */ // copy the string data from prhs[0] into a C string input_ buf. */
input_buf = mxArrayToString(prhs[0]); input_buf = mxArrayToString(prhs[0]);
@ -86,17 +86,17 @@ mexFunction(int nlhs, mxArray *plhs[],
// Ao (nstates x nvars x nvars) // Ao (nstates x nvars x nvars)
mwSize dims[3] = {nstates, nvars, nvars}; mwSize dims[3] = {nstates, nvars, nvars};
plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
a0 = mxGetPr(plhs[0]); a0 = mxGetPr(plhs[1]);
// Zeta (nstates x nvars x nvars) // Zeta (nstates x nvars x nvars)
plhs[2] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[3] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
zeta = mxGetPr(plhs[2]); zeta = mxGetPr(plhs[3]);
// Aplus (nstates x (nlags*nvars +nconstant) x nvars) // Aplus (nstates x (nlags*nvars +nconstant) x nvars)
dims[1] = npre; dims[1] = npre;
plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[2] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
aplus = mxGetPr(plhs[1]); aplus = mxGetPr(plhs[2]);
// Grand Transition Matrix // Grand Transition Matrix
Q = mxCreateDoubleMatrix(nstates, nstates, mxREAL); Q = mxCreateDoubleMatrix(nstates, nstates, mxREAL);
@ -112,11 +112,11 @@ mexFunction(int nlhs, mxArray *plhs[],
} }
// if they have passed 4 arguments then pass back Q // if they have passed 4 arguments then pass back Q
if (nlhs > 3) if (nlhs > 4)
plhs[3] = Q; plhs[4] = Q;
mxFree(model); mxFree(model);
plhs[0] = mxCreateDoubleScalar(0);
} }
#endif #endif

View File

@ -54,8 +54,8 @@ mexFunction(int nlhs, mxArray *plhs[],
// Check the left hand and right hand side arguments to make sure they conform // Check the left hand and right hand side arguments to make sure they conform
if (mxIsChar(prhs[0]) != 1) if (mxIsChar(prhs[0]) != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename."); DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename.");
if (nlhs != 1) if (nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("You must specify one output argument"); DYN_MEX_FUNC_ERR_MSG_TXT("You must specify two output arguments.");
// copy the string data from prhs[0] into a C string input_ buf. */ // copy the string data from prhs[0] into a C string input_ buf. */
input_buf = mxArrayToString(prhs[0]); input_buf = mxArrayToString(prhs[0]);
@ -81,30 +81,30 @@ mexFunction(int nlhs, mxArray *plhs[],
{ {
// regimes x percentile x horizon x nvar // regimes x percentile x horizon x nvar
mwSize dims[4] = {nstates, options->num_percentiles, options->horizon, nvars}; mwSize dims[4] = {nstates, options->num_percentiles, options->horizon, nvars};
plhs[0] = mxCreateNumericArray(4, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(4, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
{ {
// regimes x horizon x (nvar*nvar) // regimes x horizon x (nvar*nvar)
mwSize dims[3] = {nstates, options->horizon, nvars}; mwSize dims[3] = {nstates, options->horizon, nvars};
plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
if (options->num_percentiles > 1) if (options->num_percentiles > 1)
{ {
// percentile x horizon x (nvar*nvar) // percentile x horizon x (nvar*nvar)
mwSize dims[3] = {options->num_percentiles, options->horizon, nvars}; mwSize dims[3] = {options->num_percentiles, options->horizon, nvars};
plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
{ {
// horizon x (nvar*nvar) // horizon x (nvar*nvar)
mwSize dims[2] = {options->horizon, nvars}; mwSize dims[2] = {options->horizon, nvars};
plhs[0] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
// hard coding dates for now to be off // hard coding dates for now to be off
@ -188,7 +188,7 @@ mexFunction(int nlhs, mxArray *plhs[],
mxFree(p); mxFree(p);
mxFree(model); mxFree(model);
plhs[0] = mxCreateDoubleScalar(0);
} }
#endif #endif

View File

@ -52,8 +52,8 @@ mexFunction(int nlhs, mxArray *plhs[],
// Check the left hand and right hand side arguments to make sure they conform // Check the left hand and right hand side arguments to make sure they conform
if (mxIsChar(prhs[0]) != 1) if (mxIsChar(prhs[0]) != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename."); DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename.");
if (nlhs != 1) if (nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("You must specify one output argument"); DYN_MEX_FUNC_ERR_MSG_TXT("You must specify two output arguments.");
// copy the string data from prhs[0] into a C string input_ buf. */ // copy the string data from prhs[0] into a C string input_ buf. */
input_buf = mxArrayToString(prhs[0]); input_buf = mxArrayToString(prhs[0]);
@ -78,30 +78,30 @@ mexFunction(int nlhs, mxArray *plhs[],
{ {
// regimes x percentile x horizon x (nvar*nvar) // regimes x percentile x horizon x (nvar*nvar)
mwSize dims[4] = {nstates, options->num_percentiles, options->horizon, (nvars*nvars)}; mwSize dims[4] = {nstates, options->num_percentiles, options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(4, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(4, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
{ {
// regimes x horizon x (nvar*nvar) // regimes x horizon x (nvar*nvar)
mwSize dims[3] = {nstates, options->horizon, (nvars*nvars)}; mwSize dims[3] = {nstates, options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
if (options->num_percentiles > 1) if (options->num_percentiles > 1)
{ {
// percentile x horizon x (nvar*nvar) // percentile x horizon x (nvar*nvar)
mwSize dims[3] = {options->num_percentiles, options->horizon, (nvars*nvars)}; mwSize dims[3] = {options->num_percentiles, options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
{ {
// horizon x (nvar*nvar) // horizon x (nvar*nvar)
mwSize dims[2] = {options->horizon, (nvars*nvars)}; mwSize dims[2] = {options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
// Use filter probabilities? // Use filter probabilities?
@ -188,7 +188,7 @@ mexFunction(int nlhs, mxArray *plhs[],
mxFree(model); mxFree(model);
mxFree(p); mxFree(p);
plhs[0] = mxCreateDoubleScalar(0);
} }
#endif #endif

View File

@ -51,8 +51,8 @@ mexFunction(int nlhs, mxArray *plhs[],
/* Check the left hand and right hand side arguments to make sure they conform */ /* Check the left hand and right hand side arguments to make sure they conform */
if (mxIsChar(prhs[0]) != 1) if (mxIsChar(prhs[0]) != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename."); DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename.");
if (nlhs != 1) if (nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("You must specify one output argument"); DYN_MEX_FUNC_ERR_MSG_TXT("You must specify two output arguments.");
// copy the string data from prhs[0] into a C string input_ buf. */ // copy the string data from prhs[0] into a C string input_ buf. */
input_buf = mxArrayToString(prhs[0]); input_buf = mxArrayToString(prhs[0]);
@ -78,30 +78,30 @@ mexFunction(int nlhs, mxArray *plhs[],
{ {
/* regimes x percentile x horizon x (nvar*nvar) */ /* regimes x percentile x horizon x (nvar*nvar) */
mwSize dims[4] = {nstates, options->num_percentiles, options->horizon, (nvars*nvars)}; mwSize dims[4] = {nstates, options->num_percentiles, options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(4, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(4, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
{ {
/* regimes x horizon x (nvar*nvar) */ /* regimes x horizon x (nvar*nvar) */
mwSize dims[3] = {nstates, options->horizon, (nvars*nvars)}; mwSize dims[3] = {nstates, options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
if (options->num_percentiles > 1) if (options->num_percentiles > 1)
{ {
/* percentile x horizon x (nvar*nvar) */ /* percentile x horizon x (nvar*nvar) */
mwSize dims[3] = {options->num_percentiles, options->horizon, (nvars*nvars)}; mwSize dims[3] = {options->num_percentiles, options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
else else
{ {
/* horizon x (nvar*nvar) */ /* horizon x (nvar*nvar) */
mwSize dims[2] = {options->horizon, (nvars*nvars)}; mwSize dims[2] = {options->horizon, (nvars*nvars)};
plhs[0] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL); plhs[1] = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
out_buf = mxGetPr(plhs[0]); out_buf = mxGetPr(plhs[1]);
} }
/* Use filter probabilities? */ /* Use filter probabilities? */
@ -242,7 +242,7 @@ mexFunction(int nlhs, mxArray *plhs[],
mxFree(p); mxFree(p);
mxFree(model); mxFree(model);
plhs[0] = mxCreateDoubleScalar(0);
} }
#endif #endif