diff --git a/src/read/load_m_file_data.m b/src/read/load_m_file_data.m index 3ae720a031ff297e86f574bf5bae4d6c739a8e3d..3c526f96b4cb04a23d15bccfd2ea6be47e248ae5 100644 --- a/src/read/load_m_file_data.m +++ b/src/read/load_m_file_data.m @@ -16,7 +16,7 @@ function [freq, init, data, varlist, tex, ops, tags] = load_m_file_data(file) % % be a scalar integer and INIT__ a string like '1938M11', '1945Q3', '1973W3' or '2009A'. If these variables are not specified % default values for freq and init are 1 and dates(1,1). -% Copyright (C) 2012-2018 Dynare Team +% Copyright (C) 2012-2021 Dynare Team % % This file is part of Dynare. % @@ -45,14 +45,15 @@ if isoctave clear argn; end -save tmp__dataSet__.mat; -% the following aims at preventing horse-race conditions between writing the -% file and then immediately loading it, see https://git.dynare.org/Dynare/dseries/-/merge_requests/40 -rehash; +% store variables to structure, workaround for https://git.dynare.org/Dynare/dseries/-/merge_requests/40 +fields=[who].'; -[freq, init, data, varlist, tex, ops, tags] = load_mat_file_data('tmp__dataSet__.mat'); +assigns= cellfun(@(f) ['tmp__dataSet__struct.' f '=' f ';'],fields,'uniformoutput',0); +for line_iter=1:length(assigns) + eval(assigns{line_iter}); +end -delete tmp__dataSet__.mat; +[freq, init, data, varlist, tex, ops, tags] = load_mat_file_data(tmp__dataSet__struct); return diff --git a/src/read/load_mat_file_data.m b/src/read/load_mat_file_data.m index 6a43f7f2300a60d833f7ae1ff9aa3de29fd42107..74753d59fba1960fbc39c551f0c487d0cc3cd934 100644 --- a/src/read/load_mat_file_data.m +++ b/src/read/load_mat_file_data.m @@ -3,7 +3,8 @@ function [freq, init, data, varlist, tex, ops, tags] = load_mat_file_data(file) % Loads data in a matlab/octave mat-file. % % INPUTS -% - file string, name of the matlab/octave mat file (with path) +% - file string, name of the matlab/octave mat file (with path) +% or structure % % OUTPUTS % - freq integer scalar equal to 1, 4, 12 or 52 (for annual, quaterly, monthly or weekly frequencies). @@ -33,7 +34,12 @@ function [freq, init, data, varlist, tex, ops, tags] = load_mat_file_data(file) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -datafile = load(file); +if ~isstruct(file) + datafile = load(file); +else + datafile=file; +end + if isfield(datafile,'INIT__') if isdate(datafile.INIT__)