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: xASL_adm_ManageMoCoMat.m
    path of file: ./repos/ExploreASL/External/SPMmodified/xASL
    
    the code of the file until where you have to start completion: function xASL_adm_ManageMoCoMat(PathIn)
% Manage the .mat orientation sidecar that SPM produces from realign
%
% FORMAT: xASL_adm_ManageMoCoMat(PathIn)
%
% INPUT:
%   PathIn  - path to NIfTI file (REQUIRED)
%
% OUTPUT: n/a
% -----------------------------------------------------------------------------------------------------------------------------------------------------
% DESCRIPTION: This function manages the orientation matrices that SPM puts
%              in an external .mat sidecar file if there are more than 1
%              volumes. The first volume should be equal to the orientation
%              header of the NIfTI, if not, we assume that the NIfTI
%              header is correct.
%              This function performs several checks & corrects if
%              necessary, combined with throwing a warning:
%
%              - A) the nVolumes in .mat & .nii image should be equal, if not, delete sidecar
%              - B) .mat should have more than one volume, if not delete sidecar
%              - C) If there are illegal numbers in the diagonal of the .mat
%                   orientation matrices (here only checked for zeros or non
%                   finite values) then the .mat is removed
%              - D) If this is true for the first volume only, the .mat is
%                   retained but the first volume orientation is overwritten
%                   with a zero matrix

    
function xASL_adm_ManageMoCoMat(PathIn)
% Manage the .mat orientation sidecar that SPM produces from realign
%
% FORMAT: xASL_adm_ManageMoCoMat(PathIn)
%
% INPUT:
%   PathIn  - path to NIfTI file (REQUIRED)
%
% OUTPUT: n/a
% -----------------------------------------------------------------------------------------------------------------------------------------------------
% DESCRIPTION: This function manages the orientation matrices that SPM puts
%              in an external .mat sidecar file if there are more than 1
%              volumes. The first volume should be equal to the orientation
%              header of the NIfTI, if not, we assume that the NIfTI
%              header is correct.
%              This function performs several checks & corrects if
%              necessary, combined with throwing a warning:
%
%              - A) the nVolumes in .mat & .nii image should be equal, if not, delete sidecar
%              - B) .mat should have more than one volume, if not delete sidecar
%              - C) If there are illegal numbers in the diagonal of the .mat
%                   orientation matrices (here only checked for zeros or non
%                   finite values) then the .mat is removed
%              - D) If this is true for the first volume only, the .mat is
%                   retained but the first volume orientation is overwritten
%                   with a zero matrix
%
% EXAMPLE: xASL_adm_ManageMoCoMat('/analysis/Sub-001/ASL_1/ASL4D.nii');
% __________________________________
% Copyright (C) 2015-2019 ExploreASL

% ------------------------------------------------------------------------------------------------------------
% Admin, input arguments & file loading
% ------------------------------------------------------------------------------------------------------------
if nargin < 1 || isempty(PathIn)
	error('Needs at least one input.');
end

[Fpath, Ffile, Fext] = xASL_fileparts(PathIn);

if ~(strcmp(Fext,'.nii') || strcmp(Fext,'.nii.gz'))
    warning('Input was no NIfTI file, skipping...');
    return;
end