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: spm_eeg_inv_forward_ui.m
    path of file: ./repos/spm12
    
    the code of the file until where you have to start completion: function D = spm_eeg_inv_forward_ui(varargin)
% Forward Solution user interface
% FORMAT D = spm_eeg_inv_forward_ui(D,val)
% D        - input data struct (optional)
% val      - model of interest (optional)
%
% D        - same data struct including the forward solution
%__________________________________________________________________________
%
% Call the forward computation for either EEG or MEG data using various
% types of solutions using FieldTrip.
%__________________________________________________________________________
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging

% Jeremie Mattout & Christophe Phillips
% $Id: spm_eeg_inv_forward_ui.m 6059 2014-06-19 11:57:31Z vladimir $

%-Initialisation
%--------------------------------------------------------------------------
[D, val] = spm_eeg_inv_check(varargin{:});


    
function D = spm_eeg_inv_forward_ui(varargin)
% Forward Solution user interface
% FORMAT D = spm_eeg_inv_forward_ui(D,val)
% D        - input data struct (optional)
% val      - model of interest (optional)
%
% D        - same data struct including the forward solution
%__________________________________________________________________________
%
% Call the forward computation for either EEG or MEG data using various
% types of solutions using FieldTrip.
%__________________________________________________________________________
% Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging

% Jeremie Mattout & Christophe Phillips
% $Id: spm_eeg_inv_forward_ui.m 6059 2014-06-19 11:57:31Z vladimir $

%-Initialisation
%--------------------------------------------------------------------------
[D, val] = spm_eeg_inv_check(varargin{:});

D.inv{val}.forward = struct([]);

for i = 1:numel(D.inv{val}.datareg)
    switch D.inv{val}.datareg(i).modality
        case 'EEG'
            models = {'EEG BEM', '3-Shell Sphere'};
        case 'MEG'
            models = {'Single Sphere', 'MEG Local Spheres', 'Single Shell'};
        otherwise
            error('Unsupported modality');
    end