diff --git a/src/@dseries/merge.m b/src/@dseries/merge.m index aab032ee6900dec5d140097281f867b1ec9ef29a..6827b7bc0357a3ff3996384b4d3f1c28dae697ec 100644 --- a/src/@dseries/merge.m +++ b/src/@dseries/merge.m @@ -32,13 +32,24 @@ function q = merge(o, p, rewritewithnans) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if ~isdseries(p) +if ~isdseries(p) || ~isdseries(o) error('dseries::merge: Both inputs must be dseries objects!') end +if isempty(o) && ~isempty(p) + q = p; + return +elseif ~isempty(o) && isempty(p) + q = o; + return +elseif isempty(o) && isempty(p) + q = p; + return +end + if ~isequal(frequency(o), frequency(p)) if isempty(inputname(1)) - error(['dseries::merge: Cannot merge dseries objects (frequencies are different)!']) + error('dseries::merge: Cannot merge dseries objects (frequencies are different)!') else error(['dseries::merge: Cannot merge ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) end diff --git a/src/@dseries/save.m b/src/@dseries/save.m index 22ef9a08f13bc4038a41e6872ce5a85382233d22..9a6c86bac03629d2a7b87aa82075b920a9cc3e51 100644 --- a/src/@dseries/save.m +++ b/src/@dseries/save.m @@ -36,7 +36,7 @@ switch format fid = fopen([basename, '.m'],'w'); fprintf(fid,'%% File created on %s.\n',datestr(now)); fprintf(fid,'\n'); - fprintf(fid,'FREQ__ = %s;\n',num2str(frequency(o))); + fprintf(fid,'FREQ__ = %u;\n', frequency(o)); fprintf(fid,'INIT__ = ''%s'';\n',date2string(firstdate(o))); fprintf(fid,'\n'); fprintf(fid,'NAMES__ = {'); @@ -72,15 +72,15 @@ switch format if ~isempty(fieldnames(o.tags)) % User has defined tags on the variables. tagnames = fieldnames(o.tags); - TAGS__ = fprintf(fid, 'struct();\n'); + fprintf(fid, 'TAGS__ = struct();\n'); for i=1:length(tagnames) - fprintf(fid, 'TAGS__.%s = cell(%s, 1);\n', tagnames{i}, num2str(vobs(o))); + fprintf(fid, 'TAGS__.%s = cell(%u, 1);\n', tagnames{i}, vobs(o)); for j=1:vobs(o) if ~isempty(o.tags.(tagnames{i}){j}) if ischar(o.tags.(tagnames{i}){j}) - fprintf(fid, 'TAGS__.%s(%s) = {''%s''};\n', tagnames{i}, num2str(j), o.tags.(tagnames{i}){j}); + fprintf(fid, 'TAGS__.%s(%u) = {''%s''};\n', tagnames{i}, j, o.tags.(tagnames{i}){j}); elseif isnumeric(o.tags.(tagnames{i}){j}) && iscalar(o.tags.(tagnames{i}){j}) - fprintf(fid, 'TAGS__.%s(%s) = {%s};\n', tagnames{i}, num2str(j), o.tags.(tagnames{i}){j}); + fprintf(fid, 'TAGS__.%s(%u) = {%s};\n', tagnames{i}, j, o.tags.(tagnames{i}){j}); else error('dseries::tags: Cannot save this type of tag!') end @@ -103,16 +103,12 @@ switch format TEX__ = o.tex; OPS__ = o.ops; TAGS__ = o.tags; - str = []; - for v = 1:vobs(o) - str = sprintf('%s %s = o.data(:,%s);', str, o.name{v}, num2str(v)); - end - eval(str); + DATA__ = o.data; currentdirectorycontent = dir(); if ismember([basename, '.mat'], {currentdirectorycontent.name}) copyfile([basename, '.mat'], [basename, '.old.mat']); end - save([basename '.mat'], 'INIT__', 'FREQ__', 'NAMES__', 'TEX__', 'OPS__', 'TAGS__', o.name{:}); + save([basename '.mat'], 'INIT__', 'FREQ__', 'NAMES__', 'TEX__', 'OPS__', 'TAGS__', 'DATA__'); case 'csv' currentdirectorycontent = dir(); if ismember([basename, '.csv'],{currentdirectorycontent.name}) diff --git a/src/read/load_data.m b/src/read/load_data.m index b93c4903f8f7c0835dcbf2bbfbd907f1c2d3e1d3..a1eeeaa776ddd686d7a81f571c80d2c031c78f4a 100644 --- a/src/read/load_data.m +++ b/src/read/load_data.m @@ -25,13 +25,13 @@ function [init, data, varlist, tex, ops, tags] = load_data(filename) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if ~nargin || ~ischar(filename) || isempty(filename) - error('dseries:load_data: WrongInputArguments', 'Input argument cannot be an empty string!') + error('dseries:load_data: Input argument cannot be an empty string!') elseif check_file_extension(filename,'m') - [freq, init, data, varlist, tex, ops, tags] = load_m_file_data(filename); + [~, init, data, varlist, tex, ops, tags] = load_m_file_data(filename); elseif check_file_extension(filename,'mat') - [freq, init, data, varlist, tex, ops, tags] = load_mat_file_data(filename); + [~, init, data, varlist, tex, ops, tags] = load_mat_file_data(filename); elseif check_file_extension(filename,'csv') - [freq, init, data, varlist] = load_csv_file_data(filename); + [~, init, data, varlist] = load_csv_file_data(filename); tex = []; ops = cell(length(varlist), 1); tags = struct(); @@ -46,7 +46,7 @@ elseif check_file_extension(filename,'xls') || check_file_extension(filename,'xl range = []; sheet = []; end - [freq, init, data, varlist] = load_xls_file_data(filename, sheet, range); + [~, init, data, varlist] = load_xls_file_data(filename, sheet, range); tex = []; ops = cell(length(varlist), 1); tags = struct(); diff --git a/src/read/load_mat_file_data.m b/src/read/load_mat_file_data.m index 23a9b32d5f63784d18ffdce22c576c3caca19430..da7f53227058e5c5c7c8c544fff82cbb780e4a07 100644 --- a/src/read/load_mat_file_data.m +++ b/src/read/load_mat_file_data.m @@ -85,21 +85,28 @@ else tags = struct(); end -data = []; -if isempty(varlist) - varlist = fieldnames(datafile); -end - -for i=1:length(varlist) - try - tmp = datafile.(varlist{i}); - if isvector(tmp) - data = [data, tmp(:)]; - else - error('load_mat_file:: All the variables must be vectors (%s is not a vector)!', varlist{i}) +if isfield(datafile,'DATA__') + data = datafile.DATA__; + datafile = rmfield(datafile, 'DATA__'); +else + % Previously to dynare 4.6 variables were stored as vectors of + % common length in the mat file. This part of the code deals + % with mat files generated by these older versions of Dynare. + data = []; + if isempty(varlist) + varlist = fieldnames(datafile); + end + for i=1:length(varlist) + try + tmp = datafile.(varlist{i}); + if isvector(tmp) + data = [data, tmp(:)]; + else + error('load_mat_file:: All the variables must be vectors (%s is not a vector)!', varlist{i}) + end + catch + error('load_mat_file:: All the vectors (variables) in %s must have the same number of rows (observations)!', inputname(1)) end - catch - error('load_mat_file:: All the vectors (variables) in %s must have the same number of rows (observations)!', inputname(1)) end end diff --git a/src/utilities/x13/select_x13_binary.m b/src/utilities/x13/select_x13_binary.m index b7b3257eae52fe8194b98cd7d4e5f539515d4f4a..f24ce5768faa88a28fddc23c09a6cb30832948a5 100644 --- a/src/utilities/x13/select_x13_binary.m +++ b/src/utilities/x13/select_x13_binary.m @@ -59,7 +59,9 @@ end if ~exist(x13_binary, 'file') if warn_only - warning('X13 binary is not available.\nIf you are under Debian or Ubuntu, you can install it through your package manager, with ''apt install x13as''.\nIf you are under Windows or macOS, this probably means that you did not install the dseries toolbox through an official package.\n'); + warning(sprintf(['X13 binary is not available.\n' ... + 'If you are under Debian or Ubuntu, you can install it through your package manager, with ''apt install x13as''.\n' ... + 'If you are under Windows or macOS, this probably means that you did not install the dseries toolbox through an official package.\n'])); x13_binary = ''; else error('Can''t find X13 binary');