function comprout=gifwrite(mat,colormap,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'.
%
%	The extension '.gif' will be added to 'filename' if it doesn't
%	already have an extension.
%
%	See also: GIFREAD, BMPWRITE, HDFWRITE, PCXWRITE, TIFFWRITE,
%	          XWDWRITE.

%	Rick Paxson 10-22-92
%	Copyright (c) 1993 by The MathWorks, Inc.
%	$Revision: 1.18 $  $Date: 1993/09/24 16:32:07 $

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
colormap = colormap';
if min(min(mat)) <= 0
  error('Image Data cannot have values <= 0.');
else
  mat = mat - 1;
  mat = mat';
  gif(mat, colormap, filename);
end
