% Setup
% -------------------------------------------------------------------------
% Base URL where the zip files are stored
base_url = 'http://www.fil.ion.ucl.ac.uk/spm/data/spmcourse';

% Get default MATLAB folder
base_dir = userpath;

% Make output directory
base_out_dir = fullfile(base_dir,'mri_course_data');
if ~exist(base_out_dir, 'file')
    mkdir(base_out_dir);
end

% Switch to that directory
cd(base_out_dir);

fprintf('Data will be saved in: %s\n\n',base_out_dir);

% Download SPM and add to path
% -------------------------------------------------------------------------
disp('Downloading SPM...');
unzip([base_url '/spm_25.01.02.zip']);

% Alternatively, we can use the Github .zip file (extra level of directory tree)
%unzip('https://github.com/spm/spm/releases/download/25.01.02/spm_25.01.02.zip');

disp('Adding SPM to path');
addpath(fullfile(base_out_dir,'spm_25.01.02'));
savepath

% Download files for day 1
% -------------------------------------------------------------------------
disp('Downloading datasets needed for day 1');
unzip([base_url '/day_1.zip']);

% Download files for day 2
% -------------------------------------------------------------------------
disp('Downloading datasets needed for day 2');
unzip([base_url '/day_2.zip']);

% Finish up
% -------------------------------------------------------------------------
disp('All data downloaded. Please follow analysis instructions provided');
disp('Done');
