-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathread_eco.m
67 lines (54 loc) · 1.82 KB
/
read_eco.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
%% read_eco
% read eco codes in allEco.mat for specified entries
%%
function codes = read_eco(entries, varargin)
% created 2018/05/10 by Bas Kooijman, modified 2019/12/29
%% Syntax
% codes = <../read_eco.m *read_eco*>(entries, varargin)
%% Description
% Reads eco-codes in allEco.mat for specified entries.
%
% Input:
%
% * entries: n-cell string with names of entries
% * varargin: names of variables or cell-string with names of variables
%
% Output
%
% * codes: (n,x)-cell-array with codes
%% Remarks
% * Use <read_allEco.html *read_allEco*> to include all entries.
% * See also <prt_ecoCodes.html *prt_ecoCodes*> to print a table with ecoCodes.
%% Example of use
% embryo = read_eco(select('Aves'), 'embryo');
persistent allStat
if ~exist('allStat','var') || length(allStat) == 0
load('allstat') % get all parameters and statistics in structure allStat
end
n_fields = length(fields(allStat)); load('n_entries', 'n_entries');
if ~(n_fields == n_entries)
fprintf(['Warning from read_eco: allStat has ', num2str(n_fields), ' fields, but the lists-of-lists have ', num2str(n_entries), ' entries\n'])
date_check;
end
n = length(entries);
if iscell(varargin{1})
varargin = varargin{:}; % unpack cell string
end
nargin = length(varargin);
for j = 1:nargin
if ~ismember(varargin{j}, {'climate', 'ecozone', 'habitat', 'embryo', 'migrate', 'food', 'gender', 'reprod'})
fprintf (['Error in read_eco: variable "', varargin{j}, '" is not recognized\n']);
codes = []; return
end
end
codes = cell(n,nargin);
for i = 1:n
for j = 1:nargin
try
codes{i,j} = allStat.(entries{i}).ecoCode.(varargin{j});
catch
feval(['[~, ~, metaData, ~, ~] = mydata_', entries{i}])
codes{i,j} = metaData.ecoCode.(varargin{j});
end
end
end