function fieldmap(meshele,meshnod,fieldnod,fieldrange);
% FIELDMAP  plots a colored field to triangular grid field defined on nodes
% 
%  Usage:   fieldmap(meshele,meshnod,fieldnod,[fieldrange]);
%
%  Inputs:  meshele = element list
%           meshnod = node list (num, x, y)
%           fieldnod = field variable to plot 
%           fieldrange = range for plot [vmin vmax] (optional)
%
%  Version 1: Tom Gross  
%  Version 1.1: Rich Signell  1/13/96
%       cleaned up documentation, removed axis limits from parameter list

fieldnod=fieldnod(:);

if nargin==4
  maxfield = fieldrange(2);
  minfield = fieldrange(1);
else
  maxfield = max(fieldnod);
  minfield = min(fieldnod);
end
caxis([minfield maxfield]);

x = meshnod(:,2);
y = meshnod(:,3);

field3 = meshele(:,2:4);
field3(:)=fieldnod(meshele(:,2:4));
field3 = mean(field3')';

x3 = meshele(:,2:4);
x3(:)=x(meshele(:,2:4));
y3 = meshele(:,2:4);
y3(:)=y(meshele(:,2:4));
fill(x3',y3',field3')
caxis([minfield maxfield]);
shading flat
set(gca,'asp',[nan 1]);
