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_trk.m
    path of file: ./repos/spm/external/fieldtrip/fileio/private
    
    the code of the file until where you have to start completion: function [track] = read_trk(filename, refine)

%read TrackVis .trk format data
% fillPath: filename of track to read.
%for format details http://www.trackvis.org/docs/?subsect=fileformat



    
function [track] = read_trk(filename, refine)

%read TrackVis .trk format data
% fillPath: filename of track to read.
%for format details http://www.trackvis.org/docs/?subsect=fileformat


fid = fopen(filename);
hdr = get_hdr(fid);
if hdr.hdr_size~=1000
  fclose(fid);
  fid = fopen(filePath, 'r', 'b'); % Big end