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: plot_contact.m
    path of file: ./repos/tracacode/1911-COAWST/script/mfiles/rutgers/grid
    
    the code of the file until where you have to start completion: function plot_contact(G, S)

%
% PLOT_CONTACT:  Plots various ROMS Nested Grids Contact Points Figures
%
% h = plot_contact(G, S)
%
% This function plot contact points for each contact region.
%
% On Input:
%
%    G          Information grids structure (1 x Ngrids struct array)
%
%                 G(ng) = get_roms_grid ( char(Gnames(ng)) )
%
%    S          Nested Grids Structure (struct array)
%
%                 [S, G] = contact (Gnames, Cname, ...)
%

% svn $Id: plot_contact.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      %
%=========================================================================%

%--------------------------------------------------------------------------
% Plot perimeters and boundary edged conectivity.
%--------------------------------------------------------------------------
  
for cr=1:S.Ncontact,

    
function plot_contact(G, S)

%
% PLOT_CONTACT:  Plots various ROMS Nested Grids Contact Points Figures
%
% h = plot_contact(G, S)
%
% This function plot contact points for each contact region.
%
% On Input:
%
%    G          Information grids structure (1 x Ngrids struct array)
%
%                 G(ng) = get_roms_grid ( char(Gnames(ng)) )
%
%    S          Nested Grids Structure (struct array)
%
%                 [S, G] = contact (Gnames, Cname, ...)
%

% svn $Id: plot_contact.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      %
%=========================================================================%

%--------------------------------------------------------------------------
% Plot perimeters and boundary edged conectivity.
%--------------------------------------------------------------------------
  
for cr=1:S.Ncontact,
  dg = S.contact(cr).donor_grid;
  rg = S.contact(cr).receiver_grid;

  if (S.spherical),
    XminD = min(min(G(dg).lon_rho)); XmaxD = max(max(G(dg).lon_rho));
    YminD = min(min(G(dg).lat_rho)); YmaxD = max(max(G(dg).lat_rho));
    XminR = min(min(G(rg).lon_rho)); XmaxR = max(max(G(rg).lon_rho));
    YminR = min(min(G(rg).lat_rho)); YmaxR = max(max(G(rg).lat_rho));
    Xmin  = min(XminD, XminR);       Xmax  = max(XmaxD, XmaxR);
    Ymin  = min(YminD, YminR);       Ymax  = max(YmaxD, YmaxR);
  else
    XminD = min(min(G(dg).x_rho));   XmaxD = max(max(G(dg).x_rho));
    YminD = min(min(G(dg).y_rho));   YmaxD = max(max(G(dg).y_rho));
    XminR = min(min(G(rg).x_rho));   XmaxR = max(max(G(rg).x_rho));
    YminR = min(min(G(rg).y_rho));   YmaxR = max(max(G(rg).y_rho));
    Xmin  = min(XminD, XminR);       Xmax  = max(XmaxD, XmaxR);
    Ymin  = min(YminD, YminR);       Ymax  = max(YmaxD, YmaxR);
  end