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: refine.m
    path of file: ./repos/PsPM/src/Import/fieldtrip/fileio/private
    
    the code of the file until where you have to start completion: function [pntr, trir, texr] = refine(pnt, tri, method, texture, varargin)

% REFINE a 3D surface that is described by a triangulation
%
% Use as
%   [pnt, tri]          = refine(pnt, tri)
%   [pnt, tri]          = refine(pnt, tri, 'banks')
%   [pnt, tri]          = refine(pnt, tri, 'updown', numtri)
%   [pnt, tri, texture] = refine(pnt, tri, 'banks', texture) 
%
% If no method is specified, the default is to refine the mesh globally by bisecting
% each edge according to the algorithm described in Banks, 1983.
%
% The Banks method allows the specification of a subset of triangles to be refined
% according to Banks' algorithm. Adjacent triangles will be gracefully dealt with.
%
% The alternative 'updown' method refines the mesh a couple of times
% using Banks' algorithm, followed by a downsampling using the REDUCEPATCH
% function.
%
% If the textures of the vertices are specified, the textures for the new
% vertices are computed
%
% The Banks method is a memory efficient implementation which remembers the

    
function [pntr, trir, texr] = refine(pnt, tri, method, texture, varargin)

% REFINE a 3D surface that is described by a triangulation
%
% Use as
%   [pnt, tri]          = refine(pnt, tri)
%   [pnt, tri]          = refine(pnt, tri, 'banks')
%   [pnt, tri]          = refine(pnt, tri, 'updown', numtri)
%   [pnt, tri, texture] = refine(pnt, tri, 'banks', texture) 
%
% If no method is specified, the default is to refine the mesh globally by bisecting
% each edge according to the algorithm described in Banks, 1983.
%
% The Banks method allows the specification of a subset of triangles to be refined
% according to Banks' algorithm. Adjacent triangles will be gracefully dealt with.
%
% The alternative 'updown' method refines the mesh a couple of times
% using Banks' algorithm, followed by a downsampling using the REDUCEPATCH
% function.
%
% If the textures of the vertices are specified, the textures for the new
% vertices are computed
%
% The Banks method is a memory efficient implementation which remembers the
% previously inserted vertices. The refinement algorithm executes in linear
% time with the number of triangles. It is mentioned in
% http://www.cs.rpi.edu/~flaherje/pdf/fea8.pdf, which also contains the original
% reference.

% Copyright (C) 2002-2014, 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: refine.m 395 2016-12-19 13:51:00Z tmoser $

if nargin<3
  method = 'banks';
end