function tiftogif(filename,rotate)
% tiftogif(filename): print the current frame to a tif and convert to gif

print('-dtiff','-r80',filename)
% unixstr =  [ 'tifftopnm ' filename '.tif | pnmrotate -90 | ' ...
%      ' ppmtogif > ' filename '.gif'];

rotate = ' ';
if nargin > 1
  rotate = ' | pnmrotate -90 ';
end

unixstr =  [ 'tifftopnm ' filename '.tif | ' rotate ...
      ' ppmtogif > ' filename '.gif'];

unixstr = [ unixstr '&& /bin/rm ' filename '.tif']
unix(unixstr)