function DATA=data_diff(D1,D2,iiview)
%
% Subtracts D1.data - D2.data, interpolating if necessary.
%
%
% 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.
if nargin<3, iiview=0; end
%
ndim_min=min(D1.ndim,D2.ndim);
for jdim=1:ndim_min,
    if D1.dims(jdim)>D2.dims(jdim),
%         DATA.dims(jdim)=D1.dims(jdim);
%         DATA.scales{jdim}=D1.scales{jdim};
        new_scales=D2.scales; new_scales{jdim}=D1.scales{jdim};
        D2=data_interp(D2,jdim,1,new_scales,0);
    elseif D1.dims(jdim)<D2.dims(jdim),
%         DATA.dims(jdim)=D2.dims(jdim);
%         DATA.scales{jdim}=D2.scales{jdim};
        new_scales=D1.scales; new_scales{jdim}=D2.scales{jdim};
        D1=data_interp(D1,jdim,1,new_scales,0);
    end
end
DATA=structure_copy(D1,{'data'});
%
DATA.data=D1.data - D2.data;
DATA.title=[D1.title,' - ',D2.title];
DATA.clim=[min(DATA.data(:)),max(DATA.data(:))];
if iiview, view5(DATA); end
