-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakesbxdata.m
51 lines (47 loc) · 1.75 KB
/
makesbxdata.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
function sbxdata = makesbxdata(username, password, varargin)
% MAKESBXDATA Specify parameters for a SliceBox service.
%
% sbxdata = MAKESBXDATA(username, password) Creates an sbxdata object
% using username and password to connect to the server. The rest of
% the parameters are read from the file 'sbxsettings.conf'.
%
% sbxdata = MAKESBXDATA(username, password, url, cachepath) In case no
% 'sbxsettings.conf' file exists, the parameters 'url' and
% 'cachepath' are required.
%
% sbxdata = MAKESBXDATA(_, Name, Value) Specify the 'url' or 'cachepath'
% to overwrite the parameters from 'sbxsettings.conf'.
sbxdata = struct;
p = inputParser;
%If settings file exist, use contents as default. Otherwise, require url
%and cachepath.
if (exist('sbxsettings.conf', 'file') == 2)
sbxconf = fopen('sbxsettings.conf');
cells = textscan(sbxconf,'%s %s','delimiter','=');
fclose(sbxconf);
names = cells{1};
values = cells{2};
conf = cell2struct(values, names);
addRequired(p, 'username');
addRequired(p, 'password');
addParameter(p, 'url', conf.url);
addParameter(p, 'cachepath', conf.cachepath);
parse(p,username,password,varargin{:});
else
p = inputParser;
addRequired(p, 'username');
addRequired(p, 'password');
addRequired(p, 'url');
addRequired(p, 'cachepath');
parse(p, username, password, varargin{:});
end
wo = weboptions('Username', p.Results.username, 'Password', p.Results.password');
sbxdata.weboptions = wo;
sbxdata.url = p.Results.url;
sbxdata.cachepath = p.Results.cachepath;
%Test for cache directory
cachepath = sbxdata.cachepath;
if exist(cachepath, 'dir') ~= 7
ME = MException('SBX:makesbxdata:NoCacheDirectory','Cache directory does not exist!');
throw(ME);
end