function [h] = squiggle(varargin);
% SQUIGGLE stacked-line plot, typically used for plotting seismic and radar profiler data.
% SQUIGGLE(Z) is a squiggle plot of each column in the matrix Z. Each value in Z is scaled
% to the maximum absolute data value. The X and Y axis are the sample and line numbers, respectively.
% SQUIGGLE(X,Y,Z) X and Y specify the (x,y) coordinates as plaid matrices (as created by MESHGRID).
% SQUIGGLE(Z,N) and SQUIGGLE(X,Y,Z,N) scales the data by factor N before plotting. default: N=1.
% h = SQUIGGLE(.....) returns the figure handle.
%
%
% 13-Sep-2004
% Ian Howat, UCSC Earth Sciences
% ihowat@es.ucsc.edu
error(nargchk(1,4,nargin));
nin = nargin;
m = 1;
if nin == 1 | nin == 2;
A = varargin{1};
X = (0:size(A,2)-1);
Y = (0:size(A,1)-1);
[X,Y] = meshgrid(X,Y);
elseif nin == 3| nin == 4;
X = varargin{1};
Y = varargin{2};
A = varargin{3};
end;
if nin == 2| nin ==4;
m = varargin{end};
end;
A = (A./ (max(max(abs(A)))/m)) + X;
h = plot(A(:,1),Y(:,1));
hold on;
i=1;
for i =1: size(A,2);
h = plot(A(:,i),Y(:,i));
i=i+1;
end;
axis ij;
axis tight;