function [h]=fillseg(X,c1,c2);
% function [h]=fillseg(X,c1,c2);
% x is a two column matrix 
% containing line segments separated by NaNs, this routine
% fills in the segments with color c1 and edgecolor c2, where
% c1 and c2 are colors defined as [r g b];  c1 and c2 can be
% three column matrices, in which case the first row is used to
% fill the first segment, the second row is used to fill the 
% second segment, etc.
%
ii=find(isnan(X(:,1)));
nseg=length(ii)-1;
if(nseg>0),
% fill out matrix c1 and c2
if(length(c1(:))==3),
  c1=c1(ones(nseg,1),:);
  c2=c2(ones(nseg,1),:);
elseif(length(c1(:))~=(3*nseg)),
  [m,n]=size(c1);
  clast=c1(m,:);
  c=clast(ones(nseg,1),:);
  c(1:m,:)=c1(1:m,:);
  c1=c;
  [m,n]=size(c2);
  clast=c2(m,:);
  c=clast(ones(nseg,1),:);
  c(1:m,:)=c2(1:m,:);
  c2=c;
end
for iseg=1:nseg;
     i1=ii(iseg)+1;
     i2=ii(iseg+1)-1;
     ind=i1:i2;
     h(iseg)=fill(X(ind,1),X(ind,2),c1(iseg,:));...
       set(h(iseg),'edgecolor',c2(iseg,:));
  end
end
