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

% The preceding empty line is important
% $Log: gbsjssc.m,v $
% Revision 1.3  1999/06/24 19:05:02  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: gbsjssc.m,v 1.3 1999/06/24 19:05:02 kwoklin Exp $
% fix pressure 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.
  num_url = 0; 
  Pass_Times = []; times = [];
  Pass_Depths = []; depths = [];
  lats = []; lons = [];
  depthtemp = [];
  url = []; infotext = []; text = [];
  Constraint = [];
  % To prevent named file conflict, force variable names to be appeared as variables.  
  year = []; yrday0_gmt = []; lat = []; lon = []; barop = [];

  yearname = deblank(DodsName1(1,:));
  dayname = deblank(DodsName1(2,:));
  id = deblank(DodsName1(3,:));

  % 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);
  StartYearShort = StartYear - 1900;
  StartYrday = (StartTime - StartYear) * DaysInYear;
  URLdate = ['&', yearname, '=', num2str(StartYearShort), '&', dayname, '>=', num2str(StartYrday,9),...
             '&', dayname, '<=', num2str(LastYrday,9)];

  %Now, for depth, lat and lon constraint
  Ldepth = num2str(-getranges(3,2),9);
  Udepth = num2str(-getranges(3,1),9);
  URLdepth = sprintf('%s','&',DepthName,'>=',Ldepth,'&',DepthName,'<=',Udepth);
  
  Ulat = num2str(getranges(2,2));
  Llat = num2str(getranges(2,1));
  URLlat = sprintf('%s','&',LatitudeName,'>=',Llat,'&',LatitudeName,'<=',Ulat);

  Llon = getranges(1,1);
  Rlon = getranges(1,2);

  returned_var = [];  loaddodscall = 0; sj07 = 0;
  returned_var = sprintf('%s',yearname,',',dayname,',',DepthName,',',LatitudeName,',',LongitudeName);

  % work around for mixing longitude values (both positive and negative)
  % build contraint based on different cruises ... sj07 can not select depth (all null values)
  if StartYrday > dayend(1)                                   %for sj07
    URLlon = sprintf('%s','&',LongitudeName,'<=',num2str(-Llon),'&',LongitudeName,'>=',num2str(-Rlon));
    EndYrday = LastYrday; TmpStartYrday = StartYrday;
    loaddodscall = 1;    sj07 = 1;
    constraint = [Constraint, URLdate, URLlat, URLlon];      
  elseif StartYrday <= dayend(1) & LastYrday <= dayend(1)     %for sj05
    URLlon = sprintf('%s','&',LongitudeName,'>=',num2str(Llon),'&',LongitudeName,'<=',num2str(Rlon));
    EndYrday = LastYrday; TmpStartYrday = StartYrday;
    loaddodscall = 1;     sj07 = 0;
    constraint = [Constraint, URLdate, URLlat, URLlon, URLdepth];    
  elseif StartYrday <= dayend(1) & LastYrday > dayend(1)      %for both
    URLlon = sprintf('%s','&',LongitudeName,'>=',num2str(Llon),'&',LongitudeName,'<=',num2str(Rlon));
    URLlon = str2mat(URLlon, sprintf('%s','&',LongitudeName,'<=',num2str(-Llon),'&',LongitudeName,'>=',num2str(-Rlon)));
    URLid = ['&', id, '=05'];
    URLid = str2mat(URLid, ['&', id, '=07']);
    EndYrday = [dayend(1); LastYrday];
    TmpStartYrday = [StartYrday; dayend(1)+1];
    loaddodscall = 2;    sj07 = 1;
    constraint = [Constraint, URLdate, URLlat, deblank(URLlon(1,:)), URLdepth, deblank(URLid(1,:))];
    constraint = str2mat(constraint, [URLdate, URLlat, deblank(URLlon(2,:)), deblank(URLid(2,:))]);
  end

  for i = 1:loaddodscall
    url = [Server, '?', returned_var, deblank(constraint(i,:))];
    loaddods('-F',url);

    dayp = eval(dayname);
    if dayp(1) > 1e-10 | dayp(1) == 0
      num_url = num_url + 1;
      Pass_Times = [Pass_Times; StartYearShort,TmpStartYrday(i),EndYrday(i),str2num(Ldepth),str2num(Udepth),...
                    str2num(Llat),str2num(Ulat),Llon,Rlon];
      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)];
      if sj07 == 1 & i == 1
        lons = [lons; -eval(LongitudeName)];
      elseif sj07 == 1 & i == 2
        lons = [lons; -eval(LongitudeName)];
      else
        lons = [lons; eval(LongitudeName)];
      end
    end  %end of if dayp(1) 
  end  %end of for loop  
  %depths = [depths; -max(depthtemp); -min(depthtemp)];
  loaddodsbool = 0;

return
  

  
