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: palm_icodown.m
    path of file: ./repos/CBIG/external_packages/matlab/non_default_packages/palm/palm-alpha109
    
    the code of the file until where you have to start completion: function palm_icodown(varargin)
% Downsample a data-per-vertex (DPV), data-per-face (DPF),
% surface (SRF), or surfvol (MGH/MGZ) from a higher-order tessellated
% icosahedron to a lower order one. Note that the file must have been
% derived from either FreeSurfer or Brainder tools. It may not work
% if the vertices follow a different sequence inside the file.
%
% For facewise, the downsampling method is pycnophylactic and,
% therefore, should be used for quantities that require mass
% conservation, such as areal quantities.
% For vertexwise, the method removes the redundant vertices.
% Consider smoothing if needed before downsampling.
%

    
function palm_icodown(varargin)
% Downsample a data-per-vertex (DPV), data-per-face (DPF),
% surface (SRF), or surfvol (MGH/MGZ) from a higher-order tessellated
% icosahedron to a lower order one. Note that the file must have been
% derived from either FreeSurfer or Brainder tools. It may not work
% if the vertices follow a different sequence inside the file.
%
% For facewise, the downsampling method is pycnophylactic and,
% therefore, should be used for quantities that require mass
% conservation, such as areal quantities.
% For vertexwise, the method removes the redundant vertices.
% Consider smoothing if needed before downsampling.
%
% Usage:
% palm_icodown(filein,ntarget,fileout,surface)
%
% - filein  : File to be downsampled.
% - ntarget : Icosahedron order of the downsampled file.
% - fileout : Output file, downsampled.
% - suface  : Optional. For facewise, if the face indices aren't
%             ordered in the usual manner, entering a surface
%             is necessary to merge the faces correctly.
%
% _____________________________________
% Anderson M. Winkler
% Yale University / Institute of Living
% Apr/2012 (first version)
% Jul/2016 (this version, with vertexwise, surface and mgh/mgz)
% http://brainder.org

% Accept arguments
nargin  = numel(varargin);
filein  = varargin{1};
ntarget = varargin{2};
fileout = varargin{3};

% Constants for the icosahedron
V0 = 12;
F0 = 20;

% Read data from disk
X = palm_miscread(filein);
% try
%     [dpx,crd,idx] = dpxread(filein);
%     nX = numel(dpx);
%     ftype = 'dpx';
% catch
%     try
%         [vtx,fac] = srfread(filein);
%         nV = size(vtx,1);
%         ftype = 'srf';
%     catch
%         error('File %s not recognised as either DPX (curvature) or SRF (surface).',filein);
%     end