function [url,loaddodsbool,infotext,times,Pass_Times,depths,Pass_Depths,lats,lons,num_url] = gbnmfsdriftercat ...
         (getarchive, getranges, getmode)
%
%    This function will build gbnmfsdrifter file name and return infotext and time/lat/lon/url
%    to the browser
%

% The preceding empty line is important
% klee 04/01/99

% reading selected ranges

if exist(getarchive) == 2   
  eval(getarchive)
else
  dodsmsg('Metadata not found!')
  return
end

  % Initialize variables.
  num_url = 0;
  Pass_Times = []; times = [];
  lats = []; lons = [];
  url = []; infotext = []; text = [];
  yearname = deblank(DodsName1(1,:));
  dayname = deblank(DodsName1(2,:));

  % Get beginning and ending of time interval.
  BeginTime = max(TimeRange(1), getranges(4,1));
  LastTime = min(TimeRange(2), getranges(4,2));

  StartTime = BeginTime; 
  StartYear = floor(StartTime);  
  DaysInYear = 365;
  if isleap(StartYear)
    DaysInYear = 366;                % This is a leapyear.
  end
  StartYrday = (StartTime - StartYear) * DaysInYear;

  LastYear = floor(LastTime);
  LastYrday = (LastTime - LastYear) * DaysInYear;

  %Now, for lat and lon constraint
  Ulat = num2str(getranges(2,2));
  Llat = num2str(getranges(2,1));
  URLlat = sprintf('%s','&', LatitudeName, '>=', Llat, '&', LatitudeName, '<=', Ulat);

  Llon = num2str(getranges(1,1));
  Rlon = num2str(getranges(1,2));
  % for [-180, 180]  
  URLlon = sprintf('%s','&', LongitudeName, '>=', Llon, '&', LongitudeName, '<=', Rlon); 

  Constraint = ['&',yearname,'=',num2str(StartYear),'&',dayname,'>=',num2str(StartYrday,9), ...
                '&',dayname,'<=',num2str(LastYrday,9), URLlat, URLlon];

  returned_var = [];
  returned_var = sprintf('%s', dayname,',',LatitudeName,',',LongitudeName);
  url = [Server, '?', returned_var, Constraint];
      
  %Now, get the inventory for this year
  loaddods('-F',url);

  %record time, depth, lat and lon info back to get function
  dayp = [];
  dayp = eval(dayname);
  if ~isempty(dayp) & (dayp(1) > 1e-10 | dayp(1) == 0)
    num_url = num_url + 1;
    Pass_Times = [Pass_Times; StartYear,StartYrday,LastYrday,str2num(Llat),...
                  str2num(Ulat),str2num(Llon),str2num(Rlon)];
    Ndays = size(dayp,1);
    timetemp = StartYear + (dayp(1:Ndays)-1) / DaysInYear;
    tmp = find(timetemp >= getranges(4,1) & timetemp <= getranges(4,2));
    times = [times; timetemp(tmp)];
    lats = [lats; eval(LatitudeName)];
    lons = [lons; eval(LongitudeName)];
  end
  loaddodsbool = 0;
return









