diff --git a/doc/dynare.texi b/doc/dynare.texi index 86c058224..0382dcf78 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -3774,7 +3774,7 @@ variables in declaration order. Of course, the shown form of the approximation is only stylized, because it neglects the required different ordering in @math{y^s} and @math{y^h_t}. The precise form of the approximation that shows the way Dynare deals with differences between declaration and DR-order, is -@math{y_t(oo_.dr.order_var) = y^s(oo_.dr.order_var) + A (y_{t-1}(oo_.dr.order_var(k2))-y^s(oo_.dr.order_var(k2))) + B u_t} +@math{y_t(oo\_.dr.order\_var) = y^s(oo\_.dr.order\_var) + A \cdot y_{t-1}(oo\_.dr.order\_var(k2))-y^s(oo\_.dr.order\_var(k2)) + B\cdot u_t} where @math{k2} selects the state variables, @math{y_t} and @math{y^s} are in declaration order and the coefficient matrices are in DR-order. Effectively, all variables on the right hand side are brought into DR order for computations and then assigned to @math{y_t} in declaration order. diff --git a/dynare++/parser/cc/atom_assignings.cpp b/dynare++/parser/cc/atom_assignings.cpp index 7335c9003..7b688f259 100644 --- a/dynare++/parser/cc/atom_assignings.cpp +++ b/dynare++/parser/cc/atom_assignings.cpp @@ -9,6 +9,7 @@ #include "utils/cc/exception.h" #include +#include using namespace ogp; diff --git a/matlab/@dynSeries/extract.m b/matlab/@dynSeries/extract.m index 7ca0ec5d9..8db2be194 100644 --- a/matlab/@dynSeries/extract.m +++ b/matlab/@dynSeries/extract.m @@ -66,7 +66,7 @@ for i=1:nargin-1 while ~isempty(expression) [token, expression] = strtok(expression,','); candidate = [VariableName(1:idArobase(1)-1), token, VariableName(idArobase(2)+1:end)]; - id = strmatch(candidate,B.name,'exact'); + id = find(strcmp(candidate,B.name)); if isempty(id) error(['dynSeries::extract: Variable ''' candidate ''' does not exist in dynSeries object ''' inputname(1) '''!']) else @@ -88,7 +88,7 @@ for i=1:nargin-1 while ~isempty(expression_2) [token_2, expression_2] = strtok(expression_2,','); candidate = [VariableName(1:idArobase(1)-1), token_1, VariableName(idArobase(2)+1:idArobase(3)-1), token_2, VariableName(idArobase(4)+1:end)]; - id = strmatch(candidate,B.name,'exact'); + id = find(strcmp(candidate,B.name)); if isempty(id) error(['dynSeries::extract: Variable ''' candidate ''' does not exist in dynSeries object ''' inputname(1) '''!']) else @@ -114,7 +114,7 @@ end % Get indices of the selected variables idVariableName = NaN(length(VariableName_),1); for i = 1:length(idVariableName) - idx = strmatch(VariableName_{i},B.name,'exact'); + idx = find(strcmp(VariableName_{i},B.name)); if isempty(idx) error(['dynSeries::extract: Variable ' VariableName_{i} ' is not a member of ' inputname(1) '!']) end diff --git a/matlab/@dynSeries/pop.m b/matlab/@dynSeries/pop.m index 371374eff..cb86737e5 100644 --- a/matlab/@dynSeries/pop.m +++ b/matlab/@dynSeries/pop.m @@ -45,7 +45,7 @@ function [ts,id] = pop(ts,a) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -id = strmatch(a,ts.name,'exact'); +id = find(strcmp(a,ts.name)); if isempty(id) id = 0; return diff --git a/matlab/@dynSeries/rename.m b/matlab/@dynSeries/rename.m index 9ba5186af..b8903738a 100644 --- a/matlab/@dynSeries/rename.m +++ b/matlab/@dynSeries/rename.m @@ -21,7 +21,7 @@ if ~ischar(old) || ~ischar(new) error(['dynSeries::rename: Input arguments ''' inputname(2) ''' and ''' inputname(3) ''' have to be strings!']) end -idname = strmatch(old,ts.name,'exact'); +idname = find(strcmp(old,ts.name)); if isempty(idname) error(['dynSeries::rename: Variable ' old ' is unknown in dynSeries object ' inputname(1) '!']) diff --git a/matlab/@dynSeries/subsasgn.m b/matlab/@dynSeries/subsasgn.m index 034f72502..11c2cf8b0 100644 --- a/matlab/@dynSeries/subsasgn.m +++ b/matlab/@dynSeries/subsasgn.m @@ -84,7 +84,7 @@ switch length(S) for i = 1:B.vobs if ~isequal(S(1).subs{i},B.name{i}) % Rename a variable. - id = strmatch(S(1).subs{i},A.name); + id = find(strcmp(S(1).subs{i},A.name)); if isempty(id) % Add a new variable a change its name. B.name(i) = {S(1).subs{i}}; @@ -118,7 +118,7 @@ switch length(S) % Single variable selection. if ~isequal(S(1).subs,B.name{1}) % Rename a variable. - id = strmatch(S(1).subs,A.name); + id = find(strcmp(S(1).subs,A.name)); if isempty(id) % Add a new variable a change its name. B.name(1) = {S(1).subs}; diff --git a/matlab/@dynSeries/subsref.m b/matlab/@dynSeries/subsref.m index d487859ff..32a235b40 100644 --- a/matlab/@dynSeries/subsref.m +++ b/matlab/@dynSeries/subsref.m @@ -154,7 +154,7 @@ switch S(1).type B = feval(S(1).subs,A,S(2).subs{:}); S = shiftS(S); otherwise % Extract a sub-object by selecting one variable. - ndx = strmatch(S(1).subs,A.name,'exact'); + ndx = find(strcmp(S(1).subs,A.name)); if ~isempty(ndx) B = dynSeries(); B.data = A.data(:,ndx); diff --git a/matlab/@dynSeries/tex_rename.m b/matlab/@dynSeries/tex_rename.m index 5cfa27fc4..28a2de480 100644 --- a/matlab/@dynSeries/tex_rename.m +++ b/matlab/@dynSeries/tex_rename.m @@ -32,7 +32,7 @@ assert(ischar(newtex), 'dynSeries::tex_rename: the newtex name must be a string' if nargin == 2 idname = 1; else - idname = strmatch(name, ts.name, 'exact'); + idname = find(strcmp(name, ts.name)); if isempty(idname) error(['dynSeries::tex_rename: Variable ' name ' is unknown in dynSeries object ' inputname(1) '!']) end diff --git a/matlab/getIrfShocksIndx.m b/matlab/getIrfShocksIndx.m index 715a530bc..737bfcfb1 100644 --- a/matlab/getIrfShocksIndx.m +++ b/matlab/getIrfShocksIndx.m @@ -1,6 +1,14 @@ function irf_shocks_indx=getIrfShocksIndx() - -% Copyright (C) 2011 Dynare Team +% irf_shocks_indx=getIrfShocksIndx() +% returns the unique indices of the exogenous shocks specified for IRF +% generation using the irf_shocks-command +% +% Inputs: +% none +% Outputs: +% irf_shocks_indx: [1 by n_irf_shocks] vector storing the indices +% +% Copyright (C) 2011-13 Dynare Team % % This file is part of Dynare. % @@ -26,4 +34,10 @@ else for i=1:size(options_.irf_shocks,1) irf_shocks_indx(i) = find(strcmp(deblank(options_.irf_shocks(i,:)), cellstr(M_.exo_names))); end + irf_shocks_indx_unique=unique(irf_shocks_indx); + if options_.debug && (length(irf_shocks_indx_unique) ~= length(irf_shocks_indx)) + fprintf('\nSTOCH_SIMUL: Warning: The IRFs for some shocks have been requested twice.\n') + fprintf('STOCH_SIMUL: The redundant entries will be ignored.\n') + end + irf_shocks_indx=irf_shocks_indx_unique; end diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 19829085d..ad894a6e3 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -690,7 +690,7 @@ string eofbuff; return token::INT_NUMBER; } --?[0-9]+[Mm]([1-9]|1[0-2])|-?[0-9]+[Qq][1-4]|-?[0-9]+[Ww]([1-9]{1}|[1-4][0-9]|5[0-2]) { +-?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2])) { yylval->string_val = new string(yytext); return token::DATE_NUMBER; } diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 37029fdcf..38bf5a782 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -2449,8 +2449,7 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in void ParsingDriver::add_native(const string &s) { - string ss = string(s); - mod_file->addStatement(new NativeStatement(ss)); + mod_file->addStatement(new NativeStatement(s)); } void diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc index 38da6e366..59021287b 100644 --- a/preprocessor/Statement.cc +++ b/preprocessor/Statement.cc @@ -18,7 +18,6 @@ */ #include "Statement.hh" -#include ModFileStructure::ModFileStructure() : check_present(false), @@ -66,76 +65,11 @@ Statement::computingPass() { } -NativeStatement::NativeStatement(string &native_statement_arg) : +NativeStatement::NativeStatement(const string &native_statement_arg) : native_statement(native_statement_arg) { } -void -NativeStatement::computingPass() -{ - using namespace boost::xpressive; - // Return if this is a comment - sregex comment_expr = sregex::compile( "\\s*\%.*" ); - match_results results; - if (regex_match(native_statement, results, comment_expr)) - return; - - // Otherwise, look at the line and consider substituting date - size_t idx = -1; - vector apostrophes; - while((idx = native_statement.find("'", idx + 1)) != string::npos) - if (apostrophes.size() < 2) - apostrophes.push_back(idx); - else - if (idx == apostrophes.back() + 1) - apostrophes.pop_back(); - else - apostrophes.push_back(idx); - - bool skip = false; - string newstr = ""; - sregex date_expr = sregex::compile( "-?[0-9]+[Mm](1[0-2]|[1-9])|-?[0-9]+[Qq][1-4]|-?[0-9]+[Ww]([1-4][0-9]|5[0-2]|[1-9])" ); - string format( "dynDate('$&')" ); - size_t lastidx = 0; - for (size_t i = 0; i < apostrophes.size(); i++) - if (apostrophes[i] == 0) - skip = true; - else - if (skip) - { - newstr.append(native_statement.substr(lastidx, apostrophes[i] - lastidx)); - lastidx = apostrophes[i]; - skip = false; - } - else - { - newstr.append(regex_replace(native_statement.substr(lastidx, apostrophes[i] - lastidx), - date_expr, format)); - lastidx = apostrophes[i]; - skip = true; - } - size_t length = native_statement.length() - lastidx; - size_t commentidx = native_statement.substr(lastidx, length).find("%", 0); - if (commentidx != string::npos) - length = commentidx; - - newstr.append(regex_replace(native_statement.substr(lastidx, length), date_expr, format)); - - if (commentidx != string::npos) - { - lastidx += commentidx; - newstr.append(native_statement.substr(lastidx, native_statement.length() - lastidx)); - } - - native_statement = newstr; -} - -void -regexReplace() -{ -} - void NativeStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/preprocessor/Statement.hh b/preprocessor/Statement.hh index 82f64fa79..cd3fd5cf3 100644 --- a/preprocessor/Statement.hh +++ b/preprocessor/Statement.hh @@ -121,12 +121,10 @@ public: class NativeStatement : public Statement { private: - string native_statement; + const string native_statement; public: - NativeStatement(string &native_statement_arg); - virtual void computingPass(); + NativeStatement(const string &native_statement_arg); virtual void writeOutput(ostream &output, const string &basename) const; - void regexReplace(); }; class OptionsList