function [times, Pass_Times] = daily2(TimeRange, IntervalTime, ranges)
%
% Given IntervalTime in hrs, return IntervalTime for all hits
% 

% The preceding empty line is important
% $Log: daily2.m,v $
% Revision 1.1  1999/06/01 07:10:26  dbyrne
%
%
% Moved up from kleedata/
%
% Revision 1.2  1999/05/28 17:32:48  kwoklin
% Add all globec datasets. Fix depth representation for all globec datasets
% and nbneer dataset. Fix frontal display for htn and glkfront. Make use of
% getjgsta for all jgofs datasets. Point usgsmbay to new server. Point htn,
% glk, fth and prevu to new FF server.                                 klee
%

% $Id: daily2.m,v 1.1 1999/06/01 07:10:26 dbyrne Exp $
% klee    02/99

times = [];
itimes = [];
Pass_Times = [];
url = [];

StartTime = max(TimeRange(1), ranges(4,1));
LastTime = min(TimeRange(2), ranges(4,2));

IntervalDay = IntervalTime / 24;

LastYear = floor(LastTime);
yearday = 365;
if isleap(LastYear)
  yearday = 366;
end

LastDay = (LastTime - LastYear) * yearday + 1;
LastHour = (LastDay - floor(LastDay)) * 24;
LastMin = (LastHour - floor(LastHour)) * 60;
LastDay = floor(LastDay);  LastHour = floor(LastHour);
LastMin = floor(LastMin);

More = 1;

while More == 1
  StartYear = floor(StartTime);
  yearday = 365;
  if isleap(StartYear)   
    yearday = 366;
  end 
  StartDay = (StartTime - StartYear) * yearday + 1;
  StartHour = (StartDay - floor(StartDay)) * 24;
  StartMin = (StartHour - floor(StartHour)) * 60;
  StartDay = floor(StartDay);   StartHour = floor(StartHour);
  StartMin = floor(StartMin);

  EndYear = floor(StartYear) + 1;
  if EndYear >= LastTime    % in the same year
    More = 0;
    Endoffset = ceil((LastDay - 1) / IntervalDay) + floor(LastHour / IntervalTime) + floor(LastMin/60/IntervalTime);    
  else
    Endoffset = yearday / IntervalDay;
    %proceed to next year
    StartTime = StartYear + 1;
  end     %end of if EndYear >= LastTime

  %Number of offset to start with
  Startoffset = ceil((StartDay - 1) / IntervalDay) + ceil(StartHour / IntervalTime) + ceil(StartMin/60/IntervalTime);
  if Startoffset == 0, Startoffset = 1; end
  IDay = StartDay;
  IHour = ceil(StartHour/IntervalTime) * IntervalDay * 24;
  IMin = ceil(StartMin/60/IntervalTime) * IntervalDay * 24 * 60;
  times = [times (StartYear + (StartDay - 1 + IHour/24 + IMin/24/60) / yearday)];
  Pass_Times = [Pass_Times; StartYear, IDay, IHour, IMin];
  %loop through each intervaltime
  tmptime(1) = times(size(times,2));
  for i = 2 : (Endoffset - Startoffset + 1)
    tmptime(i) = IntervalDay/yearday + tmptime(i-1);
    times = [times tmptime(i)];
  end   %end of for loop
end   %end of while loop
