function [times, pass_times, urls, url] = pathcat(catalog_server, time, ranges)
%----------------------------------------------------------------------------
%
% This function generates a time and satellite type for each satellite pass
% in the specified interval.
%
% Formal parameters:
% catalog_server: URL of the catalog server.
% time: The time range of the data set.
%
% The return values are:
% times: The time in years (and fractions, see note below) for all hits.
% pass_times: This is a matrix of time with the year, day and hour
% of each hit. Note that the day here is the calendar day.
%
%----------------------------------------------------------------------------

% Get beginning and ending of time interval.
start_time = max(time(1), ranges(4,1));
end_time = min(time(2), ranges(4,2));

start_year = floor(start_time);
start_day = floor(year2day(start_time, start_year)+1);

end_year = floor(end_time);
end_day = floor(year2day(end_time, end_year)+1);

start_hour = year2day(start_time,start_year)+1 - start_day;
end_hour   = year2day(end_time,end_year)+1 - end_day;
start_hour = floor(start_hour * 24);
end_hour   = ceil(end_hour * 24);

% The JPL Pathfinder dataset contains two images per day, one for the
% ascending pass and one for the descending. Thus, to query the catalog
% server we need to know the year, day and time to within 1/2 a day.

vars = [ 'ptime,file_url' ];

% Column indices of `vals' matrix
year = 1;
day  = 2;
hour = 3;
% The file url is at 4:n

% initialize returning variables
urls        = '';
pass_times = [];
times      = [];

% Query the catalog server
[pass_times, urls, url] = qpathcat(catalog_server, vars, start_year, ...
    end_year, start_day, end_day, start_hour, end_hour);

if isempty(pass_times)
  return;
end

times = day2year(pass_times(:,day)-1 + pass_times(:,hour)/24, pass_times(:,year));

return;
