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: readBESApos.m
    path of file: ./repos/fieldtrip/external/besa
    
    the code of the file until where you have to start completion: function sensor = readBESApos(filename, type)

% readBESApos read sensor information from a *.pos file. BESA stores
% magnetometer information in *.pmg, and gradiometer information in *.pos,
% however BESA Research doesn’t mind which extension is used, the
% distinction between gradiometers and magnetometers is based on the number
% of values on each line in the file.
% Brief format description:
% - one sensor per line
% - magnetometers: label (optional), six coordinates per line (location,
%   orientation)
% - gradiometers: label (optional), nine coordinates per line (location of

    
function sensor = readBESApos(filename, type)

% readBESApos read sensor information from a *.pos file. BESA stores
% magnetometer information in *.pmg, and gradiometer information in *.pos,
% however BESA Research doesn’t mind which extension is used, the
% distinction between gradiometers and magnetometers is based on the number
% of values on each line in the file.
% Brief format description:
% - one sensor per line
% - magnetometers: label (optional), six coordinates per line (location,
%   orientation)
% - gradiometers: label (optional), nine coordinates per line (location of
%   primary sensor, location of secondary sensor, orientation).
%
% Parameters:
%     [filename]
%         In the case that the current folder is not the folder containing 
%         the file it should be the full path including the name of the 
%         pos file else only the name of the file should be specified.
%
%     [type]
%         Optional parameter defining specific type of sensors that should
%         be read from file. 
%         Possible values: 'all' for all types of sensors
%                          'mag' for magnetometer sensors only
%                          'grad' for gradiometer sensors only
%         Default value is 'all'.
% 
% Return:
%     [sensor] 
%         The output is a structure containing the following fields:
%               NumSensors:     Defines number of sensors.
%               Label:          Label of each sensor.
%               Type:           Type of each sensor (either mag or grad).
%               Coordinates:    Coordinates of each sensor. Three values
%                               for magnetometers. Six values (location of
%                               primary sensor & location of secondary
%                               sensor) for gradiometers.
%               Orientations:   Orientations of each sensor.
% 
% Copyright (C) 2014, BESA GmbH
%
% File name: readBESApos.m
%
% Author: Robert Spangler
% Created: 2014-01-08

if isempty(findstr(filename,'.'))
  filename = [filename,'.pos'];
end