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_nirs_scalpcouplingindex.m
    path of file: ./repos/fieldtrip/external/artinis
    
    the code of the file until where you have to start completion: function dataout = ft_nirs_scalpcouplingindex(cfg, datain)

% FT_NIRS_SCALPCOUPLINGINDEX computes the zero-lag cross-correlation between pairs of
% raw NIRS-channels to identify bad channels. In the output data structure the bad
% channels are removed, or filled with NaNs.
%
% Use as
%   [outdata] = ft_scalpcouplingindex(cfg, indata)
% where cfg is a configuration structure and indata is raw NIRS-data (in optical
% densities, ODs) that is represented according to the output of FT_PREPROCESSING.
%
% The configuration should contain the following options
%   cfg.threshold   = scalar, the correlation value which has to be exceeded to be
%                     labelled a 'good' channel (default = 0.75)
%   cfg.keepchannel = string, determines how to deal with channels that are not selected, can be
%                     'no'  completely remove deselected channels from the data (default)
%                     'nan' fill the channels that are deselected with NaNs
%
% To facilitate data-handling and distributed computing you can u
    
function and scripts
ft_revision = '$Id$';
ft_nargin   = nargin;
ft_nargout  = nargout;

% do the general setup of the function

% the ft_preamble function works by calling a number of scripts from
% fieldtrip/utility/private that are able to modify the local workspace

ft_defaults                   % this ensures that the path is correct and that the ft_defaults global variable is available
ft_preamble init              % this will reset ft_warning and show the function help if nargin==0 and return an error
ft_preamble debug             % this allows for displaying or saving the function name and input arguments upon an error
ft_preamble loadvar    datain % this reads the input data in case the user specified the cfg.inputfile option
ft_preamble provenance datain % this records the time and memory usage at the beginning of the function

% the ft_abort variable is set to true or false in ft_preamble_init
if ft_abort
  % do not continue function execution in case the outputfile is present and the user indicated to keep it
  return
end

% ensure that the input data is raw NIRS-data, this will also do
% backward-compatibility conversions of old data that for example was
% read from an old *.mat file
datain = ft_checkdata(datain, 'datatype', 'raw', 'senstype', 'nirs');

% get the options
cfg.threshold    = ft_getopt(cfg, 'threshold', 0.75);
cfg.keepchannel = ft_getopt(cfg, 'keepchannel', 'no');

% ensure that the options are valid
cfg = ft_checkopt(cfg, 'threshold', 'doublescalar');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the actual computation is done in the middle part
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% if sample rate is too high (>10Hz) or we hit Nyquist then resample
dataf = datain;
if dataf.fsample > 10 || dataf.fsample <= 5
  rescfg = [];
  rescfg.resamplefs = 10;
  dataf = ft_resampledata(rescfg, dataf);
end