function cline(x, y, z, varargin)
%
% SYNOPSIS
%
%   cline(x, y, z [, 'name', value, ... ])
%
% DESCRIPTION
% 
%   Plot a colored line on a 2-dimensional plot. The color is determined by 
%   the values in vector Z.
%
% OPTIONS
%
%   Options are a list of name/value pairs. Allowed names are
%
%   'dir', string
%      The side on which to plot the patches: {'startbord'} or 'port'.
%
%   'width', number
%      Width of the pacthes. This is a fraction of the shortest
%      axis. Default is 0.05.
%
%   'c_axis', [cmin, cmax]
%      The color axis to use (see CAXIS). Default is the max and min value
%      from the Z vector.
%
%   'c_map', string
%      The colormap to use (see COLORMAP). Default is 'jet'.
%
%   'c_path', { patch properties }
%      A cell array of path properties to send to the PATH
%      function. Default is { 'EdgeColor', 'none' } to remove patch
%      outlines. 
%
%   'm_map', number
%      Set it to 1 if patches are to be plotted on M_MAP generated plot and 
%      zero otherwise.

%--------------------------------------------------------------------------
% 
% cline.m -- 
% 
% Author          : Jaccard Pierre
% Created On      : 2000/08/21 06:44:02
% Last Modified By: Jaccard Pierre
% Last Modified On: 2001/09/24 12:05:30
% Directory       : /home1/jaccard/pcd/codas/2000-11-21/codas3/gfi/matlab/matlab50/
% ----------------------------------------------------------------------- +
% VERSION CONTROL: 
% 
%   $Author$
%   $Date$
%   $Id$
%   $Name$
%   $Revision$
%   $State$
%   $Log$
% 
%--------------------------------------------------------------------------

% Arguments and defaults:

[ dir, width, c_axis, c_map, c_patch, m_map ] = parsearg( varargin, ...
		'dir', 'starbord', 'width', 0.05, 'c_axis', '', 'c_map', 'jet', ...
		'c_patch', { 'EdgeColor', 'none' }, 'm_map', 0);

% Check vector size:

if size(x,1) > 1,
	x = x';
end
if size(y,1) > 1,
	y = y';
end
if size(z,1) > 1,
	z = z';
end

% Calculate width:

%w = width * min([ (max(y) - min(y)), (max(x) - min(x)) ]);
w = width;

% Generate orthogonal vectors:

%ii = 2:length(x);
%dx = x(ii) - x(ii-1);
%dy = y(ii) - y(ii-1);
%ds = sqrt(dx.*dx + dy.*dy);

%dnx = dy ./ ds;
%dny = dx ./ ds;
%if strcmp(dir, 'starbord'),
%	dny = -dny;
%else
%	dnx = -dnx;
%end

% Generate patch coordinates:

%X = [ x(ii-1) ; x(ii) ; x(ii) + w*dnx(ii-1) ; x(ii-1) + w*dnx(ii-1) ];
%Y = [ y(ii-1) ; y(ii) ; y(ii) + w*dny(ii-1) ; y(ii-1) + w*dny(ii-1) ];
%Z = 0.5 * (z(ii) + z(ii-1));

ii = 1:length(x);
X = [ x - w/2 ; x + w/2 ; x + w/2 ; x - w/2 ];
Y = [ y - w/2 ; y - w/2 ; y + w/2 ; y + w/2 ];
Z = z;

if m_map,
	[X, Y] = m_ll2xy(X, Y);
end

% Install colors and axis scale:

colormap(c_map);
if isempty(c_axis),
	caxis([ min(Z), max(Z) ]);
else
	caxis(c_axis);
end

% Draw the patches on current plot

patch(X, Y, Z, c_patch{:});

return;



