%function selectChart
function selectChart(callback)
	global chartPathName, global mission

if nargin == 1, 
	str = get(get(gcf,'CurrentObject'),'UserData');
	if ~isstr(str), return, end
	button = questdlg(['You selected chart ' str],'','Accept', ...
		'Cancel','Accept');
	if strcmp(button,'Accept'),
		if ~isempty(mission),
			mission{1} = setfield(mission{1},'chart',str);
		end
		close(gcf)
	end
	return
end

if isempty(chartPathName),
	chartPathName = [fileDlg(cd,[],'dirs',cd) '\'];
end

load coast
fig = figure;
axesm giso; framem; gridm on
plotm(lat,long,'k-')
set(gcf,'toolbar','figure')
set(gcf,'WindowButtonDownFcn','selectChart(1)')
title(['Available Charts: ' chartPathName],'Interpreter','none', ...
	'FontWeight','Bold')
xlabel('Select chart with mouse.  Zoom must be off.','FontWeight','Bold')

try,
	chartX = [];
	chartY = [];
	jj = 0;
	d = dir([chartPathName '*.tifw']);
	if length(d) == 0,
		d = dir(['*.tifw']);
	end
	if length(d) == 0,
		uiwait(msgbox('No charts found'))
		close(fig)
		chartPathName = [];
		return
	end
	for ii = 1:length(d),
		if findstr(d(ii).name,'u'), continue, end
		jj = jj+1;
		mapInfo = load([chartPathName d(ii).name]);
		mapName = strtok(d(ii).name,'u.');
		names{jj} = mapName;
		data = imfinfo([chartPathName mapName],'tif');
		x = mapInfo(5) + (1:data.Width)*mapInfo(1);
		y = fliplr(mapInfo(6) + (data.Height:-1:1)*mapInfo(4));
		X = [min(x) max(x) max(x) min(x) min(x)];
		Y = [min(y) min(y) max(y) max(y) min(y)];
		
		chartX = [chartX; X'; NaN];
		chartY = [chartY; Y'; NaN];
		plotm(Y,X,'-+r')
		textm(max(y),max(x),mapName)
	end
	
	h = patchesm(chartY,chartX,'FaceColor','r');
	
	for ii = 1:length(h),
		set(h(ii),'UserData',names{ii})
	end

catch,
	errorbox('Error reading charts')
	close(fig)
end