%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Hardcopy plots
% AUTHOR:  Rob McEwen
% DATE:    01/5/9
% INPUTS:  nplots, hardflag
% NOTES:   This will print nplot plots, and assumes that they are consecutively
%          numbered.
%
%    $Id: mprint.m,v 1.8 2001/06/25 04:38:12 rob Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  
%
% hardflag = 1     =>     Save as .eps
% hardflag = 2     =>     Save as .eps and send to Bering
%
  nameStr = ' Fig';
  optstr  = ' -depsc';      %Encapsulated Postscript

  if( exist('nplots') == 0 ), 
    disp('Set nplots to the number of plots to be printed, or a vector')
    disp('of a subset of the displayed plots.')
    disp(' ')
    disp('hardflag = 0     =>     return.')
    disp('hardflag = 1     =>     Save as .eps')
    disp('hardflag = 2     =>     Save as .eps and send to Bering')
    disp('hardflag = 3     =>     Save as .eps and send to Tahoe')
    return
  end;

  if( exist('hardflag') == 0 ), 
    hardflag = 0; 
  end;
  if ( hardflag==0 )  
    disp('hardflag = 0     =>     return.')
    disp('hardflag = 1     =>     Save as .eps')
    disp('hardflag = 2     =>     Save as .eps and send to Bering')
    disp('hardflag = 3     =>     Save as .eps and send to Tahoe')
  end

  if hardflag >= 1,
%
% 1) If nplots is a scalar, say 14, print all figures, that is, 1 through 14. 
% 2) If nplots is a vector, say [2 14], print ONLY figures 2 and 14.
% 3) if nplots has only two equal elements, print ONLY one, e.g. nplots = [4 4].
%
    if( length(nplots) ~= 1 )
      nn = length(nplots);
      indexArray = nplots;
    else
      nn = nplots;
      indexArray = [1:nn];
    end

    if( nn == 2 )
      if( indexArray(1) == indexArray(2) ) 
	nn = 1;
      end
    end
    
    for i = 1:nn
      ii = indexArray(i);
      disp([' Saving Fig', num2str(ii)])
      eval(['print -f', num2str(ii), optstr, nameStr, num2str(ii)])
      if hardflag == 2
        disp([' Printing Fig', num2str(ii)])
        eval(['!lp -dbering', nameStr, num2str(ii), '.eps'])
      elseif hardflag == 3,
        eval(['!lp -opostscript -onb -dtahoe ', nameStr, num2str(ii), '.eps'])
      end %if
    i = i+1;
    end %for

  end %if

  hardflag = 0;
