Skip to content

Commit 89b0972

Browse files
committed
fix data dowload
1 parent cf90f25 commit 89b0972

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

demos/MoAE/download.m

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
function filename = download(URL, output_dir, verbose)
2+
%
3+
% USAGE::
4+
%
5+
% filename = download(URL, output_dir, verbose)
6+
%
7+
% (C) Copyright 2021 Remi Gau
8+
if nargin < 2
9+
output_dir = pwd;
10+
end
11+
12+
msg = sprintf('Downloading dataset from:\n %s\n\n', URL);
13+
printToScreen(msg, verbose);
14+
15+
tokens = regexp(URL, '/', 'split');
16+
protocol = tokens{1};
17+
18+
filename = tokens{end};
19+
20+
if exist(filename, 'file')
21+
delete(filename);
22+
end
23+
24+
if strcmp(protocol, 'http:')
25+
26+
if isunix()
27+
if verbose
28+
system(sprintf('wget %s', URL));
29+
else
30+
system(sprintf('wget -q %s', URL));
31+
end
32+
else
33+
urlwrite(URL, filename);
34+
end
35+
36+
% move file in case it was not downloaded in the root dir
37+
if ~exist(fullfile(output_dir, filename), 'file')
38+
printToScreen([filename ' --> ' output_dir], verbose);
39+
movefile(filename, fullfile(output_dir, filename));
40+
end
41+
filename = fullfile(output_dir, filename);
42+
43+
else
44+
45+
ftp_server = tokens{3};
46+
ftpobj = ftp(ftp_server);
47+
48+
filename = strjoin(tokens(4:end), '/');
49+
filename = mget(ftpobj, filename, output_dir);
50+
51+
end
52+
53+
if iscell(filename)
54+
filename = filename{1};
55+
end
56+
57+
printToScreen(' Done\n\n', verbose);
58+
59+
end
60+
61+
function printToScreen(msg, verbose)
62+
if verbose
63+
fprintf(1, msg);
64+
end
65+
end

demos/MoAE/download_moae_ds.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ function download_moae_ds(downloadData)
1717
spm_mkdir(fullfile(working_directory, 'inputs'));
1818

1919
%% Get data
20-
fprintf('%-10s:', 'Downloading dataset...');
21-
urlwrite(URL, 'MoAEpilot.zip');
22-
fprintf(1, ' Done\n\n');
20+
filename = download(URL, fullfile(working_directory, 'inputs'), true);
2321

2422
fprintf('%-10s:', 'Unzipping dataset...');
25-
unzip('MoAEpilot.zip');
23+
unzip(filename);
2624
movefile('MoAEpilot', fullfile(working_directory, 'inputs', 'raw'));
25+
delete(filename)
2726
fprintf(1, ' Done\n\n');
2827

2928
end

0 commit comments

Comments
 (0)