function xyz_array=adi_array_plot(array_root,tsize)
%
% Call xyz_array=adi_array_plot(array_root,tsize);
%
% array_root        = _array geometry file root in ../NAV directory ([] ==> plot
%                     array in RDA structure REC
% tsize             = plot size (default is GUI.tsize);
%
% Call xyz_array=adi_array_plot([]) to plot array in RDA structure REC, OR
% Call xyz_array=adi_array_plot(array_root) to plot array in geometry file
%		[array_root,'_array'] in ../NAV directory;
%
% Routines that work with array geometry files include:
% adi_array_make, adi_array_plot, adi_array_rot, adi_array_find, adi_array_geom;
%
gui_global
adi_global
%
if nargin<2, tsize=GUI.tsize; end
if nargin<1 | isempty(array_root),
	if isempty(REC),
		disp(['Structure REC is empty.  Run RDA and load array file in ', ...
			'REC: nph,dph box first.']);
		return
	end
	disp('Plotting array in REC structure');
	nxy=REC.nxy;
	zr=REC.z + REC.dzr; nzr=REC.nzr;
	xyz_array=[1000*REC.dxy, zr];
else
	[xyz_array,cavg,nph,geom_file,iif]=adi_array_find(array_root);
	zr=xyz_array(:,3);
	nxy=max(length(unique(xyz_array(:,1))),length(unique(xyz_array(:,2))));
	nzr=length(unique(zr));
end
%
if nxy>1,
	figure(131); clf;
%	phi_rec=REC.LOB*pi/180;
%	rot_mat=[sin(phi_rec) cos(phi_rec); -cos(phi_rec) sin(phi_rec)];
%	xy_array=1000*REC.dxy*rot_mat;
%
	plot_cfill(xyz_array(:,1),xyz_array(:,2),'o','r',7);
	axis('tight');
%	if max(dxy)-min(dxy) > .01*(max(zr)-min(zr)), axis('equal'); end
	if Bdef.iibold, wt='Bold'; else, wt='Normal'; end
    xy_skip=1;
    for jxy=1:xy_skip:nxy,
		text(xyz_array(jxy,1),xyz_array(jxy,2),[' ',int2str(jxy)],'FontName',Bdef.fname, ...
			'FontWeight',wt,'FontSize',Bdef.ptsize);
    end
	xlabel('E-W - m'); ylabel('N-S - m');
	plot_set3(gca,1.5,Bdef.fname,Bdef.ptsize,Bdef.iibold);
	plot_size(gca,'in',tsize(1),tsize(2)); zoom on; grid on; axis equal;
end
%
if nzr>1,
	figure(132); clf;
%	phi_rec=REC.LOB*pi/180;
%	rot_mat=[sin(phi_rec) cos(phi_rec); -cos(phi_rec) sin(phi_rec)];
%	xy_array=1000*REC.dxy*rot_mat;
	dxy=sqrt(sum(xyz_array(:,1:2).^2,2));
%
	plot_cfill(dxy,zr,'o','r',7);
	axis('tight'); axis('ij');
	if max(dxy)-min(dxy) > .01*(max(zr)-min(zr)), axis('equal'); end
% Make top, bottom of plot correspond to water column:
	hw=interp2(BATHY.xax(:),BATHY.yax(:),BATHY.hw,REC.xy(1),REC.xy(2));
	if min(dxy)~=max(dxy), axis([min(dxy),max(dxy),0,hw]), else, axis([-1,1,0,hw]); end
%
	if Bdef.iibold, wt='Bold'; else, wt='Normal'; end
	text(dxy(1),zr(1),' 1','FontName',Bdef.fname, ...
		'FontWeight',wt,'FontSize',Bdef.ptsize);
	text(dxy(nzr),zr(nzr),[' ',int2str(nzr)],'FontName',Bdef.fname, ...
		'FontWeight',wt,'FontSize',Bdef.ptsize);
	xlabel('Horizontal Dist - m'); ylabel('Depth - m');
	plot_set3(gca,1.5,Bdef.fname,Bdef.ptsize,Bdef.iibold);
	plot_size(gca,'in',tsize(1),tsize(2)); zoom on; grid on;
end

%
% 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.
