function [times, pass_times, url] = fsu_nscat7cat(CatalogServer, Time, ranges)
%----------------------------------------------------------------------------
%
% Consult the nscat30 catalog server to find images that fall within the time
% range given by the user.
%
% 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 and day
% url: dummy return value to satisfy cat function type signature.
%
%
%   17 April 1999, pdh
%----------------------------------------------------------------------------

% The preceeding blank line is important for cvs.
% $Id: fsun7c.m,v 1.4 1999/11/05 22:15:31 dbyrne Exp $
%

% $Log: fsun7c.m,v $
% Revision 1.4  1999/11/05 22:15:31  dbyrne
%
%
% Added some code to catch a bug in the fileserver -- was returning 0's
% in hour, day, year vectors when no data were actually available.
% Added in code so that FS url was passed back to browser.
%
% -- dbyrne 99/11/5
%
% Revision 1.2  1999/11/05 22:05:58  root
% Fixed bad return from CS -- was returning zeroes in day,hour,year when
% no data were actually available. -- dbyrne 99/11/05
%
% Revision 1.1  1999/09/02 18:33:02  root
% *** empty log message ***
%
% Revision 1.3  1999/06/29 16:51:49  kwoklin
% Quick fixes on some cat files.           klee
%
% Revision 1.2  1999/05/27 13:37:36  paul
% initialize urlmat dodsdates (global variables)
%
% Revision 1.1  1999/05/21 16:55:51  paul
% Initial version....phemenway
%


global urlmat;
global dodsdates;


% Initialize variables.

More = 1;
times = [];
tmptimes = [];
cs = [];
urlmat = []; url = [];
dodsdates = [];
year = []; hour = []; day = [];

% Get beginning and ending of time interval.

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

% Process the beginning year and day

BeginYear=floor(BeginTime);
DaysInYear = 365;
if (rem(BeginYear,4) == 0 & rem(BeginYear,100)~=0) | ...
   rem(BeginYear,400)==0
  DaysInYear = 366;                % This is a leapyear.
end

% Add 1 since Jan 1 is day 0.
BeginDay = (BeginTime - floor(BeginTime)) * DaysInYear + 1;  
BeginHour = (BeginDay - floor(BeginDay)) * 24;
BeginDay = floor(BeginDay);
BeginHour = floor(BeginHour);

bdst=sprintf('%03d',BeginDay);
byst=sprintf('%03d',BeginYear);



% Process the ending year and day

LastYear = floor(LastTime);
DaysInYear = 365;
if (rem(LastYear,4) == 0 & rem(LastYear,100)~=0) | ...
   rem(LastYear,400)==0
  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);

ldst=sprintf('%03d',LastDay);
lyst=sprintf('%03d',LastYear);

Constraint = [ 'year,day,hour,DODS_URL,DODS_Date(FSU_nscat7)&date("' ...
      byst '/' bdst '","' lyst '/' ldst '")' ];

cs=[CatalogServer '?' Constraint];
loaddods(cs)

url=mkstrmat(DODS_URL);
urlmat=url;
% pass out the C-S URL!!!
url=cs;

if all(hour == 0) & all(day == 0) & all(year == 0)
  pass_times = [];
  times = [];
else
  pass_times = [year day+(hour/24)];
  times = cald2yr(pass_times(:,2),pass_times(:,1));
end
dodsdates=pass_times;

return
