%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 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.17 2008/10/22 20:13:30 rob Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Type "mprint" with no arguments for help.
%
  if( exist('nameStr') == 0 ) nameStr = ' Fig'; end
  optstr  = ' -depsc2';      %Encapsulated Postscript

  if( exist('nplots') == 0 | exist('hardflag') == 0 | hardflag == 0 )
    disp('Set nplots to the number of plots to be printed, or a vector')
    disp('of a subset of the displayed plots.')
    disp('Set nameStr to the desired name.')
    disp(' ')
    disp('nplots   = 0     =>     return.')
    disp('hardflag = 0     =>     return.')
    disp('hardflag = 1     =>     Save as .pdf')
    disp('hardflag = 2     =>     Save as .eps')
    disp('hardflag = 3     =>     Save as .tif')
    disp('hardflag = 4     =>     Save as .png')
    disp('hardflag = 5     =>     Save as .eps and send to Chesapeake')
    disp('hardflag = 6     =>     Save as .eps and send to Banda')
    disp('hardflag = 7     =>     Save as .tif without compression.')
    disp('hardflag = 8     =>     Save as .ps level2 color.')
    disp('hardflag = 9     =>     Save as .jpg.')
    disp('hardflag = 10    =>     Save as Illustrator compatible file.')
    hardflag = 0;
    return; 
  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

    if( hardflag == 1 ) optstr  = ' -dpdf';  end;   %.pdf file
    %   hardflag == 2   Defaults to -depsc2 =>       .eps file
    if( hardflag == 3 ) optstr  = ' -dtiff'; end;   %.tif file
    if( hardflag == 4 ) optstr  = ' -dpng';  end;   %.png file
    if( hardflag == 7 ) optstr  = ' -dtiffnocompression'; end;   %.tif file
    if( hardflag == 8 ) optstr  = ' -dpsc2'; end;   %.ps level2 color
    if( hardflag == 9 ) optstr  = ' -djpeg90'; end;   %.jpg quality
    if( hardflag == 10) optstr  = ' -dill';  end;   

    for i = 1:nn
      ii = indexArray(i);
      %
      % optstr(4:end) displays the file type.
      %
      disp([' Saving Fig', num2str(ii), '.', optstr(4:end)])
      eval(['print -f', num2str(ii), optstr, nameStr, num2str(ii)])
      if hardflag == 5
        disp([' Printing Fig', num2str(ii)])
        eval(['!lp -dchesapeake', nameStr, num2str(ii), '.eps'])
      elseif hardflag == 6,
        disp([' Printing Fig', num2str(ii)])
        eval(['!lp -opostscript -onb -dbanda ', nameStr, num2str(ii), '.eps'])
      end %if
    i = i+1;
    end %for

  end %if

  hardflag = 0;
