You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tor_global.m
    path of file: ./repos/CanlabCore/CanlabCore/Image_computation_tools
    
    the code of the file until where you have to start completion: % :Usage:
% ::
%
%     [g, gslice, stdslice, s]] = tor_global(P, [maskname])
%
% Compute global image values within an optional mask
% alternative to spm_global
%
% Pass in a file name for mask:
% ::
%
%    g = tor_global(P, 'my_gray_mask.img')
%
% Use Worsley's fmri_mask_thresh to implicitly mask based on first image:
% ::
%
%    g = tor_global(P, 1);
%

    
function [g, gslice, stdslice, s] = tor_global(P, varargin)
    
    switch spm('Ver')
        case 'SPM2'
            % spm_defaults is a script
            disp('WARNING: spm defaults not set for spm2. Make sure your defaults are set correctly');

        case {'SPM5', 'SPM8', 'SPM12'}
            % spm_defaults is a function
            spm_defaults()

        otherwise
            % unknown SPM
            disp('Unknown version of SPM!');
            spm_defaults()
    end