function [start_time,stop_time]=overlap(cdf1,cdf2)
% OVERLAP finds the overlapping time period for two data files
% or multiple data files in a text array,
%
% USAGE:  [start_time,stop_time]=overlap(cdf1,cdf2);
%     or
%         [start_time,stop_time]=overlap(cdf_files);
%   i.e    cdf_files=['cdf_file1.cdf'
%                     'cdf_file2.cdf'
%                     'junk.cdf     ']'
if nargin==2,
  [start,stop]=mcgtim(cdf1);
  start1=julian(start);
  stop1=julian(stop);
  [start,stop]=mcgtim(cdf2);
  start2=julian(start);
  stop2=julian(stop);
  start_max=max(start1,start2);
  stop_min=min(stop1,stop2);
else
  cdf_files=cdf1;
  [m,n]=size(cdf_files);
  start_max=-1.e35;
  stop_min=1.e35;
  for i=1:m,
    cdfnam=cdf_files(i,:);
    cind=find(cdfnam~=' ');
    cdf=cdfnam(cind);
    [t1,t2]=mcgtim(cdf);
    start(i)=julian(t1);
    stop(i)=julian(t2);
  end
  start_max=max(start);
  stop_min=min(stop);
end
if(start_max>stop_min),
  disp('Time series do not overlap!')
else
  start_time=gregorian(start_max);
  stop_time=gregorian(stop_min);
end
