Skip to content
Snippets Groups Projects
Commit 62b61f23 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Merge branch 'load_m_file' into 'master'

load_m_file_data.m: pass structure instead of file

See merge request Dynare/dseries!41
parents 1ead1dff da16dc4c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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__)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment