function [times, Pass_Times, cs] = urieccat(CatalogServer, Time, ranges)
%
% This function generates a time and satellite type for each satellite pass
% in the specified interval.
%
% Time       - The time range of the data set.
%
% The returned arguments are:
%
% times      - The time in years (and fractions, see note below) for all hits.
% Pass_Times - This is the vector of time with the year, day, hour and minute
%              of each hit. Note that the day here is the calendar day; i.e.,
%              the value that would be obtained by taking the fraction of the
%              year, multiplying by 365 (or 366 for a leap year) AND adding 1.
%
% Note Jan 1, year day 001 is decimal day 0, so we need to be careful.
% January 1 starts at midnight on the 365/366th day of the previous year.
% Yearday 0 starts at midnight on the 365/366th day of the previous year.
% Need two times, the one that Deidre uses in the interface, argout1, 
% (year here) and the one that is used to specify the JPL day, argout2
% (yearday here).
%
% $Id: urieccat.m,v 1.8 1998/11/09 20:26:57 dbyrne Exp $
%
%----------------------------------------------------------------------------


% The preceding empty line is important.

% $Log: urieccat.m,v $
% Revision 1.8  1998/11/09 20:26:57  dbyrne
% *** empty log message ***
%
% Revision 1.3  1998/11/05 16:01:56  root
% Changed LonVector and LatVector to be used if no Lon returned and tried the update function.
% DataScale and DataNull should now be optional!
%
% Revision 1.6  1998/09/13 21:31:19  dbyrne
% Updated to elminate global variables and add multivariables.
%
% Revision 1.2  1998/09/09 09:23:13  dbyrne
% Changes to make creation of a 'time' variable more sensible.
%
% Revision 1.1  1998/05/17 14:18:13  dbyrne
% *** empty log message ***
%
% Revision 1.3  1997/12/09 07:13:56  jimg
% Version four compatible matrix
%
% Revision 1.2  1997/10/29 19:47:45  jimg
% Fixed installation including links to geturl, writeval and loaddods.mex*
%
% Revision 1.1.1.1  1997/09/22 14:13:55  tom
% Imported Matlab GUI sources to CVS
%

% Initialize variables.

More = 1;
Pass_Times = [];
times = [];
cs = [];

% Get beginning and ending of time interval.

BeginTime = max(Time(1), ranges(4,1));
LastTime = min(Time(2), ranges(4,2));

StartTime = BeginTime;

LastYear = floor(LastTime);
DaysInYear = 365;
if rem(LastYear,4) == 0 & LastYear ~= 1900
  DaysInYear = 366;                % This is a leapyear.
end

% Add 1 since Jan 1 is day 0.
LastDay = (LastTime - floor(LastTime)) * DaysInYear + 1;  
LastHour = (LastDay - floor(LastDay)) * 24;
LastDay = floor(LastDay);
LastHour = floor(LastHour);

% Iterate, making one call to the catalog server for every year requested in
% the time range. 

while More == 1
  
  % Begin by defining starting constraint.
  
  StartYear = floor(StartTime);
  StartYearShort = StartYear - 1900;
  
  DaysInYear = 365;
  if isleap(StartYear)
    DaysInYear = 366;                % This is a leapyear.
  end
  
  % Add 1 since Jan 1 is day 0.
  StartDay = (StartTime - StartYear) * DaysInYear + 1;  
  StartHour = (StartDay - floor(StartDay)) * 24;
  StartDay = floor(StartDay);
  StartHour = floor(StartHour);
  
  Constraint = ['year==', num2str(StartYearShort), '&day>=', ...
	num2str(StartDay)];
  
  EndTime = StartYear + 1;
  EndYear = floor(EndTime);
  
  % Now for ending constraint.
  
  if EndTime >= LastTime % All in same year
    More = 0;
    EndTime = LastTime;
    EndDay = LastDay;
    EndHour = LastHour;
  else
    DaysInYear = 365;
    if isleap(EndYear)
      DaysInYear = 366;                % This is a leapyear.
    end
    EndDay = DaysInYear;
    EndHour = 24;
    StartTime = EndTime;
  end
  
  EndYearShort = floor(EndTime) - 1900;
  
  Constraint = [Constraint, '&day<=', num2str(EndDay)];
  
  % Get the inventory for this year.
  
  clear id
  
  % I modified the following call so that the catalog servers are called
  % with the new -F option. That kludge is a work-around for JGOFS serves
  % which transmit all data (including numbers) as String variables.
  % 1/9/98 jhrg.
  
  % eval(['loaddods(''', CatalogServer, '?', Constraint,''')'])
  cs = [ CatalogServer '?' Constraint ];
  loaddods('-F', cs);
  
  % Are there any satellite passes in the specified interval?
  
  if exist('id') ~= 1
    disp(['There are no satellite images between ', num2str(StartYear),...
	  ' day ', num2str( StartDay), ' and ', num2str(EndYear),...
	  ' day ', num2str(EndDay)])
    return
  end
  
  NPasses = size(day,1);
  
  % Load the inventory of satellite passes into the inventory.
  
  ipcc = 0;
  for i=1:NPasses
    min(i) = (minsec(i) - 90000) / 100.0 + 0.001;
    minutes = floor(min(i));
    seconds = floor((min(i) - minutes) * 100.0);
    
    timetemp = year(i) + 1900 + ...
	(day(i) - 1 + (hr(i) + (minutes + seconds / 60) / 60) / 24.0) ...
	/ DaysInYear; 
    
    if (timetemp >= ranges(4,1)) & (timetemp <= ranges(4,2))
      ipcc = ipcc + 1;
      times(ipcc) = timetemp;
      % Minus 1 in previous line to go from yearday to fractions of a
      % year; Jan 1 is day fraction 0. 
      eval('i_rps=id(i)');
      p_rps=[ year(i), day(i), hr(i), minutes,seconds, i_rps]; 
      Pass_Times = [ Pass_Times; p_rps];
    end
  end
end
return
