%function tzgrid()

% Test for zgrid.m

%grid:
x = 1:0.1:10;
y = 5:0.2:20;
nxg = length(x);
nyg = length(y);

%Input data:
%xp = (1:0.3:10).';
xp = ([1:0.25:5 5.1:0.4:10]).';    % Variable input grid
nx = length(xp);
yp = 4:0.5:18;
ny = length(yp);

Xp = xp(:,ones(1,ny));
Yp = yp(ones(nx,1),:);

% x is the row dimension--increases down the column.
Zp = sin(Xp) .* cos((Yp-8).*sin(Xp/3));

% Put in some NaNs, to make a hole:
Zp(1:10,5:15) = NaN;

% Make a blanking polygon.
xbp = [Xp(1,1); Xp(end, 1); Xp(end, end); Xp(1, end); Xp(1, 15); Xp(10,15); Xp(10,5); Xp(1,5); Xp(1,1)];
ybp = [Yp(1,1); Yp(end, 1); Yp(end, end); Yp(1, end); Yp(1, 15); Yp(10,15); Yp(10,5); Yp(1,5); Yp(1,1)];

%[Zg, Xg, Yg, Zb] = zgrid(yp, xp, Zp, x, y, [1 3 5 1], [5 12 5 5]);
%[Zg, Xg, Yg, Zb] = zgrid(yp, xp, Zp, x, y, 'cay', 0.1);
%[Zg, Xg, Yg, Zb] = zgrid(xp, yp, Zp, x, y, 'cay', 0.1);
%[Zg, Xg, Yg, Zb] = zgrid(Xp, Yp, Zp, x, y, 'cay', 0.1);

[Zg, Xg, Yg, Zb] = zgrid(xp, yp, Zp, 3, 3, ...
 'cay', 3, 'nsegmin', 1, 'nrng', 5, 'dyfrac', 0.5, 'del', 1.2 , ...
     xbp, ybp);

%figure(2); contour(x, y, Zg.', 10);  % Note need to transpose Zg
% Above form is not correct when "stretch" form of zgrid is used
figure(1); contourf(Xg, Yg, Zg, 10); title('After zgrid');
figure(2); contourf(Xp, Yp, Zp, 10); title('Before zgrid');
%Note: the x,y,Zg.' form of contouring is faster by about 10%;
% 2.25 s versus 2.45 s for the Xg,Yg,Zg form.  (On Toshiba 420,
% 100 MHz Pentium laptop.)  The zgrid operation was only 0.42 s.

