function gifwrite(x,map,FileName)
% GIFWRITE Write a GIF (Graphics Interchange Format) file to disk.
%	GIFWRITE(X,MAP,'FileName') writes a GIF file containing the indexed
%	image X and colormap MAP to a disk file called 'FileName'.

if strcmp(version,'4.2c')
  if nargin ~= 3 | ~isstr(FileName)
    error('Requires 3 input arguments and FILENAME must be a string');
  end
  
  if ~any(FileName==46), FileName = [FileName '.gif']; end

  % assume normal orientation of the colormap passed in
  map = map';
  if min(min(x)) <= 0
    error('Image Data cannot have values <= 0.');
  else
    x = x - 1;
    x = x';
    eval('gif(x, map, FileName);');
  end
else
  eval('imgwrite(x,map,FileName);');
end
