function ovlay_avg(DATA,kavg1,kavg2,kvar,kvar2);
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
AVG1=data_avg(DATA,kavg1,[],1,0,0);
AVG1.vdims=[kvar2,kavg2,kvar]; AVG1.ii_img=1;
[AVG1,V1]=view5(AVG1); fig1=gcf;
%
AVG2=data_avg(DATA,[kavg1,kavg2],[],1,0,0); 
AVG2.ii_img=-1; AVG2.vdims=[kvar,kvar2,kavg1]; 
[AVG2,V2]=view5(AVG2,[kvar,kvar2,kavg1]); fig2=gcf;
%
nvar=AVG1.dims(kvar),
ii=cell(5,1); for jdim=1:5, ii{jdim}=1; end
dimx=V1.vdims(2); dimy=V1.vdims(1); nx=AVG1.dims(dimx); ny=AVG1.dims(dimy);
xax=AVG1.scales{dimx}; yax=AVG1.scales{dimy};
dmax=zeros(nvar,1); ncol=0;
while 1==1,
	figure(fig1);
	disp('Click on point to overlay on averaged plot');
    [x0,y0,button]=ginput(1); if isempty(x0), break; end
    hold on;
    ncol=ncol + 1;
    [dum,jx0]=min(abs(xax - x0));
    [dum,jy0]=min(abs(yax - y0));
    plot_cfill(xax(jx0),yax(jy0),'o','m',5);
    ii{dimy}=jy0;
    ii{dimx}=[max(jx0-3,1):min(jx0+3,nx)];
    figure(fig2); hold on;
    for jvar=1:nvar,
        ii{kvar}=jvar;
%        [dum,jcolmax]=max(AVG1.data(ii),[],dimx);
        [xmax,d1max]=quad_peak(xax(ii{dimx}),AVG1.data(ii{1},ii{2},ii{3},ii{4},ii{5})),
%        dmax(jvar,ncol)=d1max;
        plot_cfill(AVG2.scales{kvar2}(jy0),d1max);
        zoom on; pause;
    end
end
%
