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_cfg_eeg_momentfit.m
    path of file: ./repos/spm/config
    
    the code of the file until where you have to start completion: function momentfit = spm_cfg_eeg_momentfit
% Configuration file for imaging source inversion reconstruction.
% This version to supply position and orientation parameters idea is to
% estimate dipole moments given priors and return a model evidence for
% these priors.
%__________________________________________________________________________

% Gareth Barnes
% Copyright (C) 2019-2022 Wellcome Centre for Human Neuroimaging


momentfit      = cfg_exbranch;
momentfit.tag  = 'momentfit';
momentfit.name = 'Bayesian moment fit';
momentfit.val  = @momentfit_cfg;
momentfit.help = {'Run imaging source reconstruction'};
momentfit.prog = @run_momentfit;
momentfit.vout = @vout_momentfit;
%dipfit.modality = {'MEG'};


%==========================================================================
function varargout = momentfit_cfg

persistent cfg
if ~isempty(cfg), varargout = {cfg}; return; end

D = cfg_files;
D.tag = 'D';
D.name = 'M/EEG datasets';
D.filter = 'mat';
D.num = [1 Inf];
D.help = {'Select the M/EEG mat files.'};

val = cfg_entry;
val.tag = 'val';
val.name = 'Inversion index';
val.strtype = 'n';
val.help = {'Index of the cell in D.inv where the forward model can be found and the results will be stored.'};
val.val = {1};

all = cfg_const;
all.tag = 'all';
all.name = 'All';
all.val  = {1};
all.help = {''};

condlabel = cfg_entry;
condlabel.tag = 'condlabel';
condlabel.name = 'Condition label';
condlabel.strtype = 's';
condlabel.val = {''};
condlabel.help = {''};

conditions = cfg_repeat;
conditions.tag = 'conditions';
conditions.name = 'Conditions';
conditions.help = {'Specify the labels of the conditions to be included in the inversion'};
conditions.num  = [1 Inf];
conditions.values  = {condlabel};
conditions.val = {condlabel};

whatconditions = cfg_choice;
whatconditions.tag = 'whatconditions';
whatconditions.name = 'What conditions to include?';
whatconditions.values = {all, conditions};
whatconditions.val = {all};
whatconditions.help = {'What conditions to include?'};

whichgenerator = cfg_menu;
whichgenerator.tag = 'whichgenerator';
whichgenerator.name = 'Fit current dipole (in volume conductor) or magnetic dipole (in free space) ';
whichgenerator.labels = {'current',  'magnetic'};
whichgenerator.values = {1,0};
whichgenerator.help = {'Fitting field due to an electrical current within the head or a coil (magnetic dipole) outside of the head ?'};

woi = cfg_entry;
woi.tag = 'woi';
woi.name = 'Time window of interest';
woi.strtype = 'r';
woi.num = [1 2];
woi.val = {[-Inf Inf]};
woi.help = {'Time window to include in the inversion (ms)'};


hanning = cfg_menu;
hanning.tag = 'hanning';
hanning.name = 'PST Hanning window';
hanning.help = {'Multiply the time series by a Hanning taper to emphasize the central part of the response.'};
hanning.labels = {'yes', 'no'};
hanning.values = {1, 0};
hanning.val = {1};


locs  = cfg_entry;
locs.tag = 'locs';
locs.name = 'Source locations';
locs.strtype = 'r';
locs.num = [Inf 3];
locs.help = {'Source locations as n x 3 matrix'};
locs.val = {zeros(0, 3)};

source_ori  = cfg_entry;
source_ori.tag = 'source_ori';
source_ori.name  = 'Source orientations as n x 3 matrix';
source_ori.strtype = 'r';
source_ori.num  = [Inf 3];
source_ori.help = {'Source orientation as n x 3 matrix of unit vectors'};
source_ori.val = {ones(1, 3)};

moms  = cfg_entry;
moms.tag = 'moms';
moms.name = 'Prior mean of source moments';
moms.strtype = 'r';
moms.num = [Inf 1];
moms.help = {'Input source moments as n x 1 matrix (in nAm)'};
moms.val = {zeros(1, 1)};

momvar  = cfg_entry;
momvar.tag = 'momvar';
momvar.name = 'Prior variance of source moments';
momvar.strtype = 'r';
momvar.num = [Inf 1];
momvar.help = {'Prior source moment variance as n x 1 matrix (in (nAm) ^2)'};
momvar.val = {ones(1,1 )*100};

ampsnr  = cfg_entry;
ampsnr.tag = 'ampsnr';
ampsnr.name = 'Estimated amplitude SNR';
ampsnr.strtype = 'r';
ampsnr.num = [ 1 1];
ampsnr.help = {'Estimate amplitude SNR as a ratio (1 for equal signal and noise amplitude)'};
ampsnr.val = {10};

niter = cfg_entry;
niter.tag = 'niter';
niter.name = 'Number of fit iterations';
niter.strtype = 'n';
niter.help = {'Number of restarts of algorithm to avoid local extrema'};
niter.val = {10};

modality = cfg_menu;
modality.tag = 'modality';
modality.name = 'Select modalities';
modality.help = {'Select modalities for the inversion (only relevant for multimodal datasets).'};
modality.labels = {'EEG', 'MEG', 'EEG+MEG'};

    
function momentfit = spm_cfg_eeg_momentfit
% Configuration file for imaging source inversion reconstruction.
% This version to supply position and orientation parameters idea is to
% estimate dipole moments given priors and return a model evidence for
% these priors.
%__________________________________________________________________________

% Gareth Barnes
% Copyright (C) 2019-2022 Wellcome Centre for Human Neuroimaging


