function plotelt(elt)
% plotelt(elt)
% plot each of the elements
% use color according to errest

% mms {@(#) Sat Jan  3 11:25:10 2009 }
% $Id: plotelt.m,v 1.2 2012/01/19 20:37:30 mike Exp $

if length(elt)<1
  error('plotelt: elt is empty')
end

NUM_COLORS=64;
VALUE_YELLOW=20;

% generate a colormap
red=[1 0 0];     % large (bad) values
green=[0 1 0];   % small (good) values
yellow=[1 1 0];  % intermediate values

r=[linspace(green(1),yellow(1),VALUE_YELLOW)'
   linspace(yellow(1),red(1),NUM_COLORS-VALUE_YELLOW)'];
g=[linspace(green(2),yellow(2),VALUE_YELLOW)'
   linspace(yellow(2),red(2),NUM_COLORS-VALUE_YELLOW)'];
b=[linspace(green(3),yellow(3),VALUE_YELLOW)'
   linspace(yellow(3),red(3),NUM_COLORS-VALUE_YELLOW)'];

colormap([r g b]);

% find max error
maxErr=abs(elt(1).errest);
for k=2:length(elt)
  maxErr=max(maxErr,abs(elt(k).errest));
end

color=round(abs(elt(1).errest)/maxErr*NUM_COLORS);
patch([elt(1).x,elt(1).x+elt(1).h,elt(1).x+elt(1).h,elt(1).x], ...
      [elt(1).y,elt(1).y,elt(1).y+elt(1).h,elt(1).y+elt(1).h], ...
      color);
hold on
for k=2:length(elt)
color=round(abs(elt(k).errest)/maxErr*NUM_COLORS);
patch([elt(k).x,elt(k).x+elt(k).h,elt(k).x+elt(k).h,elt(k).x], ...
      [elt(k).y,elt(k).y,elt(k).y+elt(k).h,elt(k).y+elt(k).h], ...
      color);
end
hold off
