function errorshade(x, y, l, u, t)
%ERRORSHADE Plot graph with shaded error belt.
%	ERRORSHADE(X,Y,L,U,T) plots the graph of vector X vs. vector Y
%	with error bars specified by the vectors L (lower) and U (upper).
%	The vectors X, Y, L and U must be the same length.  
%	U defaults to L if not specified.
%       T is the type: 'plot' is default; 'log' for loglog

%	D. Stammer, MIT, 2-1-1995.
%       modified by D. Menemenlis, 6 feb 95

x = x(:); y = y(:); l=l(:);

if nargin < 3
  error('Not enough arguments')
elseif nargin == 3,  
  u = l;
  t = 'plot';
elseif nargin == 4 & ~isstr(u)
  l = l(:);
  u = u(:);
  t = 'plot';
elseif nargin == 4
  t=u;
  u=l;
else
  u=u(:);
end

if isstr(x) | isstr(y) | isstr(l) | isstr(u)
  error('Arguments must be numeric.')
end

if any(size(x)~=size(y)) | any(size(x)~=size(l)) |  any(size(x)~=size(u)),
  error('The sizes of X, Y, L and U must be the same.');
end

colormap(gray(8))
npt = length(x);
xp=[x' x(npt : -1 : 1)']';
yp=[y'+l' y(npt : -1 : 1)'-l(npt : -1 : 1)']';


fill(xp,yp,.9*[1 1 1],'linestyle','none');
% $$$ if ishold
% $$$   plot(xp,yp,'linewidth',.01),
% $$$ else
% $$$   hold on, plot(xp,yp,'linewidth',.01), hold off
% $$$ end

if strcmp(t,'log')
  if min(abs([x; y; u; l; xp; yp])) == 0
    error('The sizes of X, Y, L and U must be the same.');
  end
  set(gca,'YScale','log','XScale','log'),
end

