close all 
clear
clc

% Geometry definition.
xmin  = 0;
xmax  = 1;
ymin  = 0;
ymax  = 1;
tag1  = 'R1';
gobj1 =  gobj_rectangle( xmin, xmax, ymin, ymax, tag1 );

xc    = (xmax-xmin)/2;
yc    = (ymax-ymin)/2;
r     = 0.25;
tag2  = 'C1';
gobj2 =  gobj_circle( [xc yc], r, tag2 );
gobj3 =  gobj_rectangle( -xmax, xmin, ymin, ymax, 'R2' );
gobj4 =  gobj_rectangle( xmax, 2*xmax, ymin, ymax, 'R3' );
geom.objects = { gobj1 gobj2 gobj3 gobj4};
formula = 'R1 - C1';
geom = geom_apply_formula( geom, formula );
fea.geom = geom;

% Grid generation.
hmax = 0.1;
HoleGrid = gridgen( fea.geom.objects{3}, 'hmax', hmax );
InGrid = gridgen( fea.geom.objects{1}, 'hmax', hmax,'gridgen','quad' );
OutGrid = gridgen(fea.geom.objects{2}, 'hmax', hmax,'gridgen','quad'  );

plotgrid( HoleGrid)
hold on
plotgrid( InGrid)
plotgrid(OutGrid)

% Grid merge
grid = gridmerge(InGrid,2,OutGrid,4); % this works, but is not what I'm interested in
grid = gridmerge(InGrid,2,HoleGrid,4); % this throws the following error:

% Error using horzcat
% Dimensions of arrays being concatenated are not consistent.
% 
% Error in featool
% 
% Error in featool
% 
% Error in featool
% 
% Error in gridmerge (line 71)
% [varargout{:}] = featool( 'feval', 'gridmerge', varargin{:}
% );
% 
% Error in GridExample (line 37)
% grid = gridmerge(InGrid,2,HoleGrid,4); % this works, but is
% not what I'm interested in

