From da16dc4c105067c69234635132e0bbd9f9e5ecaf Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer <jpfeifer@gmx.de> Date: Fri, 17 Dec 2021 09:19:21 +0100 Subject: [PATCH] load_m_file_data.m: pass structure instead of file Next attempt to prevent horse race conditions, see https://git.dynare.org/Dynare/dseries/-/merge_requests/40 --- src/read/load_m_file_data.m | 15 ++++++++------- src/read/load_mat_file_data.m | 10 ++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/read/load_m_file_data.m b/src/read/load_m_file_data.m index 3ae720a..3c526f9 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 6a43f7f..74753d5 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__) -- GitLab