function [url,loaddodsbool,infotext,times,depths,lats,lons,num_url] = gsoaerou ...
         (getarchive, getranges, getmode, ...
          getvariablelist, getserverlist,passtimes,passdepths,whichurl)
%
%    This function will build AEROCE Trace file name and return infotext and url
%    to the browser
%

% The preceding empty line is important
% $Log: gsoaerou.m,v $
% Revision 1.4  2000/03/31 20:49:15  kwoklin
% Reduce output args for lat/lon displaying problem.  klee
%
% Revision 1.3  2000/03/16 05:58:03  dbyrne
%
%
% fixed up infotext a bit. -- dbyrne 00/03/14
%
% Revision 1.2  2000/01/12 18:51:14  kwoklin
% Second checkup.  klee
%
% Revision 1.1  1999/07/22 19:28:06  kwoklin
% Add R. Platner's local data files in.   klee
%

% $Id: gsoaerou.m,v 1.4 2000/03/31 20:49:15 kwoklin Exp $
% Ruth Platner  07/06/99
% This is based on the following revision of nbnerr.m
% $Log: gsoaerou.m,v $
% Revision 1.4  2000/03/31 20:49:15  kwoklin
% Reduce output args for lat/lon displaying problem.  klee
%
% Revision 1.3  2000/03/16 05:58:03  dbyrne
%
%
% fixed up infotext a bit. -- dbyrne 00/03/14
%
% Revision 1.2  2000/01/12 18:51:14  kwoklin
% Second checkup.  klee
%
% Revision 1.1  1999/07/22 19:28:06  kwoklin
% Add R. Platner's local data files in.   klee
%
% Revision 1.1  1999/06/07 16:06:29  paul
% renamed nbneer.m to nbnerr.m     renamed nbneeru.m to nbnerru.m
% renamed nbneeru to nbnerru inside nbnerr.m
%

% initiate
  num_url = 1; Constraint = [];
  infotext = []; times = []; Pass_Times = []; 
  depths = []; Pass_Depths = []; lats = []; lons = [];
  depth = []; lat = []; lon = []; time = [];
  loaddodsbool = 0; url = [];
% To prevent named file conflict, force variable names to appear as variables.  
  time=[]; lat=[]; lon=[]; depth=[]; height = [];


% reading selected ranges

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

% Replace DodsName SelectableVariables with all the Aerosol data

  if strcmp(deblank(DodsName),'Umbrella') == 1
    DodsName = UmbrellaDods;
    SelectableVariables = UmbrellaVariables;
  end

% Find the time range selected by user and build the constraint

  StartDate = num2str(getranges(4,1),7);
  EndDate = num2str(getranges(4,2),7);
  URLdate = sprintf('%s','&',dods_dbk(DodsName1(4,:)),'<=',EndDate, ...
                         '&',dods_dbk(DodsName1(4,:)),'>=',StartDate);

% Find the geographic range selected by user and build the constraint

  Ulat = num2str(getranges(2,2),4);
  Llat = num2str(getranges(2,1),4);
  URLlat = sprintf('%s','&lat>=',Llat,'&lat<=',Ulat);
  Llon = num2str(getranges(1,1)); 
  Rlon = num2str(getranges(1,2)); 
  % for [-180, 180]  
  URLlon = sprintf('%s','&lon>=',Llon,'&lon<=',Rlon);

% Find the height range selected by user and build the constraint. 
% The Browser doesn't know how to deal with heights yet, these have been
% entered in the data as negative depths, but they can't be displayed yet.

  Ldepth = num2str(getranges(3,1),7);
  Udepth = num2str(getranges(3,2),7);
  URLdepth = sprintf('%s', '&height>=',Ldepth,'&height<=',Udepth);
 
  % builds constraints 
  returned_var = [];
  infotext = [];
  nvars = size(SelectableVariables,1);
  nvard = size(DodsName,1);
  if strcmp(getmode, 'cat') | strcmp(getmode, 'datasize')
      returned_var = sprintf('%s',dods_dbk(DodsName1(4,:)), ',', ...
	  LatitudeName, ',', LongitudeName, ',', DepthName);
      Constraint = sprintf('%s', returned_var, URLdate, URLlat, URLlon, URLdepth);
      URL = sprintf( '%s', Server, '?', Constraint);

      % works for FreeForm of JGOFS data
      if findstr(URL, 'nph-jg')
        loaddods('-F',URL);
      else
        loaddods(URL);
      end

      if ~isempty(time)
        if time(1) > 1e-10   % for Linux6.1, no data returns 0
          tmp = find(time >= getranges(4,1) & time <= getranges(4,2));
          times = [times; time(tmp)];
          tmp = find(height >= getranges(3,1) & height <= getranges(3,2));
          depths = [depths; height(tmp)];
          lats = [lats; lat(tmp)];
          lons = [lons; lon(tmp)];
        else 
          num_url = num_url - 1;
        end
      else
        num_url = num_url - 1;
      end
      loaddodsbool = 0;
  elseif strcmp(getmode, 'get')
      for i = 1:size(getvariablelist,1)
          returned_var = [returned_var, dods_dbk(getvariablelist(i,:))]; 
          if i < size(getvariablelist,1)
              returned_var = [returned_var, ','];
          end
      end
      Constraint = sprintf('%s', returned_var, URLdate, URLlat, URLlon, URLdepth);
      if exist('TextField') == 1 
        infotext = sprintf('%s', ...
	    'Every station is assigned a number ',...
	    'which ranges from 1 to 4; ',...
	    'The numbers will be stored in Rxx_station',...
	    'Station names and numbers are ',...
	    'organized as following:');
	 text = '';
        for i = 1:size(TextField,1)
          texti = sprintf('%s%2d%s%s\n',DodsName(nvars+1,:), i, ' -- ', ...
	      TextField(i,:));
	  text = [text texti];
        end
        infotext = [infotext, text];
      end
      cs = sprintf('%s',URLdate, URLlat, URLlon, URLdepth);
      infotext = [infotext, sprintf('%s\n%s\n%s\n%s\n%s\n%s%s\n%s','',...
	    '"Error" for each element is also available in the database.',...
	      '   ',...
	      '** To get Error information on the measured element ** ',...
	      'issue the ''loaddods'' command from the MATLAB prompt line, ',...
	      'using a URL like this:',...
	      '   ', ...
	      [ 'URL  = ', Server '?' 'AlError,BrError,CaError', cs], ...
	      [ '   '],...
	      [ 'It will return a set of date, height and error vectors ',...
		'corresponding to the data.'])];
      loaddodsbool = 1;
  end

  % builds URL w/ Server and Constraint

  URL = sprintf( '%s', Server, '?', Constraint);
  url = URL;

  return
