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: cifti_write_from_template.m
    path of file: ./repos/brainSurfer/scripts/HCP/cifti
    
    the code of the file until where you have to start completion: function cifti_write_from_template(ciftitemplate, data, filename, varargin)
    %function cifti_write_from_template(ciftitemplate, newdata, filename, ...)
    %   Use a template cifti struct with a dense or parcels diminfo and a new data
    %   matrix to write a new cifti file.  The file extension is used to figure out
    %   what type of diminfo belongs on the other dimension.
    %
    %   The cifti extension on the filename must be one of '.dtseries.nii', '.dscalar.nii',
    %   '.dconn.nii', '.ptseries.nii', '.pscalar.nii', or '.pconn.nii'.
    %
    %   If the 'ciftitemplate' cifti struct has more than one mapping of the necessary type
    %   (dconn or pconn), you must provide additional arguments of ", 'dimension', 2" or

    
function cifti_write_from_template(ciftitemplate, data, filename, varargin)
    %function cifti_write_from_template(ciftitemplate, newdata, filename, ...)
    %   Use a template cifti struct with a dense or parcels diminfo and a new data
    %   matrix to write a new cifti file.  The file extension is used to figure out
    %   what type of diminfo belongs on the other dimension.
    %
    %   The cifti extension on the filename must be one of '.dtseries.nii', '.dscalar.nii',
    %   '.dconn.nii', '.ptseries.nii', '.pscalar.nii', or '.pconn.nii'.
    %
    %   If the 'ciftitemplate' cifti struct has more than one mapping of the necessary type
    %   (dconn or pconn), you must provide additional arguments of ", 'dimension', 2" or
    %   similar to select the dimension to copy the diminfo from.
    %
    %   If the filename indicates a dscalar or pscalar, there are additional options
    %   'namelist' and 'metadatalist' to set the contents of the scalar map.
    %
    %   If the filename indicates a dtseries or ptseries, there are additional options
    %   'start', 'step', and 'unit' to set the contents of the series map.
    %
    %   You can also specify any option pairs that cifti_write accepts.
    [options, template_varargs] = myargparse(varargin, {'stacklevel', 'disableprovenance', 'keepmetadata'}, true); %stacklevel is an implementation detail, don't add to help
    if isempty(options.stacklevel)
        options.stacklevel = 2; %note the '+ 1' in the cifti_write call, so that this function can be switched with cifti_write even in advanced situations
    end