%PROGRAM NAME: function ZZWINv2.m
function zz = ZZWINv2(x12,dw,z)
%-----------------------------------------------
x1 = round(x12(1)); x2 = round(x12(2));
% Compute centroid of z-array
xx1win1 = x1-dw; xx1win2 = x1+dw;
xx2win1 = x2-dw; xx2win2 = x2+dw;
ZZwin= z(xx1win1:xx1win2,xx2win1:xx2win2);
[zzmag,zzI] = max(ZZwin);
[zzM II] = max(zzmag);
zz1 = zzI(II)+x1 - 1 -dw;
[zzmag,zzI] = max(ZZwin');
[zzM II] = max(zzmag);
zz2 = zzI(II)+x2 - 1 -dw;
zz =[zz1 ; zz2];
%-----------------------------------------------