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: align_ijk2xyz.m
    path of file: ./repos/spm12/external/fieldtrip/private
    
    the code of the file until where you have to start completion: function [interp, permutevec, flipflags, transform] = align_ijk2xyz(interp)

% ALIGN_IJK2XYZ flips and permutes the 3D volume data such that the
% voxel indices and the headcorodinates approximately correspond. The
% homogenous transformation matrix is modified accordingly, to ensure that
% the headcoordinates of each individual voxel do not change. 
% First, the volumes are permuted in order to get the largest (absolute)
% values on the diagonal of the transformation matrix. This permutation is
% reflected by the second output argument.
% Second, the volumes are flipped along the dimensions for which the main
% diagonal elements of the transformation matrix are negative. This is
% reflected by the third output argument.
%
% The second and third argument are in the output in order to be able to
% reverse the operation. Note that in such case first the data have to be
% 'unflipped', and then 'unpermuted' (using ipermute, rather than permute).

if isfield(interp, 'inside') && isfield(interp, 'outside')

    
function [interp, permutevec, flipflags, transform] = align_ijk2xyz(interp)

% ALIGN_IJK2XYZ flips and permutes the 3D volume data such that the
% voxel indices and the headcorodinates approximately correspond. The
% homogenous transformation matrix is modified accordingly, to ensure that
% the headcoordinates of each individual voxel do not change. 
% First, the volumes are permuted in order to get the largest (absolute)
% values on the diagonal of the transformation matrix. This permutation is
% reflected by the second output argument.
% Second, the volumes are flipped along the dimensions for which the main
% diagonal elements of the transformation matrix are negative. This is
% reflected by the third output argument.
%
% The second and third argument are in the output in order to be able to
% reverse the operation. Note that in such case first the data have to be
% 'unflipped', and then 'unpermuted' (using ipermute, rather than permute).

if isfield(interp, 'inside') && isfield(interp, 'outside')
  % reformat the inside field to a full volume so that it can be flipped/permuted as well
  tmp = [];
  tmp(interp.inside)  = 1;
  tmp(interp.outside) = 0;
  interp.inside  = tmp;
  interp.outside = [];
end