-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathget_id_lepidoptera.m
58 lines (47 loc) · 1.24 KB
/
get_id_lepidoptera.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
%% get_id_lepidoptera
% gets id of species name in Global Lepidoptera Names Index
%%
function id = get_id_lepidoptera(my_pet, open)
% created 2021/08/13 by Bas Kooijman
%% Syntax
% id = <../get_id_lepidoptera.m *get_id_lepidoptera*>(my_pet, open)
%% Description
% Gets identifier for Global Lepidoptera Names Index
%
% Input:
%
% * my_pet: character string with name of a taxon
% * open: optional boolean for opening in browser (default: 0)
%
% Output:
%
% * id: character string with id in Global Lepidoptera Names Index
%% Remarks
% Outputs empty strings if identification was not successful.
%% Example of use
% id = get_id_lepidoptera('Manduca_sexta',1)
address = 'http://www.nhm.ac.uk/our-science/data/lepindex/detail/?taxonno=';
if ~exist('open','var')
open = 0;
end
my_pet = strrep(my_pet,' ','+');
my_pet = strrep(my_pet,'_','+');
try
url = urlread(['http://webservice.catalogueoflife.org/col/webservice?name=', my_pet]);
catch
id = ''; return
end
i_0 = strfind(url, 'lepindex/detail/?taxonno=');
if isempty(i_0)
id = ''; return
end
i_0 = i_0(1) + 25; i_1 = strfind(url(i_0:end),'</online_resource>') - 2 + i_0(1);
id = url(i_0:i_1(1));
try
urlread([address, id]);
catch
id = ''; return
end
if open
web([address, id],'-browser');
end