function gridy(x, y, z, nx, ny);

% ------------------------------------------------------
% Generate a mesh grid....

x1 = min(x); x2 = max(x); 
xs = (x2-x1)/nx;
xi = (x1-xs):xs:(x2+xs);

y1 = min(y); y2 = max(y);
ys = (y2-y1)/ny;
yi = (y1-ys):ys:(y2+ys);

[xi, yi] = meshgrid(xi', yi);

% ------------------------------------------------------
% Create temperature data grid...

xii = round((x - x1)/xs) + 1;
yii = round(y - y1)/ys) + 1;
ok = find(((xii > 0) & (xii < (nx+2))) & (okay & ((yii > 0) & (yii < (ny+2)))));

ztemp = ones(size(xi)) * mean(temp(ok));
ntemp = zeros(size(xi));

for i = 1:length(z),
   ii = xii(ok(i));
   jj = yii(ok(i));
   
   if ntemp(jj,ii) > 0
      ztemp(jj,ii) = ztemp(jj,ii) + z;
      ntemp(jj,ii) = ntemp(jj,ii) + 1;
   else
      ztemp(jj,ii) = z;
      ntemp(jj,ii) = 1;
   end;
end;   

ok = find(ntemp>0);
ztemp(ok) = ztemp(ok)./ntemp(ok);

clear xii; clear yii; clear ok; clear okind; 

% ------------------------------------------------------
% Interpolate on a row by row basis....

n = size(ztemp);
for i = 1:n(1)
   ind = find(ntemp(i,:));
   if length(ind > 1)
      ztempfill(i,:) = interp1(xi(i,ind), ztemp(i, ind), xi(i,:));
   else
      ztempfill(i,:) = nan;
   end;
end;

% ------------------------------------------------------
% Plot data....

figure;
pcolor(xi,yi,ztempfill); 
set( gca, 'YDir', 'rev'); 
caxis([2.8 3.5]);
shading flat, 
colorbar
hold on
plot(dist, depth));
ylabel( 'depth (m)' )
xlabel( 'x (m)' );

