function save_figure (h, fname, fmt, size, units)
%--------------------------------------------------
%Save a figure to disk
%save_figure (h,fname,fmt,size)
%
%h is the figure handle
%fname is the filename
%fmt is the format name
%size is the size in pixels. e.g [640 480]
%
%e.g:
%save_figure(h,'C:\dump\test.png','-dpng',[640 480]);
%--------------------------------------------------
if (units == 'points')
    set(h, 'PaperPositionMode', 'manual', 'PaperUnits', 'points');
    size = size / 2.0;
    size = [0 0 size];
    set(h, 'PaperPosition', size);
elseif (units == 'inches')
    set(h, 'PaperPositionMode', 'manual', 'PaperUnits', 'inches');
    set (h, 'PaperPosition', size);
else
    set(h,'PaperPositionMode','auto')
end

print(h, fmt, fname);
end
