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: read_besa_swf.m
    path of file: ./repos/bspm/thirdparty/spm12/external/fieldtrip/fileio/private
    
    the code of the file until where you have to start completion: function [swf] = read_besa_swf(filename)

% READ_BESA_SWF
%
% Use as
%   [swf] = read_besa_swf(filename)
%
% This will return a structure with the header information in
%   swf.label     cell array with labels
%   swf.data      data matrix, Nchan X Npnts
%   swf.npnt
%   swf.tsb
%   swf.di
%   swf.sb

% Copyright (C) 2006, 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.

    
function [swf] = read_besa_swf(filename)

% READ_BESA_SWF
%
% Use as
%   [swf] = read_besa_swf(filename)
%
% This will return a structure with the header information in
%   swf.label     cell array with labels
%   swf.data      data matrix, Nchan X Npnts
%   swf.npnt
%   swf.tsb
%   swf.di
%   swf.sb

% Copyright (C) 2006, 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$

fid = fopen(filename);
line = fgetl(fid);
head = sscanf(line,'Npts= %f TSB= %f DI= %f SB= %f'); % new BESA versions include more information in the .swf file header; skip that
Npts = head(1);
TSB  = head(2);
DI   = head(3);
SB   = head(4);

offset = ftell(fid);

% try reading a label and a number
dum = textscan(fid, '%s %f', 1);
fseek(fid, offset, 'bof');

if  isempty(dum{2})
  % first line contains all labels, each subsequent line is one timepoint for all channels
  line = fgetl(fid);
  line(line==' ') = [];
  label = tokenize(line, ':')';
  if isempty(label{end