Commit d71e785d authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Allow commands without arguments and fix commands compatibility.

parent 86b2daf7
......@@ -41,147 +41,174 @@ fprintf(fid, ' data = %s', sprintf(data2txt(o.y.data)));
fprintf(fid, '}\n\n');
% Write TRANSFORM block
if ~all(cellfun(@isempty, struct2cell(o.transform)))
optionnames = fieldnames(o.transform);
fprintf(fid, 'transform {\n');
for i=1:length(optionnames)
if ~isempty(o.transform.(optionnames{i}))
printoption(fid, optionnames{i}, o.transform.(optionnames{i}));
if ismember('transform', o.commands)
fprintf(fid, 'transform {');
if ~all(cellfun(@isempty, struct2cell(o.transform)))
fprintf(fid, '\n');
optionnames = fieldnames(o.transform);
for i=1:length(optionnames)
if ~isempty(o.transform.(optionnames{i}))
printoption(fid, optionnames{i}, o.transform.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
end
% Write REGRESSION block
if ~all(cellfun(@isempty, struct2cell(o.regression)))
optionnames = fieldnames(o.regression);
fprintf(fid, 'regression {\n');
for i=1:length(optionnames)
if ~isempty(o.regression.(optionnames{i}))
if isequal(optionnames{i}, 'user') % Write needed data to a file.
% Determine the set of needed data
conditionningvariables = strsplit(o.regression.user, {',' , '(' , ')' , ' '});
conditionningvariables = conditionningvariables(~cellfun(@isempty,conditionningvariables));
% Check that these data are available.
for i=1:length(conditionningvariables)
if ~ismember(conditionningvariables{i}, o.x.name)
fclose(fid);
error('x13:regression: Variable %s is unkonwn', conditionningvariables{i})
if ismember('regression', o.commands)
fprintf(fid, 'regression {');
if ~all(cellfun(@isempty, struct2cell(o.regression)))
optionnames = fieldnames(o.regression);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.regression.(optionnames{i}))
if isequal(optionnames{i}, 'user') % Write needed data to a file.
% Determine the set of needed data
conditionningvariables = strsplit(o.regression.user, {',' , '(' , ')' , ' '});
conditionningvariables = conditionningvariables(~cellfun(@isempty,conditionningvariables));
% Check that these data are available.
for i=1:length(conditionningvariables)
if ~ismember(conditionningvariables{i}, o.x.name)
fclose(fid);
error('x13:regression: Variable %s is unkonwn', conditionningvariables{i})
end
end
end
% Select the data.
if length(conditionningvariables)<vobs(o.x)
x = o.x{conditionningvariables{:}};
else
x= o.x;
end
% Print user statement.
fprintf(fid, ' user = %s\n', o.regression.user);
% Print data statement.
fprintf(fid, ' data = %s\n', sprintf(data2txt(x.data)));
elseif isequal(optionnames{i}, 'start')
if ischar(o.regression.start)
if isdate(o.regression.start)
PERIOD = dates(o.regression.start);
% Select the data.
if length(conditionningvariables)<vobs(o.x)
x = o.x{conditionningvariables{:}};
else
x= o.x;
end
% Print user statement.
fprintf(fid, ' user = %s\n', o.regression.user);
% Print data statement.
fprintf(fid, ' data = %s\n', sprintf(data2txt(x.data)));
elseif isequal(optionnames{i}, 'start')
if ischar(o.regression.start)
if isdate(o.regression.start)
PERIOD = dates(o.regression.start);
else
error('x13:regression: Option start cannot be interpreted as a date!')
end
elseif isdates(o.regression.start)
PERIOD = o.regression.start;
else
error('x13:regression: Option start cannot be interpreted as a date!')
end
elseif isdates(o.regression.start)
PERIOD = o.regression.start;
printstart(fid, PERIOD);
else
error('x13:regression: Option start cannot be interpreted as a date!')
printoption(fid, optionnames{i}, o.regression.(optionnames{i}));
end
printstart(fid, PERIOD);
else
printoption(fid, optionnames{i}, o.regression.(optionnames{i}));
end
end
if isempty(o.regression.start)
fprintf(fid, ' start = %i.%i\n', o.x.init.year, o.x.init.subperiod);
end
end
if isempty(o.regression.start)
fprintf(fid, ' start = %i.%i\n', o.x.init.year, o.x.init.subperiod);
end
fprintf(fid, '}\n\n');
fprintf(fid, '\n');
end
% Write ARIMA block
if ~all(cellfun(@isempty, struct2cell(o.arima)))
optionnames = fieldnames(o.arima);
fprintf(fid, 'arima {\n');
for i=1:length(optionnames)
if ~isempty(o.arima.(optionnames{i}))
printoption(fid, optionnames{i}, o.arima.(optionnames{i}));
if ismember('arima', o.commands)
fprintf(fid, 'arima {');
if ~all(cellfun(@isempty, struct2cell(o.arima)))
optionnames = fieldnames(o.arima);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.arima.(optionnames{i}))
printoption(fid, optionnames{i}, o.arima.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
end
% Write AUTOMDL block
if ~all(cellfun(@isempty, struct2cell(o.automdl)))
optionnames = fieldnames(o.automdl);
fprintf(fid, 'automdl {\n');
for i=1:length(optionnames)
if ~isempty(o.automdl.(optionnames{i}))
printoption(fid, optionnames{i}, o.automdl.(optionnames{i}));
if ismember('automdl', o.commands)
fprintf(fid, 'automdl {');
if ~all(cellfun(@isempty, struct2cell(o.automdl)))
optionnames = fieldnames(o.automdl);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.automdl.(optionnames{i}))
printoption(fid, optionnames{i}, o.automdl.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
end
% Write OUTLIER block
if ~all(cellfun(@isempty, struct2cell(o.outlier)))
optionnames = fieldnames(o.outlier);
fprintf(fid, 'outlier {\n');
for i=1:length(optionnames)
if ~isempty(o.outlier.(optionnames{i}))
printoption(fid, optionnames{i}, o.outlier.(optionnames{i}));
if ismember('outlier', o.commands)
fprintf(fid, 'outlier {');
if ~all(cellfun(@isempty, struct2cell(o.outlier)))
optionnames = fieldnames(o.outlier);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.outlier.(optionnames{i}))
printoption(fid, optionnames{i}, o.outlier.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
end
% Write FORECAST block
if ~all(cellfun(@isempty, struct2cell(o.forecast)))
optionnames = fieldnames(o.forecast);
fprintf(fid, 'forecast {\n');
for i=1:length(optionnames)
if ~isempty(o.forecast.(optionnames{i}))
printoption(fid, optionnames{i}, o.forecast.(optionnames{i}));
if ismember('forecast', o.commands)
fprintf(fid, 'forecast {');
if ~all(cellfun(@isempty, struct2cell(o.forecast)))
optionnames = fieldnames(o.forecast);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.forecast.(optionnames{i}))
printoption(fid, optionnames{i}, o.forecast.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
end
% Write ESTIMATE block
if ~all(cellfun(@isempty, struct2cell(o.estimate)))
optionnames = fieldnames(o.estimate);
fprintf(fid, 'estimate {\n');
for i=1:length(optionnames)
if ~isempty(o.estimate.(optionnames{i}))
printoption(fid, optionnames{i}, o.estimate.(optionnames{i}));
if ismember('estimate', o.commands)
fprintf(fid, 'estimate {');
if ~all(cellfun(@isempty, struct2cell(o.estimate)))
optionnames = fieldnames(o.estimate);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.estimate.(optionnames{i}))
printoption(fid, optionnames{i}, o.estimate.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
end
% Write CHECK block
if ~all(cellfun(@isempty, struct2cell(o.check)))
optionnames = fieldnames(o.check);
fprintf(fid, 'check {\n');
for i=1:length(optionnames)
if ~isempty(o.check.(optionnames{i}))
printoption(fid, optionnames{i}, o.check.(optionnames{i}));
if ismember('check', o.commands)
fprintf(fid, 'check {');
if ~all(cellfun(@isempty, struct2cell(o.check)))
optionnames = fieldnames(o.check);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.check.(optionnames{i}))
printoption(fid, optionnames{i}, o.check.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
end
% Write X11 block
if ~all(cellfun(@isempty, struct2cell(o.x11)))
optionnames = fieldnames(o.x11);
fprintf(fid, 'x11 {\n');
for i=1:length(optionnames)
if ~isempty(o.x11.(optionnames{i}))
printoption(fid, optionnames{i}, o.x11.(optionnames{i}));
if ismember('x11', o.commands)
fprintf(fid, 'x11 {');
if ~all(cellfun(@isempty, struct2cell(o.x11)))
optionnames = fieldnames(o.x11);
fprintf(fid, '\n');
for i=1:length(optionnames)
if ~isempty(o.x11.(optionnames{i}))
printoption(fid, optionnames{i}, o.x11.(optionnames{i}));
end
end
end
fprintf(fid, '}\n\n');
......
......@@ -28,6 +28,20 @@ switch S(1).type
disp(o.(S(1).subs))
else
if isequal(S(2).type,'()')
if ~ismember(S(1).subs, o.commands)
switch S(1).subs
case 'arima'
if ismember('automdl', o.commands)
error('x13:arima: ARIMA command is not compatible with AUTOMDL command!')
end
case 'automdl'
if ismember('arima', o.commands)
error('x13:automdl: AUTOMDL command is not compatible with ARIMA command!')
end
otherwise
end
o.command(end+1) = {S(1).subs};
end
if isempty(S(2).subs)
% Reset the member to its default (empty).
o.(S(1).subs) = setdefaultmember(S(1).subs);
......
......@@ -30,6 +30,7 @@ classdef x13<handle % --*-- Unitary tests --*--
check = []; % Check command.
x11 = []; % X11 cmmand
results = []; % Estimation results
commands = {}; % List of commands.
end
methods
......@@ -54,6 +55,7 @@ classdef x13<handle % --*-- Unitary tests --*--
o.check = setdefaultmember('check');
o.x11 = setdefaultmember('x11');
o.results = struct();
o.commands = {};
return
end
if isdseries(y)
......@@ -83,6 +85,7 @@ classdef x13<handle % --*-- Unitary tests --*--
o.check = setdefaultmember('check');
o.x11 = setdefaultmember('x11');
o.results = struct();
o.commands = {};
end
end
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment