function [url, loaddodsbool, infotext, times, Pass_Times, depths, Pass_Depths, lats, lons, num_url] = mmhydrou ...
         (getarchive, getranges, getmode, ...
          getvariablelist, getserverlist,passtimes,passdepths,whichurl)
%
%    This function will build marmap file names and return infotext and url
%    to the browser
%

% The preceding empty line is important
% The preceding empty line is important
% $Log: mmhydrou.m,v $
% Revision 1.5  2000/03/31 20:57:11  kwoklin
% Add to handle faulty loaddods call.  klee
%
% Revision 1.4  1999/07/21 18:00:02  kwoklin
% Fix some errors in data file and data range. klee
%
% Revision 1.1  1999/06/01 07:10:34  dbyrne
%
%
% Moved up from kleedata/
%
% Revision 1.3  1999/05/28 22:53:06  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: mmhydrou.m,v 1.5 2000/03/31 20:57:11 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

% initiate 
  num_url = 1; 
  lats=[]; lons=[]; times=[]; depths=[]; Pass_Times=[]; Pass_Depths=[];
  pressure = []; lat = []; lon = []; time = [];
  Constraint = []; URL = [];
% To prevent named file conflict, force variable names to be appeared as variables.
  time=[]; mintime=[]; maxtime=[]; southlat=[]; northlat=[]; westlon=[]; eastlon=[];
  lat=[]; lon=[]; pres=[];  

% reading selected ranges

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

  StartDate = num2str(getranges(4,1),9);
  EndDate = num2str(getranges(4,2),9);

  URLDate = sprintf('%s','&',dods_dbk(DodsName1(2,:)),'<=',EndDate,...
                         '&',dods_dbk(DodsName1(3,:)),'>=',StartDate); 
  URLdate = sprintf('%s','&',dods_dbk(DodsName1(1,:)),'<=',EndDate,...
                         '&',dods_dbk(DodsName1(1,:)),'>=',StartDate);


  Ulat = num2str(getranges(2,2),4);
  Llat = num2str(getranges(2,1),4);
  URLLat = sprintf('%s','&',dods_dbk(DodsName1(4,:)),'<=',Ulat,...
                        '&',dods_dbk(DodsName1(5,:)),'>=',Llat);
  URLlat = sprintf('%s','&',dods_dbk(DodsName1(8,:)),'>=',Llat,...
                        '&',dods_dbk(DodsName1(8,:)),'<=',Ulat);

  Llon = num2str(getranges(1,1),4);
  Rlon = num2str(getranges(1,2),4);
  % for [-180, 180]  
  URLLon = sprintf('%s','&',dods_dbk(DodsName1(6,:)),'<=',Rlon,...
                        '&',dods_dbk(DodsName1(7,:)),'>=',Llon);
  URLlon = sprintf('%s','&',dods_dbk(DodsName1(9,:)),'>=',Llon,...
                        '&',dods_dbk(DodsName1(9,:)),'<=',Rlon);

  %URLdepth = sprintf('%s','&pres>=',num2str(floor(getranges(3,1))),'&pres<=7500');
                     %num2str(ceil(getranges(3,2))));
  URLdepth = sprintf('%s','&pres>=',num2str(floor(getranges(3,1))),'&pres<=',...
                     num2str(ceil(getranges(3,2))));
 
  % builds constraints 
  returned_var = [];
  infotext = []; text = [];
  nvars = size(SelectableVariables,1);
  TextNo = str2mat('11','22','23','14','25','16','17','28','29');
  if strcmp(getmode, 'cat') | strcmp(getmode, 'datasize')
      returned_var = sprintf('%s', TimeName, ',', LatitudeName, ',', LongitudeName, ',', DepthName);
      Constraint = sprintf('%s', returned_var, ...
                           URLDate, URLdate, URLLat, URLlat, URLLon, URLlon, URLdepth);
      URL = sprintf( '%s', Server, '?', Constraint);
      loaddods('-F',URL);
      if ~isempty(time) & time(1) > 1e-10
        tmp = find(time >= getranges(4,1) & time <= getranges(4,2));
        times = [times; time(tmp)];
        depths = [depths; eval(DepthName)];
        %mindepth = min(pres); maxdepth = max(pres);
        %depths = [depths; mindepth; maxdepth];
        lats = [lats; lat];
        lons = [lons; lon];
      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
      returned_var = [returned_var, ',', dods_dbk(OptionalVariables(1,:))];
      %Constraint = sprintf('%s', returned_var, URLDate, URLdate, URLLat, ...
      %                     URLlat, URLLon, URLlon, URLdepth);
      Constraint = sprintf('%s', returned_var, URLDate, URLdate, URLlat, URLlon, URLdepth);
      if exist('TextField') == 1 
        infotext = sprintf('%s\n', ...
	    'Every CountryCode/CruiseId is assigned a number ',...
	    'which ranges from 1 to total; ',...
	    'The numbers will be stored in Rxx_IdNo',...
	    'CountryCode/CruiseId 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
      loaddodsbool = 1;
  end

  % builds URL w/ server (Server in archive.m) and Constraint

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

  return

  

  

  
