function xyz=wedg_ray_plot(pic_file,dB_dyn,iiv,tsize,iiq);
%
% Call xyz=wedg_ray_plot(pic_file,dB_dyn,iiv,tsize,iiq);
%
%
% 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<2, dB_dyn=40; end
if nargin<3, iiv=1:4; end
if nargin<4, tsize=[5,2]; end
if nargin<5, iiq=0; end
%
if ischar(pic_file),
        str=['load ',pic_file]; eval(str);
        k=findstr(pic_file,'.'); if ~isempty(k), pic_file=pic_file(1:k(1)-1); end
        str=['xyz = ',pic_file,';']; eval(str);
else
        xyz=pic_file;
end
xyz(:,1:2)=.001*xyz(:,1:2);
xyz(:,3)=-xyz(:,3);
%
[nr,nc]=size(xyz);
ii1=find(xyz(:,4)==0);
ii2=[ii1(2:end)-1;nc];
nray=length(ii1);
npts=ii2 - ii1 + 1; npt_max=max(npts);
xyz_rays=NaN*ones(npt_max,3,nray); dB_rays=zeros(1,nray);
for jray=1:nray,
        ii=[ii1(jray):ii2(jray)]; dB_rays(jray)=xyz(ii1(jray),5);
        xyz_rays(1:npts(jray),:,jray)=xyz(ii,1:3);
end
dB_max=ceil(max(dB_rays)/5)*5;
dB_min=dB_max-dB_dyn;
%
iirec=find(xyz(:,4)==2); nrec=length(iirec);
iisrc=find(xyz(:,4)==3); nsrc=length(iisrc);
xyz_rec=xyz(iirec,1:3);
xyz_src=xyz(iisrc,1:3);
%
dB_lims=[dB_min,dB_max];
if any(iiv==1),
	figure(330);
	plot_rays(nrec,nsrc,nray,xyz_rec,xyz_src,xyz_rays,npts,dB_rays,dB_lims,tsize,iiq); view(0,90);
end
%
if any(iiv==2),
	figure(331);
	plot_rays(nrec,nsrc,nray,xyz_rec,xyz_src,xyz_rays,npts,dB_rays,dB_lims,tsize,0); view(0,0);
end
%
if any(iiv==3),
	figure(332);
	plot_rays(nrec,nsrc,nray,xyz_rec,xyz_src,xyz_rays,npts,dB_rays,dB_lims,tsize,0); view(90,0);
end
%
if any(iiv==4),
	figure(333);
	plot_rays(nrec,nsrc,nray,xyz_rec,xyz_src,xyz_rays,npts,dB_rays,dB_lims,tsize,0); view(45,30);
end
%
%%%
%
function plot_rays(nrec,nsrc,nray,xyz_rec,xyz_src,xyz_rays,npts,dB_rays,dB_lims,tsize,iieq)
%
clf;
dB_min=dB_lims(1); dB_max=dB_lims(2); dB_dyn=dB_max-dB_min;
%
col='k';
for jrec=1:nrec,
        plot3(xyz_rec(jrec,1),xyz_rec(jrec,2),xyz_rec(jrec,3),'Marker','o','MarkerSize',8, ...
        'MarkerFaceColor',col,'MarkerEdgeColor','none','Color',col);
        hold on;        
end
col='r';
for jsrc=1:nsrc,
        plot3(xyz_src(jsrc,1),xyz_src(jsrc,2),xyz_src(jsrc,3),'Marker','o', ...
        'MarkerSize',8, ...
        'MarkerFaceColor',col,'MarkerEdgeColor','none','Color',col);
end
cmap=jet;
iiray=find(dB_rays>dB_min); nray_ok=length(iiray);
for jray0=1:nray_ok,
	jray=iiray(jray0);
    ii=[1:npts(jray)];
    jcol=max(1,64 - max(0,round(63*(dB_max-dB_rays(jray))/dB_dyn)));
    col=cmap(jcol,:);
    plot3(xyz_rays(ii,1,jray),xyz_rays(ii,2,jray),xyz_rays(ii,3,jray),'Color',col);
end
set(gca,'Zdir','Reverse');
xlabel('Up/Down Slope Range - km');
ylabel('Cross-Slope Range - km');
zlabel('Depth - m');
set(gca,'clim',dB_lims);
plot_set3(gca,1.5,'Arial',14,1);
plot_size(gca,'in',tsize(1),tsize(2));
if iieq, axis('equal'); end
hc=mycolorbar3('vert',0);
%plot_set3(hc,1.5,'Arial',14,1);
