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

Moved routines and updated submodules dseries and dates.

parent 55e8c231
function b = check_file_extension(file,type)
% Copyright (C) 2012 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/>.
% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr
% Clean-up path
file = strrep(file, '../', '');
file = strrep(file, './', '');
remain = file;
while ~isempty(remain)
[ext, remain] = strtok(remain,'.');
end
b = strcmp(ext,type);
\ No newline at end of file
function [n,message] = common_strings_in_cell_arrays(a,b)
%@info:
%! @deftypefn {Function File} {[@var{n}, @var{message} ] =} common_strings_in_cell_arrays (@var{a}, @var{b})
%! @anchor{common_strings_in_cell_arrays}
%! @sp 1
%! Counts the number of common strings in two cell arrays of strings @var{a} and @var{b}.
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item a
%! One dimensional cell array of strings.
%! @item b
%! One dimensional cell array of strings.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item n
%! Scalar integer, number of common strings.
%! @item message
%! String, formatted list of common strings.
%! @end table
%! @end deftypefn
%@eod:
% 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/>.
common_strings = intersect(a,b);
n = numel(common_strings);
if nargout>1
switch n
case 0
message = [];
case 1
message = common_strings{1};
case 2
message = [common_strings{1} ' and ' common_strings{2}];
otherwise
message = common_strings{1};
for i = 2:n-1
message = [message ', ' common_strings{i}];
end
message = [message ' and ' common_strings{n}];
end
end
%@test:1
%$ % Define cell arrays of strings.
%$ A = {'A1'; 'A2'; 'A3'; 'A4'};
%$ B = {'B1'; 'B2'; 'B3'; 'B4'};
%$
%$ try
%$ n = common_strings_in_cell_arrays(A,B);
%$ [m,message] = common_strings_in_cell_arrays(A,B);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dassert(n,m);
%$ t(3) = dassert(n,0);
%$ t(4) = dassert(isempty(message),1);
%$ end
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define cell arrays of strings.
%$ A = {'A1'; 'A2'; 'A3'; 'A4'};
%$ B = {'B1'; 'A2'; 'B3'; 'A4'};
%$
%$ try
%$ n = common_strings_in_cell_arrays(A,B);
%$ [m,message] = common_strings_in_cell_arrays(A,B);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dassert(n,m);
%$ t(3) = dassert(n,2);
%$ t(4) = dassert(message,'A2 and A4');
%$ end
%$ T = all(t);
%@eof:2
%@test:2
%$ % Define cell arrays of strings.
%$ A = {'A1'; 'A2'; 'A3'; 'A4'; 'A5'; 'A6'};
%$ B = {'B1'; 'A2'; 'B3'; 'A4'; 'A1'};
%$
%$ try
%$ n = common_strings_in_cell_arrays(A,B);
%$ [m,message] = common_strings_in_cell_arrays(A,B);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dassert(n,m);
%$ t(3) = dassert(n,3);
%$ t(4) = dassert(message,'A2, A4 and A1');
%$ end
%$ T = all(t);
%@eof:3
function str = get_random_string(n);
%@info:
%! @deftypefn {Function File} {@var{str} =} get_random_string (@var{n})
%! @anchor{get_random_string}
%! @sp 1
%! Builds a random string (starting with a letter).
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item a
%! Scalar integer, number of characters in the generated string.
%! @end table
%! @sp 1
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item str
%! Generated string
%! @end table
%! @sp 2
%! @strong{This function is called by:}
%! @sp 2
%! @strong{This function calls:}
%! @ref{set_time}
%!
%! @end deftypefn
%@eod:
% Copyright (C) 2012 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/>.
% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr
str0 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
m0 = 2*26;
m1 = m0+10;
str = str0(ceil(rand*m0)); % First character has to be a letter!
str = [str, str0(ceil(rand(1,n-1)*m1))];
\ No newline at end of file
function matrix = insert_column_vector_in_a_matrix(matrix, vector, i) % --*-- Unitary tests --*--
% 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/>.
if nargin<2
error('insert_column_vector_in_a_matrix: I need at least two input arguments!')
end
if ~isequal(ndims(matrix),2)
error(['insert_column_vector_in_a_matrix: First input ''' inputname(1) ''' must be a matrix!'])
end
[n,m] = size(matrix);
if nargin<3
i = m+1;
end
if ~isvector(vector) || ~isequal(numel(vector),size(vector,1)) || ~isequal(numel(vector),n)
error(['insert_column_vector_in_a_matrix: Second input argument ''' inputname(2) ''' must be a ' int2str(n) ' by 1 vector!'])
end
switch i
case m+1
matrix = [matrix, vector];
case 1
matrix = [vector, matrix];
otherwise
matrix = [matrix(:,1:i-1), vector, matrix(:,i:m)];
end
%@test:1
%$ % Define a datasets.
%$ A = rand(8,3); b = rand(8,1);
%$
%$ try
%$ A4 = insert_column_vector_in_a_matrix(A, b);
%$ A1 = insert_column_vector_in_a_matrix(A, b, 1);
%$ A2 = insert_column_vector_in_a_matrix(A, b, 2);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(A4,[A,b],1e-15);
%$ t(3) = dassert(A1,[b,A],1e-15);
%$ t(4) = dassert(A2,[A(:,1), b, A(:,2:end)],1e-15);
%$ end
%$ T = all(t);
%@eof:1
\ No newline at end of file
function one_dimensional_cell_array = insert_object_in_a_one_dimensional_cell_array(one_dimensional_cell_array, object, i) % --*-- Unitary tests --*--
% 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/>.
if nargin<2
error('insert_object_in_a_one_dimensional_cell_array: I need at least two input arguments!')
end
if ~iscell(one_dimensional_cell_array)
error(['insert_column_vector_in_a_matrix: First input ''' inputname(1) ''' must be a cell array!'])
end
[nr, nc] = size(one_dimensional_cell_array);
if ~isequal(nr*nc,numel(one_dimensional_cell_array))
error(['insert_column_vector_in_a_matrix: First input ''' inputname(1) ''' must be a one dimensional cell array!'])
end
n = numel(one_dimensional_cell_array);
if nargin<3
i = n+1;
end
one_dimensional_cell_array = one_dimensional_cell_array(:);
switch i
case n+1
one_dimensional_cell_array = [one_dimensional_cell_array; object];
case 1
one_dimensional_cell_array = [object; one_dimensional_cell_array];
otherwise
one_dimensional_cell_array = [one_dimensional_cell_array(1:i-1); object; one_dimensional_cell_array(i:n)];
end
if nc>nr
one_dimensional_cell_array = transpose(one_dimensional_cell_array);
end
%@test:1
%$ A = {'A1'; 'A2'; 'A3'}; b = [1, pi];
%$
%$ try
%$ C4 = insert_object_in_a_one_dimensional_cell_array(A, b);
%$ C1 = insert_object_in_a_one_dimensional_cell_array(A, b, 1);
%$ C2 = insert_object_in_a_one_dimensional_cell_array(A, b, 2);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(C4,[A;b]);
%$ t(3) = dassert(C1,[b;A],1e-15);
%$ t(4) = dassert(C2,[A(1); b; A(2:3)]);
%$ end
%$ T = all(t);
%@eof:1
\ No newline at end of file
Subproject commit 46ea0bd1c30e7c76d823247689b6e59417f11c44
Subproject commit cb29cec352522cf2e8b029a2febe5ae502f86859
Subproject commit b1abd7ab95bfc04f5b18850a18478af8b6fe5573
Subproject commit 73edfb1fd1964e44dc7afcf7d512a3e305e50828
function one_dimensional_cell_array = replace_object_in_a_one_dimensional_cell_array(one_dimensional_cell_array, object, i)
% 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/>.
if nargin<3
error('replace_object_in_a_one_dimensional_cell_array: I need at least three input arguments!')
end
if ~iscell(one_dimensional_cell_array)
error(['replace_column_vector_in_a_matrix: First input ''' inputname(1) ''' must be a cell array!'])
end
[nr, nc] = size(one_dimensional_cell_array);
if ~isequal(max([nr,nc]),numel(one_dimensional_cell_array))
error(['replace_column_vector_in_a_matrix: First input ''' inputname(1) ''' must be a one dimensional cell array!'])
end
n = numel(one_dimensional_cell_array);
if ~isint(i) || i<1 || i>n
error(['replace_column_vector_in_a_matrix: Last input ''' inputname(3) ''' must be a positive integer less than or equal to ' int2str(n) '!'])
end
one_dimensional_cell_array = one_dimensional_cell_array(:);
% Remove object i.
switch i
case n
one_dimensional_cell_array = one_dimensional_cell_array(1:n-1);
case 1
one_dimensional_cell_array = one_dimensional_cell_array(2:n);
otherwise
one_dimensional_cell_array = [one_dimensional_cell_array(1:i-1); one_dimensional_cell_array(i+1:n)];
end
% convert object to a cell array if needed.
if ~iscell(object)
object = {object};
end
% Insert object at position i
one_dimensional_cell_array = insert_object_in_a_one_dimensional_cell_array(one_dimensional_cell_array, object(:), i);
% transpose cell array if needed.
if nc>nr
one_dimensional_cell_array = transpose(one_dimensional_cell_array);
end
%@test:1
%$ A = {'A12'; 'A3'; 'A4'}; B = {'A1'; 'A2'};
%$
%$ try
%$ C = replace_object_in_a_one_dimensional_cell_array(A, B, 1);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(C,[B; A(2:3)]);
%$ end
%$ T = all(t);
%@eof:1
%@test:2
%$ A = {'A1'; 'A3'; 'A4'}; B = 'B1';
%$
%$ try
%$ C = replace_object_in_a_one_dimensional_cell_array(A, B, 2);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ D = {'A1';'B1';'A4'};
%$ if t(1)
%$ t(2) = dassert(C,D);
%$ end
%$ T = all(t);
%@eof:2
\ No newline at end of file
function a = iscellofchar(b)
% Copyright (C) 2012-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/>.
a = 1;
if ndims(b)>2
error(['iscellofchar: Input argument ''' inputname(1) ''' has to be a two dimensional cell array!'])
end
[n,m] = size(b);
p = numel(b);
q = 0;
for i=1:m
for j=1:n
if ischar(b{j,i})
q = q + 1;
end
end
end
if ~isequal(q,p)
a = 0;
end
\ No newline at end of file
function a = isglobalinbase(var)
% 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/>.
tmp = whos('global');
if isempty(strmatch(var,{tmp.name}))
a = 0;
else
a = 1;
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.
%
% 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/>.
if nargin<2
info = 0;
end
if info
if iscell(name)
nn = length(name);
else
nn = 1;
end
end
if isoctave
tex = regexprep(name, '_', '\_');
else
tex = regexprep(name, '_', '\\_');
end
if info
for i=1:nn
if iscell(name)
texname = tex{i};
else
texname = tex;
end
idx = strfind(texname,'_');
ndx = length(idx);
ntx = length(texname);
if ndx
gotonextcondition = 1;
if isequal(ndx,1) && ~isequal(idx,2) && ~isequal(idx,ntx)
texname = [ texname(1:idx-2) '_{' texname(idx+1:end) '}'];
gotonextcondition = 0;
end
if gotonextcondition && isequal(ndx,2) && ~isequal(idx(1),2) && isequal(idx(2),ntx)
texname = [ texname(1:idx(1)-2) '_{' texname(idx(1)+1:end) '}' ];
gotonextcondition = 0;
end
if gotonextcondition && isequal(ndx,2) && idx(2)<ntx
texname = [ texname(1:idx(2)-2) '_{' texname(idx(2)+1:end) '}' ];
gotonextcondition = 0;
end
if gotonextcondition && ndx>2
if idx(end)<ntx
texname = [ texname(1:idx(end)-2) '_{' texname(idx(end)+1:end) '}' ];