function rout=hdfwrite( dat1, dat2, dat3, dat4, filename )
%HDFWRITE Write data to HDF file.
%	HDFWRITE(I,'filename') writes the binary or intensity 
%	image I to an HDF file.
%
%	HDFWRITE(X,MAP,'filename') writes an indexed image X and
%	its colormap MAP to an HDF file.
%
%	HDFWRITE(R,G,B,'filename') writes an RGB image to
%	an HDF file.
%
%	Images are always written to the file in append mode, and
%	with RLE compression.
%
%	See also: HDFPEEK, HDFREAD, BMPWRITE, GIFWRITE, PCXWRITE,
%	          TIFFWRITE, XWDWRITE.

%	Author: J.M. Winograd	7-93
%	Copyright (c) 1993 The Mathworks, Inc.
%	$Revision: 1.10 $  $Date: 1993/10/21 12:59:32 $

error( nargchk( 2, 5, nargin ) );

if nargin < 5
   filename = eval(['dat',num2str(nargin)]);
end
if ~isstr(filename)
    error( 'FILENAME must be a string.' );
end

if (isempty(findstr(filename,'.'))==1)
    filename=[filename,'.hdf'];
end;

if nargin == 2
    result = hdfwc( filename, dat1 );
elseif nargin == 3
    result = hdfwc( filename, dat1, dat2 );
elseif nargin == 4
    if ~isstr(dat3) & (size(dat1) ~= size(dat2)) | (size(dat1) ~= size(dat3))
   	   error('R, G, B must all be the same size.');
    end
    result = hdfwc( filename, dat1, dat2, dat3 );
elseif nargin == 5
    if (size(dat1) ~= size(dat2)) | (size(dat1) ~= size(dat3))
	   error('R, G, B must all be the same size.');
    end
    result = hdfwc( filename, dat1, dat2, dat3, dat4 );
end

if nargout==1, rout = result; end
