#
#	Convert a plot output (generated by most commands in Darwin)
#	to a xxx.gif file
#
#	Arguments are all optional and order-independent
#
#	landscape	- produce a landscape gif
#	portrait	- produce a portrait gif (default)
#	output=filename - place the output in a filename
#
#			Gaston H Gonnet (Nov 2, 2002)
#
Plot2Gif := proc( )

opts := '';
outfile := 'temp.gif';
tmpfile := '/tmp/18374' . getpid();
CallSystem( 'rm -f ' . tmpfile );

for z in [args] do
    if z='landscape' then opts := opts . ' -landscape'
    elif z='portrait' then opts := opts . ' -portrait'
    elif type(z,'output'=string) then outfile := z[2]
    else error(z,'argument not valid') fi
    od;

psfile := Set(plotoutput);
if CallSystem( sprintf( 'pstopnm -stdout -ppm -quiet %s %s >%s',
	opts, psfile, tmpfile ) ) <> 0 then
	error( 'pstopnm execution failed' ) fi;

if CallSystem( sprintf( 'ppmtogif -quiet <%s >%s', tmpfile, outfile )) <> 0
	then error( 'ppmtogif execution failed' ) fi;

CallSystem( 'rm -f ' . tmpfile );
NULL
end:

