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

% The preceding empty line is important
% $Log: gbsjctdc.m,v $
% Revision 1.4  2000/03/31 20:53:49  kwoklin
% Add to handle falty loaddods call.    klee
%
% Revision 1.3  1999/06/24 19:05:01  kwoklin
% Change file name of nbnerr.m. Fix some display bugs, define precision level
% of lat/lon/depth/time, and fix some more bugs in globec files.        klee
%
% Revision 1.1  1999/06/01 07:10:33  dbyrne
%
%
% Moved up from kleedata/
%
% Revision 1.3  1999/05/28 22:53:05  kwoklin
% Point to new server for all jgofs datasets. Update getjgsta on loaddods.
% Fix infotext for all gb geturl files. Fix transmissivity for some gb
% files. Modify some variable names on gb files.       klee
%

% $Id: gbsjctdc.m,v 1.4 2000/03/31 20:53:49 kwoklin Exp $
% fix depth representation to lat/lon basis            klee 05/28/99
% fix depth representation to min and max only         klee 05/05/99
% klee 04/01/99

% reading selected ranges

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

  % Initialize variables.
  More = 1;
  num_url = 0; 
  Pass_Times = []; times = [];
  Pass_Depths = []; depths = [];
  lats = []; lons = [];
  depthtemp = [];
  url = []; infotext = []; text = [];

  % To prevent named file conflict, force variable names to be appeared as variables.  
  yrday_gmt = []; lat = []; lon = []; press = [];

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

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

  StartTime = BeginTime;
  StartYear = floor(StartTime);
  StartYrday = (StartTime - StartYear) * DaysInYear;

  Constraint = ['&', deblank(DodsName1(1,:)), '>=', num2str(StartYrday,9)];

  Tmplast = find(LastYrday <= dayend);
  Tmpstart = find(StartYrday <= dayend);
  TmpEnd = [min(Tmpstart):Tmplast(length(Tmplast))];
  TmpLen = length(TmpEnd);
  num_url = num_url + TmpLen;

  %Now, for depth constraint
  Udepth = num2str(getranges(3,2),9);
  Ldepth = num2str(getranges(3,1),9);
  URLdepth = sprintf('%s', '&',DepthName,'>=',Ldepth,'&',DepthName,'<=',Udepth);

  %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 = [Constraint, URLdepth, URLlat, URLlon];

  returned_var = [];
  returned_var = sprintf('%s', TimeName, ',', LatitudeName, ',', LongitudeName, ',', DepthName);

  for i = 1:TmpLen
    Tmpendyrday = dayend(TmpEnd(i));
    if LastTime <= (Tmpendyrday/DaysInYear + StartYear), Tmpendyrday = LastYrday; end
    constraint = [Constraint, '&', deblank(DodsName1(1,:)), '<=', num2str(Tmpendyrday)];
    whichserver = TmpEnd(i);
    server = [Server, deblank(Serverexd(TmpEnd(i),:))];
    url = [server, '?', returned_var, constraint];

    loaddods('-F',url);

    dayp = [];
    dayp = eval(deblank(DodsName1(1,:)));
    if dayp(1) > 1e-10 & if ~isempty(dapy)
      Pass_Times = [Pass_Times; StartYear,StartYrday,Tmpendyrday,str2num(Ldepth),str2num(Udepth),str2num(Llat), ...
                    str2num(Ulat),str2num(Llon),str2num(Rlon),whichserver];
      Ndays = size(dayp,1);
      timetemp = StartYear + dayp(1:Ndays) / DaysInYear;
      tmp = find(timetemp >= getranges(4,1) & timetemp <= getranges(4,2));
      times = [times; timetemp(tmp)];

      depths = [depths; eval(DepthName)];
      %depthtemp = [depthtemp; eval(DepthName)];
      lats = [lats; eval(LatitudeName)];
      lons = [lons; eval(LongitudeName)];
    else
      num_url = num_url - 1;
    end  %end of if dayp(1) 
  end  %end of for loop  
  %depths = [depths; max(depthtemp); min(depthtemp)];
  loaddodsbool = 0;

return
  

  
