function print_figs(fig_nums, print_options)
% PRINT_FIGS prints all of the figures whose handles are passed to it.
%   function print_figs(fig_nums)
%   fig_nums is a vector of figure handles. (-1 represents all figures)
%   print_options is a character string of options to pass to the printer.
%
% EXAMPLE:
%   print_figs([3 10:14], '-Pdpg')
% This will send figures 3, 10, 11, 12, 13, 14 to the printer 'dpg'
%   print_figs(2, '-dpsc fred.ps')
% This will send figure 2 to the postscript file fred.ps
%   print_figs(-1, '-Psands')
% This will send all of the figures to the printer 'sands'

% $Id: print_figs.m,v 1.3 1998/02/03 01:27:44 mansbrid Exp $
% Copyright J. V. Mansbridge, CSIRO, Fri Nov  7 16:43:40 EST 1997

% Check that fig_nums is a vector

if nargin == 0
  fig_nums = gcf;
elseif nargin <= 2
  dims = size(fig_nums);
  if (ischar(fig_nums) == 1) | (min(dims) ~= 1)
    error('fig_nums must be a vector')
  end
else
  error('print_figs should have 2 or less arguments')
end

% Check that the vector fig_nums contains proper figure numbers

han = get(0, 'Children');
if (length(fig_nums) == 1) & (fig_nums == -1)
  fig_nums = han;
else
  for ii = 1:length(fig_nums)
    if all(fig_nums(ii) ~= han)
      error('Not all of the handles passed correspond to existing figure')
    end
  end
end

if nargin < 2
  print_options = '';
end

for ii = 1:length(fig_nums)
  str = ['print -f' num2str(fig_nums(ii)) ' ' print_options];
  eval(str)
end
