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: osp_combineCoils.m
    path of file: ./repos/osprey/process
    
    the code of the file until where you have to start completion: function [MRSCont] = osp_combineCoils(MRSCont, kk, ll, ref_ll, w_ll)
%% [MRSCont] = osp_combineCoils(MRSCont)
%   This function performs a the receiver coil combination of multi-array
%   data. All coil-combination procedures are performed using the ratio of
%   the maximum signal in each receiver to the square of the noise as the
%   weighting factor (Hall et al., NeuroImage 86:35-42 (2014)).
%
%   If the MRSCont structure contains a reference scan (i.e. data
%   acquired with the same TE and sequence as the metabolite data), the
%   metabolite and reference data are combined based on this scan. If there
%   is no reference scan, the metabolite data is combined based on its own
%   coil sensitivities.
%
%   If MRSCont contains a (short-TE) water scan, it is combined separately
%   using coil sensitivities derived from its own signals.
%
%   USAGE:

    
function [MRSCont] = osp_combineCoils(MRSCont, kk, ll, ref_ll, w_ll)
%% [MRSCont] = osp_combineCoils(MRSCont)
%   This function performs a the receiver coil combination of multi-array
%   data. All coil-combination procedures are performed using the ratio of
%   the maximum signal in each receiver to the square of the noise as the
%   weighting factor (Hall et al., NeuroImage 86:35-42 (2014)).
%
%   If the MRSCont structure contains a reference scan (i.e. data
%   acquired with the same TE and sequence as the metabolite data), the
%   metabolite and reference data are combined based on this scan. If there
%   is no reference scan, the metabolite data is combined based on its own
%   coil sensitivities.
%
%   If MRSCont contains a (short-TE) water scan, it is combined separately
%   using coil sensitivities derived from its own signals.
%
%   USAGE:
%       [MRSCont] = osp_combineCoils(MRSCont);
%
%   INPUTS:
%       MRSCont     = Osprey MRS data container.
%
%   OUTPUTS:
%       MRSCont     = Osprey MRS data container.
%
%   AUTHOR:
%       Dr. Georg Oeltzschner (Johns Hopkins University, 2019-02-20)
%       goeltzs1@jhmi.edu
%
%   CREDITS:
%       This code is based on numerous functions from the FID-A toolbox by
%       Dr. Jamie Near (McGill University)
%       https://github.com/CIC-methods/FID-A
%       Simpson et al., Magn Reson Med 77:23-33 (2017)
%
%   HISTORY:
%       2019-02-20: First version of the code.
%% Calculate coil combination weights
if nargin<5
    
    % Loop over all datasets
    for kk = 1:MRSCont.nDatasets(1)
        for ll = 1: 1:MRSCont.nDatasets(2)
            metab_ll = MRSCont.opts.MultipleSpectra.metab(ll);
            % For SPECIAL acquisitions, some of the sub-spectra need to be combined
            % prior to determining the CC coefficients. We'll set a flag here.
            isSpecial = strcmpi(MRSCont.raw_uncomb{metab_ll,kk}.seq, 'special');
            MRSCont.flags.isSPECIAL = isSpecial;
            % Check if reference scans exist, if so, get CC coefficients from there
            if MRSCont.flags.hasRef
                ref_ll = MRSCont.opts.MultipleSpectra.metab(ll);
                if isSpecial
                    % Workflow adopted from https://github.com/CIC-methods/FID-A/blob/master/exampleRunScripts/run_specialproc_auto.m
                    cweights          = op_getcoilcombos(op_combinesubspecs(MRSCont.raw_ref_uncomb{ref_ll,kk}, 'diff'), 1, 'h');
                else
                    cweights          = op_getcoilcombos(MRSCont.raw_ref_uncomb{ref_ll,kk},1,'h');
                end