diff --git a/matlab/convert_dyn_45_to_44.m b/matlab/convert_dyn_45_to_44.m index ed1e704af..9d503bf4b 100644 --- a/matlab/convert_dyn_45_to_44.m +++ b/matlab/convert_dyn_45_to_44.m @@ -1,10 +1,34 @@ -function []=convert_dyn_45_to_44 -% function []=convert_dyn_45_to_44 -% This function converts the oo_-structure fields that have been changed in Dynare 4.5. -% following https://github.com/DynareTeam/dynare/pull/771 to the old format -% of Dynare 4.4 +function oo_ = convert_dyn_45_to_44(M_, options_, oo_) +%function oo_ = convert_dyn_45_to_44(M_, options_, oo_ +% Converts oo_ from 4.5 to 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 . %% add initial conditions to Bayesian forecasts if isfield(oo_,'PointForecast') diff --git a/matlab/convert_oo_.m b/matlab/convert_oo_.m index 355f5a812..ef5f72280 100644 --- a/matlab/convert_oo_.m +++ b/matlab/convert_oo_.m @@ -1,13 +1,16 @@ -function oo_ = convert_oo_(oo_, ver) -%function oo_ = convert_oo_(oo_, ver) +function oo_ = convert_oo_(M_, options_, oo_, from_ver, to_ver) +%function oo_ = convert_oo_(M_, options_, oo_, from_ver, to_ver) % Converts oo_ from oo_.dynare_version to ver % % INPUTS -% oo_ [struct] dynare output struct -% ver [string] desired oo_ output version +% M_ [struct] dynare model struct +% 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 -% oo_ [struct] dynare output struct +% oo_ [struct] dynare output struct % % SPECIAL REQUIREMENTS % none @@ -27,21 +30,56 @@ function oo_ = convert_oo_(oo_, ver) % 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 . +% along = with Dynare. If not, see . -check_valid_ver(ver); +check_valid_ver(to_ver); +check_valid_ver(from_ver); -if isfield(oo_, 'dynare_version') - ver_orig = oo_.dynare_version; -else - ver_orig = '4.4.3'; +MIN_VER = '4.4'; +MAX_VER = '4.5'; + +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 -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; end -if ver_less_than(ver_orig, '4.5.0') && ver_greater_than_equal(ver, '4.5.0') - oo_.exo_simul = oo_.exo_simul'; +if ver_greater_than(to_ver, from_ver) + moving_up = 1; +else + moving_up = -1; 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