diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6501527ec4564460f0cee71207c5b98cb1a6cf8b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*~ +externals +src/git.info +src/git.last-commit-hash \ No newline at end of file diff --git a/src/@dseries/cumprod.m b/src/@dseries/cumprod.m index 1f4b656e1dad49225aff980e917345d9c8a94b43..bf7e96b86ed33e11443cb02213640ea9d311be47 100644 --- a/src/@dseries/cumprod.m +++ b/src/@dseries/cumprod.m @@ -179,9 +179,7 @@ end %$ ds = dseries([.25; .5; 1; 2; 4; 8; 16], [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts,ts); -%$ warning_config +%$ t(1) = dassert(ts.data,ds.data); %$ T = all(t); %@eof:3 @@ -203,9 +201,7 @@ end %$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts3,ts4); -%$ warning_config +%$ t(1) = dassert(ts3.data,ts4.data); %$ T = all(t); %@eof:4 @@ -227,8 +223,6 @@ end %$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts3,ts4); -%$ warning_config +%$ t(1) = dassert(ts3.data,ts4.data); %$ T = all(t); %@eof:5 \ No newline at end of file diff --git a/src/@dseries/cumsum.m b/src/@dseries/cumsum.m index d5fe1c426bd09446e4b52d0dae17561ae82f8076..350657566fc9bd2b4728af4684649301c8a11be4 100644 --- a/src/@dseries/cumsum.m +++ b/src/@dseries/cumsum.m @@ -124,9 +124,7 @@ end %$ ts2 = dseries(transpose(1:10), [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts1,ts2); -%$ warning_config +%$ t(1) = dassert(ts1.data,ts2.data); %$ T = all(t); %@eof:1 @@ -147,9 +145,7 @@ end %$ ts2 = dseries(transpose(1:10), [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts1,ts2); -%$ warning_config +%$ t(1) = dassert(ts1.data,ts2.data); %$ T = all(t); %@eof:2 @@ -162,7 +158,7 @@ end %$ %$ % Instantiate a time series object. %$ ts1 = dseries(A,[],A_name,[]); -%$ +%$ %$ % Call the tested method. %$ ts1 = cumsum(ts1,dates('3Y')); %$ @@ -170,9 +166,7 @@ end %$ ts2 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7], [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts1,ts2); -%$ warning_config +%$ t(1) = dassert(ts1.data,ts2.data); %$ T = all(t); %@eof:3 @@ -194,9 +188,7 @@ end %$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts3,ts4); -%$ warning_config +%$ t(1) = dassert(ts3.data,ts4.data); %$ T = all(t); %@eof:4 @@ -218,8 +210,6 @@ end %$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []); %$ %$ % Check the results. -%$ warning off, % Because the names of the variables are not the same... -%$ t(1) = dassert(ts3,ts4); -%$ warning_config +%$ t(1) = dassert(ts3.data,ts4.data); %$ T = all(t); %@eof:5 \ No newline at end of file diff --git a/src/@dseries/dseries.m b/src/@dseries/dseries.m index 27a0fe4efd9d04c860424adc39ad861fc9ba5dde..7492c44598ccca5301e232ef143ab15ad0a1137a 100644 --- a/src/@dseries/dseries.m +++ b/src/@dseries/dseries.m @@ -277,7 +277,12 @@ end %$ t = zeros(6,1); %$ %$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data.m','dynseries_test_data.m'); +%$ if ~status +%$ error() +%$ end %$ ts = dseries('dynseries_test_data.m'); +%$ delete('dynseries_test_data.m'); %$ t(1) = 1; %$ catch %$ t = 0; @@ -298,7 +303,12 @@ end %$ t = zeros(6,1); %$ %$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data.mat','dynseries_test_data.mat'); +%$ if ~status +%$ error() +%$ end %$ ts = dseries('dynseries_test_data.mat'); +%$ delete('dynseries_test_data.mat'); %$ t(1) = 1; %$ catch %$ t = 0; @@ -319,7 +329,12 @@ end %$ t = zeros(8,1); %$ %$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data.csv','dynseries_test_data.csv'); +%$ if ~status +%$ error() +%$ end %$ ts = dseries('dynseries_test_data.csv'); +%$ delete('dynseries_test_data.csv'); %$ t(1) = 1; %$ catch %$ t = 0; @@ -409,7 +424,12 @@ end %@test:9 %$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-1.xls','dynseries_test_data-1.xls'); +%$ if ~status +%$ error() +%$ end %$ ts = dseries('dynseries_test_data-1.xls'); +%$ delete('dynseries_test_data-1.xls'); %$ t(1) = 1; %$ catch %$ t(1) = 0; @@ -430,7 +450,12 @@ end %@test:10 %$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-2.xls','dynseries_test_data-2.xls'); +%$ if ~status +%$ error() +%$ end %$ ts = dseries('dynseries_test_data-2.xls'); +%$ delete('dynseries_test_data-2.xls'); %$ t(1) = 1; %$ catch %$ t(1) = 0; @@ -451,7 +476,12 @@ end %@test:11 %$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-3.xls','dynseries_test_data-3.xls'); +%$ if ~status +%$ error() +%$ end %$ ts = dseries('dynseries_test_data-3.xls'); +%$ delete('dynseries_test_data-3.xls'); %$ t(1) = 1; %$ catch %$ t(1) = 0; @@ -472,7 +502,12 @@ end %@test:12 %$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-4.xls','dynseries_test_data-4.xls'); +%$ if ~status +%$ error() +%$ end %$ ts = dseries('dynseries_test_data-4.xls'); +%$ delete('dynseries_test_data-4.xls'); %$ t(1) = 1; %$ catch %$ t(1) = 0; diff --git a/src/@dseries/save.m b/src/@dseries/save.m index 3e8b478fc8ebad46cb55453135ef8a71d8da7385..87584a7aa77c2f31c174120a5949196c078cd2e6 100644 --- a/src/@dseries/save.m +++ b/src/@dseries/save.m @@ -29,8 +29,9 @@ end switch format case 'm' - if exist([basename, '.m'],'file') - copyfile([basename, '.m'],[basename, '.old.m']); + currentdirectorycontent = dir(); + if ismember([basename, '.m'],{currentdirectorycontent.name}) + copyfile([basename, '.m'],[basename, '.m.csv']); end fid = fopen([basename, '.m'],'w'); fprintf(fid,'%% File created on %s.\n',datestr(now)); @@ -72,12 +73,14 @@ switch format str = [str, A.name{v} ' = A.data(:,' num2str(v) ');' ]; end eval(str); - if exist([basename, '.mat'],'file') + currentdirectorycontent = dir(); + if ismember([basename, '.mat'],{currentdirectorycontent.name}) copyfile([basename, '.mat'],[basename, '.old.mat']); end save([basename '.mat'],'INIT__','FREQ__','NAMES__','TEX__',A.name{:}); case 'csv' - if exist([basename, '.csv'],'file') + currentdirectorycontent = dir(); + if ismember([basename, '.csv'],{currentdirectorycontent.name}) copyfile([basename, '.csv'],[basename, '.old.csv']); end fid = fopen([basename, '.csv'],'w'); @@ -106,6 +109,8 @@ end %$ t = 0; %$ end %$ +%$ delete('ts1.csv'); +%$ %$ T = all(t); %@eof:1 @@ -125,6 +130,8 @@ end %$ t = 0; %$ end %$ +%$ delete('ts1.m'); +%$ %$ T = all(t); %@eof:2 @@ -144,6 +151,8 @@ end %$ t = 0; %$ end %$ +%$ delete('ts1.mat'); +%$ %$ T = all(t); %@eof:3 @@ -167,5 +176,7 @@ end %$ t = 0; %$ end %$ +%$ delete('ts1.csv'); +%$ %$ T = all(t); %@eof:4 diff --git a/src/@dseries/subsref.m b/src/@dseries/subsref.m index 67b99f0b215ff146d44db0af349a5819e3645215..6a165a33ed1750a25b4b88b166e37b6d637a6141 100644 --- a/src/@dseries/subsref.m +++ b/src/@dseries/subsref.m @@ -364,7 +364,12 @@ end %$ t = zeros(5,1); %$ %$ try -%$ A = dataset('dynseries_test_data.csv'); +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data.csv','dynseries_test_data.csv'); +%$ if ~status +%$ error() +%$ end +%$ A = dseries('dynseries_test_data.csv'); +%$ delete('dynseries_test_data.csv'); %$ t(1) = 1; %$ catch %$ t = 0; @@ -467,6 +472,8 @@ end %$ t = 0; %$ end %$ +%$ delete('ts1.csv'); +%$ %$ T = all(t); %@eof:7 @@ -481,6 +488,7 @@ end %$ try %$ ts1 = dseries(A,[],A_name,[]); %$ ts1.save('test_generated_data_file','m'); +%$ delete('test_generated_data_file.m'); %$ t = 1; %$ catch %$ t = 0; @@ -589,32 +597,34 @@ end %$ t = 0; %$ end %$ +%$ delete('ts1.csv') +%$ %$ T = all(t); %@eof:12 -%@test:13 -%$ try -%$ data = transpose(0:1:50); -%$ ts = dseries(data,'1950Q1'); -%$ a = ts.lag; -%$ b = ts.lead; -%$ tt = dynTimeIndex(); -%$ c = ts(tt-1); -%$ d = ts(tt+1); -%$ t(1) = 1; -%$ catch -%$ t(1) = 0; -%$ end -%$ -%$ if t(1)>1 -%$ t(2) = (a==c); -%$ t(3) = (b==d); -%$ end -%$ -%$ T = all(t); -%@eof:13 +% % @test:13 +% %$ try +% %$ data = transpose(0:1:50); +% %$ ts = dseries(data,'1950Q1'); +% %$ a = ts.lag; +% %$ b = ts.lead; +% %$ tt = dynTimeIndex(); +% %$ c = ts(tt-1); +% %$ d = ts(tt+1); +% %$ t(1) = 1; +% %$ catch +% %$ t(1) = 0; +% %$ end +% %$ +% %$ if t(1)>1 +% %$ t(2) = (a==c); +% %$ t(3) = (b==d); +% %$ end +% %$ +% %$ T = all(t); +% %@eof:13 -%@test:14 +%@test:13 %14 %$ try %$ data = transpose(0:1:50); %$ ts = dseries(data,'1950Q1'); @@ -633,9 +643,9 @@ end %$ end %$ %$ T = all(t); -%@eof:14 +%@eof:13 -%@test:15 +%@test:14 %15 %$ try %$ ds = dseries(transpose(1:5)); %$ ts = ds(ds.dates(2:3)); @@ -650,9 +660,9 @@ end %$ end %$ %$ T = all(t); -%@eof:15 +%@eof:14 -%@test:16 +%@test:15 %16 %$ try %$ ds = dseries(transpose(1:5)); %$ ts = ds(ds.dates(2:6)); @@ -662,9 +672,9 @@ end %$ end %$ %$ T = all(t); -%@eof:16 +%@eof:15 -%@test:17 +%@test:16 %17 %$ try %$ ds = dseries(transpose(1:5)); %$ ts = ds(dates('1Y'):dates('6Y')); @@ -674,9 +684,9 @@ end %$ end %$ %$ T = all(t); -%@eof:17 +%@eof:16 -%@test:18 +%@test:17 %18 %$ try %$ ds = dseries(transpose(1:5)); %$ ts = ds(dates('-2Y'):dates('4Y')); @@ -686,4 +696,4 @@ end %$ end %$ %$ T = all(t); -%@eof:18 \ No newline at end of file +%@eof:17 \ No newline at end of file diff --git a/src/@dseries/vertcat.m b/src/@dseries/vertcat.m index 093bee9c08957e3432a7f8e17a048f3bb945954d..da3178962699449c72e7b343325e54f9dfc0bc71 100644 --- a/src/@dseries/vertcat.m +++ b/src/@dseries/vertcat.m @@ -66,11 +66,21 @@ function d = vertcat_(b, c) if ~isequal(vobs(b), vobs(c)) error('dseries::vertcat: Number of variables must be common!') end + reorder_variables_in_c = false; if ~isequal(b.name, c.name) - error('dseries::vertcat: Variables must be common!') + [t, idx] = ismember(c.name, b.name); + if all(t) + reorder_variables_in_c = true; + else + error('dseries::vertcat: Variables must be common!') + end end d = b; - d.data = [b.data; c.data]; + if reorder_variables_in_c + d.data = [b.data; c.data(:,idx)]; + else + d.data = [b.data; c.data]; + end d.dates = [b.dates; c.dates]; %@test:1 diff --git a/src/initialize_dseries_toolbox.m b/src/initialize_dseries_toolbox.m new file mode 100644 index 0000000000000000000000000000000000000000..4948e569728f78628f1f300a9199fc65c1f0a2d4 --- /dev/null +++ b/src/initialize_dseries_toolbox.m @@ -0,0 +1,39 @@ +% Check that the dates module is available. +try + initialize_dates_toolbox; +catch + urlwrite('https://github.com/DynareTeam/dates/archive/master.zip','master.zip'); + warning('off','MATLAB:MKDIR:DirectoryExists') + mkdir('../externals') + warning('on','MATLAB:MKDIR:DirectoryExists') + unzip('master.zip','../externals') + delete('master.zip') + addpath([pwd() '/../externals/dates-master/src']) + initialize_dates_toolbox; +end + +% Get the path to the dseries toolbox. +dseries_src_root = strrep(which('initialize_dseries_toolbox'),'initialize_dseries_toolbox.m',''); + +% Add some subfolders to the path. +addpath([dseries_src_root '/read']) +addpath([dseries_src_root '/utilities/is']) +addpath([dseries_src_root '/utilities/str']) +addpath([dseries_src_root '/utilities/insert']) +addpath([dseries_src_root '/utilities/file']) +addpath([dseries_src_root '/utilities/from']) + +% Add missing routines if dynare is not in the path +if ~exist('demean','file') + addpath([dseries_src_root '/utilities/missing/demean']) +end + +if ~exist('ndim','file') + addpath([dseries_src_root '/utilities/missing/ndim']) +end + +if ~exist('sample_hp_filter','file') + addpath([dseries_src_root '/utilities/missing/sample_hp_filter']) +end + +dseries('initialize'); \ No newline at end of file diff --git a/src/read/load_csv_file_data.m b/src/read/load_csv_file_data.m index f6b1ed537ae3cf14b11e16b647f9169550d06d2c..a6fdfc416a315bf0873280b0711c7b7768ab2527 100644 --- a/src/read/load_csv_file_data.m +++ b/src/read/load_csv_file_data.m @@ -11,7 +11,7 @@ function [freq, init, data, varlist] = load_csv_file_data(file) % o data matrix of doubles, the data. % o varlist cell of strings, names of the variables. % -% REMARKS +% REMARKS % The varlist output will be set only if the first line contains variable % names. Similarly, if the first column does not contain dates, then % freq will be 1 and init will be year 1. @@ -62,7 +62,7 @@ if isoctave fid = fopen(file, 'r'); bfile = fread(fid); fclose(fid); - + if isunix || ismac newline_code = 10; elseif ispc @@ -70,7 +70,7 @@ if isoctave else error('load_csv_file_data is not implemented for your OS'); end - + % Get the positions of the end-of-line code end_of_line_locations = find(bfile==newline_code); if ispc && isempty(end_of_line_locations) @@ -78,16 +78,33 @@ if isoctave end_of_line_locations = find(bfile==newline_code); end; tmp = find(bfile==newline_code); - + % Get the number of lines in the file ndx = length(tmp); - + % Create a cell of indices for each line b = [1; end_of_line_locations+1]; c = [end_of_line_locations-1; length(bfile)+1]; b = b(1:end-1); c = c(1:end-1); linea = 1; + + + % Test the content of the first elements of the first column + withtime = 1; + for r=2:length(b) + linee = char(transpose(bfile(b(r):c(r)))); + [B,C] = get_cells_id(linee,','); + if ~isdates(linee(B(1):C(1))) + break + end + end + + % Test the content of the first line + linee = char(transpose(bfile(b(1):c(1)))); + [B,C] = get_cells_id(linee,','); + withnames = isvarname(linee(B(2):C(2))); + if withnames % Get the first line of the csv file (names of the variables). linee = char(transpose(bfile(b(linea):c(linea)))); @@ -105,7 +122,7 @@ if isoctave varlist = strtrim(varlist); linea = linea+1; end - + % Get following line (number 1 or 2 depending on withnames flag) linee = char(transpose(bfile(b(linea):c(linea)))); comma_locations = transpose(strfind(linee,',')); @@ -126,14 +143,14 @@ if isoctave else first = 1; end - + if ~withnames number_of_variables = length(tmp)-withtime; end - + % Initialization of matrix data. data = zeros(ndx,number_of_variables); - + % Populate data. for linea = 1+withnames:ndx linee = char(transpose(bfile(b(linea):c(linea)))); @@ -142,17 +159,18 @@ if isoctave data(linea,i-withtime) = str2double(linee(B(i):C(i))); end end - + % Remove first line if withnames data = data(1+withnames:ndx, :); end + return else A = importdata(file, ','); if ~isstruct(A) data = A; T = {}; withvars = 0; - withtime = 0; + withtime = 0; else data = A.data; T = A.textdata; diff --git a/src/read/load_mat_file_data.m b/src/read/load_mat_file_data.m index 98825a49a3113f4648a3aa619b27f067b7a0bd90..3cba896db45aa95a0e5cd669f137456f4e5934eb 100644 --- a/src/read/load_mat_file_data.m +++ b/src/read/load_mat_file_data.m @@ -107,6 +107,8 @@ end %$ return %$ end %$ +%$ delete('datafile_for_test.mat'); +%$ %$ % Check the results. %$ t(2) = dassert(freq,12); %$ t(3) = dassert(isa(init,'dates'),true); @@ -141,6 +143,8 @@ end %$ return %$ end %$ +%$ delete('datafile_for_test.mat'); +%$ %$ % Check the results. %$ t(2) = dassert(freq,12); %$ t(3) = dassert(isa(init,'dates'),true); diff --git a/src/utilities/file/check_file_extension.m b/src/utilities/file/check_file_extension.m new file mode 100644 index 0000000000000000000000000000000000000000..70107015e0e3c38bd24fbe2dc2358b10e0beeb30 --- /dev/null +++ b/src/utilities/file/check_file_extension.m @@ -0,0 +1,38 @@ +function b = check_file_extension(file,type) + +% Check file extension of a file. Returns 1 (true) if the extension of ```file``` is equal to +% ```type```, 0 (false) otherwise. +% +% INPUTS +% - file [str] file name. +% - type [str] file extension. +% +% OUTPUTS +% - b [bool] + + +% Copyright (C) 2012-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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/>. + +% 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 diff --git a/src/from.m b/src/utilities/from/from.m similarity index 100% rename from src/from.m rename to src/utilities/from/from.m diff --git a/src/utilities/insert/insert_column_vector_in_a_matrix.m b/src/utilities/insert/insert_column_vector_in_a_matrix.m new file mode 100644 index 0000000000000000000000000000000000000000..11884240161c4f9473bdacc0303774e3b2e1b9f0 --- /dev/null +++ b/src/utilities/insert/insert_column_vector_in_a_matrix.m @@ -0,0 +1,74 @@ +function matrix = insert_column_vector_in_a_matrix(matrix, vector, i) % --*-- Unitary tests --*-- + +% Inserts a vector in a matrix in a column specified by i. +% +% INPUTS +% - matrix [float] n*m matrix. +% - vector [float] n*1 vector. +% - i [integer] scalar between 1 and m+1. Default value is m+1. +% +% OUTPUTS +% - matrix [float] n*(m+1) matrix. + +% Copyright (C) 2013-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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 diff --git a/src/utilities/insert/insert_object_in_a_one_dimensional_cell_array.m b/src/utilities/insert/insert_object_in_a_one_dimensional_cell_array.m new file mode 100644 index 0000000000000000000000000000000000000000..c8ce6632fd6e6d5a82c3a13a7a04bdebf5284b24 --- /dev/null +++ b/src/utilities/insert/insert_object_in_a_one_dimensional_cell_array.m @@ -0,0 +1,81 @@ +function one_dimensional_cell_array = insert_object_in_a_one_dimensional_cell_array(one_dimensional_cell_array, object, i) % --*-- Unitary tests --*-- + +% Inserts an object in a one dimensional cell array in a position specified by i. +% +% INPUTS +% - one_dimensional_cell_array [any] cell array with n objects. +% - object [any] scalar object. +% - i [integer] scalar between 1 and n+1. Default value is m+1. +% +% OUTPUTS +% - one_dimensional_cell_array [any] cell array with n+1 elements. + +% Copyright (C) 2013-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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 diff --git a/src/utilities/insert/replace_object_in_a_one_dimensional_cell_array.m b/src/utilities/insert/replace_object_in_a_one_dimensional_cell_array.m new file mode 100644 index 0000000000000000000000000000000000000000..b5fcfff553733a3d996ddca09c9bc831df5223f8 --- /dev/null +++ b/src/utilities/insert/replace_object_in_a_one_dimensional_cell_array.m @@ -0,0 +1,105 @@ +function one_dimensional_cell_array = replace_object_in_a_one_dimensional_cell_array(one_dimensional_cell_array, object, i) + +% Replaces an object in a one dimensional cell array in a position specified by i. +% +% INPUTS +% - one_dimensional_cell_array [any] cell array with n objects. +% - object [any] scalar object. +% - i [integer] scalar between 1 and n. +% +% OUTPUTS +% - one_dimensional_cell_array [any] cell array with n+1 elements. + +% Copyright (C) 2013-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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 diff --git a/src/utilities/is/iscellofchar.m b/src/utilities/is/iscellofchar.m new file mode 100644 index 0000000000000000000000000000000000000000..a9100f61ca57a94d1a32642753a3d4d57ad1cfdb --- /dev/null +++ b/src/utilities/is/iscellofchar.m @@ -0,0 +1,46 @@ +function a = iscellofchar(b) + +% Returns true iff ```b``` is a cell of char. +% +% INPUTS +% - b [any] +% +% OUTPUTS +% - a [bool] + +% Copyright (C) 2012-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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 = true; + +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 = false; +end \ No newline at end of file diff --git a/src/isdseries.m b/src/utilities/is/isdseries.m similarity index 70% rename from src/isdseries.m rename to src/utilities/is/isdseries.m index 9d2c7d2497887f75a8b336f097fedc07a2791ce3..3c9e71f90cd1556c378127e19fe091e195a80d93 100644 --- a/src/isdseries.m +++ b/src/utilities/is/isdseries.m @@ -1,15 +1,15 @@ function B = isdseries(A) -% Copyright (C) 2011-2013 Dynare Team -% -% This file is part of Dynare. +% Returns true iff ```A``` is a dseries object. + +% Copyright (C) 2011-2015 Dynare Team % -% Dynare is free software: you can redistribute it and/or modify +% 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 % 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, +% Dynare dseries submodule 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. diff --git a/src/utilities/is/isglobalinbase.m b/src/utilities/is/isglobalinbase.m new file mode 100644 index 0000000000000000000000000000000000000000..8280ac610a04155d96fd4b0cec013697c6708431 --- /dev/null +++ b/src/utilities/is/isglobalinbase.m @@ -0,0 +1,31 @@ +function a = isglobalinbase(var) + +% Returns true iff ```var``` is a global variable in the main workspace. +% +% INPUTS +% - var [any] +% +% OUTPUTS +% - a [bool] + +% Copyright (C) 2013-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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 diff --git a/src/utilities/missing/demean/demean.m b/src/utilities/missing/demean/demean.m new file mode 100644 index 0000000000000000000000000000000000000000..bcfa3b5dbfad4934c9561e00de77a09771f52186 --- /dev/null +++ b/src/utilities/missing/demean/demean.m @@ -0,0 +1,32 @@ +function c = demean(x) + +% Removes the mean of each column of a matrix. +% +% INPUTS +% - x [float] T*n matrix. +% +% OUTPUTS +% - c [float] T*n matrix, the demeaned matrix x. + +% Copyright (C) 2011-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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 ndim(x)==1 + c = x-mean(x); +elseif ndim(x)==2 + c = bsxfun(@minus,x,mean(x)); +else + error('descriptive_statistics::demean:: This function is not implemented for arrays with dimension greater than two!') +end \ No newline at end of file diff --git a/src/utilities/missing/ndim/ndim.m b/src/utilities/missing/ndim/ndim.m new file mode 100644 index 0000000000000000000000000000000000000000..dc62e80d231b86bdef33ce6866ccea676b9561ec --- /dev/null +++ b/src/utilities/missing/ndim/ndim.m @@ -0,0 +1,26 @@ +function n = ndim(x) + +% Returns the number of non singleton dimensions of a matlab array. +% +% INPUTS +% - x [array] +% +% OUTPUTS +% - n [integer] number of non singleton dimensions. + +% Copyright (C) 2012-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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/>. + +n = sum(size(x)>1); \ No newline at end of file diff --git a/src/utilities/missing/sample_hp_filter/sample_hp_filter.m b/src/utilities/missing/sample_hp_filter/sample_hp_filter.m new file mode 100644 index 0000000000000000000000000000000000000000..77dddb82ad59ca4b048ca13f0f16992cd7a2cbd1 --- /dev/null +++ b/src/utilities/missing/sample_hp_filter/sample_hp_filter.m @@ -0,0 +1,43 @@ +function [hptrend,hpcycle] = sample_hp_filter(y,s) + +% HP filters a collection of time series. +% +% INPUTS +% y [double] T*n matrix of data (n is the number of variables) +% s [double] scalar, smoothing parameter. +% +% OUTPUTS +% hptrend [double] T*n matrix, trend component of y. +% hpcycle [double] T*n matrix, cycle component of y. + +% Copyright (C) 2010-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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/>. + +[T,n] = size(y); + +if nargin<2 || isempty(s) + s = 1600; +end + +D = spdiags(repmat([s, -4.0*s, (1 + 6.0*s), -4.0*s, s], T, 1), -2:2, T, T);% Sparse matrix. +D(1,1) = 1.0+s; D(T,T) = D(1,1); +D(1,2) = -2.0*s; D(2,1) = D(1,2); D(T-1,T) = D(1,2); D(T,T-1) = D(1,2); +D(2,2) = 1.0+5.0*s; D(T-1,T-1) = D(2,2); + +hptrend = D\y; + +if nargout>1 + hpcycle = y-hptrend; +end \ No newline at end of file diff --git a/src/utilities/str/common_strings_in_cell_arrays.m b/src/utilities/str/common_strings_in_cell_arrays.m new file mode 100644 index 0000000000000000000000000000000000000000..724183fb37fafb52b689a21869cf637c807143b8 --- /dev/null +++ b/src/utilities/str/common_strings_in_cell_arrays.m @@ -0,0 +1,110 @@ +function [n,message] = common_strings_in_cell_arrays(a,b) + +% Counts the number of common strings in two cell arrays of strings ```a``` and ```b```. +% +% INPUTS +% - a [cell] One dimensional cell array of strings. +% - b [cell] One dimensional cell array of strings. +% +% OUTPUTS +% - n [integer] scalar, the number of common strings. +% - message [string] formatted list of common strings. + +% Copyright (C) 2013-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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 + diff --git a/src/utilities/str/get_random_string.m b/src/utilities/str/get_random_string.m new file mode 100644 index 0000000000000000000000000000000000000000..44a45f4aabaadbe56d3ed0ca49036c0cce248b12 --- /dev/null +++ b/src/utilities/str/get_random_string.m @@ -0,0 +1,32 @@ +function s = get_random_string(n); + +% Builds a random string (starting with a letter). +% +% INPUTS +% - n [integer] scalar, length of the generated string. +% +% OUTPUTS +% - s [string] random string of length n. + +% Copyright (C) 2012-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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/>. + +s0 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + +m0 = 2*26; +m1 = m0+10; + +s = s0(ceil(rand*m0)); % First character has to be a letter! +s = [s, s0(ceil(rand(1,n-1)*m1))]; \ No newline at end of file diff --git a/src/utilities/str/name2tex.m b/src/utilities/str/name2tex.m new file mode 100644 index 0000000000000000000000000000000000000000..71a543e648948821bc1a81228053b39805996eeb --- /dev/null +++ b/src/utilities/str/name2tex.m @@ -0,0 +1,208 @@ +function tex = name2tex(name, info) % --*-- Unitary tests --*-- + +% Converts plain text name into tex name. +% +% Builds a random string (starting with a letter). +% +% INPUTS +% - name [string or cell of strings] name(s) to be converted. +% - info [integer] scalar equal to 0 or 1 (adds curly braces for indices). +% +% OUTPUTS +% - tex [string or cell of strings] + +% Copyright (C) 2012-2015 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 +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare dseries submodule 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) '}' ]; + else + texname = [ texname(1:idx(end-1)-2) '_{' texname(idx(end-1)+1:end) '}' ]; + end + end + if iscell(name) + tex(i) = { texname }; + else + tex = texname; + end + end + end +end + +%@test:1 +%$ t = zeros(16,1); +%$ t1 = name2tex('_azert'); +%$ t2 = name2tex('azert_'); +%$ t3 = name2tex('_azert_'); +%$ t4 = name2tex('azert_uiop'); +%$ t5 = name2tex('azert_uiop_qsdfg'); +%$ t6 = name2tex('azert_uiop_qsdfg_'); +%$ t7 = name2tex('_azert_uiop_qsdfg'); +%$ t8 = name2tex('_azert_uiop_qsdfg_'); +%$ t11 = name2tex('_azert',1); +%$ t12 = name2tex('azert_',1); +%$ t13 = name2tex('_azert_',1); +%$ t14 = name2tex('azert_uiop',1); +%$ t15 = name2tex('azert_uiop_qsdfg',1); +%$ t16 = name2tex('azert_uiop_qsdfg_',1); +%$ t17 = name2tex('_azert_uiop_qsdfg',1); +%$ t18 = name2tex('_azert_uiop_qsdfg_',1); +%$ +%$ t(1) = dassert(strcmp(t1,'\\_azert'),true); +%$ t(2) = dassert(strcmp(t2,'azert\\_'),true); +%$ t(3) = dassert(strcmp(t3,'\\_azert\\_'),true); +%$ t(4) = dassert(strcmp(t4,'azert\\_uiop'),true); +%$ t(5) = dassert(strcmp(t5,'azert\\_uiop\\_qsdfg'),true); +%$ t(6) = dassert(strcmp(t6,'azert\\_uiop\\_qsdfg\\_'),true); +%$ t(7) = dassert(strcmp(t7,'\\_azert\\_uiop\\_qsdfg'),true); +%$ t(8) = dassert(strcmp(t8,'\\_azert\\_uiop\\_qsdfg\\_'),true); +%$ t(9) = dassert(strcmp(t11,'\\_azert'),true); +%$ t(10) = dassert(strcmp(t12,'azert\\_'),true); +%$ t(11) = dassert(strcmp(t13,'\\_azert\\_'),true); +%$ t(12) = dassert(strcmp(t14,'azert_{uiop}'),true); +%$ t(13) = dassert(strcmp(t15,'azert\\_uiop_{qsdfg}'),true); +%$ t(14) = dassert(strcmp(t16,'azert\\_uiop_{qsdfg\\_}'),true); +%$ t(15) = dassert(strcmp(t17,'\\_azert\\_uiop_{qsdfg}'),true); +%$ t(16) = dassert(strcmp(t18,'\\_azert\\_uiop_{qsdfg\\_}'),true); +%$ +%$ T = all(t); +%@eof:1 + +%@test:2 +%$ t = zeros(16,1); +%$ t1 = name2tex({'_azert'}); +%$ t2 = name2tex({'azert_'}); +%$ t3 = name2tex({'_azert_'}); +%$ t4 = name2tex({'azert_uiop'}); +%$ t5 = name2tex({'azert_uiop_qsdfg'}); +%$ t6 = name2tex({'azert_uiop_qsdfg_'}); +%$ t7 = name2tex({'_azert_uiop_qsdfg'}); +%$ t8 = name2tex({'_azert_uiop_qsdfg_'}); +%$ t11 = name2tex({'_azert'},1); +%$ t12 = name2tex({'azert_'},1); +%$ t13 = name2tex({'_azert_'},1); +%$ t14 = name2tex({'azert_uiop'},1); +%$ t15 = name2tex({'azert_uiop_qsdfg'},1); +%$ t16 = name2tex({'azert_uiop_qsdfg_'},1); +%$ t17 = name2tex({'_azert_uiop_qsdfg'},1); +%$ t18 = name2tex({'_azert_uiop_qsdfg_'},1); +%$ +%$ t(1) = dassert(t1,{'\\_azert'}); +%$ t(2) = dassert(t2,{'azert\\_'}); +%$ t(3) = dassert(t3,{'\\_azert\\_'}); +%$ t(4) = dassert(t4,{'azert\\_uiop'}); +%$ t(5) = dassert(t5,{'azert\\_uiop\\_qsdfg'}); +%$ t(6) = dassert(t6,{'azert\\_uiop\\_qsdfg\\_'}); +%$ t(7) = dassert(t7,{'\\_azert\\_uiop\\_qsdfg'}); +%$ t(8) = dassert(t8,{'\\_azert\\_uiop\\_qsdfg\\_'}); +%$ t(9) = dassert(t11,{'\\_azert'}); +%$ t(10) = dassert(t12,{'azert\\_'}); +%$ t(11) = dassert(t13,{'\\_azert\\_'}); +%$ t(12) = dassert(t14,{'azert_{uiop}'}); +%$ t(13) = dassert(t15,{'azert\\_uiop_{qsdfg}'}); +%$ t(14) = dassert(t16,{'azert\\_uiop_{qsdfg\\_}'}); +%$ t(15) = dassert(t17,{'\\_azert\\_uiop_{qsdfg}'}); +%$ t(16) = dassert(t18,{'\\_azert\\_uiop_{qsdfg\\_}'}); +%$ +%$ T = all(t); +%@eof:2 + +%@test:3 +%$ t = zeros(4,1); +%$ try +%$ t1 = name2tex({'_azert';'azert_';'_azert_';'azert_uiop';'azert_uiop_qsdfg';'azert_uiop_qsdfg_'}); +%$ t(1) = 1; +%$ catch +%$ % Nothing to do here. +%$ end +%$ +%$ if t(1) +%$ try +%$ t2 = name2tex({'_azert';'azert_';'_azert_';'azert_uiop';'azert_uiop_qsdfg';'azert_uiop_qsdfg_'},1); +%$ t(2) = 1; +%$ catch +%$ % Nothing to do here. +%$ end +%$ end +%$ +%$ if t(1) +%$ t(3) = dassert(t1,{'\\_azert';'azert\\_';'\\_azert\\_';'azert\\_uiop';'azert\\_uiop\\_qsdfg';'azert\\_uiop\\_qsdfg\\_'}); +%$ end +%$ +%$ if t(2) +%$ t(4) = dassert(t2,{'\\_azert';'azert\\_';'\\_azert\\_';'azert_{uiop}';'azert\\_uiop_{qsdfg}';'azert\\_uiop_{qsdfg\\_}'}); +%$ end +%$ +%$ T = all(t); +%@eof:3 + +%@test:4 +%$ try +%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dd.csv','dd.csv'); +%$ if ~status +%$ error() +%$ end +%$ db = dseries('dd.csv'); +%$ delete('dd.csv'); +%$ t(1) = 1; +%$ catch +%$ t(1) = 0; +%$ end +%$ +%$ T = all(t); +%@eof:4 diff --git a/tests/runalldseriestests.m b/tests/runalldseriestests.m new file mode 100644 index 0000000000000000000000000000000000000000..eba08296a7de1004776f3b7ac736dc4fad9a459e --- /dev/null +++ b/tests/runalldseriestests.m @@ -0,0 +1,32 @@ +opath = path(); + +% Check that the m-unit-tests module is available. +try + initialize_unit_tests_toolbox; +catch + urlwrite('https://github.com/DynareTeam/m-unit-tests/archive/master.zip','master.zip'); + warning('off','MATLAB:MKDIR:DirectoryExists') + mkdir('../externals') + warning('on','MATLAB:MKDIR:DirectoryExists') + unzip('master.zip','../externals') + delete('master.zip') + addpath([pwd() '/../externals/m-unit-tests-master/src']) + initialize_unit_tests_toolbox; +end + +% Initialize the dseries module +try + initialize_dseries_toolbox; +catch + unit_tests_root = strrep(which('runalldseriestests'),'runalldseriestests.m',''); + addpath([unit_tests_root '../src']); + initialize_dseries_toolbox; +end + +tmp = dseries_src_root; +tmp = tmp(1:end-1); % Remove trailing slash. +run_unitary_tests_in_directory(tmp); + +delete('*.log'); +rmdir('../externals/m-unit-tests-master','s'); +path(opath); \ No newline at end of file