function handles=bathy_image_ekw(BATHY,iinewfig,bsize,conts,hmax,iiclab,iikm,iifig_size,iibar,cmap,iigrid,linegrid,iilog);
%
% Call handles=bathy_image_ekw(BATHY,iinewfig,bsize,conts,hmax,iiclab,iikm,iifig_size,iibar,cmap,iigrid,linegrid,iilog);
%
% INPUTS:
% BATHY     = structure containing bathymetry (produced
% 			  by bathy_convert) containing BATHY.lat,BATHY.long,BATHY.hw.
% iinewfig	= 0 to plot in current figure, 1 to create new figure.
% bsize		= size of image [w,h] in inches;
% conts		= contour values in m ([] for no contours);
% hmax      = max waterdepth to map to bottom of colormap;
% iiclab	= 1 to label contours;
% iikm		= label x,y-axes as: 0=deg,1=km,2=km&deg,-1=nmi,-2=nmi&deg;
% iifig_size= 0 to not change size of figure in plot_size;
% iibar     = 1 to plot colorbar;
% cmap      = color map (default = reverse jet);
% iigrid    = 1 to overlay grid lines;
% linegrid  = line style for grid lines;
% iilog		= 0 for plot depths in m; 1 for plot depths in 10*log10(m); 2 to image
%			  image slope also;
%
% OUTPUT:
% handles	= [gca hc], handles to image axis and colorbar axis (optional);
%
%
% 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<1, error('bathy_image_ekw requires BATHY input'); end
if nargin<2| isempty(iinewfig), iinewfig=1; end
if nargin<3 | isempty(bsize), bsize=[4 4]; end
if nargin<4, conts=[]; end
if nargin<5 | isempty(hmax), hmax=max(BATHY.hw(:)); end
if nargin<6 | isempty(iiclab), iiclab=1; end
if nargin<7 | isempty(iikm), iikm=2; end
if nargin<8 | isempty(iifig_size), iifig_size=1; end
if nargin<9 | isempty(iibar), iibar=1; end
if nargin<10 | isempty(cmap), cmap=jet(64); cmap=cmap(end:-1:1,:); end
if nargin<11 | isempty(iigrid), iigrid=1; end
if nargin<12 | isempty(linegrid), linegrid=1; end
if nargin<13 | isempty(iilog), iilog=0; end
%
if iilog<0 | iilog>2, error('Illegal iilog (0 or 1 or 2)'); end
%
if BATHY.lat(1)==0 & BATHY.long(1)==0 & abs(iikm)==2,
	iikm=sign(iikm); 
end
if iikm==0, 
	x=BATHY.long; y=BATHY.lat; 
    xlab='Longitude - deg'; ylab='Latitude - deg';
elseif iikm>0,
	x=BATHY.xax; y=BATHY.yax; 
    xlab='E-W Position - km'; ylab='N-S Position - km';
elseif iikm<0,
	x=BATHY.xax/1.852; y=BATHY.yax/1.852; 
	xlab='East-West Position - nmi'; ylab='North-South Position - nmi';
end
% Make new figure of correct size so that colorbar is right height:
bsize=bathy_size(bsize,BATHY.xax,BATHY.yax,iinewfig);
%
% ccol='k' or 'r' means to image and set contours to black or red, 
% ccol=[] means to make contours colored without image; 
% ccol=0 means to make contours black without image,
ccol='k'; ii_img=isstr(ccol); 
%
if iilog==0;
	z=BATHY.hw;
	if ii_img, imagesc(x,y,z); end
	htitle='; Depths in m';
	hold on; [c,hzero]=contour(x,y,z,[0.1 0.1],'m');
elseif iilog==1,
	z=real(10*log10(max(BATHY.hw,1)));
	if ii_img, imagesc(x,y,z); end
	htitle='; Depths in 10*log10(m)';
	hold on; [c,hzero]=contour(x,y,z,[0.1,0.1],'m');
	clim=get(gca,'clim');
	clim(1)=max(clim(1),10); clim(2)=max(clim(2),clim(1)+.001);
	set(gca,'clim',clim);
end
clim=get(gca,'clim'); hmin=min(min(BATHY.hw));
if hmax>0 & hmax>hmin,
	if ~iilog, clim(2)=hmax; else, clim(2)=10*log10(hmax); end
	set(gca,'clim',clim); 
end
if clim(1)==0,
% Make land appear as gray:
	cmap(1,:)=[.5 .5 .5];
	clim(1)=-(clim(2)-clim(1))/size(cmap,1);
	set(gca,'clim',clim);
end
colormap(cmap); 
%
xlabel(xlab); ylabel(ylab);
axis('xy'); axis('tight'); % axis('equal');
plot_set3(gca,1.5,'Arial',14,1);
plot_size(gca,'in',bsize(1),bsize(2),.75,.5,iifig_size);
set(hzero,'Linewidth',2);
%
% Put on contours and labels:
if ~isempty(conts), 
	if length(conts)==1, conts=conts*[1 1]; end
	if iilog==1, conts=10*log10(conts); conts=round(10*conts)/10; end
	if ii_img,
		[c,h_cont]=contour(x,y,z,conts,ccol);
		if iiclab & ~isempty(c), 
			hlab=clabel(c,h_cont); 
			set(hlab,'Color',ccol);
			set(hlab,'FontName','Arial','FontSize',12);
			set(hlab,'FontWeight','Bold');
		end
	else
		if isempty(ccol),
			[c,h_cont]=contour(x,y,z,conts);
		else
			[c,h_cont]=contour(x,y,z,conts,'k');
		end
		if iiclab & ~isempty(c), 
			hlab=clabel(c,h_cont); 
			set(hlab,'FontName','Arial','FontSize',12);
			set(hlab,'FontWeight','Bold');
		end
		axis('tight');
	end
end
% Grid lines:
if iigrid, grid on; set(gca,'GridLineStyle',linegrid); end
% Place colorbar last:
if iibar & ii_img, 
	hc=mycolorbar2('vert',1,'Depth - m'); 
    mycbar_conts(hc,0,'m'); mycbar_conts(hc,conts,'k');
else
	hc=[];
end
if nargout>0, handles=[gca]; end
%%
% for iikm=2 make second set of axes:
if abs(iikm)==2,
	ax1=gca; ax1pos=get(ax1,'Position'); ax1units=get(ax1,'Units');
	ax2=axes('Units',ax1units,'Position',ax1pos,'XAxisLocation','top', ...
		'YAxisLocation','right','Color','None','Xcolor','r','Ycolor','r');
	[ny,nx]=size(z);
	line(BATHY.long([1,nx]),BATHY.lat([1,ny]),'Visible','Off','Parent',ax2);
	xlabel('Longitude - deg'); ylabel('Latitude - deg');
	axis('xy'); axis('tight');
	plot_set3(gca,1.5,'Arial',14,1);
% Move colorbar and make figure larger if necessary:
	if iibar, 
		barpos=get(hc,'Position'); barpos(1)=barpos(1) + .65;
		set(hc,'Position',barpos);
		if iifig_size==1,
            figpos=get(gcf,'Position'); figpos(3)=figpos(3) + .65;
		    set(gcf,'Position',figpos);
        end
	end
	axes(ax1);
%	if nargout>0, handles=[ax1,hc,ax2]; end
	if nargout>0, handles=[handles, ax2]; end
elseif abs(iikm)==3,
% Flag for no axes or labels:
	xlabel([]); ylabel([]);
	set(gca,'XtickLabel',[]); set(gca,'YtickLabel',[]);
end	
