%
% routine to plot time series in multiples of "inc" pts
%
%   function plotmult(t,y1,y2,inc,sec,[t2]);
%
% plots time series in increments of "inc" data points
% for visual checks on coherence between vectors y1 and y2
%
%   t = time vector 
%  y1 = input1(red)
%  y2 = input2(yellow) 
% inc = npts to plot each time
% sec = number of seconds to pause (zero means forever)
%  t2 = time associated with y2 (if different from "t")
%
function plotmult(t,y1,y2,inc,sec,t2);
%
disp('First series in in RED');

if nargin<4;
  inc=100;
end;
%
% Make sure time is an n by 1 vector
%
[nr,nc]=size(t);
if nr==1;
 t=t';
end;
%
% Determine the axis size and keep it that way
%
ii=find(isnan(y1)~=1);
my1=min(y1(ii));
mxy1=max(y1(ii));
ii=find(isnan(y2)~=1);
my2=min(y2(ii));
mxy2=max(y2(ii));
mina=min([my1 my2]);
maxa=max([mxy1 mxy2]);
%
[nr,nc]=size(t);
%
for k=1:inc:nr-inc;
%
 if nargin==6;
  id=find(t2>t(k)&t2<t(k+inc));
  plot(t(k:k+inc),y1(k:k+inc),'r',...
  t2(id),y2(id));
 else;
  plot(t(k:k+inc),y1(k:k+inc),'r',...
  t(k:k+inc),y2(k:k+inc));
 end;
 axis([t(k) t(k+inc) mina maxa]);
 if sec==0;
  pause;
 else;
  pause(sec)
 end;
end;
