function SP=data_parse(DATA,kdim,iiparse,iiview);
% Call SP=data_parse(DATA,kdim,iiparse,iiview);
%
% kdim		= dimension(s) over which to operate;
% iiparse	= indices to keep on dimension kdim (see help;
% iiview	= 1 to call view5 on the output SP (default is 0);
%
%
% 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==0, error('Must have at least DATA as input'); end
if nargin<2,
    str=sprintf('    %s   ',DATA.labels{1:DATA.ndim}); disp(['Axis labels: ',str]);
    str=['Axis limits: '];
    for jdim=1:DATA.ndim, str=[str,'   ',sprintf('[%1.2f %1.2f]',DATA.scales{jdim}([1,end]))]; end
    disp(str)
    str=sprintf('       %i       ',DATA.dims); disp(['Axis lengths: ',str]);
    kdim=    str2num(input(['                 Enter dimension number over which to parse: '],'s'));
    iiparse= str2num(input(['For parse dimension, enter indices to keep ([1:4,10], e.g.): '],'s'));
    iiview=  str2num(input(['          Automatically view output? (1=yes,0=no,[]=yes)   : '],'s'));
    if isempty(iiview), iiview=1; end
else
	if nargin<3 iiparse=[]; end
    if nargin<4 | isempty(iiview), iiview=0; end
end
%
SP=structure_copy(DATA,{'data'});
%
KD=cell(1,DATA.ndim);
for jdim=1:DATA.ndim,
    KD{jdim}=[1:DATA.dims(jdim)];
end

KD{kdim}=data_dim_lim(iiparse,DATA.scales{kdim});
%
SP.data=DATA.data(KD{:});
SP.scales{kdim}=DATA.scales{kdim}(KD{kdim});
if isfield(DATA,'scales2'),
%TEMP    SP.scales2{kdim}=DATA.scales2{kdim}(KD{kdim});
end
SP.dims(kdim)=length(KD{kdim});
%
if iiview, view5(SP); end
