Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Show changes
......@@ -41,7 +41,7 @@ function us = ydiff(ts) % --*-- Unitary tests --*--
us = ts;
switch ts.freq
switch frequency(ts)
case 1
us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
us.data(1,:) = NaN;
......@@ -55,21 +55,21 @@ switch ts.freq
for i = 1:ts.vobs
us.name(i) = {['ydiff(' us.name{i} ')']};
us.tex(i) = {['\Delta_4 ' us.tex{i}]};
end
end
case 12
us.data(13:end,:) = ts.data(13:end,:)-ts.data(1:end-12,:);
us.data(1:12,:) = NaN;
for i = 1:ts.vobs
us.name(i) = {['ydiff(' us.name{i} ')']};
us.tex(i) = {['\Delta_{12} ' us.tex{i}]};
end
end
case 52
us.data(53:end,:) = ts.data(53:end,:)-ts.data(1:end-52,:);
us.data(1:52,:) = NaN;
for i = 1:ts.vobs
us.name(i) = {['ydiff(' us.name{i} ')']};
us.tex(i) = {['\Delta_{52} ' us.tex{i}]};
end
end
otherwise
error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
end
......
......@@ -41,7 +41,7 @@ function us = ygrowth(ts) % --*-- Unitary tests --*--
us = ts;
switch ts.freq
switch frequency(ts)
case 1
us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
us.data(1,:) = NaN;
......@@ -55,7 +55,7 @@ switch ts.freq
for i = 1:ts.vobs
us.name(i) = {['ygrowth(' us.name{i} ')']};
us.tex(i) = {['\delta_4 ' us.tex{i}]};
end
end
case 12
us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1;
us.data(1:12,:) = NaN;
......
......@@ -62,6 +62,7 @@ addpath([dynareroot '/utilities/tests/'])
addpath([dynareroot '/utilities/dates/'])
addpath([dynareroot '/utilities/dataset/'])
addpath([dynareroot '/utilities/general/'])
addpath([dynareroot '/utilities/dseries/'])
addpath([dynareroot '/reports/'])
% For functions that exist only under some Octave versions
......@@ -248,4 +249,8 @@ if verbose
skipline()
end
% Save empty dates and dseries objects (necessary if a mod file is not preprocessed).
dates('initialize');
dseries('initialize');
cd(origin);
......@@ -27,12 +27,16 @@ time(:,1) = time(:,1) + fix(p/freq);
time(:,2) = time(:,2) + rem(p,freq);
id1 = find(time(:,2)>freq);
time(id1,1) = time(id1,1) + 1;
time(id1,2) = time(id1,2) - freq;
if ~isempty(id1)
time(id1,1) = time(id1,1) + 1;
time(id1,2) = time(id1,2) - freq;
end
id2 = find(time(:,2)<1);
time(id2,1) = time(id2,1) - 1;
time(id2,2) = time(id2,2) + freq;
if ~isempty(id2)
time(id2,1) = time(id2,1) - 1;
time(id2,2) = time(id2,2) + freq;
end
%@test:1
%$ t(1) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 1),[1950 2]);
......
function time = add_periods_to_date(time, freq, p) % --*-- Unitary tests --*--
% Adds a p periods (p can be negative) to a date (or a set of dates) characterized by array time and frequency freq.
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
time(1) = time(1) + fix(p/freq);
time(2) = time(2) + rem(p,freq);
if time(2)>freq
time(1) = time(1) + 1;
time(2) = time(2) - freq;
end
if time(2)<1
time(1) = time(1) - 1;
time(2) = time(2) + freq;
end
%@test:1
%$ t(1) = dyn_assert(add_periods_to_date([1950 1], 4, 1),[1950 2]);
%$ t(2) = dyn_assert(add_periods_to_date([1950 1], 4, 2),[1950 3]);
%$ t(3) = dyn_assert(add_periods_to_date([1950 1], 4, 3),[1950 4]);
%$ t(4) = dyn_assert(add_periods_to_date([1950 1], 4, 4),[1951 1]);
%$ t(5) = dyn_assert(add_periods_to_date([1950 1], 4, 5),[1951 2]);
%$ t(6) = dyn_assert(add_periods_to_date([1950 1], 4, 6),[1951 3]);
%$ t(7) = dyn_assert(add_periods_to_date([1950 1], 4, 7),[1951 4]);
%$ t(8) = dyn_assert(add_periods_to_date([1950 1], 4, 8),[1952 1]);
%$ T = all(t);
%@eof:1
%@test:2
%$ t(1) = dyn_assert(add_periods_to_date([1950 1], 4, -1),[1949 4]);
%$ t(2) = dyn_assert(add_periods_to_date([1950 1], 4, -2),[1949 3]);
%$ t(3) = dyn_assert(add_periods_to_date([1950 1], 4, -3),[1949 2]);
%$ t(4) = dyn_assert(add_periods_to_date([1950 1], 4, -4),[1949 1]);
%$ t(5) = dyn_assert(add_periods_to_date([1950 1], 4, -5),[1948 4]);
%$ t(6) = dyn_assert(add_periods_to_date([1950 1], 4, -6),[1948 3]);
%$ t(7) = dyn_assert(add_periods_to_date([1950 1], 4, -7),[1948 2]);
%$ t(8) = dyn_assert(add_periods_to_date([1950 1], 4, -8),[1948 1]);
%$ T = all(t);
%@eof:2
\ No newline at end of file
......@@ -25,11 +25,11 @@ function b = isdate(str) % --*-- 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 length(str)>1
%if length(str)>1
b = isquaterly(str) || isyearly(str) || ismonthly(str) || isweekly(str);
else
b = 0;
end
%else
%b = 0;
%end
%@test:1
%$
......
......@@ -26,7 +26,11 @@ function b = ismonthly(str) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ischar(str)
b = ~isempty(regexp(str,'^-?[0-9]*[Mm]([1-9]|1[0-2])$'));
if isempty(regexp(str,'^-?[0-9]*[Mm]([1-9]|1[0-2])$','once'))
b = 0;
else
b = 1;
end
else
b = 0;
end
......
......@@ -25,8 +25,12 @@ function b = isquaterly(str) % --*-- 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 ischar(str)
b = ~isempty(regexp(str,'^-?[0-9]*[Qq][1-4]$'));
if ischar(str)
if isempty(regexp(str,'^-?[0-9]*[Qq][1-4]$','once'))
b = 0;
else
b = 1;
end
else
b = 0;
end
......
......@@ -26,7 +26,11 @@ function b = isweekly(str) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ischar(str)
b = ~isempty(regexp(str,'^-?[0-9]*[Ww]([1-9]|[1-4][0-9]|5[0-2])$'));
if isempty(regexp(str,'^-?[0-9]*[Ww]([1-9]|[1-4][0-9]|5[0-2])$','once'))
b = 0;
else
b = 1;
end
else
b = 0;
end
......
......@@ -26,7 +26,11 @@ function b = isyearly(str) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ischar(str)
b = ~isempty(regexp(str,'^-?[0-9]*[YyAa]$'));
if isempty(regexp(str,'^-?[0-9]*[YyAa]$','once'))
b = 0;
else
b = 1;
end
else
b = 0;
end
......
......@@ -26,7 +26,7 @@ end
if isyearly(a)
year = 1:(regexp(a,'[AaYy]')-1);
date.freq = 1;
date.time = write_time_field(a, year);
date.time = write_time_field_y(a, year);
return
end
......@@ -51,13 +51,14 @@ if isweekly(a)
return
end
function b = write_time_field(c, d)
b(1) = str2num(c(d));
if ismember(c(d(end)+1),{'Y','y','A','a'})
b(2) = 1;
else
b(2) = str2num(c(d(end)+2:end));
end
b(1) = str2double(c(d));
b(2) = str2double(c(d(end)+2:end));
function b = write_time_field_y(c, d)
b(1) = str2double(c(d));
b(2) = 1;
%@test:1
%$
......
function from(varargin)
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
lvarargin = lower(varargin);
to_id = strmatch('to',lvarargin);
do_id = strmatch('do',lvarargin);
if isempty(to_id) || isempty(do_id)
error(get_error_message_0())
end
if do_id<to_id
msg = sprinf('dseries::from: Wrong syntax! The TO keyword must preceed the DO keyword.\n');
error(get_error_message_0(msg))
end
if ~isdate(varargin{1})
% The first argument is not a string formatted date. Test if this argument refers to a dates object
% in the caller workspace.
try
d1 = evalin('caller', varargin{1});
if ~isdates(d1)
error(['dseries::from: Variable ' varargin{1} ' is not a dates object!'])
end
catch
error(['dseries::from: Variable ' varargin{1} ' is unknown!'])
end
if ~exist('d1')
msg = sprintf('dseries::from: Wrong syntax! The FROM statement must be followed by a string formatted date.\n');
error(get_error_message_0(msg))
end
else
d1 = dates(varargin{1}); % First date
end
if ~isequal(to_id,2)
msg = sprintf('dseries::from: Wrong syntax! The first dates object must be immediately followed by the TO keyword.\n');
error(get_error_message_0(msg))
end
if ~isdate(varargin{3})
% The third argument is not a string formatted date. Test if this argument refers to a dates object
% in the caller workspace.
try
d2 = evalin('caller', varargin{3});
if ~isdates(d2)
error(['dseries::from: Variable ' varargin{3} ' is not a dates object!'])
end
catch
error(['dseries::from: Variable ' varargin{3} ' is unknown!'])
end
if ~exist('d2')
msg = sprintf('dseries::from: Wrong syntax! The TO keyword must be followed by a second dates object.\n');
error(get_error_message_0(msg))
end
else
d2 = dates(varargin{3}); % Last date
end
if d1>d2
error('dseries::from: The first date must preceed the second one!')
end
if ~isequal(do_id,4)
msg = sprintf('dseries::from: Wrong syntax! The second dates object must be immediately followed by the DO keyword.\n');
error(get_error_message_0(msg))
end
% Build the recursive expression.
EXPRESSION = char([varargin{5:end}]);
% Get all the variables involved in the recursive expression.
variables = unique(regexpi(EXPRESSION, '\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)|\w*\.\w*\(t\)|\w*\.\w*\(t\-\d\)|\w*\.\w*\(t\+\d\)','match'));
% Copy EXPRESSION in expression. In the next loop we will remove all indexed variables from expression.
expression = EXPRESSION;
% Build an incidence table (max lag/lead for each variable)
%
% Column 1: Name of the variable.
% Column 2: Maximum lag order.
% Column 3: Equal to 1 if the variable appears at the current period, 0 otherwise.
% Column 4: Maximum lead order.
% Column 5: Vector of effective lag orders.
% Column 6: Vector of effective lead orders.
%
% Initialization.
leadlagtable = cell(0,6);
% Loop over the variables (dseries objects).
for i=1:length(variables)
expression = strrep(expression,variables{i},'');
current = ~isempty(regexpi(variables{i},'\(t\)'));
lag = ~isempty(regexpi(variables{i},'\(t\-\d\)'));
lead = ~isempty(regexpi(variables{i},'\(t\+\d\)'));
start = regexpi(variables{i},'\(t\)|\(t\-\d\)|\(t\+\d\)');
index = variables{i}(start:end);
variables(i) = {variables{i}(1:start-1)};
if isempty(leadlagtable)
leadlagtable(1,1) = {variables{i}};
if current
leadlagtable(1,3) = {1};
else
leadlagtable(1,3) = {0};
end
if lag
tmp = regexpi(index,'\d','match');
leadlagtable(1,2) = {str2double(tmp{1})};
leadlagtable(1,5) = {str2double(tmp{1})};
else
leadlagtable(1,2) = {0};
leadlagtable(1,5) = {[]};
end
if lead
tmp = regexpi(index,'\d','match');
leadlagtable(1,4) = {str2double(tmp{1})};
leadlagtable(1,6) = {str2double(tmp{1})};
else
leadlagtable(1,4) = {0};
leadlagtable(1,6) = {[]};
end
else
linea = strmatch(variables{i},leadlagtable(:,1));
if isempty(linea)
% This is a new variable!
linea = size(leadlagtable,1)+1;
leadlagtable(linea,1) = {variables{i}};
leadlagtable(linea,2) = {0};
leadlagtable(linea,3) = {0};
leadlagtable(linea,4) = {0};
leadlagtable(linea,5) = {[]};
leadlagtable(linea,6) = {[]};
end
if current
leadlagtable(linea,3) = {1};
end
if lag
tmp = regexpi(index,'\d','match');
leadlagtable(linea,2) = {max(str2double(tmp{1}),leadlagtable{linea,2})};
leadlagtable(linea,5) = {sortrows([leadlagtable{linea,5}; str2double(tmp{1})])};
end
if lead
tmp = regexpi(index,'\d','match');
leadlagtable(linea,4) = {max(str2double(tmp{1}),leadlagtable{linea,4})};
leadlagtable(linea,6) = {sortrows([leadlagtable{linea,6}; str2double(tmp{1})])};
end
end
end
% Set the number of variables
number_of_variables = size(leadlagtable,1);
% Initialize a cell array containing the names of the variables.
variable_names = cell(1);
% Test that all the involved variables are available dseries objects. Also check that
% these time series are defined over the time range given by d1 and d2 (taking care of
% the lags and leads) and check that each object is a singleton
for i=1:number_of_variables
current_variable = leadlagtable{i,1};
idvar = strfind(current_variable,'.');
if isempty(idvar)
idvar = 0;
end
if idvar
current_variable_0 = current_variable(1:idvar-1);
else
current_variable_0 = current_variable;
end
try
var = evalin('caller',current_variable_0);
catch
error(['dseries::from: Variable ' current_variable_0 ' is unknown!'])
end
if idvar
try
eval(sprintf('var = var.%s;',current_variable(idvar+1:end)))
catch
error(sprintf('dseries::from: Variable %s is not a member of dseries oject %s!', current_variable(idvar+1:end), current_variable_0))
end
end
if ~isdseries(var)
error(['dseries::from: Variable ' current_variable ' is not a dseries object!'])
else
if ~var.vobs
msg = sprintf('dseries::from: Object %s must not be empty!\n',current_variable);
error(msg)
end
if var.vobs>1
msg = sprintf('dseries::from: Object %s must contain only one variable!\n',current_variable);
error(msg)
end
if i>1
if ismember(var.name,variable_names)
error('dseries::from: All the dseries objects should contain variables with different names!')
else
variable_names(i) = {var.name{1}};
end
else
variable_names(i) = {var.name{1}};
end
if d1<var.dates(1)+leadlagtable{i,2}
msg = sprintf('dseries::from: Initial date of the loop (%s) is inconsistent with %s''s range!\n',char(d1),current_variable);
msg = [msg, sprintf(' Initial date should be greater than or equal to %s.',char(var.dates(1)+leadlagtable{i,2}))];
error(msg)
end
if d2>var.dates(end)-leadlagtable{i,4}
msg = sprintf('dseries::from: Last date of the loop (%s) is inconsistent with %s''s range!\n',char(d2),current_variable);
msg = [msg, sprintf(' Last date should be less than or equal to %s.',char(var.dates(end)-leadlagtable{i,4}))];
error(msg)
end
eval(sprintf('%s = var;',current_variable));
end
end
% Check that the recursion is assigning something to a variable
equal_id = strfind(EXPRESSION,'=');
if isempty(equal_id)
error('dseries::from: Wrong syntax! The expression following the DO keyword must be an assignment (missing equal symbol).')
end
if isequal(length(equal_id),1)
% Get the name of the assigned variable (with time index)
assignedvariablename = regexpi(EXPRESSION(1:equal_id-1), '\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)|\w*\.\w*\(t\)|\w*\.\w*\(t\-\d\)|\w*\.\w*\(t\+\d\)','match');
if isempty(assignedvariablename)
error('dseries::from: Wrong syntax! The expression following the DO keyword must be an assignment (missing variable before the equal symbol).')
end
if length(assignedvariablename)>1
error('dseries::from: No more than one variable can be assigned!')
end
% Check if the model is static
start = regexpi(assignedvariablename{1},'\(t\)|\(t\-\d\)|\(t\+\d\)');
index = assignedvariablename{1}(start:end);
assignedvariablename = assignedvariablename{1}(1:start-1);
indva = strmatch(assignedvariablename, leadlagtable(:,1));
dynamicmodel = ~isempty(regexpi(EXPRESSION(equal_id:end), ...
sprintf('%s\\(t\\)|%s\\(t\\-\\d\\)|%s\\(t\\+\\d\\)',assignedvariablename,assignedvariablename,assignedvariablename),'match'));
% Check that the dynamic model for the endogenous variable is not forward looking.
if dynamicmodel
indum = index2num(index);
if indum<leadlagtable{indva,4}
error('dseries::from: It is not possible to simulate a forward looking model!')
end
end
% Check that the assigned variable does not depend on itself (the assigned variable can depend on its past level but not on the current level).
if dynamicmodel
tmp = regexpi(EXPRESSION(equal_id+1:end), ...
sprintf('%s\\(t\\)|%s\\(t\\-\\d\\)|%s\\(t\\+\\d\\)',assignedvariablename,assignedvariablename,assignedvariablename),'match');
tmp = cellfun(@extractindex, tmp);
tmp = cellfun(@index2num, tmp);
if ~all(tmp(:)<indum)
error(sprintf('dseries::from: On the righthand side, the endogenous variable, %s, must be indexed by %s at most.',assignedvariablename,num2index(indum-1)))
end
end
else
error('dseries::from: Not yet implemented! Only one assignment is allowed in the FROM-TO-DO statement.')
end
% Put all the variables in a unique dseries object.
list_of_variables = leadlagtable{1,1};
for i=2:number_of_variables
list_of_variables = [list_of_variables, ',' leadlagtable{i,1}];
end
eval(sprintf('tmp = [%s];', list_of_variables));
% Get base time index
t1 = find(d1==tmp.dates);
t2 = find(d2==tmp.dates);
% Get data
data = tmp.data;
% Isolate the (potential) parameters in the expression to be evaluated
[~, TMP314] = strsplit(expression,'([0-9]*\.[0-9]*|\w*)','DelimiterType','RegularExpression','CollapseDelimiters',false);
% Here I remove the numbers (TMP314 -> TMP314159).
TMP3141 = regexp(TMP314,'(([0-9]*\.[0-9]*)|([0-9]*))','match');
TMP31415 = find(cellfun(@isempty,TMP3141));
TMP314159 = TMP314(TMP31415);
if dynamicmodel
% Transform EXPRESSION by replacing calls to the dseries objects by references to data.
for i=1:number_of_variables
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t\\)',leadlagtable{i,1}),sprintf('data(t,%s)',num2str(i)));
for j=1:length(leadlagtable{i,5})
lag = leadlagtable{i,5}(j);
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t-%s\\)',leadlagtable{i,1},num2str(lag)), ...
sprintf('data(t-%s,%s)',num2str(lag),num2str(i)));
end
for j=1:length(leadlagtable{i,6})
lead = leadlagtable{i,6}(j);
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t+%s\\)',leadlagtable{i,1},num2str(lead)), ...
sprintf('data(t+%s,%s)',num2str(lead),num2str(i)));
end
end
% Get values for the parameters (if any)
if ~isempty(TMP314159)
for i=1:length(TMP314159)
wordcandidate = TMP314159{i};
try % If succesful, word is a reference to a variable in the caller function/script.
thiswordisaparameter = evalin('caller', wordcandidate);
eval(sprintf('%s = thiswordisaparameter;',wordcandidate));
catch
% I assume that word is a reference to a function.
end
end
end
% Do the job. Evaluate the recursion.
eval(sprintf('for t=%s:%s, %s; end',num2str(t1),num2str(t2),EXPRESSION));
else
% Transform EXPRESSION by replacing calls to the dseries objects by references to data.
for i=1:number_of_variables
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t\\)',leadlagtable{i,1}), ...
sprintf('data(%s:%s,%s)',num2str(t1),num2str(t2),num2str(i)));
for j=1:length(leadlagtable{i,5})
lag = leadlagtable{i,5}(j);
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t-%s\\)',leadlagtable{i,1},num2str(lag)), ...
sprintf('data(%s:%s,%s)',num2str(t1-lag),num2str(t2-lag),num2str(i)));
end
for j=1:length(leadlagtable{i,6})
lead = leadlagtable{i,6}(j);
EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t+%s\\)',leadlagtable{i,1},num2str(lead)), ...
sprintf('data(%s:%s,%s)',num2str(t1-lead),num2str(t2-lead),num2str(i)));
end
end
% Transform some operators (^ -> .^, / -> ./ and * -> .*)
EXPRESSION = strrep(EXPRESSION,'^','.^');
EXPRESSION = strrep(EXPRESSION,'*','.*');
EXPRESSION = strrep(EXPRESSION,'/','./');
% Get values for the parameters (if any)
if ~isempty(TMP314159)
for i=1:length(TMP314159)
wordcandidate = TMP314159{i};
try % If succesful, word is a reference to a variable in the caller function/script.
thiswordisaparameter = evalin('caller', wordcandidate);
eval(sprintf('%s = thiswordisaparameter;',wordcandidate));
catch
% I assume that word is a reference to a function.
end
end
end
% Do the job. Evaluate the static expression.
eval(sprintf('%s;',EXPRESSION));
end
% Put assigned variable back in the caller workspace...
if isempty(strfind(assignedvariablename,'.'))
eval(sprintf('assignin(''caller'', ''%s'', dseries(data(:,indva),%s.init,%s.name,%s.tex));', ...
assignedvariablename,assignedvariablename,assignedvariablename,assignedvariablename))
else
DATA = num2cell(data(:,indva));
strdata = sprintf('%f ', DATA{:});
evalin('caller',sprintf('%s = dseries(transpose([%s]),%s.init,%s.name,%s.tex);', ...
assignedvariablename,strdata,assignedvariablename,assignedvariablename,assignedvariablename))
end
function msg = get_error_message_0(msg)
if ~nargin
msg = sprintf('Wrong syntax! The correct syntax is:\n\n');
else
msg = [msg, sprintf('The correct syntax is:\n\n')];
end
msg = [msg, sprintf(' from d1 to d2 do SOMETHING\n\n')];
msg = [msg, sprintf('where d1<d2 are dates objects, and SOMETHING is a recursive expression involving dseries objects.')];
function index = extractindex(str)
index = regexpi(str,'\(t\)|\(t\-\d\)|\(t\+\d\)','match');
function i = index2num(id)
if isequal('(t)',id)
i = 0;
return
end
if isequal('-',id(3))
i = - str2num(id(4:end-1));
else
i = str2num(id(4:end-1));
end
function id = num2index(i)
if isequal(i,0)
id = '(t)';
return
end
if i<0
id = ['(t-' int2str(abs(i)) ')'];
else
id = ['(t+' int2str(i) ')'];
end
\ No newline at end of file
function tex = name2tex(name, info) % --*-- Unitary tests --*--
% Converts plain text name into tex name.
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
......@@ -64,7 +64,7 @@ if info
if gotonextcondition && ndx>2
if idx(end)<ntx
texname = [ texname(1:idx(end)-2) '_{' texname(idx(end)+1:end) '}' ];
else
else
texname = [ texname(1:idx(end-1)-2) '_{' texname(idx(end-1)+1:end) '}' ];
end
end
......@@ -93,9 +93,9 @@ end
%$ t14 = name2tex('azert_uiop',1);
%$ t15 = name2tex('azert_uiop_qsdfg',1);
%$ t16 = name2tex('azert_uiop_qsdfg_',1);
%$ t17 = name2tex('_azert_uiop_qsdfg',1);
%$ t17 = name2tex('_azert_uiop_qsdfg',1);
%$ t18 = name2tex('_azert_uiop_qsdfg_',1);
%$
%$
%$ t(1) = dyn_assert(strcmp(t1,'\\_azert'),1);
%$ t(2) = dyn_assert(strcmp(t2,'azert\\_'),1);
%$ t(3) = dyn_assert(strcmp(t3,'\\_azert\\_'),1);
......@@ -106,7 +106,7 @@ end
%$ t(8) = dyn_assert(strcmp(t8,'\\_azert\\_uiop\\_qsdfg\\_'),1);
%$ t(9) = dyn_assert(strcmp(t11,'\\_azert'),1);
%$ t(10) = dyn_assert(strcmp(t12,'azert\\_'),1);
%$ t(11) = dyn_assert(strcmp(t13,'\\_azert\\_'),1);
%$ t(11) = dyn_assert(strcmp(t13,'\\_azert\\_'),1);
%$ t(12) = dyn_assert(strcmp(t14,'azert_{uiop}'),1);
%$ t(13) = dyn_assert(strcmp(t15,'azert\\_uiop_{qsdfg}'),1);
%$ t(14) = dyn_assert(strcmp(t16,'azert\\_uiop_{qsdfg\\_}'),1);
......@@ -185,7 +185,6 @@ end
%@eof:3
%@test:4
%$ pwd
%$ try
%$ db = dseries('csv/dd.csv');
%$ t(1) = 1;
......
......@@ -554,6 +554,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
mOutputFile << "clear all" << endl;
mOutputFile << "tic;" << endl
<< "% Save empty dates and dseries objects in memory." << endl
<< "dates('initialize');" << endl
<< "dseries('initialize');" << endl
<< "% Define global variables." << endl
<< "global M_ oo_ options_ ys0_ ex0_ estimation_info" << endl
<< "options_ = [];" << endl
<< "M_.fname = '" << basename << "';" << endl
......