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: ft_sourcedepth.m
    path of file: ./repos/spm/external/fieldtrip/forward
    
    the code of the file until where you have to start completion: function [depth] = ft_sourcedepth(dippos, headmodel)

% FT_SOURCEDEPTH computes the distance from the source to the surface of
% the source compartment (usually the brain) in the volume conduction model.
%
% Use as
%   depth = ft_sourcedepth(dippos, headmodel);
% where
%   dippos    =  Nx3 matrix with the position of N sources
%   headmodel =  structure describing volume condition model
%
% A negative depth indicates that the source is inside the source
% compartment, positive indicates outside.
%
% See also FT_INSIDE_HEADMODEL

% Copyright (C) 2007-2008, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
%    FieldTrip is free software: you can redistribute it and/or modify

    
function [depth] = ft_sourcedepth(dippos, headmodel)

% FT_SOURCEDEPTH computes the distance from the source to the surface of
% the source compartment (usually the brain) in the volume conduction model.
%
% Use as
%   depth = ft_sourcedepth(dippos, headmodel);
% where
%   dippos    =  Nx3 matrix with the position of N sources
%   headmodel =  structure describing volume condition model
%
% A negative depth indicates that the source is inside the source
% compartment, positive indicates outside.
%
% See also FT_INSIDE_HEADMODEL

% Copyright (C) 2007-2008, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% 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$

% ensure the representation of the headmodel to be up-to-date
headmodel = ft_datatype_headmodel(headmodel);

% determine the type of volume conduction model
switch ft_headmodeltype(headmodel)

% single-sphere or multiple concentric spheres
case {'singlesphere', 'concentricspheres'}
  if ~isfield(headmodel, 'source')
    % locate the innermost compartment and remember it
    [dum, headmodel.source] = min(headmodel.r);
  end