% XWIN - Window the x-axis limits on all axes in current figure.
%    XWIN( XLIM ) sets the axis limits to those specified.
%    XWIN( 'full' ) sets the limit calculation mode to automagic.
%    XWIN with no arguments uses graphical input to prompt for limits.
%    LIM = XWIN(...) will return the new limits.
%
%    B. A. Moran, 03-Feb-1998

%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: xwin.m,v 1.1 2000/01/10 19:08:46 rob Exp $	

function lim = xwin( xlim )

if nargin < 1
    xlim = ginput(2);
    if ~isempty(xlim) xlim = xlim(:,1)'; end
end

if ~isempty(xlim)
    hhax = findobj( get(gcf,'children'), 'flat', 'type', 'axes' );
    if ~isempty(hhax)
	if ( isstr(xlim) & strcmp(lower(xlim),'full') )
	    set( hhax, 'XLimMode', 'auto' );
	    xlim = get( hhax(1), 'XLim' );
	else
	    set( hhax, 'XLim', sort(xlim) );
	end
    end
end

if nargout > 0
    lim = xlim;
end
