function colbartest()

diary on;

locations = {'north', 'south', 'west', 'east', 'northoutside', 'southoutside', ...
             'westoutside', 'eastoutside'};

for i = 1 : length (locations)
  figpos = [50, 100, 800, 300];
  run_figures (locations{i}, 'auto', 3, figpos);
  run_figures (locations{i}, 'manual', 3, figpos);
  run_figures (locations{i}, 'auto', 2, figpos);
  run_figures (locations{i}, 'manual', 2, figpos);
end

close all;
pause (1);

for i = 1 : length (locations)
  figpos = [50, 100, 300, 800];
  run_figures (locations{i}, 'auto', 3, figpos);
  run_figures (locations{i}, 'manual', 3, figpos);
  run_figures (locations{i}, 'auto', 2, figpos);
  run_figures (locations{i}, 'manual', 2, figpos);
end

close all;

diary off;

function run_figures (loc, aspect, dim, figpos)

    fig = figure ('position', figpos);
    hax = axes ();
    [xx, yy] = meshgrid (-9:.1:19, -19:.1:19);
    r = sqrt ((xx).^2 + (yy).^2);
    zz =  sin (r) ./ r;
    surf (xx, yy, zz, 'edgecolor', 'none');
    if strcmp (aspect, 'manual')
      daspect ([1, 1, 1]);
    end
    view (dim);
    set (gcf, 'color', 'c');
    haxpos1 = get (hax, 'position');
    drawnow;

    if (figpos(3) > figpos(4))
      orientation = 'landscape';
    else
      orientation = 'portrait';
    end
    filename = sprintf ('%dD_%s_%s_%s_wocb.png', ...
                        dim, loc, get (hax, 'dataaspectratiomode'), orientation);
    print (fig, filename, '-dpng', '-r100');

    hcb = colorbar (loc);
    hcbpos = get (hcb, 'position');
    haxpos2 = get (hax, 'position');
    drawnow;

    fprintf ('Dim: %d  Location: %s  Aspectratio: %s  Orientation: %s\n', ...
             dim, loc, get (hax, 'dataaspectratiomode'), orientation);
    fprintf ('HAX wo CB:   [%1.5f %1.5f %1.5f %1.5f]\n', haxpos1);
    fprintf ('HAX with CB: [%1.5f %1.5f %1.5f %1.5f]\n', haxpos2);
    fprintf ('CB pos:      [%1.5f %1.5f %1.5f %1.5f]\n', hcbpos);
    fprintf ('FIG pos:     [%d %d %d %d]\n', figpos);
    fprintf ('\n');

    filename = sprintf ('%dD_%s_%s_%s_wcb.png', ...
                        dim, loc, get (hax, 'dataaspectratiomode'), orientation);
    print (fig, filename, '-dpng', '-r100');

end

end
