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: pm_invert_phasemap.m
    path of file: ./repos/bspm/thirdparty/spm8/toolbox/FieldMap
    
    the code of the file until where you have to start completion: function varargout = pm_invert_phasemap(varargin)
% Inverting phasemaps (trickier than it sounds).
% FORMAT ipm = invert_phasemap(pm) 
% or 
% FORMAT ipm = invert_phasemap(pm,idim) 
% or

    
function varargout = pm_invert_phasemap(varargin)
% Inverting phasemaps (trickier than it sounds).
% FORMAT ipm = invert_phasemap(pm) 
% or 
% FORMAT ipm = invert_phasemap(pm,idim) 
% or
% FORMAT ipm = invert_phasemap(P) 
% or
% FORMAT ipm = invert_phasemap(P,idim) 
% or
% FORMAT invert_phasemap(P,fname)
% or
% FORMAT invert_phasemap(P,fname,idim)
%
% Input:
% pm      1, 2 or 3D array representing a displacement field that
%         is to be inverted along one direction.
% idim    The dimension along which field is to be inverted.
% P       File-struct or -name containing displacement field.
% fname   Name of output file.
%
% Output:
% ipm     Displacement-field inverted along requested direction.
%
% This is a gateway function to invert_phasemap_dtj (do the job) 
% which is a mex-file. The job of this routine is to handle some of 
% the basic book-keeping regarding format and file creation.
%_______________________________________________________________________
% Jesper Andersson 10/1-02
% 
% Added the possibility to specify along which direction
% the field should be inverted.
%_______________________________________________________________________
% Jesper Andersson 17/3-05
%
%_______________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Jesper Andersson 
% $Id: pm_invert_phasemap.m 3644 2009-12-16 10:51:34Z christophe $

%
% Decode first input parameter.
%
if isfield(varargin{1},'dim') | ischar(varargin{1})
   if isfield(varargin{1},'dim')
      P = varargin{1}; 
   elseif ischar(varargin{1})
      P = spm_vol(varargin{1});
   end