function savefigure(name, fignum,rez)
%function SAVEFIGURE saves figure fignum in
%   savefigure(name,fignum)
%   Four different ways: as a .fig, as a .eps, as a .png 

if nargin < 2
  fignum = gcf;
end

if nargin < 3
  rez = 100;
end
% 
% if nargin < 4
%   type = 'eps';
% end

% save as .fig
saveas(fignum, name, 'fig');
% save as .eps
%saveas(fignum, name, 'eps');
% save as .png (same size as on screen)
saveSameSize(fignum, 'file', name, 'format', 'png');
% don't know
print('-depsc', ['-r' num2str(rez)], ['-f' num2str(fignum)], name);
% save convert .eps to .pdf
% unix(['epstopdf ', name,'.eps'])
unix(['ps2pdf ', name,'.eps ',name,'.pdf '])
