function setup_spice()

disp('--- SPICE / MICE setup ---')

base_dir = fullfile(tempdir,'mice_toolkit');

if ~exist(base_dir,'dir')
    mkdir(base_dir);
end

cd(base_dir)

% Detect OS
if ispc
    url = 'https://naif.jpl.nasa.gov/pub/naif/toolkit/MATLAB/PC_Windows_VisualC_MATLAB9.x_64bit/packages/mice.zip';
    archive = 'mice.zip';
elseif isunix
    url = 'https://naif.jpl.nasa.gov/pub/naif/toolkit/MATLAB/PC_Linux_GCC_MATLAB9.x_64bit/packages/mice.tar.Z';
    archive = 'mice.tar.Z';
else
    error('Unsupported OS')
end

% download
if ~isfile(archive)
    disp('Downloading MICE...')
    websave(archive,url);
end

% extract
if ispc
    unzip(archive)
else
    system(['tar -xzf ',archive]);
end

% add path
addpath(genpath(fullfile(base_dir,'mice')))

disp('MICE added to MATLAB path')

% test
try
    v = cspice_tkvrsn('toolkit');
    disp(['SPICE version: ',v])
catch
    warning('SPICE not detected correctly')
end

end