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: minimumnormestimate.m
    path of file: ./repos/malini/Codes/deconvolution - model/spm8/external/fieldtrip/inverse
    
    the code of the file until where you have to start completion: function [dipout] = minimumnormestimate(dip, grad, vol, dat, varargin)

% MINIMUMNORMESTIMATE computes a linear estimate of the current in a
% distributed source model.
% 
% Use as
%   [dipout] = minimumnormestimate(dip, grad, vol, dat, ...)
%
% Optional input arguments should come in key-value pairs and can include
%   'noisecov'         = Nchan x Nchan matrix with noise covariance
%   'sourcecov'        = Nsource x Nsource matrix with source covariance
%                        (can be empty, the default will then be identity)
%   'lambda'           = scalar, regularisation parameter (can be empty, 
%                        it will then be estimated from snr) 
%  'snr'               = scalar, signal to noise ratio
%  'reducerank'        = reduce the leadfield rank, can be 'no' or a number
%                        (e.g. 2) 
%  'normalize'         = normalize the leadfield
%  'normalizeparam'    = parameter for depth normalization (default = 0.5)
%  'keepfilter'        = 'no' or 'yes', keep the spatial filter in the
%                        output
%  'prewhiten'         = 'no' or 'yes', prewhiten the leadfield matrix with
%                        the noise covariance matrix C.
%  'scalesourcecov'    = 'no' or 'yes', scale the source covariance matrix R
%                        such that trace(leadfield*R*leadfield')/trace(C)=1
%
% Note that leadfield normalization (depth regularisation) should be done
% by scaling the leadfields outside this function, e.g. in
% prepare_leadfield. Note also that with precomputed leadfields the
% normalization parameters will not have an effect.
%
% This implements
% * Dale AM, Liu AK, Fischl B, Buckner RL, Belliveau JW, Lewine JD,
%   Halgren E (2000): Dynamic statistical parametric mapping: combining
%   fMRI and MEG to produce high-resolution spatiotemporal maps of
%   cortical activity. Neuron 26:55-67.
% * Arthur K. Liu, Anders M. Dale, and John W. Belliveau  (2002): Monte
%   Carlo Simulation Studies of EEG and MEG Localization Accuracy.
%   Human Brain Mapping 16:47-62.
% * Fa-Hsuan Lin, Thomas Witzel, Matti S. Hamalainen, Anders M. Dale,
%   John W. Belliveau, and Steven M. Stufflebeam (2004): Spectral
%   spatiotemporal imaging of cortical oscillations and interactions
%   in the human brain.  NeuroImage 23:582-595.

% TODO implement the following options
% - keepleadfield

% Copyright (C) 2004-2008, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip

    
function [dipout] = minimumnormestimate(dip, grad, vol, dat, varargin)

% MINIMUMNORMESTIMATE computes a linear estimate of the current in a
% distributed source model.
% 
% Use as
%   [dipout] = minimumnormestimate(dip, grad, vol, dat, ...)
%
% Optional input arguments should come in key-value pairs and can include
%   'noisecov'         = Nchan x Nchan matrix with noise covariance
%   'sourcecov'        = Nsource x Nsource matrix with source covariance
%                        (can be empty, the default will then be identity)
%   'lambda'           = scalar, regularisation parameter (can be empty, 
%                        it will then be estimated from snr) 
%  'snr'               = scalar, signal to noise ratio
%  'reducerank'        = reduce the leadfield rank, can be 'no' or a number
%                        (e.g. 2) 
%  'normalize'         = normalize the leadfield
%  'normalizeparam'    = parameter for depth normalization (default = 0.5)
%  'keepfilter'        = 'no' or 'yes', keep the spatial filter in the
%                        output
%  'prewhiten'         = 'no' or 'yes', prewhiten the leadfield matrix with
%                        the noise covariance matrix C.
%  'scalesourcecov'    = 'no' or 'yes', scale the source covariance matrix R
%                        such that trace(leadfield*R*leadfield')/trace(C)=1
%
% Note that leadfield normalization (depth regularisation) should be done
% by scaling the leadfields outside this function, e.g. in
% prepare_leadfield. Note also that with precomputed leadfields the
% normalization parameters will not have an effect.
%
% This implements
% * Dale AM, Liu AK, Fischl B, Buckner RL, Belliveau JW, Lewine JD,
%   Halgren E (2000): Dynamic statistical parametric mapping: combining
%   fMRI and MEG to produce high-resolution spatiotemporal maps of
%   cortical activity. Neuron 26:55-67.
% * Arthur K. Liu, Anders M. Dale, and John W. Belliveau  (2002): Monte
%   Carlo Simulation Studies of EEG and MEG Localization Accuracy.
%   Human Brain Mapping 16:47-62.
% * Fa-Hsuan Lin, Thomas Witzel, Matti S. Hamalainen, Anders M. Dale,
%   John W. Belliveau, and Steven M. Stufflebeam (2004): Spectral
%   spatiotemporal imaging of cortical oscillations and interactions
%   in the human brain.  NeuroImage 23:582-595.

% TODO implement the following options
% - keepleadfield

% Copyright (C) 2004-2008, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
% for the documentation and details.
%
%    FieldTrip is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    FieldTrip is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id: minimumnormestimate.m 7123 2012-12-06 21:21:38Z roboos $

% ensure that these are row-vectors
dip.inside  = dip.inside(:)';
dip.outside = dip.outside(:)';

% get the optional inputs for the MNE method according to Dale et al 2000, and Liu et al. 2002
noisecov       = ft_getopt(varargin, 'noisecov');
sourcecov      = ft_getopt(varargin, 'sourcecov');
lambda         = ft_getopt(varargin, 'lambda');  % can be empty, it will then be estimated based on SNR
snr            = ft_getopt(varargin, 'snr');  % is used to estimate lambda if lambda is not specified

% these settings pertain to the forward model, the defaults are set in compute_leadfield
reducerank     = ft_getopt(varargin, 'reducerank');
normalize      = ft_getopt(varargin, 'normalize');
normalizeparam = ft_getopt(varargin, 'normalizeparam');
keepfilter     = istrue(ft_getopt(varargin, 'keepfilter', false));
dowhiten       = istrue(ft_getopt(varargin, 'prewhiten',  false));
doscale        = istrue(ft_getopt(varargin, 'scalesourcecov', false));
hasleadfield   = isfield(dip, 'leadfield');
hasfilter      = isfield(dip, 'filter');

if isempty(lambda) && isempty(snr) && ~isfield(dip, 'filter')
  error('either lambda or snr should be specified');
elseif ~isempty(lambda) && ~isempty(snr)
  error('either lambda or snr should be specified, not both');
end