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: sample_grid.m
    path of file: ./repos/tracacode/1911-COAWST/script/mfiles/rutgers/utility
    
    the code of the file until where you have to start completion: function [Istr,Iend,Jstr,Jend] = sample_grid(XD,YD,XR,YR,varargin)

%
% SAMPLE_GRID:  Gets donor grid tight indices containing receiver grid
%
% [Istr,Iend,Jstr,Jend] = sample_grid(XD,YD,XR,YR,offset,plt);
%
% This function computes the donor grid indices range of the polygon
% that tightly contains the receiver grid.  This is done to sa
    
function computes the donor grid indices range of the polygon
% that tightly contains the receiver grid.  This is done to sample the
% donor grid to accelerate the interpolation of fields for the receiver
% grid.
%
% On Input:
%
%    XD            Donor grid X-coordinates (2D array)
%    YD            Donor grid Y-coordinates (2D array)
%    XR            Receiver grid X-coordinates (2D array)
%    YR            Receiver grid Y-coordinates (2D array)
%    offset        Number of extra points used to sample the
%                    donor grid so it is large enough to contain
%                    the receiver grid  (default 5)
%    plt           Switch to plot donor and receiver grids
%                    (default false)
%
% On Output:
%
%    Istr          Donor grid starting I-index for sampling
%    Iend          Donor grid ending   I-index for sampling
%    Jstr          Donor grid starting J-index for sampling
%    Jend          Donor grid ending   J-index for sampling
%

% svn $Id: sample_grid.m 938 2019-01-28 06:35:10Z arango $
%=========================================================================%
%  Copyright (c) 2002-2019 The ROMS/TOMS Group                            %
%    Licensed under a MIT/X style license                                 %
%    See License_ROMS.txt                           Hernan G. Arango      %
%=========================================================================%

%  Set optional arguments.

offset = 5;
plt = false;

switch numel(varargin)
  case 1
    offset = varargin{1};
  case 2
    offset = varargin{1};
    plt = varargin{2};
end

%--------------------------------------------------------------------------
%  Extract donor grid polygon.
%--------------------------------------------------------------------------

[ImD,JmD] = size(XD);
IstrD = 1;
Iend