function printit(plotname, varargin)
% printit(plotname, varargin)
% printit(plotname)                  (makes [plotname,'.eps'], orient tall)
% printit                            (makes plot.eps, orient tall)
%
% varargin pairs are:
%
% [name]                     [options]                     [default]
% orient              'tall', 'portrait', 'landscape'      'tall'
% switches                (see matlab)                     '-dpsc'
%                                                     (eg. '-depsc -append')
% dateit                  [0,1]                       default: 1 (add date_it)
%                                                       and filename
% append                  [0,1]                  append (only with postscript)
% if plotname is 'noprint', do nothing


if (~exist('plotname'))
   plotname = 'plot';
end

if isempty(plotname)
   fprintf('not printing to disk\n')
   return
end


cfg.orient = 'tall';
cfg.switches = '-depsc ';
cfg.dateit = 1;
cfg.append = 0;

cfg = fillstruct(cfg, varargin, 0);


if cfg.append
   cfg.switches = '-dpsc -append' ;
end
   

if isstr(cfg.dateit)
   dateit_str = cfg.dateit;
   cfg.dateit = 1;
else
   if cfg.dateit == 1
      dateit_str = [plotname, '.eps'];
   end
end



if (strcmp(plotname, 'noprint'))
   fprintf('not printing\n')
else
   orient(gcf, cfg.orient)
   if (cfg.dateit)
      date_it(dateit_str)
   end
   
   command =  sprintf('print %s %s', cfg.switches, plotname);
   eval(command);
   fprintf('printing to file (basename is "%s")\n', plotname)
end



