fix general oo_ conversion function: make recursive, works in both directions, #915
parent
f5c4ab7d80
commit
6e3a73190f
|
@ -1,10 +1,34 @@
|
||||||
function []=convert_dyn_45_to_44
|
function oo_ = convert_dyn_45_to_44(M_, options_, oo_)
|
||||||
% function []=convert_dyn_45_to_44
|
%function oo_ = convert_dyn_45_to_44(M_, options_, oo_
|
||||||
% This function converts the oo_-structure fields that have been changed in Dynare 4.5.
|
% Converts oo_ from 4.5 to 4.4
|
||||||
% following https://github.com/DynareTeam/dynare/pull/771 to the old format
|
%
|
||||||
% of Dynare 4.4
|
% INPUTS
|
||||||
|
% M_ [struct] dynare model struct
|
||||||
|
% options_ [struct] dynare options struct
|
||||||
|
% oo_ [struct] dynare output struct
|
||||||
|
%
|
||||||
|
% OUTPUTS
|
||||||
|
% oo_ [struct] dynare output struct
|
||||||
|
%
|
||||||
|
% SPECIAL REQUIREMENTS
|
||||||
|
% none
|
||||||
|
|
||||||
global M_ oo_ options_
|
% Copyright (C) 2015 Dynare Team
|
||||||
|
%
|
||||||
|
% This file is part of Dynare.
|
||||||
|
%
|
||||||
|
% Dynare is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% Dynare is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along = with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
%% add initial conditions to Bayesian forecasts
|
%% add initial conditions to Bayesian forecasts
|
||||||
if isfield(oo_,'PointForecast')
|
if isfield(oo_,'PointForecast')
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
function oo_ = convert_oo_(oo_, ver)
|
function oo_ = convert_oo_(M_, options_, oo_, from_ver, to_ver)
|
||||||
%function oo_ = convert_oo_(oo_, ver)
|
%function oo_ = convert_oo_(M_, options_, oo_, from_ver, to_ver)
|
||||||
% Converts oo_ from oo_.dynare_version to ver
|
% Converts oo_ from oo_.dynare_version to ver
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
% oo_ [struct] dynare output struct
|
% M_ [struct] dynare model struct
|
||||||
% ver [string] desired oo_ output version
|
% options_ [struct] dynare options struct
|
||||||
|
% oo_ [struct] dynare output struct
|
||||||
|
% from_ver [string] original oo_ output version
|
||||||
|
% to_ver [string] desired oo_ output version
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% oo_ [struct] dynare output struct
|
% oo_ [struct] dynare output struct
|
||||||
%
|
%
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% none
|
||||||
|
@ -27,21 +30,56 @@ function oo_ = convert_oo_(oo_, ver)
|
||||||
% GNU General Public License for more details.
|
% GNU General Public License for more details.
|
||||||
%
|
%
|
||||||
% You should have received a copy of the GNU General Public License
|
% You should have received a copy of the GNU General Public License
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
% along = with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
check_valid_ver(ver);
|
check_valid_ver(to_ver);
|
||||||
|
check_valid_ver(from_ver);
|
||||||
|
|
||||||
if isfield(oo_, 'dynare_version')
|
MIN_VER = '4.4';
|
||||||
ver_orig = oo_.dynare_version;
|
MAX_VER = '4.5';
|
||||||
else
|
|
||||||
ver_orig = '4.4.3';
|
if ver_less_than(to_ver, MIN_VER)
|
||||||
|
error(['Can only convert as far back as Dynare ' MIN_VER
|
||||||
|
'. All versions before have the same oo_ structure.']);
|
||||||
end
|
end
|
||||||
|
|
||||||
if strcmp(ver_orig, ver)
|
if ver_greater_than(to_ver, MAX_VER)
|
||||||
|
error(['Can only convert up to Dynare ' MAX_VER]);
|
||||||
|
end
|
||||||
|
|
||||||
|
min_ver = strsplit(MIN_VER, {'.', '-'});
|
||||||
|
max_ver = strsplit(MAX_VER, {'.', '-'});
|
||||||
|
from_ver_split = strsplit(from_ver, {'.', '-'});
|
||||||
|
to_ver_split = strsplit(to_ver, {'.', '-'});
|
||||||
|
|
||||||
|
if length(from_ver_split) ~= 2 || length(to_ver_split) ~= 2
|
||||||
|
error('The version numbers may only be of the form X.Y');
|
||||||
|
end
|
||||||
|
|
||||||
|
if to_ver_split{2} > from_ver_split{2}
|
||||||
|
new_to_ver = [to_ver_split{1} '.' num2str(str2double(to_ver_split{2})-1)];
|
||||||
|
else
|
||||||
|
new_to_ver = [to_ver_split{1} '.' num2str(str2double(to_ver_split{2})+1)];
|
||||||
|
end
|
||||||
|
|
||||||
|
if strcmp(from_ver, to_ver)
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
if ver_less_than(ver_orig, '4.5.0') && ver_greater_than_equal(ver, '4.5.0')
|
if ver_greater_than(to_ver, from_ver)
|
||||||
oo_.exo_simul = oo_.exo_simul';
|
moving_up = 1;
|
||||||
|
else
|
||||||
|
moving_up = -1;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
oo_ = convert_oo_(M_, options_, oo_, from_ver, new_to_ver)
|
||||||
|
|
||||||
|
if abs(to_ver_split{2} - (from_ver_split{2} - moving_up)) > 1
|
||||||
|
new_from_ver = [to_ver_split{1} '.' num2str(str2double(to_ver_split{2}) - moving_up)];
|
||||||
|
else
|
||||||
|
new_from_ver = from_ver;
|
||||||
|
end
|
||||||
|
|
||||||
|
eval(['oo_ = convert_dyn_' strrep(new_from_ver, '.', '') '_to_' ...
|
||||||
|
strrep(to_ver, '.', '') '(M_, options_, oo_);']);
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue