diff --git a/src/@x13/run.m b/src/@x13/run.m index 559e9820726840ea800dbddc3986a078e40ae7fb..2e656c7066dd683747154e9a96cb1d887499323c 100644 --- a/src/@x13/run.m +++ b/src/@x13/run.m @@ -31,7 +31,14 @@ if ~exist(x13b, 'file') end % Run spc file. -[~, ~] = system(sprintf('%s %s', x13b, basename)); +[errorflag, msg] = system(sprintf('"%s" %s', x13b, basename)); + +if errorflag + skipline() + disp(msg) + skipline() + error('X13 failed on %s.spc', basename) +end o.results.name = basename; % Base name of the generated files. @@ -44,7 +51,7 @@ if ~all(cellfun(@isempty, struct2cell(o.regression))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -59,7 +66,7 @@ if ~all(cellfun(@isempty, struct2cell(o.x11))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -99,10 +106,14 @@ if ~all(cellfun(@isempty, struct2cell(o.transform))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end + if strcmp(o.transform.function,'auto') && any(strcmp(o.transform.savelog,{'autotransform','atr'})) + temp=fileread(sprintf('%s.log', basename)); + o.results.autotransform=regexp(temp,'[^\n]*Automatic transformation test[^\n]*','match'); + end end % Save results related to the OUTLIER command @@ -118,7 +129,7 @@ if ~all(cellfun(@isempty, struct2cell(o.outlier))) header = strjoin(tmp.textdata(1)); header = strsplit(header, {'\t'}); header = header(1,2:end); - o.results.(savedoutput{i}) = dseries(data(:,2:end), o.y.init, regexprep(header,'\(|\)','')); + o.results.(savedoutput{i}) = dseries(data(:,2:end), o.y.firstobservedperiod, regexprep(header,'\(|\)','')); elseif lower(savedoutput{i}) == 'oit' header = strjoin(tmp.textdata(1,1)); header = strsplit(header, {'\t'}); @@ -219,7 +230,7 @@ if ~all(cellfun(@isempty, struct2cell(o.force))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -254,7 +265,7 @@ if ~all(cellfun(@isempty, struct2cell(o.seats))) if exist(sprintf('%s.%s', basename, lower(savedoutput{i}))) tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -273,7 +284,7 @@ if ~all(cellfun(@isempty, struct2cell(o.x11regression))) else tmp = importdata(sprintf('%s.%s', basename, lower(savedoutput{i})), '\t'); data = tmp.data; - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); end end end @@ -324,12 +335,12 @@ if ~all(cellfun(@isempty, struct2cell(o.estimate))) header = strsplit(header, {'\t'}); header = regexprep(header(1,2:end),'( ||\-)',''); for j = 1:numel(header) - o.results.(savedoutput{i}).(header{j}) = dseries(data(:,j+1), o.y.init, header(j)); + o.results.(savedoutput{i}).(header{j}) = dseries(data(:,j+1), o.y.firstobservedperiod, header(j)); end elseif lower(savedoutput{i}) == 'rrs' - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); elseif lower(savedoutput{i}) == 'rsd' - o.results.(savedoutput{i}) = dseries(data(:,2), o.y.init, savedoutput{i}); + o.results.(savedoutput{i}) = dseries(data(:,2), o.y.firstobservedperiod, savedoutput{i}); elseif lower(savedoutput{i}) == 'rts' header = strjoin(tmp.textdata(1,1)); header = strsplit(header, {'\t'}); @@ -375,3 +386,27 @@ end % Save main generated output file. o.results.out = fileread(sprintf('%s.out', basename)); + +return % --*-- Unit tests --*-- + +%@test:1 +try + data_mat=[NaN; randn(20,1)]; + ts = dseries(data_mat,'1999Q1'); + o = x13(ts); + o.transform('function','auto'); + o.automdl('savelog','amd'); + o.x11('save','(d11)'); + o.run(); + deseasonalized_data = o.results.d11; + if deseasonalized_data.init~=dates('1999Q2') + t(1) = false; + else + t(1) = true; + end +catch + t(1) = false; +end +T = all(t); + +%@eof:1 diff --git a/src/utilities/print/data2txt.m b/src/utilities/print/data2txt.m index 434c36525fa39da46407f132deb3d84d17ec86b4..0c7fd5a19bf2da5f2e142447fe58f6d49462618c 100644 --- a/src/utilities/print/data2txt.m +++ b/src/utilities/print/data2txt.m @@ -1,8 +1,8 @@ -function str= data2txt(y) +function str= data2txt(y) % --*-- Unitary tests --*-- % Prints a one dimensional array. -% Copyright (C) 2017 Dynare Team +% Copyright © 2017-2022 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -18,6 +18,49 @@ function str= data2txt(y) % along with Dynare. If not, see <https://www.gnu.org/licenses/>. str = mat2str(y); +str = strrep(str, 'NaN', '-99999'); str = strrep(str, '[', '(\n'); str = strrep(str, ';', '\n'); -str = strrep(str, ']', '\n)'); \ No newline at end of file +str = strrep(str, ']', '\n)'); + +return + +%@test:1 +try + data_mat=[NaN + 1 + 3 + 3 + 4 + 1 + 2 + 3 + 4 + 1.5 + 2.3 + 3.1 + NaN + 1.2 + NaN + 3 + 5]; + + + ts = dseries(data_mat,'1999Q1'); + o = x13(ts); + o.transform('function','log'); + o.automdl('savelog','amd'); + o.x11('save','(d11)'); + o.run(); + deseasonalized_data = o.results.d11; + if deseasonalized_data.nobs~=16 || deseasonalized_data.init~=dates('1999Q2') + t(1) = false; + else + t(1) = true; + end +catch + t(1) = false; +end +T = all(t); + +%@eof:1 \ No newline at end of file