function [times, pass_times, urllist, url] = clicat(CS, TimeRange, get_ranges)
%
%   This function will build the URI climatology sst file name.
%

% The preceding empty line is important.
% $Log: clicat.m,v $
% Revision 1.1  2000/03/09 17:35:15  kwoklin
% Add catalog server and make use of getrectf.   klee
%

% $Id: clicat.m,v 1.1 2000/03/09 17:35:15 kwoklin Exp $
% This is modified from uriclurl of Revision 1.10.   klee  03/01/2000

times = [];  pass_times = []; urla = []; url = []; urllist = [];
[times, pass_times] = monthly(TimeRange, get_ranges);
MonthFirstDay = [1 32 60 91 121 152 182 213 244 274 305 335 400];
leapMonthFirstDay = [1 32 61 92 122 153 183 214 245 275 306 336 400];
leaps = isleapm(pass_times(:,1));
months = [];  
multiyears = 0;  % boolean, multiple years
if ~isempty(times),  iniyear = pass_times(1,1); end
for i = 1:size(times,2)
  year = pass_times(i,1);
  if (year ~= iniyear),  multiyears = 1;   end
  yearday = pass_times(i,2);
  iMonth = 0;
  if leaps(i) == 0
    while (MonthFirstDay(iMonth+1) <= yearday)
       iMonth = iMonth + 1;
    end
  elseif leaps(i) == 1
    while (leapMonthFirstDay(iMonth+1) <= yearday)
       iMonth = iMonth + 1;
    end
  end
  months = [months, iMonth];
end

months1 = [];
minmonth = min(months);
maxmonth = max(months);
if multiyears == 1
  months1 = [months(1):12];
  months2 = [minmonth:months(size(months,2))];
else
  months1 = months;
end
for i = 0:multiyears
  if (i == 0)
    Constraint = ['DODS_URL&month>=',num2str(months1(1)),'&month<=',num2str(months1(size(months1,2)))];
    URL = [CS,'?',Constraint];
    url = strvcat(url,URL);
    loaddods(URL);
    urla = strvcat(urla, derefurl(eval('DODS_URL')));
  else
    Constraint = ['DODS_URL&month>=',num2str(months2(1)),'&month<=',num2str(months2(size(months2,2)))];
    URL = [CS,'?',Constraint];
    url = strvcat(url,URL);
    loaddods(URL);
    urla = strvcat(urla, derefurl(eval('DODS_URL')));
  end
end
    
%return string vector DODS_URL
urllist = urla;

return
