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
  • dbnomics/mdbnomics
  • DoraK/mdbnomics
  • giovanma/mdbnomics
3 results
Show changes
Commits on Source (31)
Showing
with 1267 additions and 455 deletions
# For checking that no file has been unduly ignored, run:
# $ git ls-files -i --exclude-per-directory=.gitignore
# Any file that is displayed should be removed from the ignore list
# (possibly by an exclusion rule beginning with an exclamation mark)
# Generic ignore rules
*~
*.o
*.a
*.fig
\#*\#
*.mat
*.asv
tests/git.info
tests/git.last-commit-hash
/missing_dbnomics
/utils
\ No newline at end of file
# For checking that no file has been unduly ignored, run:
# $ git ls-files -i --exclude-per-directory=.gitignore
# Any file that is displayed should be removed from the ignore list
# (possibly by an exclusion rule beginning with an exclamation mark)
# Generic ignore rules
*~
*.o
*.a
*.fig
\#*\#
*.mat
*.asv
# Test directory
m-unit-tests
variables:
GIT_SUBMODULE_STRATEGY: normal
TERM: linux
before_script:
- git clone https://git.dynare.org/Dynare/m-unit-tests
MATLAB_VERSION: R2023a
OLD_MATLAB_VERSION: R2015a
test_matlab:
stage: test
script:
- make check-matlab
\ No newline at end of file
- make check-matlab MATLAB=/opt/MATLAB/$MATLAB_VERSION/bin/matlab
test_old_matlab:
stage: test
script:
- make check-matlab MATLAB=/opt/MATLAB/$OLD_MATLAB_VERSION/bin/matlab
[submodule "contrib/jsonlab"]
path = contrib/jsonlab
url = https://github.com/fangq/jsonlab.git
OCTAVE ?= octave-cli
MATLAB ?= $(shell which matlab)
all: check-matlab
m-unit-tests/src/mtest.m:
git clone https://git.dynare.org/Dynare/m-unit-tests
git clone https://git.dynare.org/Dynare/m-unit-tests && cd m-unit-tests && git checkout 343d9e13654a07c348fad863f7f79a03896c6bc9
check-matlab: m-unit-tests/src/mtest.m
@$(MATLAB) -nosplash -nodisplay -r "addpath([pwd '/m-unit-tests/src']); cd tests; runalltests; quit" && [ ! -f ./tests/failed ] && [ -f ./tests/pass ]
......
This diff is collapsed.
function [dd, dat] = get_dataset(provider,dataset, varargin)
if numel(varargin) > 0
options = parse_options(varargin);
else
options = ['?limit=1000&offset=0&q=&observations=1&align_periods=1&' ...
'dimensions={}'];
end
default_api_base_url = 'https://api.db.nomics.world/v22/series/';
url = join([default_api_base_url, provider, '/', dataset, options]);
dat = webread(join(url));
docs = dat.series.docs;
nseries = dat.dataset.nb_series;
nrow = 1;
for id = 1:nseries
nrow = nrow + length(docs(id).period);
end
dimensions_codes = dat.dataset.dimensions_codes_order;
ndim = length(dimensions_codes);
ncol = ndim + 10;
dd = cell(nrow,ncol);
dd{1,1} = '@frequency';
dd{1,2} = 'dataset_code';
dd{1,3} = 'dataset_name';
dd{1,4} = 'indexed_at';
dd{1,5} = 'original_period';
dd{1,6} = 'period';
dd{1,7} = 'provider_code';
dd{1,8} = 'series_code';
dd{1,9} = 'series name';
dd{1,10} = 'value';
for i = 1:ndim
dd{1,10+i} = dimensions_codes{i};
end
row = 2;
for i = 1:nseries
doc = docs(i);
x_frequency = doc.x_frequency;
dataset_code = doc.dataset_code;
dataset_name = doc.dataset_name;
series_code = doc.series_code;
series_name = doc.series_name;
indexed_at = doc.indexed_at;
provider_code = doc.provider_code;
dimensions = doc.dimensions;
period = doc.period;
period_start_day = doc.period_start_day;
value = doc.value;
for j = 1:length(period)
dd{row,1} = x_frequency;
dd{row,2} = dataset_code;
dd{row,3} = dataset_name;
dd{row,4} = indexed_at;
dd{row,5} = period{j};
dd{row,6} = period_start_day{j};
dd{row,7} = provider_code;
dd{row,8} = series_code;
dd{row,9} = series_name;
if iscell(value)
dd{row,10} = value{j};
else
dd{row,10} = value(j);
end
for k = 1:ndim
dim_code = dimensions.(dimensions_codes{k});
dd{row,10+k} = dim_code;
end
row = row + 1;
end
end
function options_str = parse_options(arguments)
i = 1;
options = struct();
options.limit = 1000;
options.dimensions = '{}';
options.mask = '';
while i <= length(arguments)
if arguments{1} == 'limit'
options.limit = arguments{2};
i = i + 2;
elseif arguments{1} == 'dimensions'
if ~isempty(options.mask)
error('rdb: you can''t use both option dimension and option mask');
end
elseif arguments =='mask'
if options.dimensions ~= '{}'
error('rdb: you can''t use both option dimension and option mask');
end
options.mask = arguments{2};
i = i+2;
else
disp_usage();
end
end
options_str = sprintf('?limit=%d0&q=&observations=1&align_periods=1&dimensions=%s',...
options.limit, options.dimensions);
if options.mask
options_str = options_str + '&' + options.mask;
end
\ No newline at end of file
function [dd, dat] = get_dseries(provider,dataset,series_id)
%url = join(['https://api.db.nomics.world/v22/series/', provider, '/',...
% dataset, '/', series_id, '?observations=true'])
%json = urlread(join(url))
%save test json
f = fopen("test.json");
json = fgets(f);
fclose(f);
dat = jsondecode(json);
dd = ''
docs = dat.series.docs;
first_period = docs.period{1};
if docs.x_frequency == 'annual'
first_period = join([first_period, 'A']);
end
dd = dseries(docs.value, first_period, docs.series_code, docs.series_name)
function [dd, dat] = get_series(provider,dataset,series_id)
%url = join(['https://api.db.nomics.world/v22/series/', provider, '/',...
% dataset, '/', series_id, '?observations=true'])
%json = urlread(join(url))
%save test json
f = fopen("test.json");
json = fgets(f);
fclose(f);
dat = jsondecode(json);
dd = ''
docs = dat.series.docs;
first_period = docs.period{1};
if docs.x_frequency == 'annual'
first_period = join([first_period, 'A']);
end
dd = struct()
dd.values = docs.value
dd.periods = docs.period
dd.code = docs.series_code
dd.name = docs.series_name
function data = rdb(str, varargin)
if nargin == 0
[d, dd] = get_series(str)
elseif nargin == 1
[d, dd] = get_dataset(str, varargin{1})
elseif nargin == 2
[d, dd] = get_series(str, varargin{1}, varargin{2})
elseif nargin > 1
[d, dd] = get_dataset(str, vararin{1}, varargin{2:end})
end
function run_all_tests()
r = [];
r = [r; run_this_test('test_fetch_series_by_code')];
r = [r; run_this_test('test_fetch_series_by_code_mask')];
r = [r; run_this_test('test_fetch_series_by_code_mask_with_plus_in_dimension_code')];
r = [r; run_this_test('test_fetch_series_by_id')];
r = [r; run_this_test('test_fetch_series_by_ids_in_same_dataset')];
r = [r; run_this_test('test_fetch_series_by_ids_in_different_datasets')];
r = [r; run_this_test('test_fetch_series_by_dimension')];
r = [r; run_this_test('test_fetch_series_of_dataset')];
r = [r; run_this_test('test_fetch_series_by_api_link')];
r = [r; run_this_test('test_fetch_series_with_na_values')];
r = [r; run_this_test('test_fetch_series_with_max_nb_series')];
r = [r; run_this_test('test_fetch_series_with_filter_on_one_series')];
print_results(r);
function o = run_this_test(file)
try
tstart = tic;
run([file '.m']);
elapsed = toc(tstart);
o = {file, true, elapsed};
catch
o = {file, false, NaN};
end
function print_results(r)
message = sprintf('Testsuite results:\n');
for i = 1:size(r, 1)
if r{i,2}
message = sprintf('%s\n%s\t\t PASS (%ss)', message, r{i,1}, num2str(r{i,3}));
else
message = sprintf('%s\n%s\t\t FAILED', message, r{i,1});
end
end
disp(message)
This diff is collapsed.
Subproject commit 7499bd8fae221d3018d31b359a74422237a8b8ec
......@@ -17,27 +17,17 @@ function initialize_mdbnomics()
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% Get the path to the dseries toolbox.
% Get the path to the mdbnomics toolbox.
global mdb_options
mdbnomics_src_root = strrep(which('initialize_mdbnomics'), 'initialize_mdbnomics.m', '');
% Set the subfolders to be added in the path.
p = {'subroutines'};
p = {'utils'};
% Add missing routines if dynare is not in the path
if ~exist('get_file_extension','file')
p{end+1} = 'missing/get_cells_id';
end
if ~exist('get_file_extension','file')
p{end+1} = 'missing/get_file_extension';
end
if ~exist('isint','file')
p{end+1} = 'missing/iscolumn';
end
if ~exist('isint','file')
p{end+1} = 'missing/isint';
if ~exist('OCTAVE_VERSION', 'builtin') || ~exist('contains','builtin')
p{end+1} = 'missing/contains';
end
if ~exist('isoctave','file')
......@@ -48,12 +38,8 @@ if ~exist('matlab_ver_less_than','file')
p{end+1} = 'missing/matlab_ver_less_than';
end
if ~exist('OCTAVE_VERSION', 'builtin') && ~exist('strsplit','file')
p{end+1} = 'missing/strsplit';
end
if ~exist('OCTAVE_VERSION', 'builtin') && ~exist('strjoin','file')
p{end+1} = 'missing/strjoin';
if ~exist('octave_ver_less_than','file')
p{end+1} = 'missing/octave_ver_less_than';
end
if exist('OCTAVE_VERSION', 'builtin') && ~exist('user_has_octave_forge_package','file')
......@@ -64,4 +50,22 @@ end
P = cellfun(@(c)[mdbnomics_src_root c], p, 'uni', false);
addpath(P{:});
if ~isoctave()
% Check minimal MATLAB requirements.
if matlab_ver_less_than('8.5')
error('The minimum MATLAB requirement of this package is R2015a.');
end
% Add jsonlab if MATLAB version < R2016b
if matlab_ver_less_than('9.1')
addpath([mdbnomics_src_root '/../contrib/jsonlab']);
end
end
mdb_options.api_base_url = 'https://api.db.nomics.world';
mdb_options.editor_base_url = 'https://editor.nomics.world';
mdb_options.api_version = 22;
mdb_options.editor_version = 1;
assignin('caller', 'mdb_options', mdb_options);
assignin('caller', 'mdbnomics_src_root', mdbnomics_src_root);
function df = fetch_series(varargin)
% function fetch_series(varargin)
function df = mdbnomics(varargin) % --*-- Unitary tests --*--
% function mdbnomics(varargin)
% Download time series from DBnomics.
% Returns a cell array.
%
% Examples:
% Fetch one series:
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX");
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', ".FR.PCPIEC_WT");
% mdbnomics('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M.FR+DE.PCPIEC_IX+PCPIA_IX');
% mdbnomics('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', '.FR.PCPIEC_WT');
%
% Fetch all the series of a dataset:
% fetch_series('provider_code', "AMECO", 'dataset_code', "UVGD", 'max_nb_series', 500);
% mdbnomics('provider_code', 'AMECO', 'dataset_code', 'UVGD', 'max_nb_series', 500);
%
% Fetch many series from different datasets:
% fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN", "IMF/CPI/A.AT.PCPIT_IX"]);
% mdbnomics('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN', 'IMF/CPI/A.AT.PCPIT_IX'});
%
% Fetch many series from the same dataset, searching by dimension:
% fetch_series('provider_code',"AMECO", 'dataset_code', "ZUTN", 'dimensions', '{"geo":["dnk"]}');
% mdbnomics('provider_code','AMECO', 'dataset_code', 'ZUTN', 'dimensions', '{"geo":["dnk"]}');
%
% Fetch series given an "API link" URL.
% "API link" URLs can be found on DBnomics web site (https://db.nomics.world/) on dataset or series pages using "Download" buttons.
% mdbnomics('api_link', 'https://api.db.nomics.world/v22/series?series_ids=AMECO%2FZUTN%2FEA19.1.0.0.0.ZUTN&observations=1');
%
% POSSIBLE PARAMETERS
% provider_code [string] the code of the dataset provider.
......@@ -26,6 +30,7 @@ function df = fetch_series(varargin)
% max_nb_series [integer] maximum number of series requested by the API. If not provided, a default value of 50 series will be used.
% api_base_url [string] the base URL used for API requests. If not provided, a default value of: 'https://api.db.nomics.world/v22/' will be used.
% dbnomics_filters [char] filters to apply on the requested series. If provided it must be a string formatted like: '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]'.
% api_link [char] fetch series given an "API link" URL.
%
% OUTPUTS
% df
......@@ -52,11 +57,13 @@ function df = fetch_series(varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
default_api_base_url = 'https://api.db.nomics.world/v22/';
default_editor_base_url = 'https://editor.nomics.world/api/v1/';
global mdb_options
default_api_base_url = sprintf('%s/v%d/', mdb_options.api_base_url, mdb_options.api_version);
default_editor_base_url = sprintf('%s/api/v%d/', mdb_options.editor_base_url, mdb_options.editor_version);
p = inputParser;
validStringInput = @(x) isstring(x) || ischar(x) || iscellstr(x);
validStringInput = @(x) ischar(x) || iscellstr(x);
p.addParameter('provider_code', '', validStringInput);
p.addParameter('dataset_code', '', validStringInput);
p.addParameter('series_code', '', validStringInput);
......@@ -65,6 +72,7 @@ p.addParameter('series_ids', '',validStringInput);
p.addParameter('max_nb_series', NaN, @isnumeric);
p.addParameter('api_base_url', default_api_base_url, validStringInput);
p.addParameter('dbnomics_filters', '', @ischar);
p.addParameter('api_link', '', @ischar);
p.KeepUnmatched = false;
p.parse(varargin{:});
......@@ -85,7 +93,7 @@ end
series_base_url = [p.Results.api_base_url 'series'];
if isa(p.Results.dimensions, 'function_handle') && isempty(p.Results.series_code) && isempty(p.Results.series_ids)
if isempty(p.Results.provider_code) || isempty(p.Results.dataset_code)
if (isempty(p.Results.provider_code) || isempty(p.Results.dataset_code)) && isempty(p.Results.api_link)
error('When you don''t use dimensions, you must specifiy provider_code and dataset_code.');
end
api_link = sprintf('%s/%s/%s?observations=1', series_base_url, p.Results.provider_code, p.Results.dataset_code);
......@@ -95,7 +103,7 @@ if ~isa(p.Results.dimensions, 'function_handle')
if isempty(p.Results.provider_code) || isempty(p.Results.dataset_code)
error('When you use dimensions, you must specifiy provider_code and dataset_code.');
end
api_link = sprintf('%s/%s/%s?observations=1&dimensions=%s', series_base_url, p.Results.provider_code, p.Results.dataset_code, p.Results.dimensions); %jsonencode(
api_link = sprintf('%s/%s/%s?observations=1&dimensions=%s', series_base_url, p.Results.provider_code, p.Results.dataset_code, p.Results.dimensions);
end
if ~isempty(p.Results.series_code)
......@@ -109,8 +117,269 @@ if ~isempty(p.Results.series_ids)
if ~isempty(p.Results.provider_code) || ~isempty(p.Results.dataset_code)
error('When you use series_ids, you must not specifiy provider_code nor dataset_code.');
end
api_link = sprintf('%s?observations=1&series_ids=%s', series_base_url, strjoin(p.Results.series_ids,','));
if iscellstr(p.Results.series_ids)
series_ids = strjoin(p.Results.series_ids,',');
else
series_ids = p.Results.series_ids;
end
api_link = sprintf('%s?observations=1&series_ids=%s', series_base_url, series_ids);
end
if ~isempty(p.Results.api_link)
api_link = p.Results.api_link;
end
df = fetch_series_by_api_link(api_link, p.Results.dbnomics_filters, p.Results.max_nb_series, default_editor_base_url);
end
%@test:1 % test_fetch_series_by_code
%$ try
%$ df = mdbnomics('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'series_code', 'EA19.1.0.0.0.ZUTN');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'AMECO'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'ZUTN'});
%$ t(6) = dassert(length(unique(df(2:end,5))),1);
%$ t(7) = dassert(df(2,5), {'EA19.1.0.0.0.ZUTN'});
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2 % test_fetch_series_by_code_mask
%$ try
%$ df = mdbnomics('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M.FR+DE.PCPIEC_IX+PCPIA_IX');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'IMF'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'CPI'});
%$ t(6) = dassert(length(unique(df(2:end,5))),4);
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3 % test_fetch_series_by_code_mask_with_plus
%$ try
%$ df = mdbnomics('provider_code', 'SCB', 'dataset_code', 'AKIAM', 'series_code', '"J+K"+"G+H".AM0301C1');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'SCB'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'AKIAM'});
%$ t(6) = dassert(length(unique(df(2:end,5))),2);
%$ end
%$
%$ T = all(t);
%@eof:3
%@test:4 % test_fetch_series_by_dimension
%$ try
%$ df = mdbnomics('provider_code','WB','dataset_code','DB', 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'WB'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'DB'});
%$ t(6) = dassert(length(unique(df(2:end,5))),3);
%$ end
%$
%$ T = all(t);
%@eof:4
%@test:5 % test_fetch_series_by_id
%$ try
%$ df = mdbnomics('series_ids','AMECO/ZUTN/EA19.1.0.0.0.ZUTN');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'AMECO'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'ZUTN'});
%$ t(6) = dassert(length(unique(df(2:end,5))),1);
%$ t(7) = dassert(df(2,5), {'EA19.1.0.0.0.ZUTN'});
%$ end
%$
%$ T = all(t);
%@eof:5
%@test:6 % test_fetch_series_by_ids_in_different_datasets
%$ try
%$ df = mdbnomics('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'BIS/cbs/Q.S.5A.4B.F.B.A.A.LC1.A.1C'});
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ provider_codes = unique(df(2:end,2));
%$ t(2) = dassert(length(provider_codes),2);
%$ t(3) = dassert(provider_codes{1}, 'AMECO');
%$ t(4) = dassert(provider_codes{2}, 'BIS');
%$ dataset_codes = unique(df(2:end,3));
%$ t(5) = dassert(length(dataset_codes),2);
%$ t(6) = dassert(dataset_codes{1}, 'ZUTN');
%$ t(7) = dassert(dataset_codes{2}, 'cbs');
%$ series_codes = unique(df(2:end,5));
%$ t(8) = dassert(length(series_codes),2);
%$ t(9) = dassert(series_codes{1}, 'EA19.1.0.0.0.ZUTN');
%$ t(10) = dassert(series_codes{2}, 'Q.S.5A.4B.F.B.A.A.LC1.A.1C');
%$ end
%$
%$ T = all(t);
%@eof:6
%@test:7 % test_fetch_series_by_ids_in_same_dataset
%$ try
%$ df = mdbnomics('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN',...
%$ 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'});
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'AMECO'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'ZUTN'});
%$ series_codes = unique(df(2:end,5));
%$ t(6) = dassert(length(series_codes),2);
%$ t(7) = dassert(series_codes{1}, 'DNK.1.0.0.0.ZUTN');
%$ t(8) = dassert(series_codes{2}, 'EA19.1.0.0.0.ZUTN');
%$ end
%$
%$ T = all(t);
%@eof:7
%@test:8 % test_fetch_series_of_dataset
%$ try
%$ df = mdbnomics('provider_code', 'AMECO', 'dataset_code', 'ZUTN');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'AMECO'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'ZUTN'});
%$ t(6) = dassert(length(unique(df(2:end,5))), 48);
%$ end
%$
%$ T = all(t);
%@eof:8
%@test:9 % test_fetch_series_with_filter_on_one_series
%$ try
%$ filters_ = '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]';
%$ df = mdbnomics('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'series_code', 'DEU.1.0.0.0.ZUTN', 'dbnomics_filters', filters_);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'AMECO'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'ZUTN'});
%$ series_codes = unique(df(2:end,5));
%$ t(6) = dassert(length(unique(df(2:end,5))),2);
%$ t(7) = dassert(df(2,5), {'DEU.1.0.0.0.ZUTN'});
%$ t(8) = dassert(series_codes{2}, 'DEU.1.0.0.0.ZUTN_filtered');
%$ freq_ = unique(df(2:end, 1));
%$ t(9) = dassert(freq_{2}, 'monthly');
%$ t(10) = dassert(df(1,12), {'filtered'});
%$ end
%$
%$ T = all(t);
%@eof:9
%@test:10 % test_fetch_series_with_max_nb_series
%$ try
%$ df = mdbnomics('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'max_nb_series',20);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'AMECO'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'ZUTN'});
%$ series_codes = unique(df(2:end,5));
%$ assert(length(series_codes) <= 20);
%$ end
%$
%$ T = all(t);
%@eof:10
%@test:11 % test_fetch_series_with_na_values
%$ try
%$ df = mdbnomics('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'series_code', 'DEU.1.0.0.0.ZUTN');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'AMECO'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'ZUTN'});
%$ t(6) = dassert(length(unique(df(2:end,5))),1);
%$ t(7) = dassert(df(2,5), {'DEU.1.0.0.0.ZUTN'});
%$ assert(any(strcmp('NA', df(2:end,9))) == true);
%$ assert(any(isnan(cell2mat(df(2:end,10)))) == true);
%$ end
%$
%$ T = all(t);
%@eof:11
%@test:12 % test_fetch_series_by_api_link
%$ try
%$ df = mdbnomics('api_link', 'https://api.db.nomics.world/v22/series/BIS/long_pp?limit=1000&offset=0&q=&observations=1&align_periods=1&dimensions=%7B%7D');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(df(2:end,2))),1);
%$ t(3) = dassert(df(2,2), {'BIS'});
%$ t(4) = dassert(length(unique(df(2:end,3))),1);
%$ t(5) = dassert(df(2,3), {'long_pp'});
%$ t(6) = dassert(length(unique(df(2:end,5))),23);
%$ end
%$
%$ T = all(t);
%@eof:12
function datasets = mdbnomics_datasets(varargin) % --*-- Unitary tests --*--
% function mdbnomics_datasets(varargin)
% Downloads the list of available datasets for a selection of providers (or all of them) from https://db.nomics.world/.
% By default, the function returns a structure with a cell array containing the dataset codes and names of the requested providers.
%
% POSSIBLE PARAMETERS
% provider_code [char] DBnomics code of one or multiple providers. If empty, the providers are firstly
% dowloaded with the function mdbnomics_providers and then the available datasets are requested.
% simplify [logical] If true, when the datasets are requested for only one provider then a cell array is returned, not a structure.
% If not provided, the default value is false.
%
% OUTPUTS
% datasets
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 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/>.
global mdb_options
p = inputParser;
validStringInput = @(x) ischar(x) || iscellstr(x);
p.addParameter('provider_code', '', validStringInput);
p.addParameter('simplify', false, @islogical);
p.KeepUnmatched = false;
p.parse(varargin{:});
if isempty(p.Results.provider_code)
provider_code = mdbnomics_providers('code', true);
else
if ischar(p.Results.provider_code)
provider_code = {p.Results.provider_code};
else
provider_code = p.Results.provider_code;
end
end
datasets = struct();
for i = 1:numel(provider_code)
pc = provider_code{i};
provider_page = sprintf('%s/v%d/providers/%s', mdb_options.api_base_url, mdb_options.api_version, pc);
provider_info = webread(provider_page);
provider_info = provider_info.category_tree;
code = [];
name = [];
if isfield(provider_info, 'children')
unpack_children(provider_info, code, name);
else
try
for n = 1:numel(provider_info)
code = [code, {provider_info{n}.code}];
name = [name, {provider_info{n}.name}];
end
catch
for n = 1:numel(provider_info)
code = [code, {provider_info(n).code}];
name = [name, {provider_info(n).name}];
end
end
end
datasets.(pc) = horzcat(code', name');
end
if p.Results.simplify
if length(fieldnames(datasets)) == 1
datasets = datasets.(pc);
else
error('Your query corresponds to multiple providers, not possible to simplify');
end
end
end
%@test:1
%$ try
%$ datasets = mdbnomics_datasets('provider_code', 'IMF', 'simplify', true);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(datasets(:,1))), 43);
%$ t(3) = dassert(size(datasets, 2), 2);
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ datasets = mdbnomics_datasets('provider_code', 'IMF');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(fieldnames(datasets), {'IMF'});
%$ t(3) = dassert(size(datasets.IMF,1), 43);
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3
%$ try
%$ datasets = mdbnomics_datasets('provider_code', {'IMF', 'AMECO'});
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(fieldnames(datasets), {'IMF'; 'AMECO'});
%$ t(3) = dassert(size(datasets.IMF,1), 43);
%$ t(4) = dassert(size(datasets.AMECO,1), 473);
%$ end
%$
%$ T = all(t);
%@eof:3
\ No newline at end of file
function dimensions = mdbnomics_dimensions(varargin) % --*-- Unitary tests --*--
% function mdbnomics_dimensions(varargin)
% Downloads the list of dimensions (if they exist) for available datasets of a selection of providers from https://db.nomics.world/.
% By default, the function returns a structure containing the dimensions of datasets for DBnomics providers.
%
% POSSIBLE PARAMETERS
% provider_code [char] DBnomics code of one or multiple providers. If empty, the providers are firstly
% dowloaded with the function mdbnomics_providers and then the available datasets are requested.
% dataset_code [char] DBnomics code of one or multiple datasets of a provider. If empty, the datasets codes are dowloaded
% with the function mdbnomics_datasets and then the dimensions are requested.
% simplify [logical] If true, when the dimensions are requested for only one provider and one dataset then only the dimension names and their values are provided.
% If not provided, the default value is false.
%
% OUTPUTS
% dimensions
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 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/>.
global mdb_options
p = inputParser;
validStringInput = @(x) ischar(x) || iscellstr(x);
p.addParameter('provider_code', '', validStringInput);
p.addParameter('dataset_code', '', validStringInput);
p.addParameter('simplify', false, @islogical);
p.KeepUnmatched = false;
p.parse(varargin{:});
if isempty(p.Results.provider_code) && ~isempty(p.Results.dataset_code)
error('When you use dataset_code, you must specify provider_code as well.');
end
if iscell(p.Results.provider_code) || iscell(p.Results.dataset_code)
if ~isempty(p.Results.provider_code) && ~isempty(p.Results.dataset_code) && length(p.Results.provider_code) ~= length(p.Results.dataset_code)
error('Please specify as many provider codes as dataset codes.')
end
end
if isempty(p.Results.provider_code)
provider_code = mdbnomics_providers('code', true);
else
if ischar(p.Results.provider_code)
provider_code = {p.Results.provider_code};
else
provider_code = p.Results.provider_code;
end
end
if isempty(p.Results.dataset_code)
dataset_code = mdbnomics_datasets('provider_code', provider_code);
else
if ischar(p.Results.dataset_code)
dataset_code = {p.Results.dataset_code};
else
dataset_code = p.Results.dataset_code;
end
end
dimensions = struct();
for i = 1:numel(provider_code)
pc = provider_code{i};
dc = dataset_code{i};
dataset_page = sprintf('%s/v%d/datasets/%s/%s', mdb_options.api_base_url, mdb_options.api_version, pc, dc);
dataset_info = webread(dataset_page);
dataset_name = sprintf('%s_%s', pc, dc);
try
tmp1 = dataset_info.datasets.docs.dimensions_labels;
catch
try
tmp1 = dataset_info.datasets.(dataset_name).dimensions_labels;
catch
tmp1 = {};
end
end
try
tmp2 = dataset_info.datasets.docs.dimensions_values_labels;
catch
try
tmp2 = dataset_info.datasets.(dataset_name).dimensions_values_labels;
catch
tmp2 = {};
end
end
dataset_dimensions = fieldnames(tmp1);
for d = 1:numel(dataset_dimensions)
dimensions.(dataset_name).(dataset_dimensions{d}) = tmp2.(dataset_dimensions{d});
end
end
if p.Results.simplify
if length(fieldnames(dimensions)) == 1
dimensions = dimensions.(dataset_name);
else
error('Your query corresponds to multiple datasets, not possible to simplify');
end
end
end
%@test:1
%$ try
%$ dimensions = mdbnomics_dimensions('provider_code', 'IMF', 'dataset_code', 'WEO');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(fieldnames(dimensions), {'IMF_WEO'});
%$ t(3) = dassert(isfield(dimensions.IMF_WEO, 'unit'), true);
%$ t(4) = dassert(length(fieldnames(dimensions.IMF_WEO.unit)), 13);
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ dimensions = mdbnomics_dimensions('provider_code', 'IMF', 'dataset_code', 'WEO', 'simplify', true);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(isfield(dimensions, 'IMF_WEO'), false);
%$ t(3) = dassert(isfield(dimensions, 'unit'), true);
%$ t(4) = dassert(length(fieldnames(dimensions.unit)), 13);
%$ end
%$
%$ T = all(t);
%@eof:2
function series = mdbnomics_series(varargin) % --*-- Unitary tests --*--
% function mdbnomics_series(varargin)
% Downloads the list of series for available datasets of a selection of providers from https://db.nomics.world/.
% We warn the user that this function can be (very) long to execute!
% We remind that DBnomics requests data from 63 providers to retrieve 21675 datasets for a total of approximately 720 millions series.
% By default, the function returns a structure with a cell array at the end of each branch containing the series codes and names of datasets for DBnomics providers.
%
% POSSIBLE PARAMETERS
% provider_code [char] DBnomics code of one or multiple providers. If empty, the providers are firstly
% dowloaded with the function mdbnomics_providers and then the available datasets are requested.
% dataset_code [char] DBnomics code of one or multiple datasets of a provider. If empty, the datasets codes are dowloaded
% with the function mdbnomics_datasets and then the dimensions are requested.
% dimensions [char] DBnomics code of one or several dimensions in the specified provider and dataset.
% If provided it must be a string formatted like: '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}'.
% query [char] A query to filter/select series from a provider's dataset.
% only_number_of_series [logical] If true, only the number of series for the given query will be printed in the command window.
% If not provided, the default value is false.
% simplify [logical] If true, when the datasets are requested for only one provider then a cell array is returned, not a structure.
% If not provided, the default value is false.
%
% OUTPUTS
% series
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2020 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/>.
global mdb_options
p = inputParser;
validStringInput = @(x) ischar(x) || iscellstr(x);
p.addParameter('provider_code', '', validStringInput);
p.addParameter('dataset_code', '', validStringInput);
p.addParameter('dimensions', '', validStringInput);
p.addParameter('query', '', validStringInput);
p.addParameter('only_number_of_series', false, @islogical);
p.addParameter('simplify', false, @islogical);
p.KeepUnmatched = false;
p.parse(varargin{:});
if iscell(p.Results.provider_code) || iscell(p.Results.dataset_code)
if ~isempty(p.Results.provider_code) && ~isempty(p.Results.dataset_code) && length(p.Results.provider_code) ~= length(p.Results.dataset_code)
error('Please specify as many provider codes as dataset codes.')
end
end
if isempty(p.Results.provider_code)
provider_code = mdbnomics_providers('code', true);
else
if ischar(p.Results.provider_code)
provider_code = {p.Results.provider_code};
else
provider_code = p.Results.provider_code;
end
end
if isempty(p.Results.dataset_code)
dataset_code = mdbnomics_datasets('provider_code', provider_code);
else
if ischar(p.Results.dataset_code)
dataset_code = {p.Results.dataset_code};
else
dataset_code = p.Results.dataset_code;
end
end
if ~isempty(p.Results.query)
if ischar(p.Results.query)
db_query = {p.Results.query};
else
db_query = p.Results.query;
end
end
if ~isempty(p.Results.dimensions)
if ischar(p.Results.dimensions)
dimensions = {p.Results.dimensions};
else
dimensions = p.Results.dimensions;
end
end
series = struct();
for i = 1:numel(provider_code)
pc = provider_code{i};
dc = dataset_code{i};
dataset_page = sprintf('%s/v%d/series/%s/%s', mdb_options.api_base_url, mdb_options.api_version, pc, dc);
if exist('db_query', 'var')
dataset_page = sprintf('%s?q=%s', dataset_page, db_query{i});
end
if exist('dimensions', 'var')
if contains(dimensions{i}, '\\?')
spec = '&';
else
spec = '?';
end
dataset_page = sprintf('%s%sdimensions=%s', dataset_page, spec, dimensions{i});
end
dataset_info = webread(dataset_page);
dataset_name = sprintf('%s_%s', pc, dc);
limit = dataset_info.series.limit;
num_found = dataset_info.series.num_found;
if p.Results.only_number_of_series
sprintf('Number of series = %d', num_found)
return
else
sprintf('The dataset %s from provider %s contains %d series.', dc, pc, num_found)
series_code = [];
series_name = [];
if num_found > limit
sequence = 0:1:floor(num_found/limit);
if contains(dataset_page, 'offset=')
dataset_page = regexprep(dataset_page, '\\&offset=[0-9]+', '');
dataset_page = regexprep(dataset_page, '\\?offset=[0-9]+', '');
end
if contains(dataset_page, '\\?')
sep = '&';
else
sep = '?';
end
for j = 1:numel(sequence)
tmp_api_link = sprintf('%s%soffset=%d', dataset_page, sep, sequence(j)*limit);
dataset_info = webread(tmp_api_link);
series_info = dataset_info.series.docs;
for s = 1:numel(series_info)
series_code = [series_code, {series_info(s).series_code}];
series_name = [series_name, {series_info(s).series_name}];
end
end
series.(dataset_name) = horzcat(series_code', series_name');
else
series_info = dataset_info.series.docs;
for s = 1:numel(series_info)
series_code = [series_code, {series_info(s).series_code}];
series_name = [series_name, {series_info(s).series_name}];
end
series.(dataset_name) = horzcat(series_code', series_name');
end
end
end
if p.Results.simplify
if length(fieldnames(series)) == 1
series = series.(dataset_name);
else
error('Your query corresponds to multiple datasets, not possible to simplify');
end
end
end
%@test:1
%$ try
%$ series = mdbnomics_series('provider_code', 'IMF', 'dataset_code', 'WEO', 'simplify', true);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(series(:,1))), 8924);
%$ t(3) = dassert(size(series, 2), 2);
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ series = mdbnomics_series('provider_code', 'IMF', 'dataset_code', 'WEO');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(fieldnames(series), {'IMF_WEO'});
%$ t(3) = dassert(length(unique(series.IMF_WEO(:,1))), 8924);
%$ t(4) = dassert(size(series.IMF_WEO, 2), 2);
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3
%$ try
%$ series = mdbnomics_series('provider_code', 'IMF', 'dataset_code', 'WEO', 'dimensions', '{"weo-subject":["NGDP_RPCH"]}', 'simplify', true);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(series(:,1))), 194);
%$ t(3) = dassert(size(series, 2), 2);
%$ end
%$
%$ T = all(t);
%@eof:3
%@test:4
%$ try
%$ series = mdbnomics_series('provider_code', 'IMF', 'dataset_code', 'WEO', 'query', 'NGDP_RPCH');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(unique(series.IMF_WEO(:,1))), 194);
%$ t(3) = dassert(size(series.IMF_WEO, 2), 2);
%$ end
%$
%$ T = all(t);
%@eof:4
\ No newline at end of file
function rval = strjoin (cstr, delimiter)
function tf = contains(string, pattern, varargin)
% Adapted from Octave's implementation of strjoin
% CONTAINS Returns 1 if the pattern is found in string, and 0 otherwise.
%
% INPUTS
% - string [string, char, cell(str)] String to be searhced.
% - pattern [string, char, cell(str)] The searched pattern.
%
% If 'IgnoreCase',IGNORE is provided, the function ignores case if IGNORE is true.
% The default value is false.
%
% OUTPUT
% - tf [logical]
%
% Limitation: escaped characters (e.g. '\n') in delimiters will not be
% interpreted as the characters they represent.
% Copyright (C) 2013-2019 Ben Abbott
% Copyright (C) 2007 Muthiah Annamalai
% Copyright (C) 2019 Dynare Team
%
% This file is part of Dynare.
......@@ -24,40 +29,42 @@ function rval = strjoin (cstr, delimiter)
% 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 == 1
delimiter = ' ';
elseif nargin < 1 || nargin > 2
error('strjoin: must have either one or two arguments')
end
if ~(iscellstr(cstr) && (ischar(delimiter) || iscellstr(delimiter)))
error('strjoin: first argument must be a cell array, second array either a char array or a cell array')
end
if numel(cstr) == 1
rval = cstr{1};
return;
if mod(nargin,2) ~= 0
error('contains: inputs should be a text, followed by the queried patterns, then Name-Value pair arguments.');
end
if ischar(delimiter)
% There is no equivalent to do_string_escapes in MATLAB
%delimiter = do_string_escapes(delimiter);
delimiter = {delimiter};
if ~((ischar(string) || isstring(string) || iscellstr(string)) && (ischar(pattern) || isstring(pattern) || iscellstr(pattern)))
error('contains: first and second input arguments must be a string array, char array or cell array');
end
num = numel(cstr);
if numel(delimiter) == 1 && num > 1
delimiter = repmat(delimiter, 1, num);
delimiter(end) = {''};
elseif num > 0 && numel(delimiter) ~= num - 1
error('strjoin: the number of delimiters does not match the number of strings');
if ~isempty(varargin)
if ~ischar(varargin{1})
error('The #%d and #%d inputs must be a Name-Value pair.', nargin-1, nargin);
end
parameters = {'ignorecase', 'caseignore','insensitivecase', 'caseinsensitive','insensitive','ignore',...
'casesensitive', 'sensitive', 'sensitivecase'};
if ~cellfun('isempty',(cellfun(@(s)strcmpi(varargin{1}, s), parameters, 'uni', 0)))
case_ignore = varargin{end};
else
error('Unsupported parameter "%s".', varargin{1});
end
else
delimiter(end+1) = {''};
case_ignore = false;
end
if num == 0
rval = '';
else
tmp = [cstr(:).'; delimiter(:).'];
rval = [tmp{:}];
string = cellstr(string);
pattern = cellstr(pattern);
if case_ignore
string = lower(string);
pattern = lower(pattern);
end
tf = false(size(string));
for ii = 1:numel(pattern)
idx = regexp(string, pattern{ii});
for jj = 1:numel(string)
tf(jj) = tf(jj) || ~isempty(idx{jj});
end
end
end
\ No newline at end of file
function [B,C] = get_cells_id(str,sep)
% Copyright (C) 2012-2017 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/>.
sep_locations = transpose(strfind(str,sep));
B = [1; sep_locations+1];
C = [sep_locations-1; length(str)];
\ No newline at end of file
function r = iscolumn(V)
% Copyright (C) 2018 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/>.
sz = size(V);
r = (length(sz) == 2) && (sz(2) == 1);