function [w,jd]=merge(cdf,tstart,tstop);
%GETV merges velocity time series from cdf file(s)
%  USAGE 
%     [w,jd]=merge(cdf,start,stop);
%     or
%     [w,jd]=merge(cdf);
% 
%  where: cdf = string containing the name of the cdf file, or a 
%               string array containing the names of multiple cdf files, i.e.
%               cdf=['cdf_file1.cdf'
%                    'cdf_file2.cdf'
%                    'junk.cdf     '];
%         start = [yyyy mm dd hh mi sc];
%         stop  = [yyyy mm dd hh mi sc];
%
%    if start and stop are missing, then the series overlapping in time are 
%     returned.  U and V must be 'east' and 'north' in cdf file.
%
%         jd = julian day 
var1='east';
var2='north';
[m,n]=size(cdf);
for i=1:m
  cdfi=cdf(i,:);
  [fstart(i,:),fstop(i,:)]=mcgtim(cdfi);
  [icyc,ncyc,jd]=mctime(cdfi,fstart(i,:),fstop(i,:));
  jd0(i)=jd(1);
  jd1(i)=jd(length(jd));
end
if nargin==3,
  jda=julian(tstart);
  jdb=julian(tstop);
else
  jda=min(jd0);
  jdb=max(jd1);
  lbl=date_lbl(gregorian(jda),gregorian(jdb)); 
  disp(['Merged series start/stop: ' lbl])
end
delt=jd(2)-jd(1);
nt=round((jdb-jda)/delt)+1;    % how long is the output series?
jd=[jda:delt:jdb];
w=ones(nt,1)*NaN;
for i=1:m
 if(jd0(i)<=jdb & jd1(i)>=jda),
  cdfi=cdf(i,:);
  if nargin==1,
    [icyc(i),ncyc(i),jdf]=mctime(cdfi,fstart(i,:),fstop(i,:));
  else
    [icyc(i),ncyc(i),jdf]=mctime(cdfi,tstart,tstop);
  end
  u=mcvgt(cdfi,var1,icyc(i),ncyc(i));
  v=mcvgt(cdfi,var2,icyc(i),ncyc(i));
  ind=round((jdf-jda)/delt)+1;
  w(ind)=u+j*v;
 end
end
