function Links2(varargin)
nx = 5; ny = 3;
fprintf('Link ChemPlugin instances into a %d by %d grid.\n', nx, ny);

% Create the ChemPlugin instances
cp_left = ChemPlugin();
cp_right = ChemPlugin();
cp_bottom = ChemPlugin();
cp_top = ChemPlugin();

cp = cell(nx*ny,1);
for i = 1:nx*ny
    cp{i} = ChemPlugin();
end

for j = 1:ny
    for i = 1:nx
        ij = i + (j-1)*nx;
        if i == 1
            Link(cp{ij}, cp_left);
        else
            Link(cp{ij}, cp{ij-1});
        end
        if j == 1
            Link(cp{ij}, cp_bottom);
        else
            Link(cp{ij}, cp{ij-nx});
        end
        if j == ny
            Link(cp_top, cp{ij});
        end
    end
    Link(cp_right, cp{j*nx});
end

% Report the number of links to each instance
fprintf('Left boundary is linked to %d instances\n', nLinks(cp_left));
fprintf('Bottom boundary is linked to %d instances\n', nLinks(cp_bottom));

for i  = 1:nx*ny
    fprintf('Instance %d is linked to %d instances\n', i,  nLinks(cp{i}));
end

fprintf('Top boundary is linked to %d instances\n', nLinks(cp_top));
fprintf('Right boundary is linked to %d instances\n', nLinks(cp_right));

end
