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: Wrapper_QSM_FANSI.m
    path of file: ./repos/sepia/wrapper/WrapperQSM
    
    the code of the file until where you have to start completion: %% [chi] = Wrapper_QSM_FANSI(localField,mask,matrixSize,voxelSize,algorParam, headerAndExtraData)
%
% Input
% --------------
% localField    : local field map (tissue fields), in Hz
% mask          : signal mask
% matrixSize    : size of the input image
% voxelSize     : spatial resolution of each dimension of the data, in mm
% algorParam    : structure contains fields with algorithm-specific parameter(s)
% headerAndExtraData : structure contains extra header info/data for the algorithm
%
% Output
% --------------
% chi           : magnetic susceptibility map, in ppm
%
% Description: This is a wrapper function to access FANSI for SEPIA
%
% Kwok-shing Chan @ DCCN
% k.chan@donders.ru.nl
% Date created: 8 March 2020
% Date modified: 20 Feb 2022 (v1.0)
%
%
function [chi] = Wrapper_QSM_FANSI(localField,mask,matrixSize,voxelSize,algorParam, headerAndExtraData)
sepia_universal_variables;

% get algorithm parameters
algorParam = check_and_set_algorithm_default(algorParam);
method     = algorParam.qsm.method;
options.tol_update      = algorParam.qsm.tol;
options.maxOuterIter    = algorParam.qsm.maxiter;
options.mu2             = algorParam.qsm.mu2;
options.isWeakHarmonic  = algorParam.qsm.isWeakHarmonic;
options.beta            = algorParam.qsm.beta;
options.muh             = algorParam.qsm.muh;
alpha1                  = algorParam.qsm.lambda;
mu1                     = algorParam.qsm.mu1;
isGPU                   = algorParam.qsm.isGPU;

% need further decision
gradient_mode   = algorParam.qsm.gradient_mode;
constraint     	= algorParam.qsm.constraint;
solver          = algorParam.qsm.solver;

% get extra data such as magnitude/weights/B
    
function to access FANSI for SEPIA
%
% Kwok-shing Chan @ DCCN
% k.chan@donders.ru.nl
% Date created: 8 March 2020
% Date modified: 20 Feb 2022 (v1.0)
%
%
function [chi] = Wrapper_QSM_FANSI(localField,mask,matrixSize,voxelSize,algorParam, headerAndExtraData)
sepia_universal_variables;

% get algorithm parameters
algorParam = check_and_set_algorithm_default(algorParam);
method     = algorParam.qsm.method;
options.tol_update      = algorParam.qsm.tol;
options.maxOuterIter    = algorParam.qsm.maxiter;
options.mu2             = algorParam.qsm.mu2;
options.isWeakHarmonic  = algorParam.qsm.isWeakHarmonic;
options.beta            = algorParam.qsm.beta;
options.muh             = algorParam.qsm.muh;
alpha1                  = algorParam.qsm.lambda;
mu1                     = algorParam.qsm.mu1;
isGPU                   = algorParam.qsm.isGPU;

% need further decision
gradient_mode   = algorParam.qsm.gradient_mode;
constraint     	= algorParam.qsm.constraint;
solver          = algorParam.qsm.solver;

% get extra data such as magnitude/weights/B0 direction/TE/etc.
headerAndExtraData = check_and_set_SEPIA_header_data(headerAndExtraData);
b0dir = headerAndExtraData.sepia_header.B0_dir;
b0    = headerAndExtraData.sepia_header.B0;
wmap  = get_variable_from_headerAndExtraData(headerAndExtraData, 'weights', matrixSize);
magn  = get_variable_from_headerAndExtraData(headerAndExtraData, 'magnitude', matrixSize);

% add path
sepia_addpath('FANSI');
addpath(fullfile(SEPIA_HOME,'misc','qsm_algorithm','FANSI'));

%% preparation
% algorithm parameters
switch lower(gradient_mode)
    case 'vector field'
        options.gradient_mode = 0;
    case 'l1 norm'
        options.gradient_mode = 1;
    case 'l2 norm'
        options.gradient_mode = 2;
    case 'none'
        % no gradient_mode
end