function hdfwrite(varargin)
%HDFWRITE Write data to HDF file.
%   Note: HDFWRITE has been grandfathered; use IMWRITE instead.
%
%   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.
%
%   See also IMFINFO, IMREAD, IMWRITE.

%   Author: J.M. Winograd        7-93
%   updated to call IMWRITE, Chris Griffin 8/18/96
%   Copyright 1993-1998 The MathWorks, Inc.  All Rights Reserved.
%   $Revision: 5.7 $  $Date: 1997/11/24 15:35:07 $

nargs = length(varargin);

for i=1:nargs,
    if isa(varargin{i}, 'uint8')
        error('HDFWRITE doesn''t support uint8 inputs, use IMWRITE.');
    end
end

filename = varargin{end};

if ~isstr(filename)
    error( 'FILENAME must be a string.' );
end

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

switch nargs
  case 2,  % Intensity (Grayscale) Image
      imwrite(varargin{1},filename,'hdf');
  case 3,  % Indexed Image
      imwrite(varargin{1},varargin{2},filename,'hdf');
  case 4,  % RGB Truecolor image
      RGB = cat(3,varargin{1},varargin{2},varargin{3});
      imwrite(RGB,filename,'hdf');
  otherwise,
      error('Invalid input arguments');
end


