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_im_SaveOriginal4CAT.m
    path of file: ./repos/ExploreASL/External/SPMmodified/xASL
    
    the code of the file until where you have to start completion: function xASL_im_SaveOriginal4CAT(Ycls, PathIn)
%xASL_im_SaveOriginal4CAT Save the segmentation before lesion masking
%
% FORMAT: xASL_im_SaveOriginal4CAT(Ycls, PathIn)
%
% INPUT:
%   Ycls	    - ...
%   PathIn	    - ...
%
% OUTPUT: n/a
%
% -----------------------------------------------------------------------------------------------------------------------------------------------------
% DESCRIPTION: Save the segmentation before lesion masking.
%
% EXAMPLE:     n/a
%
% __________________________________
% Copyright 2015-2021 ExploreASL

%%%   If there are no lesions found, the images are untouched

[x.dir.SUBJECTDIR, x.P.STRUCT , ~]     = xASL_fileparts(PathIn);
x.P.STRUCT    = 'T1';
x.P.FLAIR     = 'FLAIR';

Lesion_T1_list      = xASL_adm_GetFileList(x.dir.SUBJECTDIR,['^Lesion_' x.P.STRUCT '.*\.nii$'],'FPList',[0 Inf]);
Lesion_FLAIR_list   = xASL_adm_GetFileList(x.dir.SUBJECTDIR,['^Lesion_' x.P.FLAIR  '.*\.nii$'],'FPList',[0 Inf]);

if  isempty(Lesion_T1_list) && isempty(Lesion_FLAIR_list)
	fprintf('%s\n','No Lesion*.nii specified, not saving the segmentation before masking');
else

	%%% ---------------------------------------------------------------------
	%%% Save probability maps before DARTEL & before lesion masking
	cPathOri{1}   = fullfile( x.dir.SUBJECTDIR, ['c1' x.P.STRUCT '_ORI.nii']);
	cPathOri{2}   = fullfile( x.dir.SUBJECTDIR, ['c2' x.P.STRUCT '_ORI.nii']);

	fprintf('%s','Saving segmentations before DARTEL (and/or cost function masking if Lesion_*.nii exist):   ')

	% First checking if they are the same size, or were resampled
	T1Path      = fullfile( x.dir.SUBJECTDIR, [x.P.STRUCT '.nii']);
	T1im        = xASL_io_Nifti2Im(T1Path);

    
function xASL_im_SaveOriginal4CAT(Ycls, PathIn)
%xASL_im_SaveOriginal4CAT Save the segmentation before lesion masking
%
% FORMAT: xASL_im_SaveOriginal4CAT(Ycls, PathIn)
%
% INPUT:
%   Ycls	    - ...
%   PathIn	    - ...
%
% OUTPUT: n/a
%
% -----------------------------------------------------------------------------------------------------------------------------------------------------
% DESCRIPTION: Save the segmentation before lesion masking.
%
% EXAMPLE:     n/a
%
% __________________________________
% Copyright 2015-2021 ExploreASL

%%%   If there are no lesions found, the images are untouched

[x.dir.SUBJECTDIR, x.P.STRUCT , ~]     = xASL_fileparts(PathIn);
x.P.STRUCT    = 'T1';
x.P.FLAIR     = 'FLAIR';

Lesion_T1_list      = xASL_adm_GetFileList(x.dir.SUBJECTDIR,['^Lesion_' x.P.STRUCT '.*\.nii$'],'FPList',[0 Inf]);
Lesion_FLAIR_list   = xASL_adm_GetFileList(x.dir.SUBJECTDIR,['^Lesion_' x.P.FLAIR  '.*\.nii$'],'FPList',[0 Inf]);

if  isempty(Lesion_T1_list) && isempty(Lesion_FLAIR_list)
	fprintf('%s\n','No Lesion*.nii specified, not saving the segmentation before masking');
else

	%%% ---------------------------------------------------------------------
	%%% Save probability maps before DARTEL & before lesion masking
	cPathOri{1}   = fullfile( x.dir.SUBJECTDIR, ['c1' x.P.STRUCT '_ORI.nii']);
	cPathOri{2}   = fullfile( x.dir.SUBJECTDIR, ['c2' x.P.STRUCT '_ORI.nii']);

	fprintf('%s','Saving segmentations before DARTEL (and/or cost function masking if Lesion_*.nii exist):   ')

	% First checking if they are the same size, or were resampled
	T1Path      = fullfile( x.dir.SUBJECTDIR, [x.P.STRUCT '.nii']);
	T1im        = xASL_io_Nifti2Im(T1Path);

	%%% Second, we calculate the volumes (dimension, transformation matrix in the CAT12 space and original space)

	% The parameters of the CAT12 space are taken from the original space and modified
	volCAT = spm_vol(T1Path); % Loads the parameters of the original space
	volOriginalvoxelSize    = sqrt(sum(volCAT.mat(1:3,1:3).^2)); % calculates the voxelsize
	volOriginalvoxelSize    = xASL_round(volOriginalvoxelSize, 2); % round to two digits after the decimal point

	% Take the size of the CAT12 space and adapt the resolution
	volCATvoxelSize   = volCAT.dim .* volOriginalvoxelSize./size(Ycls{1});

	% Replicate what CAT12 does to recalculate the CAT12-space matrix
	volCAT        = rmfield(volCAT,'private');
	volCAT.descrip = '';
	imat      = spm_imatrix(volCAT.mat);
	volCAT.dim    = size(Ycls{1});
	imat(7:9) = volCATvoxelSize .* sign(imat(7:9));
	volCAT.mat    = spm_matrix(imat);

	% The parameters of the original T1 space are unchanged
 	volOriginal = spm_vol(T1Path);
	volOriginal = rmfield(volOriginal,'private');

	% Transfer CAT12 to original = volCAT -> volOriginal
	for ii=1:2
		xASL_TrackProgress(ii-1,2);

		% Save the image
		xASL_delete(cPathOri{ii});

		if  ~min(size(Ycls{1})==size(T1im)) % if sizes are not identical
			% Transform the CAT12 image to the original space
			imHigh2Save = xASL_im_ResampleIM(Ycls{ii},volCAT.mat,volOriginal.mat,volOriginal.dim,'linear');
			% And save the result
			xASL_io_SaveNifti(PathIn,cPathOri{ii},imHigh2Save,8);
		else
			xASL_io_SaveNifti(PathIn,cPathOri{ii},Ycls{ii},8);
		end