Commit 383b12df authored by Houtan Bastani's avatar Houtan Bastani
Browse files

ms-sbvar bugfix: change the way options are passed to irf, forecast and...

ms-sbvar bugfix: change the way options are passed to irf, forecast and variance decomposition mex functions
parent 4e8dcc1a
......@@ -68,6 +68,6 @@ mexErrCheck('ms_estimation', err);
[options_, oo_] = set_ms_estimation_file(options_, oo_);
[err, oo_.ms.A0, oo_.ms.Aplus, oo_.ms.Zeta, oo_.ms.Q] = ...
mex_ms_convert_free_parameters(options_.ms.estimation_file_tag, oo_.ms.maxparams);
mex_ms_convert_free_parameters({{'file_tag',options_.ms.estimation_file_tag}}, oo_.ms.maxparams);
mexErrCheck('mex_ms_convert_free_parameters', err);
end
......@@ -39,30 +39,36 @@ clean_files_for_second_type_of_mex(M_, options_, 'forecast')
forecastdir = [options_.ms.output_file_tag filesep 'Forecast'];
create_dir(forecastdir);
opt = {options_.ms.estimation_file_tag, ...
'seed', options_.DynareRandomStreams.seed, ...
'horizon', options_.ms.horizon, ...
'number_observations',options_.ms.forecast_data_obs ...
'error_bands', options_.ms.error_bands, ...
'percentiles', options_.ms.error_band_percentiles, ...
'thin', options_.ms.thinning_factor };
opt = { ...
{'file_tag', options_.ms.estimation_file_tag}, ...
{'seed', options_.DynareRandomStreams.seed}, ...
{'horizon', options_.ms.horizon}, ...
{'number_observations', options_.ms.forecast_data_obs}, ...
{'error_bands', options_.ms.error_bands}, ...
{'percentiles', options_.ms.error_band_percentiles}, ...
{'thin', options_.ms.thinning_factor}
};
[err, forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shock_draws);
[err, forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks_per_parameter', options_.ms.shock_draws}}]);
mexErrCheck('mex_ms_forecast ergodic ', err);
plot_ms_forecast(M_,options_,forecast,'Forecast',options_.graph_save_formats,options_.TeX);
[err, regime_forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shock_draws,'regimes');
[err, regime_forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks_per_parameter', options_.ms.shock_draws}, {'regimes'}}]);
mexErrCheck('mex_ms_forecast ergodic regimes', err);
save([forecastdir filesep 'ergodic_forecast.mat'], 'forecast', 'regime_forecast');
if exist(options_.ms.mh_file,'file') > 0
[err, forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shocks_per_parameter, ...
'simulation_file',options_.ms.mh_file,'parameter_uncertainty');
[err, forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
{'simulation_file', options_.ms.mh_file}, {'parameter_uncertainty'}}]);
mexErrCheck('mex_ms_forecast bayesian ', err);
plot_ms_forecast(M_,options_,forecast,'Forecast w/ Parameter Uncertainty',options_.graph_save_formats,options_.TeX);
[err, regime_forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shocks_per_parameter, ...
'simulation_file',options_.ms.mh_file,'parameter_uncertainty','regimes');
[err, regime_forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
{'simulation_file', options_.ms.mh_file}, {'parameter_uncertainty','regimes'}}]);
mexErrCheck('mex_ms_forecast bayesian regimes ', err);
save([forecastdir filesep 'bayesian_forecast.mat'], 'forecast', 'regime_forecast');
end
......
......@@ -40,19 +40,21 @@ clean_files_for_second_type_of_mex(M_, options_, 'irf')
irfdir = [options_.ms.output_file_tag filesep 'IRF'];
create_dir(irfdir);
opt = {options_.ms.estimation_file_tag, ...
'seed', options_.DynareRandomStreams.seed, ...
'horizon', options_.ms.horizon, ...
'filtered', options_.ms.filtered_probabilities, ...
'error_bands', options_.ms.error_bands, ...
'percentiles', options_.ms.error_band_percentiles, ...
'thin', options_.ms.thinning_factor };
opt = { ...
{'file_tag', options_.ms.estimation_file_tag}, ...
{'seed', options_.DynareRandomStreams.seed}, ...
{'horizon', options_.ms.horizon}, ...
{'filtered', options_.ms.filtered_probabilities}, ...
{'error_bands', options_.ms.error_bands}, ...
{'percentiles', options_.ms.error_band_percentiles}, ...
{'thin', options_.ms.thinning_factor}
};
[err, irf] = mex_ms_irf(opt{:}, 'free_parameters', oo_.ms.maxparams, 'shocks_per_parameter', options_.ms.shock_draws);
[err, irf] = mex_ms_irf([opt(:)', {{'free_parameters', oo_.ms.maxparams}, {'shocks_per_parameter', options_.ms.shock_draws}}]);
mexErrCheck('mex_ms_irf ergodic ', err);
plot_ms_irf(M_,options_,irf,options_.varobs,'Ergodic Impulse Responses',varlist);
[err, regime_irfs] = mex_ms_irf(opt{:}, 'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shock_draws,'regimes');
[err, regime_irfs] = mex_ms_irf([opt(:)', {{'free_parameters',oo_.ms.maxparams}, {'shocks_per_parameter', options_.ms.shock_draws}, {'regimes'}}]);
mexErrCheck('mex_ms_irf ergodic regimes ',err);
for i=1:size(regime_irfs,1)
plot_ms_irf(M_,options_,squeeze(regime_irfs(i,:,:,:)),options_.varobs,['Ergodic ' ...
......@@ -61,13 +63,13 @@ end
save([irfdir filesep 'ergodic_irf.mat'], 'irf', 'regime_irfs');
if exist(options_.ms.mh_file,'file') > 0
[err, irf] = mex_ms_irf(opt{:}, 'shocks_per_parameter', options_.ms.shocks_per_parameter, ...
'parameter_uncertainty','simulation_file',options_.ms.mh_file);
[err, irf] = mex_ms_irf([opt(:)', {{'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
{'parameter_uncertainty'},{'simulation_file',options_.ms.mh_file}}]);
mexErrCheck('mex_ms_irf bayesian ',err);
plot_ms_irf(M_,options_,irf,options_.varobs,'Impulse Responses with Parameter Uncertainty',varlist);
[err, regime_irfs] = mex_ms_irf(opt{:}, 'shocks_per_parameter', options_.ms.shocks_per_parameter, ...
'simulation_file',options_.ms.mh_file,'parameter_uncertainty','regimes');
[err, regime_irfs] = mex_ms_irf([opt(:)', {{'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
{'simulation_file',options_.ms.mh_file},{'parameter_uncertainty'},{'regimes'}}]);
mexErrCheck('mex_ms_irf bayesian regimes ',err);
for i=1:size(regime_irfs,1)
plot_ms_irf(M_,options_,squeeze(regime_irfs(i,:,:,:)),options_.varobs,['Impulse ' ...
......
......@@ -41,28 +41,34 @@ create_dir(vddir);
% NOTICE THAT VARIANCE DECOMPOSITION DEFAULTS TO USING THE MEAN, NOT MEDIAN OR BANDED
opt = {options_.ms.estimation_file_tag, ...
'seed', options_.DynareRandomStreams.seed, ...
'horizon', options_.ms.horizon, ...
'filtered', options_.ms.filtered_probabilities, ...
'error_bands', options_.ms.error_bands, ...
'percentiles', options_.ms.error_band_percentiles, ...
'thin', options_.ms.thinning_factor, ...
'mean'};
opt = {
{'file_tag', options_.ms.estimation_file_tag}, ...
{'seed', options_.DynareRandomStreams.seed}, ...
{'horizon', options_.ms.horizon}, ...
{'filtered', options_.ms.filtered_probabilities}, ...
{'error_bands', options_.ms.error_bands}, ...
{'percentiles', options_.ms.error_band_percentiles}, ...
{'thin', options_.ms.thinning_factor}, ...
{'mean'} ...
};
[err, vd] = mex_ms_variance_decomposition(opt{:},'free_parameters',oo_.ms.maxparams,'shocks',options_.ms.shock_draws);
[err, vd] = mex_ms_variance_decomposition([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks', options_.ms.shock_draws}}]);
mexErrCheck('mex_ms_variance_decomposition ergodic ', err);
plot_ms_variance_decomposition(M_,options_,vd, 'Ergodic Variance Decomposition',options_.graph_save_formats,options_.TeX);
[err, regime_vd] = mex_ms_variance_decomposition(opt{:},'free_parameters',oo_.ms.maxparams,'shocks',options_.ms.shock_draws,'regimes');
[err, regime_vd] = mex_ms_variance_decomposition([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks', options_.ms.shock_draws}, {'regimes'}}]);
mexErrCheck('mex_ms_variance_decomposition ergodic regimes', err);
save([vddir filesep 'ergodic_vd.mat'], 'vd', 'regime_vd');
if exist(options_.ms.mh_file,'file') > 0
[err, vd] = mex_ms_variance_decomposition(opt{:},'simulation_file',options_.ms.mh_file,'shocks',options_.ms.shocks_per_parameter,'parameter_uncertainty');
[err, vd] = mex_ms_variance_decomposition([opt(:)', {{'simulation_file',options_.ms.mh_file}, ...
{'shocks', options_.ms.shocks_per_parameter}, {'parameter_uncertainty'}}]);
mexErrCheck('mex_ms_variance_decomposition bayesian ', err);
[err, regime_vd] = mex_ms_variance_decomposition(opt{:},'simulation_file',options_.ms.mh_file,'shocks',options_.ms.shocks_per_parameter,'parameter_uncertainty','regimes');
[err, regime_vd] = mex_ms_variance_decomposition([opt(:)', {{'simulation_file',options_.ms.mh_file}, ...
{'shocks', options_.ms.shocks_per_parameter}, {'parameter_uncertainty'}, {'regimes'}}]);
mexErrCheck('mex_ms_variance_decomposition bayesian regimes ', err);
save([vddir filesep 'bayesian_vd.mat'], 'vd', 'regime_vd');
end
......
......@@ -37,9 +37,6 @@ void
mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
using namespace std;
char *input_buf;
double *free_parameters;
int nvars, npre, nstates, nfree;
double *aplus = NULL, *a0 = NULL, *zeta = NULL, *q = NULL;
......@@ -48,23 +45,18 @@ mexFunction(int nlhs, mxArray *plhs[],
SbvarOption *options = NULL;
/* input must be a string */
if (mxIsChar(prhs[0]) != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename.");
if (nrhs !=2)
DYN_MEX_FUNC_ERR_MSG_TXT("This function takes exactly two arguments");
if (!mxIsDouble(prhs[1]))
DYN_MEX_FUNC_ERR_MSG_TXT("Second argument is a vector of free parameters");
if (nlhs < 4)
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. */
input_buf = mxArrayToString(prhs[0]);
if (input_buf == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("Could not convert input to string.");
// second element should be vector of free parameters */
free_parameters = mxGetPr(prhs[1]);
model = initialize_model_and_options(input_buf, &options, nrhs, prhs, &nstates, &nvars, &npre, &nfree);
model = initialize_model_and_options(&options, prhs, &nstates, &nvars, &npre, &nfree);
if (model == NULL || options == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue");
......
......@@ -36,10 +36,6 @@ void
mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
using namespace std;
char *input_buf;
double *out_buf;
int i, j, k, s, nfree, nstates, nvars, npre, T;
......@@ -52,16 +48,12 @@ mexFunction(int nlhs, mxArray *plhs[],
int type = F_FREE;
// Check the left hand and right hand side arguments to make sure they conform
if (mxIsChar(prhs[0]) != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename.");
if (nrhs != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("ms_forecast takes one cell array as an input argument.");
if (nlhs != 2)
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. */
input_buf = mxArrayToString(prhs[0]);
if (input_buf == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("Could not convert input to string.");
model = initialize_model_and_options(input_buf, &options, nrhs, prhs, &nstates, &nvars, &npre, &nfree);
model = initialize_model_and_options(&options, prhs, &nstates, &nvars, &npre, &nfree);
if (model == NULL || options == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue");
......
......@@ -36,8 +36,6 @@ void
mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
char *input_buf;
double *out_buf;
int i, j, k, s, nfree, nstates, nvars, npre;
......@@ -50,16 +48,13 @@ mexFunction(int nlhs, mxArray *plhs[],
int type = F_FREE, ergodic = 1;
// Check the left hand and right hand side arguments to make sure they conform
if (mxIsChar(prhs[0]) != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename.");
if (nrhs != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("ms_irf takes one cell array as an input argument.");
if (nlhs != 2)
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. */
input_buf = mxArrayToString(prhs[0]);
if (input_buf == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("Could not convert input to string.");
model = initialize_model_and_options(input_buf, &options, nrhs, prhs, &nstates, &nvars, &npre, &nfree);
// copy the string data from prhs[0] into a C string input_ buf.
model = initialize_model_and_options(&options, prhs, &nstates, &nvars, &npre, &nfree);
if (model == NULL || options == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue");
......
......@@ -348,41 +348,37 @@ initialize_sbvar_options(char *file_tag)
}
int
set_options(SbvarOption *options, int nrhs, const mxArray *prhs[])
set_options(SbvarOption *options, const mxArray *prhs[])
{
if (options == NULL)
options = initialize_sbvar_options((char *) NULL);
int i, buf_len, buf_len2;
char *input_buf = NULL;
double *temp_buf;
bool shocks_passed = false;
/* deal with optional arguments */
for (i = 0; i < nrhs; i++)
{
if (mxIsChar(prhs[i]) == 1)
int num_options = mxGetN(prhs[0]);
for (int i = 1; i < num_options; i++)
{
buf_len = mxGetN(prhs[i])*sizeof(mxChar)+1;
input_buf = (char *) mxMalloc(buf_len);
mxGetString(prhs[i], input_buf, buf_len);
mxArray *this_option = mxGetCell(prhs[0],i);
char *option_name_c = mxArrayToString(mxGetCell(this_option,0));
string option_name (option_name_c);
mxArray *this_option_value = NULL;
if (mxGetN(this_option) > 1)
this_option_value = mxGetCell(this_option,1);
if (strstr(input_buf, "horizon"))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
if (option_name == "horizon")
if (this_option_value && mxIsNumeric(this_option_value))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
temp_buf = (double *) mxGetData(this_option_value);
options->horizon = (int) temp_buf[0];
}
else
{
printf("You must pass an integer after specifying the 'horizon' option");
cout << "You must pass an integer after specifying the 'horizon' option" << endl;
return 1;
}
}
else if (strstr(input_buf, "filtered"))
else if (option_name == "filtered")
options->filtered_probabilities = true;
else if (strstr(input_buf, "error_bands"))
else if (option_name == "error_bands")
{
free(options->percentiles);
options->num_percentiles = 3;
......@@ -391,11 +387,10 @@ set_options(SbvarOption *options, int nrhs, const mxArray *prhs[])
options->percentiles[1] = 0.5;
options->percentiles[2] = 0.84;
// Check if the specified to turn off error bands
if (nrhs > i+1)
if (mxIsNumeric(prhs[i+1]))
// Check if the user specified to turn off error bands
if (this_option_value && mxIsNumeric(this_option_value))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
temp_buf = (double *) mxGetData(this_option_value);
if (temp_buf[0] == 0)
{
options->num_percentiles = 1;
......@@ -403,150 +398,132 @@ set_options(SbvarOption *options, int nrhs, const mxArray *prhs[])
options->percentiles[0] = 0.50;
}
}
}
else if (strstr(input_buf, "median"))
else if (option_name == "median")
{
free(options->percentiles);
options->num_percentiles = 1;
options->percentiles = new double[1];
options->percentiles[0] = 0.5;
}
else if (strstr(input_buf, "percentiles"))
{
if (nrhs >= i+1)
else if (option_name == "percentiles")
if (this_option_value)
{
options->num_percentiles = mxGetN(prhs[i+1]) > mxGetM(prhs[i+1]) ? mxGetN(prhs[i+1]) : mxGetM(prhs[i+1]);
options->percentiles = mxGetPr(prhs[i+1]);
options->num_percentiles = mxGetN(this_option_value)
> mxGetM(this_option_value) ? mxGetN(this_option_value)
: mxGetM(this_option_value);
options->percentiles = mxGetPr(this_option_value);
}
else
{
printf("You must pass a vector after the 'percentiles' argument with the percentiles that you want to have computed, ex 'percentiles',[.16 .5 .84]");
cout << "You must pass a vector after the 'percentiles' argument with the "
<< "percentiles that you want to have computed, ex "
<< "'percentiles',[.16 .5 .84]" << endl;
return 1;
}
}
else if (strstr(input_buf, "parameter_uncertainty"))
else if (option_name == "parameter_uncertainty")
{
options->parameter_uncertainty = true;
if (shocks_passed == false)
options->shocks = 1;
}
else if (strstr(input_buf, "shocks") || strstr(input_buf, "shocks_per_parameter"))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
else if (option_name == "shocks" || option_name == "shocks_per_parameter")
if (this_option_value && mxIsNumeric(this_option_value))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
temp_buf = (double *) mxGetData(this_option_value);
options->shocks = (int) temp_buf[0];
shocks_passed = true;
}
else
{
printf("You must pass an integer after specifying the 'shocks' option");
cout << "You must pass an integer after specifying the 'shocks' option" << endl;
return 1;
}
}
else if (strstr(input_buf, "thin"))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
else if (option_name == "thin")
if (this_option_value && mxIsNumeric(this_option_value))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
temp_buf = (double *) mxGetData(this_option_value);
options->thin = (int) temp_buf[0];
}
else
{
printf("You must pass an integer after specifying the 'thin' option");
cout << "You must pass an integer after specifying the 'thin' option" << endl;
return 1;
}
}
else if (strstr(input_buf, "simulation_file"))
else if (option_name == "simulation_file")
{
buf_len2 = mxGetN(prhs[i+1])*sizeof(mxChar)+1;
char *posterior_filename = (char *) mxMalloc(buf_len2);
mxGetString(prhs[i+1], posterior_filename, buf_len2);
char *posterior_filename = mxArrayToString(this_option_value);
strcpy(options->simulation_filename, posterior_filename);
if (!(options->simulation_file = fopen(posterior_filename, "rt")))
{
printf("The posterior simulation file does not exist");
cout << "Can not open posterior file " << options->simulation_file
<< " for reading. " << endl;
return 1;
}
mxFree(posterior_filename);
}
else if (strstr(input_buf, "regimes"))
{
else if (option_name == "regimes")
options->regimes = true;
}
else if (strstr(input_buf, "regime"))
else if (option_name == "regime")
if (this_option_value && mxIsNumeric(this_option_value))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
temp_buf = (double *) mxGetData(this_option_value);
options->regime = (int) temp_buf[0];
}
else
{
printf("You must pass an integer after specifying the 'regime' option, or alternatively you can specify 'regimes'");
cout << "You must pass an integer after specifying the 'regime' "
<< "option, or alternatively you can specify 'regimes'" << endl;
return 1;
}
}
else if (strstr(input_buf, "number_observations"))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
else if (option_name == "number_observations")
if (this_option_value && mxIsNumeric(this_option_value))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
temp_buf = (double *) mxGetData(this_option_value);
options->number_observations = (int) temp_buf[0];
}
else
{
printf("You must pass an integer after specifying the 'regime' option, or alternatively you can specify 'regimes'");
cout << "You must pass an integer after specifying the "
<< "'number_observations' option" << endl;
return 1;
}
}
else if (strstr(input_buf, "free_parameters"))
else if (option_name == "free_parameters")
if (this_option_value && mxIsNumeric(this_option_value))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
{
options->num_parameters = mxGetM(prhs[i+1]);
options->free_parameters = mxGetPr(prhs[i+1]);
options->num_parameters = mxGetM(this_option_value);
options->free_parameters = mxGetPr(this_option_value);
}
else
{
printf("You must pass a vector of free parameters after specifying 'free_parameters'");
cout << "You must pass a vector of free parameters after "
<< "specifying 'free_parameters'" << endl;
return 1;
}
}
else if (strstr(input_buf, "mean"))
else if (option_name == "mean")
{
options->mean = true;
options->num_percentiles = 0;
options->percentiles = (double *) NULL;
}
else if (strstr(input_buf, "seed"))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
else if (option_name == "seed")
if (this_option_value && mxIsNumeric(this_option_value))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
temp_buf = (double *) mxGetData(this_option_value);
options->seed = (long) temp_buf[0];
}
else
{
printf("You must pass an integer after specifying the 'seed' option");
cout << "You must pass an integer after specifying the 'seed' option" << endl;
return 1;
}
else
{
cout << "set_options error: option '" << option_name << "' not matched" << endl;
return 1;
}
}
mxFree(option_name_c);
} // End Optional Arguments
return 0;
}
......@@ -583,16 +560,14 @@ print_sbvar_options(SbvarOption *options)
}
TStateModel *
initialize_model_and_options(char *name, SbvarOption **options, int nrhs, const mxArray *prhs[], int *nstates, int *nvars, int *npre, int *nfree)
initialize_model_and_options(SbvarOption **options, const mxArray *prhs[], int *nstates, int *nvars, int *npre, int *nfree)
{
using namespace std;
char *name;
TStateModel *model = (TStateModel *) NULL;
int ret;
SbvarOption *opt;
// Initialize the StateSpace Model with the initialization file
name = mxArrayToString(mxGetCell(mxGetCell(prhs[0],0),1));
model = initialize_ms_model(name);
if (model == NULL)
{
......@@ -607,7 +582,8 @@ initialize_model_and_options(char *name, SbvarOption **options, int nrhs, const
// Process the rest of the options
opt = initialize_sbvar_options(name);
if (set_options(opt, nrhs, prhs) > 0)
mxFree(name);
if (set_options(opt, prhs) > 0)
{
cout << "There was a problem with the options passed." << endl;
return (TStateModel *) NULL;
......
......@@ -61,13 +61,13 @@ typedef struct sbvar_options_t {
int file_exist(char *filename);
char* CreateFilenameFromTag(const char *fmt,const char *tag,const char *dir);
SbvarOption * initialize_sbvar_options(char *file_tag);
int set_options(SbvarOption *options, int nrhs, const mxArray *prhs[]);
int set_options(SbvarOption *options, const mxArray *prhs[]);
int print_sbvar_options(SbvarOption *options);
TStateModel * initialize_ms_model(char *filename);
int get_var_dimensions(TStateModel *model, int *nstates, int *nvars, int *npre, int *nfree);
int set_parameters_in_VAR(TStateModel *model, double *free_parameters);
int convert_free_parameters_to_VAR(TStateModel *model, double *free_parameters, double *A0, double *Aplus, double *Zeta, double *Q );
TStateModel * initialize_model_and_options(char *name,SbvarOption **options, int nrhs, const mxArray *prhs[], int *nstates, int *nvars, int *npre, int *nfree);
TStateModel * initialize_model_and_options(SbvarOption **options, const mxArray *prhs[], int *nstates, int *nvars, int *npre, int *nfree);
#endif
#endif