function KN=orca_kplane(hdf_root,iim,freqs,cref,iilab,symcolipt,iith,iirmax,psize)
% Call KN=orca_kplane(hdf_root,iim,freqs,cref,iilab,symcolipt,iith,iirmax,psize)
% Plots modes in complex k-plane.  Set iikn=1 in ORCA2;
% hdf_root	= character string containing root name of _hdf file, OR
%			  cell array containing multiple _hdf file roots;
% iim 	= mode numbers to include (iim=[] for all);
% freqs	= [fmin fmax], frequency interval to include (freqs=[] for all); 
% cref	= reference sound speed for converting to cos(theta) (0=plot vs phase velocity,
%		  -1=plot vs group velocity);
% iilab	= 1 to label modes according to their mode number;
% symcolipt	= symbol, color, line type, line pt size: 'or-2' red circles connected with line;
% iith		= label theta values on horizontal axis;
% iirmax	= label 10-dB rmax values on vertical axis;
%
format compact
if nargin<5, iilab=1; end
if nargin<6 | isempty(symcolipt), symcolipt='or-2'; end
if nargin<7, iith=1; end
if nargin<8, iirmax=0; end
if nargin<9, psize=[]; end
%
%colors='rbgcmk'; %colors='rgm'; % TEMP
ncol=size(symcolipt,1);
figure; hold on;
%
if ischar(hdf_root),
	hdf_cell={hdf_root};
elseif iscell(hdf_root),
	hdf_cell=hdf_root;
else
	error('USER ERROR: hdf_root must be a string or cell array');
end
nroot=length(hdf_cell); jcol=0; jset=0;
% Loop over HDF file roots:
for jroot=1:nroot,
	hdf_root=char(hdf_cell(jroot));
%
	hdf_name=[hdf_root,'_hdf'];
	[setno,setnames]=scanhdf(hdf_name);
	jf1=hdf_find(setnames,'_knr');
	jf2=hdf_find(setnames,'_kni');
	if cref<0, jf3=hdf_find(setnames,'_vg'); end

	nfile=length(jf1); nfreq=0; freq_ax=[];
	if length(freqs)==1, freqs=[freqs freqs]; end
% Loop over datasets in current HDF file:
	for j=1:nfile,
		jf=jf1(j);
		string=['[f_ax,m_ax,knr,dataname]=selecthdf(''',hdf_root,'_hdf',''',jf);'];
		eval(string)
		ii=0;
		if isempty(freqs),
			ii=1;
		else
			if f_ax >= freqs(1) & f_ax <=freqs(2), ii=1; end
		end
		if ii==1,
			jf=jf2(j);
			string=['[f_ax,m_ax,kni,dataname]=selecthdf(''',hdf_root,'_hdf',''',jf);'];
			eval(string)
			nfreq=nfreq + 1; freq_ax=[freq_ax f_ax];
			nmode=length(m_ax);
% Check for members of iim>nmode:
			if isempty(iim), iim2=1:nmode; else; iim2=iim(find(iim<=nmode)); end
% Normalize real and imaginary axes:
			if cref>0,
				kref=2*pi*f_ax/cref; kref_mat=kref'*ones(1,nmode);
				knr_rat=knr./kref_mat; xlab='cos \theta';
			elseif cref==0,
				omega=(2*pi*f_ax')*ones(1,nmode);
				knr_rat=omega./knr; xlab='Phase Speed - m/s';
			else
				jf=jf3(j);
				string=['[f_ax,m_ax,vg,dataname]=selecthdf(''',hdf_root,'_hdf',''',jf);'];
				eval(string)
				knr_rat=vg; xlab='Group Speed - m/s';
			end
			kni_db_km=kni*8685.9;
% Plot:
			jcol=jcol + 1; jp=rem(jcol-1,ncol) + 1;
%			col=colors(rem(jcol-1,ncol)+1); %sy=['+',col];
			if symcolipt(jp,1)~=' ', sym=symcolipt(jp,1); else, sym='none'; end
			col=symcolipt(jp,2);
			if symcolipt(jp,3)~=' ', line=symcolipt(jp,3); else, line='none'; end
			if symcolipt(jp,4)~=' ', ptl=str2num(symcolipt(jp,4)); else, ptl=1.5; end
			plot_cfill(knr_rat(1,iim2),kni_db_km(1,iim2),sym,col,8,line,ptl);
			if iilab,
				dx=(max(knr_rat(1,iim2)) - min(knr_rat(1,iim2)))/100;
				text(knr_rat(1,iim2)+dx,kni_db_km(1,iim2),num2str(iim2'))
			end
			jset=jset + 1;
			KN(jset).hdf_file=hdf_name; KN(jset).set_name=setnames(jf,:);
			KN(jset).f_ax=f_ax; KN(jset).m_ax=m_ax; 
			KN(jset).knr=knr; KN(jset).kni=kni; KN(jset).cref=cref;
		end
	end
end
%
xlabel(xlab); 
ylabel('Attenuation  Ð dB/km'); grid;
plot_size(gca,'in',5,3);
plot_set3(gca,-1.5,'Times',14,1);
ax=axis;
pos=get(gcf,'Position');
if iith & cref>0,
	xtick=get(gca,'XTick'); 
	dy=(ax(4)-ax(3))/50;
	for j=1:length(xtick),
		theta=sprintf('%2.1f',real(acos(xtick(j))*180/pi));
		text(xtick(j),ax(4)+dy,theta,'HorizontalAl','Center', ...
			'VerticalAl','Bottom')
	end
	text(.5*(ax(1)+ax(2)),ax(4)+4*dy,'\theta - deg','HorizontalAl','Center', ...
		'VerticalAl','Bottom','Rotation',0)
	set(gcf,'Position',pos + [0 0 0 .75]);
end
if iirmax,
	ytick=get(gca,'YTick');
	dx=(ax(2)-ax(1))/50;
	for j=1:length(ytick),
		if ytick(j)>0,
			rmax=sprintf('%2.1f',10/max(1.e-5,ytick(j)));
			text(ax(2)+dx,ytick(j),rmax,'HorizontalAl','Left', ...
				'VerticalAl','Middle');
		end
	end
	text(ax(2)+6*dx,.5*(ax(3)+ax(4)),'10-dB Rmax','HorizontalAl','Center', ...
		'VerticalAl','Top','Rotation',90)
	set(gcf,'Position',pos + [0 0 1 0]);
end
if ~iith,
	if nfreq==1,
		mytitle([hdf_root,'; f=',num2str(freq_ax(1))]);
	else
		mytitle([hdf_root,'; f=',num2str(freq_ax(1)),'Ð',num2str(freq_ax(nfreq))]);
	end
end
plot_set3(gca,-1.5,'Times',14,1); zoom;
if ~isempty(psize), plot_size(gca,'in',psize(1),psize(2)); 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.
