function printc(fname,a1,a2,a3,a4)
%PRINTC	Save current Figure window to a file.
%	PRINT <filename> saves the current Figure window in PostScript
%	format to the designated filename, overwriting it if it 
%	already exists. If the filename does not end in ".ps", a ".ps"
%	string is appended. If the filename is omitted, the default
%	name is untitled.ps.
%
%	PRINT <filename> -ddevice saves it in other formats.
%	Available device options are:
%
%	   -dps    - PostScript
%	   -dpsc   - Color PostScript
%	   -dps2   - Level 2 PostScript
%	   -dpsc2  - Level 2 Color PostScript
%
%	   -deps   - Encapsulated PostScript (EPSF)
%	   -depsc  - Encapsulated Color PostScript (EPSF)
%	   -deps2  - Encapsulated Level 2 PostScript (EPSF)
%	   -depsc2 - Encapsulated Level 2 Color PostScript (EPSF)
%
%	Other PRINT options are:
%
%	   -append  - append the graph to the file, rather than
%	              overwriting (can't be used with M-file output).
%
% TEMPORARY HACK BY PHIL to print on your default printer in portrait mode only% FURTHER HACK BY WILKIN -- THIS VERSION DOES COLOUR (I HOPE).
%	Looks like we are expected to edit PS file for other options!!!!

%	Copyright (c) 1984-92 by the MathWorks, Inc.


printopt = 'lpr -P$PRINTER ';
if nargin == 0
	%[lprcmd, a1] = printopt;
         lprcmd = printopt;
         a1 = '-dpsc'
	t = fix(clock);
	fname = ['mtmp' sprintf('%02.0f%02.0f%02.0f.ps',t(4),t(5),t(6))]; % unique name
	printplot = 1;
else
	printplot = 0;
end


if nargin == 1
         lprcmd = printopt;
          a1 = '-dps'
	%[lprcmd, a1] = printopt; 
end

% Append .ps to filename if not there already
if ~any(fname == '.')
	fname = [fname '.ps'];
end

if nargin <= 2
	wsave(gcf,fname,a1)
elseif nargin == 3
	wsave(gcf,fname,a1,a2)
elseif nargin == 4
	wsave(gcf,fname,a1,a2,a3)
elseif nargin == 5
	wsave(gcf,fname,a1,a2,a4,a4)
end

if printplot
	c = computer;
	if length(c) >= 5
		if strcmp(cname(1:5),'VAX_V')
			lprcmd = [lprcmd,' ',fname,'/delete'];
		end
	elseif strcmp(c,'SGI')
		lprcmd = [lprcmd,' ',fname];
	else	% Unix/ Not SGI
		lprcmd = [lprcmd,' -r ',fname];
	end
	eval(['!',lprcmd]);
end