momentfit      = cfg_exbranch;
momentfit.tag  = 'momentfit';
momentfit.name = 'Bayesian moment fit';
momentfit.val  = @momentfit_cfg;
momentfit.help = {'Run imaging source reconstruction'};
momentfit.prog = @run_momentfit;
momentfit.vout = @vout_momentfit;
%dipfit.modality = {'MEG'};


%==========================================================================
function varargout = momentfit_cfg

persistent cfg
if ~isempty(cfg), varargout = {cfg}; return; end

D = cfg_files;
D.tag = 'D';
D.name = 'M/EEG datasets';
D.filter = 'mat';
D.num = [1 Inf];
D.help = {'Select the M/EEG mat files.'};

val = cfg_entry;
val.tag = 'val';
val.name = 'Inversion index';
val.strtype = 'n';
val.help = {'Index of the cell in D.inv where the forward model can be found and the results will be stored.'};
val.val = {1};

all = cfg_const;
all.tag = 'all';
all.name = 'All';
all.val  = {1};
all.help = {''};

condlabel = cfg_entry;
condlabel.tag = 'condlabel';
condlabel.name = 'Condition label';
condlabel.strtype = 's';
condlabel.val = {''};
condlabel.help = {''};

conditions = cfg_repeat;
conditions.tag = 'conditions';
conditions.name = 'Conditions';
conditions.help = {'Specify the labels of the conditions to be included in the inversion'};
conditions.num  = [1 Inf];
conditions.values  = {condlabel};
conditions.val = {condlabel};

whatconditions = cfg_choice;
whatconditions.tag = 'whatconditions';
whatconditions.name = 'What conditions to include?';
whatconditions.values = {all, conditions};
whatconditions.val = {all};
whatconditions.help = {'What conditions to include?'};

whichgenerator = cfg_menu;
whichgenerator.tag = 'whichgenerator';
whichgenerator.name = 'Fit current dipole (in volume conductor) or magnetic dipole (in free space) ';
whichgenerator.labels = {'current',  'magnetic'};
whichgenerator.values = {1,0};
whichgenerator.help = {'Fitting field due to an electrical current within the head or a coil (magnetic dipole) outside of the head ?'};

woi = cfg_entry;
woi.tag = 'woi';
woi.name = 'Time window of interest';
woi.strtype = 'r';
woi.num = [1 2];
woi.val = {[-Inf Inf]};
woi.help = {'Time window to include in the inversion (ms)'};


hanning = cfg_menu;
hanning.tag = 'hanning';
hanning.name = 'PST Hanning window';
hanning.help = {'Multiply the time series by a Hanning taper to emphasize the central part of the response.'};
hanning.labels = {'yes', 'no'};
hanning.values = {1, 0};
hanning.val = {1};


locs  = cfg_entry;
locs.tag = 'locs';
locs.name = 'Source locations';
locs.strtype = 'r';
locs.num = [Inf 3];
locs.help = {'Source locations as n x 3 matrix'};
locs.val = {zeros(0, 3)};

source_ori  = cfg_entry;
source_ori.tag = 'source_ori';
source_ori.name  = 'Source orientations as n x 3 matrix';
source_ori.strtype = 'r';
source_ori.num  = [Inf 3];
source_ori.help = {'Source orientation as n x 3 matrix of unit vectors'};
source_ori.val = {ones(1, 3)};

moms  = cfg_entry;
moms.tag = 'moms';
moms.name = 'Prior mean of source moments';
moms.strtype = 'r';
moms.num = [Inf 1];
moms.help = {'Input source moments as n x 1 matrix (in nAm)'};
moms.val = {zeros(1, 1)};

momvar  = cfg_entry;
momvar.tag = 'momvar';
momvar.name = 'Prior variance of source moments';
momvar.strtype = 'r';
momvar.num = [Inf 1];
momvar.help = {'Prior source moment variance as n x 1 matrix (in (nAm) ^2)'};
momvar.val = {ones(1,1 )*100};

ampsnr  = cfg_entry;
ampsnr.tag = 'ampsnr';
ampsnr.name = 'Estimated amplitude SNR';
ampsnr.strtype = 'r';
ampsnr.num = [ 1 1];
ampsnr.help = {'Estimate amplitude SNR as a ratio (1 for equal signal and noise amplitude)'};
ampsnr.val = {10};

niter = cfg_entry;
niter.tag = 'niter';
niter.name = 'Number of fit iterations';
niter.strtype = 'n';
niter.help = {'Number of restarts of algorithm to avoid local extrema'};
niter.val = {10};

modality = cfg_menu;
modality.tag = 'modality';
modality.name = 'Select modalities';
modality.help = {'Select modalities for the inversion (only relevant for multimodal datasets).'};
modality.labels = {'EEG', 'MEG', 'EEG+MEG'};
modality.values = {
    {'EEG'}
    {'MEG'}
    {'EEG', 'MEG'}
    }';
modality.val = {{'MEG'}};

[cfg,varargout{1}] = deal({D, val,whichgenerator, whatconditions, woi, locs, source_ori,moms,momvar,ampsnr, niter,modality});


%==========================================================================
function  out = run_momentfit(job)

D = spm_eeg_load(job.D{1});

% pos=D.sensors('MEG').chanpos
megind=D.indchantype(job.modality);
megind=setdiff(megind,D.badchannels);
megnames=D.chanlabels(megind);

usesamples=intersect(find(D.time>=job.woi(1)./1000),find(D.time<=job.woi(2)./1000));


if isfield(job.whatconditions,'all') %% all conditions
    condind=setdiff(1:D.ntrials,D.badtrials);
else
    condind=strmatch(job.whatconditions.condlabel,D.conditions);
end