// Convert MATLAB Dynare endo and exo names array to a vector<string> array of string pointers
// Poblem is that Matlab mx function returns a long string concatenated by columns rather than rows
...
...
@@ -68,8 +70,8 @@ extern "C" {
mexFunction(intnlhs,mxArray*plhs[],
intnrhs,constmxArray*prhs[])
{
if(nrhs<5)
mexErrMsgTxt("Must have exactly 5 input parameters.");
if(nrhs<5||nlhs<2)
DYN_MEX_FUNC_ERR_MSG_TXT("Must have exactly 5 input parameters and take at least 2 output parameters.");
constmxArray*dr=prhs[0];
constmxArray*M_=prhs[1];
...
...
@@ -78,7 +80,8 @@ extern "C" {
mxArray*mFname=mxGetField(M_,0,"fname");
if(!mxIsChar(mFname))
mexErrMsgTxt("Input must be of type char.");
DYN_MEX_FUNC_ERR_MSG_TXT("Input must be of type char.");
stringfName=mxArrayToString(mFname);
constmxArray*mexExt=prhs[4];
stringdfExt=mxArrayToString(mexExt);// Dynamic file extension, e.g. ".dll" or ".mexw32"
...
...
@@ -90,10 +93,10 @@ extern "C" {
else
kOrder=1;
if(kOrder==1&&nlhs!=1)
mexErrMsgTxt("k_order_perturbation at order 1 requires exactly 1 argument in output");
elseif(kOrder>1&&nlhs!=kOrder+1)
mexErrMsgTxt("k_order_perturbation at order > 1 requires exactly order+1 arguments in output");
if(kOrder==1&&nlhs!=2)
DYN_MEX_FUNC_ERR_MSG_TXT("k_order_perturbation at order 1 requires exactly 2 arguments in output");
elseif(kOrder>1&&nlhs!=kOrder+2)
DYN_MEX_FUNC_ERR_MSG_TXT("k_order_perturbation at order > 1 requires exactly order+2 arguments in output");
doubleqz_criterium=1+1e-6;
mxFldp=mxGetField(options_,0,"qz_criterium");
...
...
@@ -141,7 +144,8 @@ extern "C" {
dparams=(double*)mxGetData(mxFldp);
npar=(int)mxGetM(mxFldp);
if(npar!=nEndo)
mexErrMsgTxt("Incorrect number of input var_order vars.");
DYN_MEX_FUNC_ERR_MSG_TXT("Incorrect number of input var_order vars.");
vector<int>var_order_vp(nEndo);
for(intv=0;v<nEndo;v++)
var_order_vp[v]=(int)(*(dparams++));
...
...
@@ -154,14 +158,18 @@ extern "C" {
TwoDMatrixllincidence(nrows,npar,dparams);
if(npar!=nEndo)
mexErrMsgIdAndTxt("dynare:k_order_perturbation","Incorrect length of lead lag incidences: ncol=%d != nEndo=%d.",npar,nEndo);
{
ostringstreamstrstrm;
strstrm<<"dynare:k_order_perturbation "<<"Incorrect length of lead lag incidences: ncol="<<npar<<" != nEndo="<<nEndo;
DYN_MEX_FUNC_ERR_MSG_TXT(strstrm.str().c_str());
}
//get NNZH =NNZD(2) = the total number of non-zero Hessian elements
mxFldp=mxGetField(M_,0,"NNZDerivatives");
dparams=(double*)mxGetData(mxFldp);
VectorNNZD(dparams,(int)mxGetM(mxFldp));
if(NNZD[kOrder-1]==-1)
mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you used the right order option inside the stoch_simul command");
DYN_MEX_FUNC_ERR_MSG_TXT("The derivatives were not computed for the required order. Make sure that you used the right order option inside the stoch_simul command");
constintjcols=nExog+nEndo+nsPred+nsForw;// Num of Jacobian columns