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: Murat_cornering.m
    path of file: ./repos/MuRAT/bin
    
    the code of the file until where you have to start completion: function [ip,jp,kp,flag]    =   Murat_cornering(xx,yy,zz,gridD)
% function [ip,jp,kp,flag]    =   Murat_cornering(xx,yy,zz,gridD)
%
% CHECKS that the point is in the grid and
% FINDS the indices of the vertex of the cube [ip,jp,kp] of grid points
%   surrounding the point [xx,yy,zz].
%
% Input parameters:
%    xx:        x coord of point West;

    
function [ip,jp,kp,flag]    =   Murat_cornering(xx,yy,zz,gridD)
% function [ip,jp,kp,flag]    =   Murat_cornering(xx,yy,zz,gridD)
%
% CHECKS that the point is in the grid and
% FINDS the indices of the vertex of the cube [ip,jp,kp] of grid points
%   surrounding the point [xx,yy,zz].
%
% Input parameters:
%    xx:        x coord of point West;
%    yy:        y coord of point North;
%    zz:        z coord of point ;
%    gridD:     propagation grid;
%
% Output parameters:
%    ip:        index of minimum x grid coord - West;
%    jp:        index of minimum y grid coord - South;
%    kp:     i  ndex of maximum z grid coord - shallowest.


% Coordinates of the propagation grid are unwrapped
xGrid                       =   gridD.x;
yGrid                       =   gridD.y;
zGrid                       =   gridD.z;

% If point exceeds grid extrema
flag                        =   0;

% If statement to check if the point is outside the grid
if zz < min(zGrid)
    [~,ip]                  =   min(abs(xx-xGrid));
    [~,jp]                  =   min(abs(yy-yGrid));
    [~,kp]                  =   min(zGrid);
    flag                    =   1;
    return
elseif zz > max(zGrid)
    [~,ip]                  =   min(abs(xx-xGrid));
    [~,jp]                  =   min(abs(yy-yGrid));
    [~,kp]                  =   max(zGrid);
    flag                    =   1;
    return
end