function m_gebco(file, varargin)
%--------------------------------------------------------------------------
% 
% m_gebco.m -- Plot GEBCO data onto m_map plot
% 
% Author          : Jaccard Pierre
% Created On      : 2000/08/17 08:46:29
% Last Modified By: Jaccard Pierre
% Last Modified On: 2001/09/21 13:33:16
% Directory       : /home1/jaccard/pcd/codas/2000-11-21/codas3/gfi/matlab/matlab50/
% ----------------------------------------------------------------------- +
% VERSION CONTROL: 
% 
%   $Author$
%   $Date$
%   $Id$
%   $Name$
%   $Revision$
%   $State$
%   $Log$
% 
% --------------------------------------------------------------------------
%
% SYNOPSIS
%
%   m_gebco(file, [ 'levels', levels ], [ line_styles ])
%
% PARAMETERS
%
%   file
%      Name of file containing ASCII dump from the GEBCO atlas. 
%
%   'levels', levels
%      LEVELS is an array with the bathymetric levels to plot.
%
%   line_styles
%      A list of value/pair properties for the lines. This list must appear 
%      at the end of the parameter list.
%
% DESCRIPTION
%
%   Plot bathymetric lines on a map generated with the MATLAB M_MAP tools.
%   Bottom data are read from ASCII dumps from the GEBCO atlas. Format of
%   these files are two-columns data, with value of vertical level and
%   number of points, followed by the corresponding number of
%   latitude/longitude pairs for this level. Bathymetric plots with GEBCO
%   data are much more precise than contours generated by MATLAB.
%
%   Lines are not annotated, as this require to implement a function for
%   doing so and which is not implemented yet. A possibility would be to
%   load GEBCO data, interpolate them on a regular grid and generate
%   contours. However, contour precision would be lost since MATLAB is not
%   that good in generating contour plots.
%
% EXAMPLE
%
%   % Generate a projection with coast lines:
%   m_proj('mercator', 'lon', [ -60, 13], 'lat', [55, 65 ]);
%   m_usercoast('nuka-gshhs-i.map', 'patch', [.7 .7 .7]);  
%   m_grid;
%
%   % To generate a file with coast data, execute the next command after
%   % the projection has been created.
%   m_gshhs_i('save', 'nuka-gshhs-i.map');
%
%   % Plot bathymetric contours
%   m_gebco('nuka-gebco.asc', 'levels', [ 1000 2000 3000 ], 'LineWidth', 0.5);
%   m_gebco('nuka-gebco.asc', 'levels', [ 500 1500 2500 ], 'LineWidth', 0.25);
%   m_gebco('nuka-gebco.asc', 'levels', [ 100 200 ], 'LineWidth', 0.1);
% 
%--------------------------------------------------------------------------

%--- Default values:

levels = [];
line_style = { 'LineStyle', '-', 'LineWidth', 0.1, 'Color', 'b' };

%--- Process parameters

i = 0;
while i < (nargin - 1),
	i = i + 1;
	if strcmp(varargin{i}, 'levels'),
		i = i + 1;
		levels = varargin{i};
	else
		% The rest of parameters is sent to m_line as line specifications
		line_style = {varargin{i:length(varargin)}};
		i = nargin;
	end
end

%--- Loop inside file:
fid = fopen(file, 'r');
if fid < 0,
	error([ 'Opening GEBCO file ' file ]);
end
while ~feof(fid),

	%--- Read the header:
	[h,n] = fscanf(fid, '%f', 2);
	if n ~= 2,
		if feof(fid),
			break;
		else
			error([ 'Reading header from GEBCO file ' file ]);
		end
	end
	z = h(1);
	n = h(2);
	
	%--- Read positions:
	[d,m] = fscanf(fid, '%f', [2,n]);
	if m ~= (n*2),
		error([ 'Reading ' int2str(n) ' position pairs from GEBCO file ' ...
					file ]);
	end

	%--- Plot contour:
	if isempty(levels),
		i = 1;
	else
		i = find(levels == z);
	end
	if ~isempty(i) & z > 0,
		m_line(d(2,:), d(1,:), line_style{:});
	end
	
end
fclose(fid);

return;





