function [clear_button, url_count, get_variables, palette, axes_vals, ...
      color_limits, browse_fig, master_georange, data, sizes, ...
      names, index, urls, depth_name, data_range] = browse(argin,second_arg)
%
% BROWSE    DODS data browser.  A graphical user interface for DODS.
%
% USAGE     browse
%
%            Deirdre Byrne, The Island Institute, 7 April 1997
%                 dbyrne@islandinstitute.org
%

% The preceding empty line is important.
%
% $Id: browse.m,v 1.12 1998/11/09 20:19:21 dbyrne Exp $

% $Log: browse.m,v $
% Revision 1.12  1998/11/09 20:19:21  dbyrne
% *** empty log message ***
%
% Revision 1.32  1998/11/09 12:47:04  root
% Fixed small things in display.
%
% Revision 1.31  1998/11/05 16:02:05  root
% Changed LonVector and LatVector to be used if no Lon returned and tried the update function.
% DataScale and DataNull should now be optional!
%
% Revision 1.30  1998/10/23 15:26:02  root
% updating NSCAT 3.0
%
% Revision 1.29  1998/10/22 14:50:20  root
% Made datarange more consistent.
%
% Revision 1.28  1998/10/22 14:39:20  root
% made plotting coastline a little more sensible.
%
% Revision 1.27  1998/09/13 16:01:41  root
% *** empty log message ***
%
% Revision 1.26  1998/09/13 14:59:23  root
% Fixed 'clear all Rxx_' once again.
%
% Revision 1.25  1998/09/13 14:51:24  root
% Encountered (as usual) some weird problems with longitude.
%
% Revision 1.24  1998/09/12 20:54:50  root
% *** empty log message ***
%
% Revision 1.23  1998/09/12 20:00:50  root
% Finished changes so that dispmenu can be used again & again.
% Added 'checkplot' to pop the image stack if only one image in it.
%
% Revision 1.22  1998/09/12 16:49:06  root
% *** empty log message ***
%
% Revision 1.21  1998/09/12 15:28:40  root
% Made modifications necessary to let display menu be called numerous times.
%
% Revision 1.20  1998/09/12 11:20:17  root
% changing display menu
%
% Revision 1.19  1998/09/10 21:11:32  dbyrne
% Removed informative blurbs returned to user from getrectg and added
% them in here.
%
% Revision 1.18  1998/09/10 08:56:16  dbyrne
% Changed input to getfunctions so mode is first arg.
%
% Revision 1.17  1998/09/09 08:09:59  dbyrne
% changed Data_Range to DataRange
%
% Revision 1.16  1998/09/08 21:14:03  dbyrne
% *** empty log message ***
%
% Revision 1.15  1998/09/08 16:04:20  dbyrne
% browse_get_variables and browse_display_choices too long for v4. Changed
% them to browse_getvariables and browse_dispchoices
%
% Revision 1.14  1998/09/08 16:00:25  dbyrne
% *** empty log message ***
%
% Revision 1.13  1998/09/04 19:48:19  dbyrne
% Looking for a bug in 'cat' call.
%
% Revision 1.12  1998/09/04 11:26:24  dbyrne
% updating 'display' function
%
% Revision 1.11  1998/09/03 20:32:40  dbyrne
% CLeaning up multivariable plot items.
%
% Revision 1.10  1998/09/03 18:17:59  dbyrne
% finishing up multivariables
%
% Revision 1.9  1998/09/03 17:12:57  dbyrne
% Added index into returned variables as output argument for use w/plotscript
%
% Revision 1.8  1998/09/01 06:51:32  dbyrne
% working on changes in how data is passed in and out of browser
% (from get functions to unpack.m)
%
% Revision 1.7  1998/08/31 08:59:35  dbyrne
% Caught some bugs: working on new version of getrectangular
%
% Revision 1.6  1998/08/27 16:35:44  dbyrne
% making changes to universalize returned variables
%
% Revision 1.5  1998/08/27 04:44:14  dbyrne
% continuing with multivar changes. DAB 98/08/26
%
% Revision 1.4  1998/08/26 14:19:34  dbyrne
% Beginning to change how browser returns arguments to main workspace. What a mess.
% DAB 98/08/26
%
% Revision 1.3  1998/08/25 14:57:05  dbyrne
% *** empty log message ***
%
% Revision 1.2  1998/08/20 12:48:31  dbyrne
% % changes to allow for multiple variables
%
% Revision 1.1  1998/05/17 14:10:42  dbyrne
% *** empty log message ***
%
% Revision 1.7  1997/10/27 19:01:10  tom
% fixed default manual location
%
% Revision 1.6  1997/10/24 18:50:00  tom
% forgot a semicolon.
%
% Revision 1.5  1997/10/24 16:41:34  tom
% Made html access slightly more general by using the docopt command.
% of course this means that the docopt file must be correct...
%
% Revision 1.4  1997/10/24 15:50:37  tom
% added documentation, fixed dialog box behavior (found and
% exterminated bug in window management), added access to html
% documentation, modified browsopt.m.
%
% Revision 1.3  1997/10/14 02:47:41  tom
% Repaired input dialog behavior for v5. Callbacks were getting
% called, which seems wrong to me.
%
% Revision 1.2  1997/09/24 01:09:31  tom
% Added local manifest capability. Various small bug fixes.
%
% Revision 1.1.1.1  1997/09/22 14:13:53  tom
% Imported Matlab GUI sources to CVS
%

% master lists and properties: unchanging during runtime
global plotcolors master_variables master_datasets num_vars
global master_archives master_getxxx master_resolutions 
global available_resolutions num_sets master_georange master_zrange
global master_timerange master_dataprops master_rangemin
global master_rangemax switchon switchoff timetoggle dods_colors
global small_logo logo_map aspect aspectstring avhrrpal palettefile
global master_guiserver guiserver datacolor color_limits
global returnstring get_inputstring

% figure and menu handles and variables that change
global datasets ranges var brs_old_var dset brs_old_dset count num_rang
global AXES range_boxes axes_vals worldmap thandle tstring lhandle
global browse_fig display_fig save_fig scroll_fig image_string
global ui_help ui_prop ui_data ui_res ui_stride gui_buttons fontsize
global ui_prefs ui_manual ui_plots ui_display varplaces global_data_list 
global dodsdir dset_stride num_urls archive getxxx prefs VERSION fixit 
global temp_xrange check_level lyr range_day display_menu
global prev_num_urls variables datasets rangemin rangemax
global dirsep

global dispcount dispdepthname dispdatarange dispindex dispnames
global dispsizes dispclearbutton


% The location of the HTML version of the user manual
global manURL

if nargin == 0
  % prevent multiple sessions and invisible 'failed' sessions
  kids = get(0,'children');
  j = [];
  for i = 1:length(kids),
    if strcmp(get(kids(i),'userdata'),'DODS')
      if strcmp(get(kids(i),'visible'),'on')
	disp('Only one copy of the DODS browser can be run at a time')
	return
      else
	j = [j i];
      end
    end
  end
  if ~isempty(j)
    close(kids(j))
    browse
    return
  end
  
  VERSION = version; VERSION = str2num(VERSION(1));
  if VERSION > 4
    % turn off these g-damned messages
    eval('warning once')
  end
  
  % set up some values. the path
  manURL = ' ';
  dirsep = '/';
  c = computer;
  if strcmp(c(1:2),'PC')
    dirsep = '\';
  elseif strcmp(c(1:2),'MA')
    dirsep = ':';
  end
  dodsdir = which('browse');
  dodsdir = dodsdir(1:max(findstr(dodsdir,dirsep)));
  fname = [dodsdir 'brsdat1'];
  eval(['load ' fname])
  fname = [dodsdir 'brsdat2'];
  eval(['load ' fname])
  plotcolors = plotcolors(Inx,:);
  path(path, dodsdir(1:(length(dodsdir)-1)))
  path(path,[dodsdir 'DATASETS'])

  % make sure inputdlg exists
  if VERSION < 5
    w = which('inputdlg');
    if ~isstr(w) & w == 0
      fname = [dodsdir 'inputdlg.tpl'];
      fid = fopen(fname,'r');
      if fid > -1
	s = fread(fid,inf, 'uchar');
	s = setstr(s');
	fclose(fid);
	fname = [dodsdir 'inputdlg.m'];
	fid = fopen(fname,'w');
	if fid > -1
	  fwrite(fid,s','uchar');
	  fclose(fid);
	else
	  disp('         ')
	  disp('          UNABLE TO FIND OR CREATE REQUIRED FILE: inputdlg.m')
	  disp('         ')
	  disp([ '      Please copy the file: ' dodsdir 'inputdlg.tpl'])
	  disp([ '      to ' dodsdir 'inputdlg.m, and restart the browser'])
	  disp('         ')
	  return
	end
      else
	disp('    Inputdlg.m is missing!  Please consult the Mathworks ')
	disp('               for a copy of this essential file')
	return
      end
    end
  end

  % START !!!
  disp(' ')
  disp(' ')
  disp('   *********>>>> Welcome to the DODS data browser. <<<<<<<<******** ')
  disp('                     This is browse v0.7-beta                       ')
  disp(' ')
  disp(' ')
  disp('              Please wait while I set up your screen ...')
  disp(' ')
  disp(' ')
  disp('       NOTE: In Matlab Version 5.0 and higher, you must click')
  disp('         on the face of the window to activate the buttons.')
  disp(' ')
  disp('         There is a bug in some releases of Matlab v5 which prevents')
  disp('         slider controls from working smoothly on Unix/Linux platforms.')
  disp('         If you experience this behavior, please contact the Mathworks')
  disp('         at tech-support@mathworks.com or (508) 653-1415 to see about')
  disp('         a patch to correct it.')
  disp(' ')
  disp('To see which version you are using, type ''version'' at the Matlab prompt') 
  disp(' ')

  % absolute ranges that limit the extent of data selection
  % these will not change during runtime
  master_georange = [-180 180 -90 90]; 	% W E S N
  master_zrange = [-10 5000];
  master_timerange = [1800 2000];
  num_vars = size(master_variables,1);
  num_sets = size(master_datasets,1);
  gui_buttons = zeros(54,1); 
  % dodsdir = ''; % I DON'T THINK THIS IS NEEDED
  master_guiserver = 'http://dods.gso.uri.edu/MatLab_GUI/';

  % set up output return string from browser to main workspace and
  % from 'get' functions to browser once and for all *HERE*.
  returnstring = [ 'browse_clear_button browse_count ',...
	'browse_getvariables browse_palette browse_axes_vals ', ...
        'browse_color_limits browse_figure browse_georange ', ...
	'browse_data browse_sizes browse_names browse_index ', ...
	'browse_urls browse_depth_name browse_data_range'];
   get_inputstring = [ 'ranges, dset, var, dset_stride, num_urls, ', ...
     'master_georange, get_variables, archive'];
  % set up saveable values and then check them
  dods_colors = []; ranges = []; palettefile = ''; 
  figsize = []; timetoggle = []; fontsize = [];
  check_level = []; num_rang = []; axes_vals = [];
  color_limits = [];

  if exist('browsopt') == 2
    % HERE
    fname = which('browsopt');
    disp(['loading saved options file ' fname])
    eval('browsopt')
  else
    % HERE
    disp('No options file in Matlabpath.  Loading default options')
  end

  % THESE ARE ALL OPTIONS THAT MAY BE SET IN BROWSOPT.M

  % Location of HTML documentation
  if isempty(deblank(manURL))
    manURL = 'http://dods.gso.uri.edu/DODS/user/mgui-html/mgui.html';
  end

  % set initial axis values: first make sure all args are present
  default_axes_vals = [master_georange(1:2)+[-5 5] master_georange(3:4)+[-1 1] ...
	    master_zrange+[-50 0] master_timerange];
  if isempty(axes_vals)
    axes_vals = default_axes_vals;
  else
    if ~all(size(axes_vals) == [1 8])
      axes_vals = default_axes_vals;
    end
  end
  % now check to make sure limits are valid
  if axes_vals(2) <= axes_vals(1)
    % HERE 
    disp('Unable to restore saved Longitude range')
    axes_vals(1:2) = default_axes_vals(1:2);
  end
  if axes_vals(4) <= axes_vals(3)
    % HERE 
    disp('Unable to restore saved Latitude range')
    axes_vals(3:4) = default_axes_vals(3:4);
  end
  if axes_vals(6) <= axes_vals(5)
    % HERE 
    disp('Unable to restore saved Depth range')
    axes_vals(5:6) = default_axes_vals(5:6);
  end
  if axes_vals(8) <= axes_vals(7)
    % HERE 
    disp('Unable to restore saved Time range')
    axes_vals(7:8) = default_axes_vals(7:8);
  end

  % set color scheme
  if isempty(dods_colors) | ~all(size(dods_colors) == [10 3]) | ...
	any(dods_colors < 0) | any(dods_colors > 1)
    % the color scheme
    dods_colors = [0.702 0.702 0.702; % 1 vanilla -- the matlab default button color
                   0.5   0.5   0.5;   % 2 color for axis and window background
	  	   1     1     1;     % 3 color for axis and window foreground
                   1     1     1;     % 4 color for non-interactive win and axis text 
		   1     0.5   0.5;   % 5 color for edit boxes (pink)
		   0     0     0;     % 6 color for edit box text & button labels
		   0.3   0.5   1;     % 7 color for Get Data! button
		   0     0     1;     % 8 color for text & axis lines that change
		   0.7   0     0;     % 9 whizzo -- the special color
		   1     0     0];    % 10 selection range box color
  end

  if isempty(num_rang)
    num_rang = zeros(8,1);
  elseif ~all(size(num_rang(:)) == [8 1]) | ...
	sum((num_rang == 0)+(num_rang == 1)) < 8
    num_rang = zeros(8,1);
  end

  % relative ranges & vars: these will vary
  range_boxes = zeros(1,3);
  if isempty(ranges) 
    ranges = nan*ones(4,2);
  else
    if any(ranges(1,:) < master_georange(1)) | ...
	  any(ranges(1,:) > master_georange(2))
      ranges(1,:) = [nan nan];
      num_rang(1:2) = [0 0]';
    end
    if any(ranges(2,:) < master_georange(3)) | ...
	  any(ranges(2,:) > master_georange(4))
      ranges(2,:) = [nan nan];
      num_rang(3:4) = [0 0]';
    end
    if any(ranges(3,:) < master_zrange(1)) | ...
	  any(ranges(3,:) > master_zrange(2))
      ranges(3,:) = [nan nan];
      num_rang(5:6) = [0 0]';
    end
    if any(ranges(4,:) < master_timerange(1)) | ...
	  any(ranges(4,:) > master_timerange(2))
      ranges(4,:) = [nan nan];
      num_rang(7:8) = [0 0]';
    end
  end
  
  if isempty(timetoggle)
    timetoggle = 1; 
  end
  
  if isempty(fontsize)
    fontsize = 10;   
  end
  
  if isempty(available_resolutions)
    available_resolutions = [32 24 16 12 8 4 3 2 1];
  end
  
  if isempty(check_level)
    check_level = 1;
  end
  
  if length(color_limits) < 2
    color_limits = [0 255];
  end

  % load palette file NOTE THAT THIS HAS THE SIDE EFFECT OF
  % INITIALIZING THE DATA DISPLAY MENU AND THE DATASET AND
  % VARIABLE MENUS!!!!!!!!!!!!!!!!!!
  % must clear browse_fig first
  browse_fig = [];
  browse('paletteswap')
  
  % Get screen params to set up an appropriately sized window
  if isempty(figsize)
    scr_size = get(0,'ScreenSize'); scr_offset = scr_size(1:2); 
    scr_size = scr_size(3:4);
    % set up window characteristics
    fig_size = [round(scr_size(1)*0.9) round(scr_size(2)*0.67)];
    % minimum acceptable size
    fig_size(1) = max([fig_size(1) 600]);
    fig_size(2) = max([fig_size(2) 400]);
    fig_offset = [30 35];
  else
    if all(size(figsize) == [1 4])
      if all(figsize(3:4) > 0)
	fig_offset = figsize(1:2);
	fig_size = figsize(3:4);
      else
	scr_size = get(0,'ScreenSize'); scr_offset = scr_size(1:2); 
	scr_size = scr_size(3:4);
	% set up window characteristics
	fig_size = [round(scr_size(1)*0.9) round(scr_size(2)*0.67)];
	% minimum acceptable size
	fig_size(1) = max([fig_size(1) 600]);
	fig_size(2) = max([fig_size(2) 400]);
	fig_offset = [30 35];
      end
    else
      scr_size = get(0,'ScreenSize'); scr_offset = scr_size(1:2); 
      scr_size = scr_size(3:4);
      % set up window characteristics
      fig_size = [round(scr_size(1)*0.9) round(scr_size(2)*0.67)];
      % minimum acceptable size
      fig_size(1) = max([fig_size(1) 600]);
      fig_size(2) = max([fig_size(2) 400]);
      fig_offset = [30 35];
    end
  end
  
  % END OF OPTIONS THAT MAY BE SET IN BROWSOPT.M

  % set some *!($*@()$!!! version-dependent things
  if VERSION < 5
    aspectstring = sprintf('set(AXES(1),%s,[%g 1])', ...
	'''AspectRatio''', diff(axes_vals(1:2))/diff(axes_vals(3:4)));
    switchon = 'yes';
    switchoff = 'no';
  else
    aspectstring = sprintf('set(AXES(1), %s, [%i %i 1], %s, [1 1 1])', ...
	'''PlotBoxAspectRatio''', ...
	[diff(axes_vals(1:2)) diff(axes_vals(3:4))], ...
	'''DataAspectRatio''');
    switchon = 'on';
    switchoff = 'off';
  end
      
  lhandle = []; thandle = []; 
  brs_old_var = nan; var = nan; prev_num_urls = nan;
  dset = nan; brs_old_dset = nan; dset_stride = []; num_urls = 0;
  datasets = []; count = 1; worldmap = [];
  lyr = [0 0]; range_day = [0 0]; 
  global_data_list = '';

  % open the browser
  browse_fig = figure('NumberTitle','off', ...
      'Name','Distributed Oceanographic Data System Browser', ...
      'units','pixels' ,...
      'Position',[fig_offset fig_size],...
      'interruptible',switchon, ...
      'resize','on',...
      'color',dods_colors(2,:), ...
      'visible','off', ...
      'userdata','DODS');

  % SETUP UI MENUS: 
  % 1) the variable list
  ui_prop = uimenu(browse_fig,'label','Variables', ...
      'callback','browse(''scrollfig'',1)');

% 2) The dataset list
  ui_data = uimenu(browse_fig, 'label', 'Datasets', ...
      'callback','browse(''scrollfig'',2)');
  l = size(plotcolors,1);
  for i = 1:num_sets
    ii = rem(i,l)+1;
    datacolor(i,:) = plotcolors(ii,:);
  end
  
% 3) the Resolution menu
  ui_res = uimenu(browse_fig,'label','Resolution');

% 4) The Display menu
  ui_plots = uimenu(browse_fig, 'label', 'Display');
  uimenu(ui_plots,'label','Clear Display', ...
      'callback','browse(''clrimg'')');
  ui_display = uimenu(ui_plots,'label','Data Display ...', ...
      'callback','browse(''display'')');
  set(ui_display,'enable','off')
  % this is not needed now because newzoom saves new axis
  % values automatically when zooming in and out.  I'm
  % not so sure that's a good idea, but it's there.
  % uimenu(ui_plots,'label','Save Axis Limits ...', ...
  % 'callback','browse(''saveaxes'')');

  % set dataset longitude ranges from [-180 180] for selection purposes
  % THIS SHOULD BE SAVED IN BRSDAT2, not calculated every time
  rangemin = master_rangemin(:,1);
  rangemax = master_rangemax(:,1);
  for i = 1:num_sets
    x = xrange('range',master_georange, [master_rangemin(i,1) master_rangemax(i,1)]);
    if max(size(x) == 2)
      rangemin(i) = x(1); rangemax(i) = x(2);
    else
      rangemin(i) = x(1); rangemax(i) = x(4);
    end
  end
  
  % longitude
  if any(axes_vals(1:2) > default_axes_vals(2))
    prefs(1) = uimenu(ui_plots,'label','Start Longitude 180W', ...
	'callback','browse(''setlon'',0)');
    master_georange = [0 360 -90 90];
    offset = 360;
  else
    prefs(1) = uimenu(ui_plots,'label','Start Longitude 0E', ...
	'callback','browse(''setlon'',360)');
    offset = 0;
  end
  
  % time axis toggle
  if timetoggle
    prefs(2) = uimenu(ui_plots,'label','Time in Year/Yearday', ...
	'callback','browse(''timetoggle'',0)');
  else
    prefs(2) = uimenu(ui_plots,'label','Time in Year/Month/Day', ...
	'callback','browse(''timetoggle'',1)');
  end
  uimenu(ui_plots,'label','Reset Display', ...
      'callback','browse(''clrall'')');
  uimenu(ui_plots,'label','Change Color Limits', ...
      'callback','browse(''climdlg'')');
  uimenu(ui_plots,'label','Data Color Palette ...', ...
      'callback','browse(''palettedlg'')');
%  uimenu(ui_plots,'label','View Plotted Objects ...', ...
%      'callback','browse('''')');
  
% 5) The Options menu
  ui_prefs = uimenu(browse_fig,'label','Options ...');
  
  % QUERY LEVEL FOR DATASET SIZE
  prefs(3) = uimenu(ui_prefs,'label','<<Get Data!>> Threshold', ...
      'callback','browse(''qlevel'')','interruptible', switchon);
  posit = [round(fig_size(1)/3.5) round(fig_size(2)/2)];
  % METADATA WINDOW -- must be "underneath" check_level buttons
  % (which it is not now) and also transfer status buttons
  gui_buttons(31) = uicontrol('units','normalized','style','frame', ...
      'position',[0.15 0.18 0.84 0.6], ...
      'horizontalalign','left', ...
      'visible','off', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:)); drawnow
  gui_buttons(39) = uicontrol('units','normalized','style','edit', ...
      'max',2, ... 
      'position',[0.16 0.19 0.82 0.58], ...
      'horizontalalign','left', ...
      'visible','off', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'string',''); drawnow

  % buttons for checking/changing transfer limit size
  gui_buttons(19) = uicontrol('style','frame','units','pixels', ...
      'position', [posit 240 140], ...
      'horizontalalign','left', ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off');
  string = sprintf('%s\n%s\n%s\n%s\n',' Double-check any requests to', ...
      '  transfer datasets larger than:','','                      in Mb');
  gui_buttons(20) = uicontrol('style','edit','units','pixels', ...
      'position', [posit(1)+10 posit(2)+50 220 80], ...
      'max',2, ...
      'string', string, ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off');
  gui_buttons(21) = uicontrol('style','edit','units','pixels', ...
      'string', '1', ...
      'position', [posit(1)+30 posit(2)+10 100 30], ...
      'interruptible', switchon, ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off', ...
      'callback', 'browse(''setlevel'')');
  gui_buttons(29) = uicontrol('style','push','units','pixels', ...
      'string','OK', ...
      'position',[posit(1)+147 posit(2)+10 40 30], ...
      'interruptible', switchon, ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off', ...
      'callback', 'browse(''setlevel'')');
  
  % ABORT AND WARNING BUTTONS
  gui_buttons(26) = uicontrol('style','frame','units','normalized', ...
      'position',[0.20 0.37 0.20 0.18],'backgroundcolor', ...
      dods_colors(1,:), 'visible','off'); 
  string = str2mat('   Hang on!','   Transferring', ...
      '   information ...');
  gui_buttons(27) = uicontrol('style','edit','units','normalized', ...
      'position',[0.21 0.38 0.18 0.16], ...
      'backgroundcolor', dods_colors(1,:), ...
      'foregroundcolor',dods_colors(6,:), ...
      'max', 2, 'string', string, ...
      'visible','off'); 
  gui_buttons(28) = uicontrol('style','radio','units','normalized', ...
      'position',[0.31 0.38 0.08 0.06], ...
      'backgroundcolor', dods_colors(9,:), ...
      'foregroundcolor',dods_colors(6,:), ...
      'value', 0, ...
      'string', 'Cancel', ...
      'callback','browse(''oops!'')', ...
      'visible','off'); 

  posit = [round(fig_size(1)/5) 100];
  gui_buttons(22) = uicontrol('style','frame','units','pixels', ...
      'position', [posit 330 140], ...
      'horizontalalign','left', ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off');
  gui_buttons(23) = uicontrol('style','edit','units','pixels', ...
      'position', [posit(1)+10 posit(2)+50 300 80], ...
      'max',2, ...
      'string', '', ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off');
  gui_buttons(24) = uicontrol('style','push','units','pixels', ...
      'string', 'Ok', ...
      'position', [posit(1)+80 posit(2)+10 50 30], ...
      'interruptible', switchon, ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off');
  gui_buttons(25) = uicontrol('style','push','units','pixels', ...
      'string', 'Cancel', ...
      'position', [posit(1)+180 posit(2)+10 60 30], ...
      'interruptible', switchon, ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off');

  % FONTSIZE
  prefs(4) = uimenu(ui_prefs,'label','Fontsize ...');
  for i = 1:5
    j = 2*i+6;
    callbackstring = sprintf('browse(''fontsize'', %i)',j);
    uimenu(prefs(4),'label',sprintf(' 	%2i point',j), ...
	'callback',callbackstring);
  end
  
  % COLORS
  prefs(5) = uimenu(ui_prefs,'label','Colors ...');
  clrmenu(1) = uimenu(prefs(5),'label','Foreground');
  clrmenu(2) = uimenu(prefs(5),'label','Background');
  clrmenu(3) = uimenu(prefs(5),'label','Time Labels');
  clrmenu(4) = uimenu(prefs(5),'label','Selection Box');
  labels = str2mat('black','gray','white','red','green', ...
      'blue','yellow','magenta','cyan');
  for i = 1:4
    for j = 1:9;
      callbackstring = sprintf('browse(''setcolor'',%i)',10*i+j);
      uimenu(clrmenu(i),'label',labels(j,:),'callback', callbackstring);
    end
  end
  clrmenu(5) = uimenu(prefs(5),'label','Use Defaults', ...
      'callback','browse(''setcolor'',50)');

  % CLEAR DATA IN MAIN WORKSPACE
  prefs(6) = uimenu(ui_prefs,'label','Clear All Rxx_  (DELETES!)');
    
  % UPDATE DATASET LIST
  prefs(7) = uimenu(ui_prefs,'label','Update Dataset list', ...
      'foregroundcolor',dods_colors(7,:), ...
      'callback','browse(''updatedlg'')');
  if VERSION < 5
    set(prefs(7),'backgroundcolor',dods_colors(1,:))
  end

  % reset to defaults
  prefs(8) = uimenu(ui_prefs,'label','Use Default Options', ...
      'callback','browse(''resetdefault'')');
  
  % save options
  prefs(9) = uimenu(ui_prefs,'label','Save Options ...', ...
      'callback','browse(''savedlg'')');

  % save options
  prefs(10) = uimenu(ui_prefs,'label','Load Options ...', ...
      'callback','browse(''loaddlg'')');

%  % error messages to workspace or to screen?
%  prefs(11) = uimenu(ui_prefs,'label','Error messages to workspace', ...
%      'callback','browse(''errors'')');
  
  % 5) THE HELP MENU
  ui_help = uimenu(browse_fig, 'label','DODS Help!', ...
      'foregroundcolor',dods_colors(9,:));

  % I had to write this f****** script because v4 wants a str2mat
  % in the helpdlg string and v5 does not.  God this is tortuous.
  if VERSION < 5
    set(ui_help,'backgroundcolor',dods_colors(1,:))
    for j = 1:4	% number of items on the help menu
      arg = sprintf('%s%i%s%i%s%s%i%s', ...
      'str = []; str = ''str2mat(''; for i = 1:size(dlgstring', j, ...
	',1), str = [str sprintf(''''''%s'''','', dlgstring', j, ...
	  '(i,:))]; end; str = str(1:length(str)-1); str = [str '')''];', ...
      'dlgstring', j, ' = str;');
      eval(arg)
    end
   else
    for j = 1:4	% number of items on the help menu
      str = [];
      arg = sprintf('%s%i%s%i%s%i%s''''''''%s''''''''%s', ...
	  'for i = 1:size(dlgstring', j, ...
	    ',1), str = [str deblank(dlgstring', j, ...
	      '(i,:)) '' '']; end; dlgstring', j, ...
	  ' = [', ' str ', '];');
      eval(arg)
    end
  end

  label = 'DODS GUI User Manual';
  callbackstring = sprintf('!%s %s &', docopt, manURL);
  ui_manual = uimenu(ui_help, 'label', label, 'callback', callbackstring);
  label = 'What is DODS?';
  callbackstring = sprintf('helpdlg(%s, ''%s'');', ...
      dlgstring1,label);
  uimenu(ui_help, 'label', label, 'callback', callbackstring);
  label = 'Using the Browser';
  callbackstring = sprintf('helpdlg(%s, ''%s'');', ...
      dlgstring2,label);
  uimenu(ui_help, 'label', label, 'callback', callbackstring);
  label = 'Updating the dataset list';
  callbackstring = sprintf('helpdlg(%s, ''%s'');', ...
      dlgstring3,label);
  uimenu(ui_help, 'label', label, 'callback', callbackstring);
  label = 'Suggestions and Bugs';
  callbackstring = sprintf('helpdlg(%s, ''%s'');', ...
      dlgstring4,label);
  uimenu(ui_help, 'label', label, 'callback', callbackstring);
  label = 'About DODS ...';
  callbackstring = 'browse(''aboutdods'')';
  uimenu(ui_help,'label',label, 'callback',callbackstring);
   
% 6) THE PUSHBUTTONS AND EDIT BOXES
  % set up pushbutton positions
  buttonwidth = 0.12; buttonhgt = 0.06;
  fatbuttonwidth = 0.18;
  posit = [0.01 0.01 buttonwidth buttonhgt];
  shift = [buttonwidth 0 0 0]; gap = [0.01 0 0 0];  
  fatshift = [fatbuttonwidth 0 0 0];
  gui_buttons(30) = uicontrol('units','normalized','style','push', ...
      'position', posit, ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'callback','browse(''swapview'')', ...
      'string','View Text'); drawnow
  posit(3) = fatbuttonwidth;
  gui_buttons(3) = uicontrol('style','push','units','normalized', ...
      'position',posit+shift+4*gap, ...
      'string','Set Data Range', ...
      'interruptible',switchon, ...
      'callback', 'browse(''setrange'')');
  gui_buttons(4) = uicontrol('style','push','units','normalized', ...
      'position',posit+shift+fatshift+5*gap, ...
      'string', 'Clear Selections', ...
      'callback','browse(''clearrange'')');
  posit(3) = buttonwidth;
  gui_buttons(5) = uicontrol('style','push','units','normalized', ...
      'position',posit+shift+2*fatshift+9*gap, ...
      'string','Zoom', ...
      'interruptible',switchon, ...
      'callback', 'browse(''zoom'')');
  gui_buttons(6) = uicontrol('style','push','units','normalized', ...
      'position',posit+2*shift+2*fatshift+10*gap, ...
      'string','Next Plot', ...
      'interruptible',switchon, ...
      'visible','off', ...
      'backgroundcolor',dods_colors(9,:), ...
      'callback','browse(''nextplot'')');
  callbackstring = sprintf('%s; %s; %s', ...
      '[browse_figs] = browse(''quit''); ', ...
      'close(browse_figs)', ...
      'clear browse_figs'); 
  gui_buttons(7) = uicontrol('style','push','units','normalized', ...
      'position',posit+3*shift+2*fatshift+14*gap, ...
      'string','QUIT', ...
      'callback', callbackstring);

  % DRAW GEOGRAPHIC AXIS, THE WORLDMAP, THE GEOGRAPHIC BUTTONS
  % set up button chars
  buttonwidth = 0.105; buttonhgt = 0.05; buttonsep = 0.01;

  axpos = [0.05 0.1 0.82 0.7];
  AXES(1) = axes('Units', 'Normalized', 'Position', axpos,...
      'drawmode','fast','xlim', axes_vals(1:2), ...
      'ylim', axes_vals(3:4), 'box','on', ...
      'color',dods_colors(2,:), ...
      'xcolor',dods_colors(3,:), ...
      'ycolor',dods_colors(3,:), ...
      'nextplot','add', ...
      'userdata', 'GEOPLOT', ...
      'ytick',[-60:30:60],'xtickmode','auto', ...
      'ytickmode','auto'); drawnow;

  % set up coastline
  if isempty(dodsdir)
    dir = which('browse');
    dirsep = '/';
    c = computer;
    if strcmp(c(1:2),'PC')
      dirsep = '\';
    elseif strcmp(c(1:2),'MA')
      dirsep = ':';
    end
    i = max(findstr(dir,dirsep));
    dodsdir = dir(1:i);
  end
  fname = [dodsdir 'coastln'];
  eval(['load ' fname])
  x = coastlines(1,:); 
  x(coastinx) = x(coastinx)+offset;
  worldmap = line(x,coastlines(2,:), 'Color',dods_colors(3,:), ...
      'Erasemode','none'); drawnow
  clear coastlines
  eval(aspectstring)

  % BUTTONS TO MANUALLY EDIT GEOGRAPHIC RANGES
  % WEST
  gui_buttons(8) = uicontrol(browse_fig,...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position', [0.01 0.42 buttonwidth buttonhgt], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''wesn'')', ...
      'String','');
  % EAST
  gui_buttons(9) = uicontrol(browse_fig,...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position',[0.01 0.49 buttonwidth, buttonhgt], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''wesn'')', ...
      'String','');
  % SOUTH
  gui_buttons(10) = uicontrol(browse_fig, ...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position', [0.01 0.56 buttonwidth, buttonhgt], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''wesn'')', ...
      'String','');
  % NORTH
  gui_buttons(11) = uicontrol(browse_fig,...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position',[0.01 0.63 buttonwidth, buttonhgt], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''wesn'')', ...
      'String','');
  
  gui_buttons(32) = uicontrol(browse_fig,'style','text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'position', [0.115 0.63 0.03 0.05], ...
      'string','N');
  gui_buttons(33) = uicontrol(browse_fig,'style','text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'pos',[0.115 0.56 0.03 0.05], ...
      'string','S');
  gui_buttons(34) = uicontrol(browse_fig,'style','text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'pos',[0.115 0.49 0.03 0.05], ...
      'string','E');
  gui_buttons(35) = uicontrol(browse_fig,'style','text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'pos',[0.115 0.42 0.03 0.05], ...
      'string','W');
  % label the WESN buttons
  gui_buttons(16) = uicontrol('style','text', 'units','normalized', ...
      'position',[0.01 0.69 buttonwidth buttonhgt+0.01], ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'string','Range');
  gui_buttons(17) = uicontrol('style','text', 'units','normalized', ...
      'position', [0.01 0.75 buttonwidth buttonhgt], ...
      'horizontalalign','center', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'string','Set Data');

  % the all-important GET DATA button
  posit = [0.11 0.82 0.18 0.06];
  gui_buttons(1) =  uicontrol('style','push','string','<< Get Data! >>', ...
      'units','normalized', 'position', posit, ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(7,:), ...
      'callback','browse(''getdata'')');
  % the all-important GET DETAILS button
  gui_buttons(18) =  uicontrol('style','push','string','Get Details', ...
      'units','normalized', 'position', posit+[0 0.07 0 0], ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(7,:)+[0.3 0.2 0], ...
      'callback','browse(''getcat'')'); drawnow
  % THE URL BOX
  gui_buttons(2) = uicontrol('units','normalized','style','edit', ...
      'position',[0.01 0.09 0.98 0.06], ...
      'visible','off', ...
      'horizontalalign','left', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(5,:), ...
      'string',''); drawnow
  
  % Z-BAR AND ASSOCIATED BUTTONS
  axpos = [0.95 0.1 0.05 0.65];
  AXES(2) = axes('Units', 'Normalized', ...
      'Position', axpos, ...
      'drawmode','fast', ...
      'color', dods_colors(2,:), ...
      'xcolor',dods_colors(3,:), ...
      'ycolor',dods_colors(3,:), ...
      'box', 'on', ...
      'xlim',[0 1],'xtick',[], ...
      'nextplot','add', ...
      'ylim',axes_vals(5:6), ...
      'userdata',master_zrange, ...
      'ydir','reverse', ...
      'visible','on'); set(get(AXES(2), ...
      'ylabel'),'string','Depth in Meters', ...
      'color',dods_colors(4,:)); drawnow

  % buttons to manually edit z-range
  gui_buttons(12) = uicontrol(browse_fig,...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position', [0.01 0.2 0.105 0.05], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''zrange'')', ...
      'String','');
  posit(2) = axpos(2)+axpos(4)+0.01;
  gui_buttons(13) = uicontrol(browse_fig,...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position', [0.01 0.27 0.105 0.05], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''zrange'')', ...
      'String','');
  gui_buttons(36) = uicontrol(browse_fig, 'style','text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'pos',[0.01 0.33 0.09 0.05], ... 
      'string','Depth');
 
  % TIME SCALE AND ITS BOXES
  axpos = [0.3 0.84 0.68 0.1];
  AXES(3) = axes('Units', 'Normalized', ...
      'Position', axpos,...
      'drawmode','fast', ...
      'box','on', ...
      'color',dods_colors(2,:), ...
      'xcolor',dods_colors(3,:), ...
      'ycolor',dods_colors(3,:), ...
      'xlim', axes_vals(7:8), ...
      'visible','on', ...
      'nextplot','add', ...
      'ylim',[0 1], 'ytick', [], ...
      'userdata', master_timerange); 
  tstring(1) = text(0.5, 1.1,'Time in Years', 'horiz','center', ...
      'vert','bottom','color','w', 'erasemode','background',...
      'clipping','off','units','normalized', ...
      'color', dods_colors(4,:)); drawnow
  if timetoggle
    string = '1 JAN 1800';
  else
    string = '1 1800';
  end
  tstring(2) = text(0, 1.1, string, 'horiz','left', ...
      'vert','bottom','color',dods_colors(8,:), 'erasemode','background',...
      'clipping','off','units','normalized'); drawnow
  timelbl(axes_vals(7:8))

  % BUTTONS TO MANUALLY EDIT THE TIME RANGE
  gui_buttons(14) = uicontrol(browse_fig,...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position', [0.39 0.89 0.135 0.05], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''trange'')', ...
      'String','');
  gui_buttons(15) = uicontrol(browse_fig,...
      'style','edit',...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor', dods_colors(5,:), ...
      'units','normalized', ...
      'position', [0.39 0.82 0.135 0.05], ...
      'horizontalalign','right', ...
      'visible','off', ...
      'callback','browse(''trange'')', ...
      'String','');
  gui_buttons(37) = uicontrol(browse_fig, 'style', 'text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'position',[0.3 0.89 0.08 0.05], ...
      'horiz','right', ...
      'string','Begin');
  gui_buttons(38) = uicontrol(browse_fig, 'style', 'text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'position',[0.3 0.82 0.08 0.05], ...
      'horiz','right', ...
      'string','End');
  posit = [0.535 0.89 0.05 0.05];
  for i = 1:5;
    gui_buttons(39+i) = uicontrol(browse_fig,'style','text', ...
	'units','normalized', ...
	'foregroundcolor',dods_colors(6,:), ...
	'backgroundcolor',dods_colors(1,:), ...
	'string','', ...
	'visible','off', ...
	'position',posit);
    posit = posit + [0.06 0 0 0];
  end
  posit = [0.535 0.82 0.05 0.05];
  for i = 1:5
    gui_buttons(44+i) = uicontrol(browse_fig,'style','text', ...
	'units','normalized', ...
	'foregroundcolor',dods_colors(6,:), ...
	'backgroundcolor',dods_colors(1,:), ...
	'visible','off', ...
	'string','', ...
	'position',posit);
    posit = posit + [0.06 0 0 0];
  end
  posit = [0.535 0.95 0.05 0.05];
  string = str2mat('Mo','Day','Hr','min','sec');
  for i = 1:5
    gui_buttons(54+i) = uicontrol(browse_fig,'style','text', ...
	'units','normalized', ...
	'foregroundcolor',dods_colors(4,:), ...
	'backgroundcolor',dods_colors(2,:), ...
	'horiz','center', ...
	'visible','off', ...
	'string', string(i,:), ...
	'position',posit);
    posit = posit + [0.06 0 0 0];
  end
  
  % The URL count buttons
  gui_buttons(50) = uicontrol(browse_fig, 'style', 'text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'position',[0.825 0.90 0.105 0.05], ...
      'horiz','right', ...
      'string','Number of');
  gui_buttons(51) = uicontrol(browse_fig, 'style', 'text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'position',[0.825 0.85 0.105 0.05], ...
      'horiz','right', ...
      'string','URLS in');
  gui_buttons(52) = uicontrol(browse_fig, 'style', 'text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(4,:), ...
      'backgroundcolor',dods_colors(2,:), ...
      'visible','off', ...
      'position',[0.825 0.80 0.105 0.05], ...
      'horiz','right', ...
      'string','Request');
  gui_buttons(53) = uicontrol(browse_fig, 'style', 'frame', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off', ...
      'position',[0.94 0.84 0.05 0.08], ...
      'horiz','center', ...
      'string','');
  % this one actually shows the count:
  gui_buttons(54) = uicontrol(browse_fig, 'style', 'text', ...
      'units','normalized', ...
      'foregroundcolor',dods_colors(6,:), ...
      'backgroundcolor',dods_colors(1,:), ...
      'visible','off', ...
      'position',[0.95 0.85 0.03 0.06], ...
      'horiz','center', ...
      'string','');
  
  AXES(4) = axes('Units', 'Normalized', ...
      'Position', [-0.02 0.82 0.15 0.15],...
      'drawmode','fast', ...
      'box','off', ...
      'clim',[0 255], ...
      'color',dods_colors(2,:), ...
      'xcolor',dods_colors(2,:), ...
      'ycolor',dods_colors(2,:), ...
      'xlim', [1 92], 'xtick', [], ...
      'ylim',[1 92], 'ytick', [], ...
      'visible','off', ...
      'nextplot','add'); drawnow
  if VERSION < 5
    aspectstring = 'aspectratio'; aspect = [1 1];
  else
    aspectstring = 'plotboxaspectratio'; aspect = [1 1 1];
  end
  set(AXES(4),aspectstring,aspect)
  load smlogo; 
  image(small_logo); colormap(avhrrpal); drawnow

  subplot(AXES(1)); range_boxes(1) = line([ranges(1,1:2) ranges(1,2) ranges(1,2) ...
      ranges(1,2) ranges(1,1) ranges(1,1) ranges(1,1)], ...
  [ranges(2,1) ranges(2,1) ranges(2,1) ranges(2,2) ranges(2,2) ranges(2,2) ...
      ranges(2,2) ranges(2,1)], ... 
      'color',dods_colors(10,:),'visible','off', ...
      'linewidth', 2); drawnow
  subplot(AXES(2)); range_boxes(2) = line([0.01 0.99 0.99 0.99 ...
	  0.99 0.01 0.01 0.01], ...
      [ranges(3,1) ranges(3,1) ranges(3,1) ranges(3,2) ...
	  ranges(3,2) ranges(3,2) ranges(3,2) ranges(3,1)], ...
      'color',dods_colors(10,:), ...
      'linewidth', 2, 'visible','off'); drawnow
  subplot(AXES(3)); range_boxes(3) = line([ranges(4,1) ranges(4,2) ...
	  ranges(4,2) ranges(4,2) ranges(4,2) ranges(4,1) ...
	  ranges(4,1) ranges(4,1)], ...
      [0.01 0.01 0.01 0.99 0.99 0.99 0.99 0.01], ...
      'color',dods_colors(10,:), ...
      'linewidth', 2, 'visible', 'off'); drawnow

  % set edit and range boxes with saved ranges, if any
  browse('bsetrange') 

  % if not set up by now, set up the scroll windows
  k = findobj(0,'type','figure','userdata','DODS variables');
  if isempty(k)
    scroll
  else
    scroll_fig(1) = k;
  end
  k = findobj(0,'type','figure','userdata','DODS datasets');
  if isempty(k)
    scroll
  else
    scroll_fig(2) = k;
  end
  
  % If not set up by now, set up display menu screen
  if isempty(findobj(0,'type','figure','userdata','DODS display'))
    dispmenu('startup')
  end

  % set fontsize, add in range boxes and finally, reveal the figure
  browse('fontsize',fontsize)
  
  figure(browse_fig)

  % set up WORLDMAP and tweak longitude ranges of datasets
%  if master_georange(1) == 0
%    browse('setlon',360);
%  elseif master_georange(1) == -180
%    browse('setlon',0);
%  end

else
  % FIRST MAKE SURE ALL THE REQUISITE FIGURES EXIST
  if isempty(findobj(0,'type','figure','userdata','DODS display'))
    dispmenu('startup')
  end
  k = findobj(0,'type','figure','userdata','DODS variables');
  if isempty(k)
    scroll
  else
    scroll_fig(1) = k;
  end
  k = findobj(0,'type','figure','userdata','DODS datasets');
  if isempty(k)
    scroll
  else
    scroll_fig(2) = k;
  end

  if strcmp(argin,'aboutdods')
    k = get(0,'children');
    for i = 1:length(k),
      if strcmp(get(k(i),'userdata'),'About DODS')
	figure(k(i))
	return
	break
      end
    end
    load lglogo;
    scr_size = get(0,'ScreenSize');
    if VERSION < 5
      aspectstring = 'aspectratio'; aspect = [1 1];
    else
      aspectstring = 'plotboxaspectratio'; aspect = [1 1 1];
    end
    h = figure('position',[round(scr_size(3)/3) scr_size(4)-302 425 300], ...
	'color',[1 1 1],'numbertitle','off', ...
	'name','About DODS', 'resize','off', ...
	'userdata','About DODS');
    axes('units','normalized', ...
	'position', [0.175 0.3 0.65 0.65], ...
	'xlim',[0 260],'ylim',[0 260], 'nextplot','add', ...
	aspectstring, aspect, 'visible','off');
    image(large_logo); colormap(logo_map);  drawnow
    text(-0.55, 0.08,[setstr(169) ' 1994-1997 URI/MIT'],'color','k', ...
	'horiz','left','units','normalized')
    text(-0.55, -0.08,['DODS was written by James Gallagher, '...
	    'Reza Nekovei, and Dan Holloway'], ...
	'color','k','horiz','left','units','normalized')
    text(-0.55,-0.16, ['Matlab Interface (Loaddods package) by ', ...
	    'James Gallagher, Glenn Flierl,'], 'color','k', ...
	'horiz','left','units','normalized')
    text(0,-0.24, ['Peter Cornillon, and George Milkowksi '], ...
	    'color','k', 'horiz','left','units','normalized')
    text(-0.55, -0.32,['Graphical User Interface by Deirdre Byrne'], ...
	'horiz','left',	'color','k','units','normalized')
    callbackstring = sprintf('delete(%i)',h);
    uicontrol(h,'style','push', 'units','normalized', ...
	'position',[0.86 0.02 0.12 0.08], ...
	'string','OK','callback',callbackstring)
    return
  elseif strcmp(argin,'addclear')
    global_data_list = sprintf('%s%s', global_data_list, ...
	['clear ' second_arg '; ']);
    set(prefs(6),'callback', ...
	['browse(''resetcount'');' global_data_list]);
	return
  elseif strcmp(argin,'bsetrange')
    % reset saved ranges on startup, or reset ranges to coincide
    % with the selected dataset's range, if user has not pre-defined
    % the range
    if sum(num_rang(1:4)) == 4
      if master_georange(1) == 0
	if all(ranges(1,:) >= 0) & all(ranges(1,:) <= 180);
	  x = ranges(1,:);
	elseif all(ranges(1,:) < 0)
	  x = ranges(1,:) + 360;
	elseif all(minmax(ranges(1,:)) == [-180 180])
	  x = [0 360];
	elseif (ranges(1,1) < 0) & (ranges(1,2) > 0) 
	  x = [ranges(1,1)+360 ranges(1,2)];
	else
	  x = [ranges(1,1) ranges(1,2)+360];
	end
      else
	x = ranges(1,:);
      end
      if master_georange(1) == -180
	x = sort(ranges(1,:));
      end
%      if ranges(1,1) < ranges(1,2)
%	x = ranges(1,:);
%      elseif all(ranges(1,:) >= 0) & all(ranges(1,:) <= 180)
%      else
%	x = [ranges(1,2) ranges(1,1)+360];
%      end
      x = xrange('range', master_georange, x);
      if max(size(x) > 2)
	% do not allow wraparound range selection
	if range_boxes(1) > 0
	  set(range_boxes(1),'visible','off');
	end
	num_rang(1:2) = [0 0];
	set(gui_buttons(8:9),'string','')
      else
	if range_boxes(1) > 0
	  set(range_boxes(1),'xdata',[x(1:2) x(2) x(2) x(2) x(1) x(1) x(1)])
	  if strcmp(get(gui_buttons(30),'string'),'View Text')
	    set(range_boxes(1),'visible','on')
	  end
	end
	if ~isnan(x(1))
	  set(gui_buttons(8),'String',sprintf(' %.2f',x(1)))
	end
	if ~isnan(x(2))
	  set(gui_buttons(9),'String',sprintf(' %.2f',x(2)))
	end
      end
      set(gui_buttons(10),'String',sprintf('%.3f',ranges(2,1)))
      set(gui_buttons(11),'String',sprintf('%.3f',ranges(2,2)))
    else
      set(range_boxes(1),'visible','off')
      set(gui_buttons(8),'String','')
      set(gui_buttons(9),'String','')
      set(gui_buttons(10),'String','')
      set(gui_buttons(11),'String','')
    end
    if sum(num_rang(5:6)) == 2
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	set(range_boxes(2),'visible','on')
      end
      set(gui_buttons(12),'String',sprintf(' %.2f',ranges(3,2)))
      set(gui_buttons(13),'String',sprintf(' %.2f',ranges(3,1)))
    else
      set(range_boxes(2),'visible','off')
      set(gui_buttons(12),'String','')
      set(gui_buttons(13),'String','')
    end
    if sum(num_rang(7:8)) == 2
      set(gui_buttons(14),'String',sprintf(' %.5f',ranges(4,1)))
      lmo = [31 28 31 30 31 30 31 31 30 31 30 31];
      if rem(floor(ranges(4,1)),4) == 0
	if floor(ranges(4,1)) == 1900 	% 1900 was apparently not a leap year!
	  lyr = 365;
	else
	  lyr = 366;
	  lmo(2) = 29;
	end
      else
	lyr = 365;
      end
      range_day = floor((ranges(4,1)-floor(ranges(4,1)))*lyr(1))+1; % day of year
      
      t = min(find(range_day < cumsum(lmo)));
      if isempty(t)
	t = 12;
      end
      % day
      t(2) = range_day(1) - sum(lmo(1:t(1)-1));
      % hr
      t(3) = floor((((ranges(4,1)-floor(ranges(4,1)))*lyr(1)+1)-range_day(1))*24);
      % min
      t(4) = floor(((((ranges(4,1)-floor(ranges(4,1)))*lyr(1)+1)*24 - ...
	  range_day(1)*24)-t(3))*60);
      % sec
      t(5) = floor(((((ranges(4,1)-floor(ranges(4,1)))*lyr(1)+1)*24*60 - ...
	  range_day(1)*24*60)-t(3)*60)*60-t(4)*60);
      for i = 1:5;
	set(gui_buttons(39+i),'string',sprintf(' %i',t(i)))
      end
      
      set(gui_buttons(15),'String',sprintf(' %.5f',ranges(4,2)))
      lmo = [31 28 31 30 31 30 31 31 30 31 30 31];
      if rem(floor(ranges(4,2)),4) == 0
	if floor(ranges(4,2)) == 1900 	% 1900 was apparently not a leap year!
	  lyr(2) = 365;
	else
	  lyr(2) = 366;
	  lmo(2) = 29;
	end
      else
	lyr(2) = 365;
      end
      range_day(2) = floor((ranges(4,2)-floor(ranges(4,2)))*lyr(2))+1; % day of year
      t = min(find(range_day(2) < cumsum(lmo)));
      if isempty(t)
	t = 12;
      end
      % day
      t(2) = range_day(2) - sum(lmo(1:t(1)-1));
      % hr
      t(3) = floor((((ranges(4,2)-floor(ranges(4,2)))*lyr(2)+1)-range_day(2))*24);
      % min
      t(4) = floor(((((ranges(4,2)-floor(ranges(4,2)))*lyr(2)+1)*24 - ...
	  range_day(2)*24)-t(3))*60);
      % sec
      t(5) = floor(((((ranges(4,2)-floor(ranges(4,2)))*lyr(2)+1)*24*60 - ...
	  range_day(2)*24*60)-t(3)*60)*60-t(4)*60);
      for i = 1:5;
	set(gui_buttons(44+i),'string',sprintf(' %i',t(i)))
      end
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	set(range_boxes(3),'visible','on')
      end
    else
      set(range_boxes(3),'visible','off')
      set(gui_buttons(14),'String','')
      set(gui_buttons(15),'String','')
      set(gui_buttons(40:49),'string','')
    end
    return
  elseif strcmp(argin,'changecolor')
    % backgroundcolor
    set(AXES(1:3), 'color', dods_colors(2,:))
    set(browse_fig,'color', dods_colors(2,:))
    set(gui_buttons([16:17 32:38 50:52 55:59]),'backgroundcolor',dods_colors(2,:))
    avhrrpal(1,:) = dods_colors(2,:);
    figure(browse_fig); colormap(avhrrpal); drawnow
    % foregroundcolor
    set(AXES(1:3), 'xcolor', dods_colors(3,:))
    set(AXES(1:3), 'ycolor', dods_colors(3,:))
    set(worldmap, 'color', dods_colors(3,:))
    set(tstring(1), 'color', dods_colors(4,:))
    set(gui_buttons([16:17 32:38 50:52 55:59]), 'foregroundcolor', dods_colors(4,:))
    set(get(AXES(2), 'ylabel'), 'color', dods_colors(4,:))
    
    % time labels
    set(tstring(2), 'color', dods_colors(8,:))
    if ~isempty(thandle)
      set(thandle, 'color', dods_colors(8,:))
    end
    if ~isempty(lhandle)
      set(lhandle, 'color', dods_colors(8,:))
    end

    % range boxes
    set(range_boxes, 'color', dods_colors(10,:))
    return
  elseif strcmp(argin,'checkplots')
    % if there is only one plot in the image_string,
    % then it has been visible to the user and can be
    % deleted.  DAB 98/09/12
    if length(image_string) > 0
      if length(image_string) == (image_string(1)+1)
% maybe people want to overlay on last plot?	
%	delete(image_string(2:image_string(1)+1));
	image_string = [];
      end
    end
    return

  elseif strcmp(argin,'choose_var');
    % we have chosen/unchosen a variable from the scroll menu
    if any(isnan(var)),
      return
    end
    % Note: button 2 is the URL edit box
    % button 54 is the num_urls display box
    if ~isnan(dset)
      if ~datasets(dset)
	% if the selected dataset does not contain this
	% variable, unselect it
	dset = nan;
	set(gui_buttons(2),'string','');
	set(gui_buttons(39),'string','');
	set(gui_buttons(54),'string','');
	set(gui_buttons(1),'callback','browse(''getdata'')')
	archive = '';
	getxxx = '';
	return
      else
	if any(size(brs_old_var) ~= size(var))
	  set(gui_buttons(2),'string','');
	  set(gui_buttons(54),'string','');
	else % number of old and new variables the same
	  if any(brs_old_var ~= var)
	    set(gui_buttons(2),'string','');
	    set(gui_buttons(54),'string','');
	  end
	end
      end
    else
      archive = '';
      getxxx = '';
      set(gui_buttons(2),'string','');
      set(gui_buttons(39),'string','');
      set(gui_buttons(54),'string','');
      set(gui_buttons(1),'callback','browse(''getdata'')')
      return
    end

    if exist(archive) == 2
      eval(archive)
    else
      % HERE
      disp('Metadata not found!')
      return
    end
    if VERSION < 5
      callbackstring = sprintf('browse(''getdata'',''cancel''); clear %s', ...
	  returnstring);
    else
      callbackstring = 'browse(''getdata'',''cancel'')';
    end
    set(gui_buttons(25),'callback',callbackstring);

    if sum(num_rang) == 8 & sum(isnan(ranges)) == 0
      callbackstring = sprintf('[%s] = browse(''getdata''); unpack', ...
	  returnstring);
      set(gui_buttons(1),'callback', callbackstring, ...
	'backgroundcolor',dods_colors(7,:))
      callbackstring = sprintf('[%s] = browse(''getdata'',''ok''); unpack', ...
	  returnstring);
      set(gui_buttons(24), 'callback',callbackstring)
    
    else
      set(gui_buttons(1),'callback','browse(''getdata'')')
    end
    
    return
  elseif strcmp(argin,'clearrange')
    % reset graphic ranges
    select(0); set(gui_buttons(3),'backgroundcolor', dods_colors(1,:));
    ranges = nan*ones(4,2);
    num_rang = zeros(8,1);

    set(gui_buttons(8:15),'String','')
    set(range_boxes,'visible','off')
    
    % reset dataset list
    dset = nan;
    archive = '';
    getxxx = '';
    
    % reset variables list
    var = nan;

    % clear URL & Selections, metadata
    set(gui_buttons(2),'string','');
    set(gui_buttons(54),'string','');
    set(gui_buttons(39:49),'string','');
    scroll('dreset')
    scroll('vreset')
    return
  elseif strcmp(argin,'climchange')
    if nargin == 2
      if ~isempty(second_arg)
	x = sscanf(second_arg,'%g');
	if max(size(x)) == 2
	  color_limits = x(:)';
	  figure(browse_fig); set(AXES(1),'clim', x)
	end
      end
    end
    return
  elseif strcmp(argin,'climdlg')
    str = sprintf('%g %g',color_limits);
    if VERSION < 5
      OKCallback = ['Qmenu = gcf; browse(''climchange'', ' ...
	    'get(findobj(Qmenu,''Style'',''edit''),''String''));' ...
	    'delete(Qmenu); clear Qmenu'];
      eval([ 'save_fig = inputdlg(''Limits of Color Map (Data Units):'', '...
	  '''DODS Browse: color limits'', ', ...
	  'OKCallback, str);'])
    else
      % THIS SUCKS! MATLAB 4 'breaks' when this syntax
      % is used, so it must be couched in a string and
      % then evaluated.  Blecch. 
      cmd = sprintf('%s', ...
	  ['answer = inputdlg(''Limits of Color Map (Data Units):'', ', ...
	      '''DODS Browse: color limits'', 1, {str});']);
      eval(cmd)
      if ~isempty(answer)
	answer = char(answer);
	browse('climchange',answer)
      end
    end
    return
  elseif strcmp(argin,'clrall')
    % turn zoom off
    subplot(AXES(1)); newzoom off; subplot(AXES(2)); newzoom off; 
    subplot(AXES(3)); newzoom off
    set(gui_buttons(5),'backgroundcolor', dods_colors(1,:));
    % reset axes all the way 'out'
    axes_vals = [master_georange(1:2)+[-5 5] master_georange(3:4)+[-1 1] ...
	    master_zrange+[-50 0] master_timerange];
    set(get(AXES(1),'zlabel'),'userdata',axes_vals(1:4))
    set(get(AXES(2),'zlabel'),'userdata',[0 1 axes_vals(5:6)])
    set(get(AXES(3),'zlabel'),'userdata',[axes_vals(7:8) 0 1])

    if VERSION < 5
      aspectstring = sprintf('set(AXES(1),%s,[%g 1])', ...
	  '''AspectRatio''', diff(axes_vals(1:2))/diff(axes_vals(3:4)));
    else
      aspectstring = sprintf('set(AXES(1), %s, [%i %i 1], %s, [1 1 1])', ...
	  '''PlotBoxAspectRatio''', ...
	  [diff(axes_vals(1:2)) diff(axes_vals(3:4))], ...
	  '''DataAspectRatio''');
    end
    eval(aspectstring)
    
    kids = get(AXES(1),'children');
    kids = kids(find(kids ~= worldmap));
    for i = 1:length(kids)
      if ~any(kids(i) == range_boxes(1))
	delete(kids(i)); 
      end
    end
    set(AXES(1),'xlim',axes_vals(1:2),'ylim',axes_vals(3:4));
    
    kids = get(AXES(2),'children');
    for i = 1:length(kids)
      if ~any(kids(i) == range_boxes(2))
	delete(kids(i)); 
      end
    end
    set(AXES(2),'xlim',[0 1],'ylim',axes_vals(5:6));
    kids = get(AXES(3),'children');
    for i = 1:length(kids)
      if ~any(kids(i) == range_boxes(3)) & ~any(kids(i) == tstring)
	delete(kids(i)); 
      end
    end
    thandle = []; lhandle = [];

    set(AXES(3),'xlim', axes_vals(7:8),'ylim',[0 1]);
    set(AXES(3),'xtickmode','auto','xticklabelmode','auto')
    set(tstring(1),'string','Time in Years','color',dods_colors(4,:))
    set(tstring(2),'string','1 JAN 1800','color',dods_colors(8,:))
    set(gui_buttons(22:28),'visible','off')
    set(gui_buttons(1), 'backgroundcolor', dods_colors(7,:))
    set(gui_buttons(18), 'backgroundcolor', dods_colors(7,:)+[0.3 0.2 0])

    if ~isnan(dset)
      % replot selected dataset ranges on maps
      subplot(AXES(1)); 
      x = xrange('range',master_georange,[master_rangemin(dset,1) ...
	      master_rangemax(dset,1)]);
      y = [master_rangemin(dset,2) master_rangemax(dset,2)];
      if max(size(x) == 2)
	xl = [x(1:2) x(2) x(2) x(2) x(1) x(1) x(1)];
	yl = [y(1) y(1) y(1:2) y(2) y(2) y(2) y(1)];
      else
	% two boxes
	xl = [x(1:2) x(2) x(2) x(2) x(1) x(1) x(1) nan ...
		x(3:4) x(4) x(4) x(4) x(3) x(3) x(3)];
	yl = [y(1) y(1) y(1:2) y(2) y(2) y(2) y(1) nan ...
		y(1) y(1) y(1:2) y(2) y(2) y(2) y(1)];
      end

      h = line(xl,yl, 'color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      i = plot(xl,yl, '*','color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	h = [h(:); i(:)];
	set(h,'visible','on')
      end

      subplot(AXES(2)); 
      x = 0.90*dset/num_sets;
      yl = [master_rangemin(dset,3) master_rangemax(dset,3)];
      h = line([x x], yl, 'color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      i = plot([x x], yl, '*','color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	h = [h(:); i(:)];
	set(h,'visible','on')
      end
    
      subplot(AXES(3)); 
      xl = [master_rangemin(dset,4) master_rangemax(dset,4)];
      y = 0.90*dset/num_sets;
      h = line(xl, [y y], 'color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      i = plot(xl, [y y], '*','color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	h = [h(:); i(:)];
	set(h,'visible','on')
      end
    end

    image_string = [];
    set(gui_buttons(6),'visible','off','userdata','')
    refresh(browse_fig)
    return
  elseif strcmp(argin,'clrimg')
    figure(browse_fig)
    % save zoom limits
    x = get(get(AXES(1),'zlabel'),'userdata');
    if isempty(x)
      x = axes_vals(1:4);
    end
    y = get(get(AXES(2),'zlabel'),'userdata');
    if isempty(y)
      y = [0 1 axes_vals(5:6)];
    end
    z = get(get(AXES(3),'zlabel'),'userdata');
    if isempty(z)
      z = [axes_vals(7:8) 0 1];
    end
    
    % delete random things that have been plotted
    kids = get(AXES(1),'children');
    i = find(kids ~= worldmap & kids ~= range_boxes(1));
    delete(kids(i)); 
    kids = get(AXES(2),'children');
    i = find(kids ~= range_boxes(2));
    delete(kids(i)); 
    kids = get(AXES(3),'children');
    for i = 1:length(kids)
      if ~any(kids(i) == [range_boxes(3); tstring(:); thandle(:); lhandle(:)])
	delete(kids(i));
      end
    end

    % delete num_urls text
    set(gui_buttons(54),'string','')
    
    % reset zoom limits
    if ~isempty(x)
      set(get(AXES(1), 'zlabel'), 'userdata', x)
    end
    if ~isempty(y)
      set(get(AXES(2), 'zlabel'), 'userdata', y)
    end
    if ~isempty(z)
      set(get(AXES(3), 'zlabel'), 'userdata', z)
    end
    
    % replot selected dataset ranges on maps
    if ~isnan(dset)
      subplot(AXES(1)); 
      x = xrange('range',master_georange,[master_rangemin(dset,1) ...
	      master_rangemax(dset,1)]);
      y = [master_rangemin(dset,2) master_rangemax(dset,2)];
      if max(size(x) == 2)
	xl = [x(1:2) x(2) x(2) x(2) x(1) x(1) x(1)];
	yl = [y(1) y(1) y(1:2) y(2) y(2) y(2) y(1)];
      else
	% two boxes
	xl = [x(1:2) x(2) x(2) x(2) x(1) x(1) x(1) nan ...
		x(3:4) x(4) x(4) x(4) x(3) x(3) x(3)];
	yl = [y(1) y(1) y(1:2) y(2) y(2) y(2) y(1) nan ...
		y(1) y(1) y(1:2) y(2) y(2) y(2) y(1)];
      end

      h = line(xl,yl, 'color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      i = plot(xl,yl, '*','color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	h = [h(:); i(:)];
	set(h,'visible','on')
      end

      subplot(AXES(2)); 
      x = 0.90*dset/num_sets;
      yl = [master_rangemin(dset,3) master_rangemax(dset,3)];
      h = line([x x], yl, 'color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      i = plot([x x], yl, '*','color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	h = [h(:); i(:)];
	set(h,'visible','on')
      end
    
      subplot(AXES(3)); 
      xl = [master_rangemin(dset,4) master_rangemax(dset,4)];
      y = 0.90*dset/num_sets;
      h = line(xl, [y y], 'color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      i = plot(xl, [y y], '*','color',datacolor(dset,:),'erasemode','none', ...
	  'clipping','on','visible','off'); drawnow
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	h = [h(:); i(:)];
	set(h,'visible','on')
      end

    end
    
    % clear queued images, if any
    image_string = [];
    set(gui_buttons(6),'visible','off','userdata','')
    
    refresh(browse_fig)
    return
  elseif strcmp(argin,'display')
    % have to do something new and different here
    if strcmp(get(prefs(6),'enable'),'on')
      set(prefs(6),'enable','off')
      %dispmenu('display')
      dispmenu('displayfrombrowse', axes_vals, dispsizes, dispnames, ...
	  dispcount, master_georange, dispdepthname, dispdatarange, ...
	  dispindex, browse_fig, avhrrpal, dispclearbutton, ...
	  color_limits)
    end
    return
  elseif strcmp(argin,'dodsdir')
    k = findobj(gcf,'style','edit','userdata','DODSDIR');
    dir = get(k,'string');
    if ~isempty(dir)
      dodsdir = dir;
    end
    dirsep = '/';
    c = computer;
    if strcmp(c(1:2),'PC')
      dirsep = '\';
    elseif strcmp(c(1:2),'MA')
      dirsep = ':';
    end
    dodsdir = deblank(dodsdir);
    if ~strcmp(dodsdir(length(dodsdir)),dirsep)
      dodsdir = [dodsdir dirsep];
    end
    return
  elseif strcmp(argin,'errors')
    % SET ERROR MESSAGE PREFERENCES
    return
  elseif strcmp(argin,'fontsize')
    fontsize = second_arg;
    if VERSION > 4
      set(gui_buttons, 'fontsize', fontsize)
      set(display_menu, 'fontsize', fontsize)
      scroll('fontsize', fontsize)
    end
    set(tstring,'fontsize',fontsize)
    set(AXES,'fontsize',fontsize)
    set(get(AXES(2),'ylabel'),'fontsize',fontsize)
    set(thandle,'fontsize',fontsize)
  elseif strcmp(argin,'getcat')
    if ~isnan(dset) & ~isnan(var)
      if sum(num_rang) == 8
	% check -- is this a valid request, given the dataset range?
	% boolean: which datasets within the given ranges
	% only subselect based on which ranges set
	datamin = ranges(:,1)' > [rangemax(dset) master_rangemax(dset,2:4)];
	datamax = ranges(:,2)' < [rangemin(dset) master_rangemin(dset,2:4)];
	d = ~(any(datamin')' | any(datamax')');
	if ~d
	  % HERE
	  dset = nan;
	  scroll('datset')
	  disp('Dataset out of range')
	  return
	end

	% Pass in the Metadata name and query the Catalogue server
	if exist(getxxx) == 2
	  if exist('loaddods') ~= 3
	    % HERE
	    disp('Unable to find the loaddods MEX-file')
	    disp('Please make sure it is in your matlabpath')
	    set(gui_buttons(18),'backgroundcolor',dods_colors(7,:)+[0.3 0.2 0])
	    return
	  end
	  % turn off all other buttons
	  select(0);
	  set(gui_buttons(3),'backgroundcolor', ...
	      dods_colors(1,:)); set(gui_buttons(5), ...
	      'backgroundcolor',dods_colors(9,:)); drawnow
	  set(gui_buttons(5),'backgroundcolor',dods_colors(1,:))
	  subplot(AXES(1)); newzoom off; subplot(AXES(2)); newzoom off; 
	  subplot(AXES(3)); newzoom off; 
	  % turn on relevant buttons
	  % HERE
	  set(gui_buttons(18),'backgroundcolor',dods_colors(9,:)); drawnow
	  set(gui_buttons(26:27),'visible','on'); drawnow
	  x = []; y = []; z = []; n = []; t = []; url = [];
	  if all(~isnan(var))
	    get_variables = master_variables(var,:);
	  else
	    get_variables = [];
	  end
	  eval(sprintf('[x,y,z,t,n,url] = %s(''cat'', %s);', getxxx, ...
	      get_inputstring));
	  if ~isempty(n)
	    num_urls = n;
	  else
	    num_urls = 0;
	  end
	  % set the Get Data button to really go ahead
	  callbackstring = sprintf('[%s] = browse(''getdata''); unpack', ...
	      returnstring);
	  set(gui_buttons(1),'callback',callbackstring)
	  set(gui_buttons(54),'string',sprintf('%i',num_urls))
	  if isstr(url)
	    set(gui_buttons(2),'string',url)
	  end
	  if ~isempty(x)
	    if ~isempty(y)
	      subplot(AXES(1)); h = plot(x, y,'+', ...
		  'color',datacolor(dset,:),'erasemode','none', ...
		  'clipping','on','visible','off'); drawnow
	      if strcmp(get(gui_buttons(30),'string'),'View Text')
		set(h,'visible','on')
	      end
	    end
	  end
	  if ~isempty(z)
	    num_depths = length(z);
	    x = 0.90*dset/num_sets; x=x*ones(num_depths,1);
	    subplot(AXES(2)); h = plot(x, z,'*', ...
		'color',datacolor(dset,:),'erasemode','none', ...
		'clipping','on','visible','off'); drawnow
	    if strcmp(get(gui_buttons(30),'string'),'View Text')
	      set(h,'visible','on')
	    end
	  end
	  if ~isempty(t)
	    num_dates = length(t);
	    y = 0.90*dset/num_sets; y=y*ones(num_dates,1);
	    subplot(AXES(3)); h = plot(t, y,'*', ...
		'color',datacolor(dset,:),'erasemode','none', ...
		'clipping','on','visible','off'); drawnow
	    if strcmp(get(gui_buttons(30),'string'),'View Text')
	      set(h,'visible','on')
	    end
	  end
	  % HERE
	  disp('          .......done')
	  disp('    ')
	else
	  % HERE
	  disp(sprintf('Error! Cannot find your '' %s'' function.',getxxx))
	end
      else
	% HERE
	disp('Please select time, depth, longitude and latitude ranges')
      end
    else
      % HERE
      disp('Please choose a variable and a dataset from the menus above.')
    end
    set(gui_buttons(18),'backgroundcolor',dods_colors(7,:)+[0.3 0.2 0])
    set(gui_buttons(1),'backgroundcolor',dods_colors(7,:))
    set(gui_buttons(26:28),'visible','off'); 
    refresh(browse_fig)
    return
  elseif strcmp(argin,'getdata')
    if nargin == 2 % grab cancellations first
      if strcmp(second_arg,'cancel')
	set(gui_buttons(22:25),'units','pixels','visible','off')
	set(gui_buttons(1),'backgroundcolor',dods_colors(7,:))
	set(gui_buttons(26:28),'visible','off'); drawnow
	set(prefs(6),'enable','on')
	return
      end
    end
    if nargin == 1
      if (sum(num_rang) == 8) & (dset <= num_sets) & (var <= num_vars) & ...
	    ~isnan(dset) & ~isnan(var)
	if ~isnan(master_resolutions(dset)) & isempty(dset_stride)
	  % HERE
	  disp('Please select a resolution')
	  return
	end
      else
	% HERE
	disp('Please select a data set and variable from the pulldown lists above')
	disp('and geographic and time ranges with the ''set data range'' functions')
	return
      end

      if exist('loaddods') ~= 3
	% HERE
	disp('Unable to find the loaddods MEX-file')
	disp('Please make sure it is in your Matlabpath')
	set(gui_buttons(1),'backgroundcolor',dods_colors(7,:))
	return
      end

      % a final check -- is this a valid request, given the dataset range?
      datamin = ranges(:,1)' > [rangemax(dset) master_rangemax(dset,2:4)];
      datamax = ranges(:,2)' < [rangemin(dset) master_rangemin(dset,2:4)];
      d = ~(any(datamin')' | any(datamax')');
      if ~d
	% HERE
	dset = nan;
	scroll('datset')
	disp('Dataset out of range')
	return
      end
      
      if exist(getxxx) ~= 2
      % HERE
        disp(sprintf('Error! Cannot find your ''%s'' function.',getxxx))
	return
      end
      if exist(archive) ~= 2
      % HERE
        disp(sprintf('Error! Cannot find your ''%s'' function.',archive))
	return
      end
      
      % turn off all other buttons
      select(0);
      set(gui_buttons(3),'backgroundcolor', ...
	  dods_colors(1,:)); set(gui_buttons(5), ...
	  'backgroundcolor',dods_colors(9,:))
      set(gui_buttons(5),'backgroundcolor',dods_colors(1,:))
      figure(browse_fig)
      subplot(AXES(1)); newzoom off; subplot(AXES(2)); newzoom off; 
      subplot(AXES(3)); newzoom off; 

      % GET THE SIZE OF THE REQUEST -- call catalogue server if not done yet
      set(gui_buttons(1),'backgroundcolor',dods_colors(9,:))
      set(gui_buttons(26:27),'visible','on'); drawnow
      if all(~isnan(var))
	get_variables = master_variables(var,:);
      else
	get_variables = [];
      end
      eval(sprintf('[datasize, nurls] = %s(''datasize'', %s);', ...
	  getxxx, get_inputstring));
      if isempty(datasize)
	datasize = 0;
      end
      if ~isempty(nurls)
	num_urls = nurls;
      else
	num_urls = 0;
      end
      set(gui_buttons(54),'string',sprintf('%i',num_urls)); drawnow
      if exist(archive) == 2
        eval(archive)
      else
      % HERE
        disp('Metadata not found!')
        return
      end

      if all(~isnan(var))
	get_variables = master_variables(var,:);
      else
	get_variables = [];
      end
      callbackstring = sprintf('[%s] = browse(''getdata'',''ok''); unpack', ...
	  returnstring);
      % gui_buttons(24) is the 'ok' button on the size warning message
      set(gui_buttons(24), 'callback',callbackstring)
      % REMEMBER: MUST ISSUE NEW CALLBACK ARGOUTS AFTER 
      % HAVING RE-ISSUED REQUEST FOR DATA
      if datasize > check_level
	% HERE
        string = sprintf('%s%i%s\n%s%g%s\n%s%g%s\n%s', ...
	    ' WARNING: These ', nurls, ' dataset(s) take up', ...
	    ' a total of ', datasize, ' Mb, and your maximum ', ...
	    ' transfer threshold is set to: ', check_level, ...
	    ' Mb.',  ...
	    ' Would you still like to transfer the data?');
	set(gui_buttons(23),'string',string)
	set(gui_buttons(22:25),'units','pixels','visible','on', ...
	    'interruptible', switchon);
	return
      end
    end  %end of /if nargin == 1/

    % if we are here, it is a small enough dataset or we said 'ok'
    if nargin == 2
      if strcmp(second_arg,'ok')
	set(gui_buttons(22:25),'units','pixels','visible','off'); drawnow
      end
    end

    % >>>>>>>>   GET THE DATA   <<<<<<<<<<<
    if exist(archive) == 2
      eval(archive)
    else
      % HERE
      disp('Metadata not found!')
      return
    end
    % set output arguments that are info contained in browser
    clear_button = prefs(6);
    % set output arguments that are info from archive.m file
    depth_name = DepthName;
    if exist('DataRange') == 1
      data_range = DataRange;
    else
      data_range = [];
    end
    url_count = count;
    % get the data
    string = 'tmpdata, tmpsizes, tmpnames, tmpindex, tmpurl';
    image_string = [];
    sizes = []; data = []; names = []; urls = []; 
    set(gui_buttons(28),'value',0); button_value = 0;
    set(gui_buttons(26:28),'visible','on')
    set(gui_buttons(54),'string',sprintf('%i',num_urls))
    for j = 1:num_urls
      if j == 1
	% HERE
	disp('  ')
	disp('Please be patient while the data are transferred .... ')
	disp('  ')
      end
      if all(~isnan(var))
	get_variables = master_variables(var,:);
      else
	get_variables = [];
      end
      % here we actually issue the data request and deref the URL
      eval(sprintf('[%s] = %s(''get'', %s, %i);', string, ...
	  getxxx, get_inputstring, j));
      if ~isempty(tmpurl)
	set(gui_buttons(2),'string',tmpurl); drawnow
      end
      % pack the outgoing info into a single array each
      % and add in the index # to each argument
      % WITHIN THE ORDERED LIST FOR THIS URL
      if j == 1
	data = tmpdata;
	sizes = [tmpsizes [1:size(tmpsizes,1)]'];
	names = tmpnames;
	index = tmpindex(:);
	urls = tmpurl;
      else
	data = [data; tmpdata];
	sizes = [sizes; tmpsizes [1:size(tmpsizes,1)]'];
	names = str2mat(names, tmpnames);
	index = [index; tmpindex(:)];
	urls = str2mat(urls,tmpurl);
      end
      % LOOK FOR A CALL TO ABORT
      pause(1)
      button_value = get(gui_buttons(28),'value');
      if button_value
	set(gui_buttons(54),'string',sprintf(' %i',j))
	break
      end
    end % end of num_urls loop
    % HERE
    disp('                                  ')
    disp('          ..... data transfer complete')
      
    refresh(browse_fig)
    % set things that need to be saved for the display menu to work
    dispcount = count;
    dispdepthname = DepthName;
    if exist('DataRange') == 1
      dispdatarange = DataRange;
    else
      DataRange = [];
    end
    dispindex = index;
    dispnames = names;
    dispsizes = sizes;
    dispclearbutton = prefs(6);
    dispmenu('resetcallback')
    % upload color palette w/corrected backgroundcolor
    palette = avhrrpal;

    % increment count of returned datasets
    count = count + num_urls;

    % reset button callbacks and buttons
    callbackstring = sprintf('[%s] = browse(''getdata''); unpack', ...
	returnstring);
    set(gui_buttons(1),'callback', callbackstring, ...
	'backgroundcolor',dods_colors(7,:))
    callbackstring = sprintf('[%s] = browse(''getdata'',''ok''); unpack', ...
	returnstring);
    set(gui_buttons(24), 'callback',callbackstring)
    if VERSION < 5
      callbackstring = sprintf('browse(''getdata'',''cancel''); clear %s', ...
	  returnstring);
    else
      callbackstring = 'browse(''getdata'',''cancel'')';
    end
    set(gui_buttons(25),'callback',callbackstring)
    set(gui_buttons(26:28),'visible','off')
    set(ui_display,'enable','on')
    brs_old_dset = dset;
    brs_old_var = var;
    prev_num_urls = num_urls;
    return
  elseif strcmp(argin,'gsetrange')
    % remove text from num_urls & URL edit line
    % after something has changed (a dataset, a range)
    set(gui_buttons(2),'string','')
    set(gui_buttons(54),'string','')
    % remove 'transferring data' warning
    set(gui_buttons(26:28),'visible','off')
    % reset display menu 'ok' button callback
    callbackstring = sprintf('[%s] = browse(''getdata''); unpack', ...
	returnstring);
    set(gui_buttons(1),'callback',callbackstring)
    set(gui_buttons(1), ...
	'foregroundcolor',dods_colors(6,:), ...
	'backgroundcolor', dods_colors(7,:))
    return
  elseif strcmp(argin,'loaddlg')
    fname = 'browsopt.m';
    if exist(fname) ~= 2
      % there are no saved options in a default filename
      % user must supply a filename
      fname = '';
    end
    if VERSION < 5
      % FIG = INPUTDLG(PromptString,DlgName,OKCallback,DefEditStr)
      OKCallback = ['Qmenu = gcf; browse(''loadopts'', ' ...
	    'get(findobj(Qmenu,''Style'',''edit''),''String''));' ...
	    'delete(Qmenu); clear Qmenu'];
      % this is couched in an eval to prevent error messages on startup
      eval([ 'save_fig = inputdlg(''Load options from m-file: (this file MUST be in your Matlabpath)'',', ...
	    '''DODS Browse: load options'', ', ...
	    'OKCallback, fname);'])
    else
      % additional check to make sure local inputdlg.m is NOT USED
      w = which('inputdlg.m','-all');
      s = size(w,1);
      if s > 1
	for i = 1:s
	  cmd = char(w(i));
	  if ~isempty(findstr(cmd,dodsdir))
	    disp('                ')
	    disp('    PLEASE RENAME OR REMOVE THE FILE ''inputdlg.m'' ')
	    disp(['    IN YOUR BROWSER SOURCE DIRECTORY: ' dodsdir])
	    return
	  end
	end
      else
	% just in case we ran into a local inputdlg, clear it before using
	clear inputdlg
      end
      cmd = sprintf('%s', [ 'answer = inputdlg(sprintf(''Load options from m-file: (this file MUST be\nin your Matlabpath)''), ', ...
	      '''DODS Browse: load options'', 1, {fname});']);
      eval(cmd)
      if ~isempty(answer)
	answer = char(answer);
	browse('loadopts',answer)
      end
    end
    return
  elseif strcmp(argin,'loadopts')
    fname = deblank(second_arg);
    l = length(fname);
    % strip off '.m' if there is one
    if strcmp(fname(l-1:l),'.m')
      fname = fname(1:l-2);
    end
    dirsep = '/';
    c = computer;
    if strcmp(c(1:2),'PC')
      dirsep = '\';
    elseif strcmp(c(1:2),'MA')
      dirsep = ':';
    end
    if any(findstr(fname,dirsep))
      % HERE
      disp([ 'Error! Options file specification cannot ', ...
	    'contain any directory information!'])
      i = max(findstr(fname,dirsep));
      fname = fname(i+1:length(fname));
      disp([ 'Evaluating and loading ' fname])
    end
    if exist(fname) == 2
      % HERE
      s = which(fname);
      disp([ 'loading saved options file ' s])
    else
      % HERE
      disp([ 'Options file not found. Please check path and ', ...
	    'filename specfications.'])
      return
    end

    % first preserve some values in case the options file is buggy
    old_axes_vals = axes_vals;
    old_ranges = ranges;
    old_manURL = manURL;
    old_dods_colors = dods_colors;
    old_num_rang = num_rang;
    old_timetoggle = timetoggle;
    old_available_resolutions = available_resolutions;
    old_check_level = check_level;
    old_color_limits = color_limits;
    old_figsize = get(browse_fig,'position'); 
    % now load the new options
    eval(fname)

    % Location of HTML documentation
    if isempty(deblank(manURL))
      manURL = 'http://dods.gso.uri.edu/DODS/user/mgui-html/mgui.html';
    else
      manURL = old_manURL;
    end
    
    % color scheme
    if ~isempty(dods_colors) 
      if all(size(dods_colors) == [10 3]) & ...
	    all(dods_colors >= 0) & all(dods_colors <= 1)
	% do nothing, we're fine
      else
	dods_colors = old_dods_colors;
      end
    else
      dods_colors = old_dods_colors;
    end

    % axis values
    if ~isempty(axes_vals)
      if all(size(axes_vals) == [1 8])
	% now check to make sure limits are valid
	if axes_vals(2) <= axes_vals(1) & ...
	      axes_vals(4) <= axes_vals(3) & ...
	      axes_vals(6) <= axes_vals(5) & ...
	      axes_vals(8) <= axes_vals(7)
	  % we're fine
	else
	  axes_vals = old_axes_vals;
	end
      else
	axes_vals = old_axes_vals;
      end
    else
      axes_vals = old_axes_vals;
    end

    if ~isempty(num_rang)
      if all(size(num_rang(:)) == [8 1]) & ...
	    all ((num_rang == 0) | (num_rang == 1))
	% we're fine, do nothing
      else
	num_rang = old_num_rang;
      end
    else
      num_rang = old_num_rang;
    end

    if ~isempty(ranges) 
      if all (ranges(1,:) >= master_georange(1)) & ...
	    all(ranges(1,:) <= master_georange(2)) & ...
	    all(ranges(2,:) >= master_georange(3)) & ...
	    all(ranges(2,:) <= master_georange(4)) & ...
	    all(ranges(3,:) >=  master_zrange(1)) & ...
	    all(ranges(3,:) <= master_zrange(2)) & ...
	    all(ranges(4,:) >= master_timerange(1)) & ...
	    all(ranges(4,:) <= master_timerange(2))
	% we're fine, do nothing 
      else
	ranges = old_ranges;
      end
    else
      ranges = old_ranges;
    end
  
    if ~isempty(timetoggle)
      if timetoggle == 0 | timetoggle == 1
	% we're fine, do nothing
      else
	timetoggle = old_timetoggle; 
      end
    else
      timetoggle = old_timetoggle; 
    end
  
    if ~isempty(fontsize)
      if fontsize >= 10 & fontsize <= 16 & fontsize == round(fontsize) 
	%we're fine, do nothing
      else
	fontsize = old_fontsize;
      end
    else
      fontsize = old_fontsize;
    end
  
    if ~isempty(available_resolutions)
      if all(available_resolutions == round(available_resolutions)) & ...
	    all(available_resolutions == abs(available_resolutions))
	%we're fine, do nothing
      else  
	available_resolutions = old_available_resolutions;
      end
    else
      available_resolutions = old_available_resolutions;
    end
    
    if ~isempty(figsize)
      if all(size(figsize) == [1 4]) 
	if all(figsize(3:4) > 0)
	  fig_offset = figsize(1:2);
	  fig_size = figsize(3:4);
	else
	  fig_offset = old_figsize(1:2);
	  fig_size = old_figsize(3:4);
	end
      else
	fig_offset = old_figsize(1:2);
	fig_size = old_figsize(3:4);
      end
    else
      fig_offset = old_figsize(1:2);
      fig_size = old_figsize(3:4);
    end
    
    % for these last two, nothing further need be done
    if isempty(check_level)
      check_level = old_check_level;
    end
  
    if length(color_limits) < 2
      color_limits = old_color_limits;
    end

    % END OF OPTIONS THAT MAY BE SET IN BROWSOPT.M
  
    % now we need to: 
    % set the help manual location
    % set the resolutions menu
    % set the figure size and location
    % set the font size
    % refresh the figure with new dodscolors
    % reset the time labels
    % set the axes
    % set the color limits
    % refresh the figure with a new palette
    
    % set the help manual location
    callbackstring = sprintf('!%s %s &', docopt, manURL);
    ui_manual = uimenu(ui_help, 'callback', callbackstring);
    
    % set the figure size and location
    set(browse_fig, 'Position',[fig_offset fig_size])
    
    % set the fontsize
    browse('fontsize',fontsize)
    
    % set the dodscolors
    browse('changecolor')
    
    % reset the timelabel
    browse('timetoggle',timetoggle)
    
    if VERSION < 5
      aspectstring = sprintf('set(AXES(1),%s,[%g 1])', ...
	  '''AspectRatio''', diff(axes_vals(1:2))/diff(axes_vals(3:4)));
    else
      aspectstring = sprintf('set(AXES(1), %s, [%i %i 1], %s, [1 1 1])', ...
	  '''PlotBoxAspectRatio''', ...
	  [diff(axes_vals(1:2)) diff(axes_vals(3:4))], ...
	  '''DataAspectRatio''');
    end
    figure(browse_fig)
    set(AXES(1), 'xlim', axes_vals(1:2), 'ylim', axes_vals(3:4))
    eval(aspectstring)
    set(AXES(2), 'xlim', [0 1], 'ylim', axes_vals(5:6))
    set(AXES(3), 'xlim', axes_vals(7:8), 'ylim', [0 1])
    drawnow
    % set all the range boxes and WESN edit boxes with the range
    browse('bsetrange')
    % see which datasets are valid
    scroll('datset')
    % clear URL count and URL string
    browse('gsetrange')
    % set up the new palette
    if ~isempty(palettefile)
      if exist(palettefile) == 2
	browse('paletteswap')
      end
    end
  elseif strcmp(argin,'moreon')
    num_urls = second_arg;
    if num_urls > 1
      set(gui_buttons(6),'visible','on','userdata','more images')
    elseif ~isempty(image_string)
      if length(image_string) == (image_string(1)+1)
	set(gui_buttons(6),'visible','off','userdata','')
      end
    end
    return
  elseif strcmp(argin,'newboxes')
    figure(browse_fig);
    subplot(AXES(1)); 
    % delete current range box and worldmap
    if range_boxes(1) > 0
      delete(range_boxes(1))
    end
    if ~isempty(worldmap)
      delete(worldmap)
    end
    
    % reset worldmap
    if master_georange(1) == 0;
      offset = 360;
    else
      offset = 0;
    end
    if isempty(dodsdir)
      dir = which('browse');
      dirsep = '/';
      c = computer;
      if strcmp(c(1:2),'PC')
	dirsep = '\';
      elseif strcmp(c(1:2),'MA')
	dirsep = ':';
      end
      i = max(findstr(dir,dirsep));
      dodsdir = dir(1:i);
    end
    fname = [dodsdir 'coastln'];
    eval(['load ' fname])
    x = coastlines(1,:); 
    x(coastinx) = x(coastinx)+offset;
    worldmap = line(x,coastlines(2,:), ...
	'Color',dods_colors(3,:), ...
	'Erasemode','none','visible','off'); drawnow
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      set(worldmap,'visible','on')
    end
    clear coastlines
    % set x-range: THIS IS A MESS AND NEEDS TO BE FIXED UP
    % less of a mess as of 98/04/20 
    xl = ranges(1,:);
    xl = xrange('range', master_georange, ranges(1,:));
    if max(size(xl) > 2)
      xl = xl(2:3)
      xl = [xl(1:2) xl(2) xl(2) xl(2) xl(1) xl(1) xl(1)];
    else
%      if xl(1) == xl(2)
%	xl(2) = xl(2)+360;
%      end
      xl = [xl(1:2) xl(2) xl(2) xl(2) xl(1) xl(1) xl(1)];
    end
    
%    xl = xrange('range', master_georange, ranges(1,:));
%    if all(size(xl) == [1 2])
%      if ranges(1,1) > ranges(1,2)
%	xl = xl([2 1]);
%	if xl(1) == 360
%	  xl(1) = 0;
%	end
%      end
%    else
%      xl = xl(2:3);
%    end
%    xl = [xl(1:2) xl(2) xl(2) xl(2) xl(1) xl(1) xl(1)];
    yl = [ranges(2,1) ranges(2,1) ranges(2,1) ranges(2,2) ...
	  ranges(2,2) ranges(2,2) ranges(2,2) ranges(2,1)];
    range_boxes(1) = line(xl, yl,'color',dods_colors(10,:), ...
	'visible','off', 'linewidth', 2);
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      set(range_boxes(1),'visible','on')
    end

    if ~isempty(image_string)
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	set(image_string(2:image_string(1)+1),'visible','on')
      end
    end
    return
  elseif strcmp(argin,'newplot')
    % this keeps a list of image handles
    image_string = [image_string; size(second_arg,1); second_arg(:)];
    return
  elseif strcmp(argin,'nextplot')
    if length(image_string) > 0
      delete(image_string(2:image_string(1)+1));
      k = image_string(1)+1;
      if length(image_string) > k
	kk = k+1;
	l = image_string(k+1);
	set(image_string(kk+1:kk+l),'visible','on');
	image_string = image_string(kk:size(image_string,1),:);
	set(gui_buttons(6),'userdata','more images')
      end
      if length(image_string) == (image_string(1)+1)
	set(gui_buttons(6),'visible','off','userdata','')
      end
    else
      set(gui_buttons(6),'visible','off','userdata','')
    end
    return
  elseif strcmp(argin,'oops!')
    set(gui_buttons(26:28),'visible','off')
    set(gui_buttons(1),'backgroundcolor',dods_colors(7,:))
    return
  elseif strcmp(argin,'palettedlg')
    if VERSION < 5 
      OKCallback = ['Qmenu = gcf; browse(''paletteswap'', ' ...
	    'get(findobj(Qmenu,''Style'',''edit''),''String''));' ...
	    'delete(Qmenu); clear Qmenu'];
      eval([ 'save_fig = inputdlg(''Load palette file:'', ', ...
	  '''DODS Browse: load palette'',', ...
	  'OKCallback, palettefile);'])
    else
      cmd = sprintf('%s', ...
	  ['answer = inputdlg(''Load palette file:'', ', ...
	      '''DODS Browse: load palette'', 1, {palettefile});']);
      eval(cmd)
      if ~isempty(answer)
	answer = char(answer);
	browse('paletteswap',answer)
      end
    end
    return
  elseif strcmp(argin,'paletteswap')
    if nargin == 2
      palettefile = second_arg;
    end
    % load palette file
    avhrrpal = []; i = []; j = [];
    if ~isempty(palettefile)
      dirsep = '/';
      c = computer;
      if strcmp(c(1:2),'PC')
	dirsep = '\';
      elseif strcmp(c(1:2),'MA')
	dirsep = ':';
      end
      i = max(findstr(palettefile,dirsep))+1;
      if isempty(i)
	i = 1;
      end
      j = max(findstr(palettefile,'.'))-1;  
      if isempty(j)
	j = length(palettefile);
      end
      if exist(palettefile) == 2
	eval(['load ' palettefile])
	eval(['avhrrpal = ' palettefile(i:j) ';'])
      else
	% HERE 
	disp('Not able to load requested palettefile!')
	dir = which('browse');
	l = findstr(dir,'browse.m')-1;
	dir = dir(1:l);
	palettefile = [dir 'avhrrpal.pal'];
	eval(['load ' palettefile])
      end
    else
      dir = which('browse');
      l = findstr(dir,'browse.m')-1;
      dir = dir(1:l);
      palettefile = [dir 'avhrrpal.pal'];
      eval(['load ' palettefile])
    end
    avhrrpal(1,:) = dods_colors(2,:);
    % THIS IS A NEW AS OF 98/09/13 -- dbyrne
    if ~isempty(browse_fig)
      c1 = get(browse_fig,'colormap');
      c1 = size(c1,1);
      set(browse_fig,'colormap',avhrrpal)
      c2 = size(avhrrpal,1);
      % if the size of the color palettes is different,
      % rescale any images on the geographic window 
      if c1 ~= c2
	k = findobj(AXES(1), 'type', 'image');
	k = [k; findobj(AXES(1), 'type', 'surface')];
	for i = 1:length(k)
	  x = get(k(i),'cdata');
	  x = x*c2/c1;  
	  set(k(i),'cdata',x)
	end
      end
    end
    % END OF NEW PART
    return
  elseif strcmp(argin,'qlevel')
    set(gui_buttons([19:21 29]),'visible','on','units','pixels')
    set(gui_buttons(21),'string',sprintf('%g',check_level))
    return
  elseif strcmp(argin,'quit')
    k = get(0,'children');
    browse_figs = [];
    if any(k == scroll_fig(1))
      browse_figs = [browse_figs scroll_fig(1)];
    end
    if any(k == scroll_fig(2))
      browse_figs = [browse_figs scroll_fig(2)];
    end
    if any(k == display_fig)
      browse_figs = [browse_figs display_fig];
    end
    if any(k == browse_fig)
      browse_figs = [browse_figs browse_fig];
      clear_button = browse_figs;
    end
    return
  elseif strcmp(argin,'reallygetdata')
  elseif strcmp(argin,'resetcount')
    global_data_list = '';
    count = 1;
    % turn off the 'clear all Rxx button'
    set(prefs(6),'callback','','enable','off');
    set(ui_display,'enable','off')
    dispmenu('resetcallback')
    if ~isnan(dset)
      archive = deblank(master_archives(dset,:));
    else
      return
    end
    if exist(archive) == 2
      eval(archive)
    else
      if dset > 0
      % HERE
	disp('Metadata not found!')
      end
      dset = nan;
      archive = '';
      getxxx = '';
      return
    end

    % reset button callbacks and buttons
    if ~isnan(dset) & ~isnan(var) & sum(num_rang) == 8
      callbackstring = sprintf('[%s] = browse(''getdata''); unpack', ...
	  returnstring);
      set(gui_buttons(1),'callback', callbackstring, ...
	  'backgroundcolor',dods_colors(7,:))
      callbackstring = sprintf('[%s] = browse(''getdata'',''ok''); unpack', ...
	  returnstring);
      set(gui_buttons(24), 'callback',callbackstring)

      if VERSION < 5
	callbackstring = sprintf('browse(''getdata'',''cancel''); clear %s', ...
	    returnstring);
      else
	callbackstring = 'browse(''getdata'',''cancel'')';
      end
      set(gui_buttons(25),'callback',callbackstring)
    else
      set(gui_buttons(1),'callback','browse(''getdata'')')
    end
    
    return
  elseif strcmp(argin,'resetdefault')

    % figure size and position
    scr_size = get(0,'ScreenSize'); scr_offset = scr_size(1:2); 
    scr_size = scr_size(3:4);
    % set up window characteristics
    fig_size = [round(scr_size(1)*0.9) round(scr_size(2)*0.67)];
    % minimum acceptable size
    fig_size(1) = max([fig_size(1) 600]);
    fig_size(2) = max([fig_size(2) 400]);
    fig_offset = [30 35];
    
    % resolution
    available_resolutions = [32 24 16 12 8 4 3 2 1];
    
    % font
    fontsize = 10;
    browse('fontsize',fontsize)

    % the color scheme
    dods_colors = [0.702 0.702 0.702; % 1 vanilla -- the matlab default button color
                   0.5   0.5   0.5;   % 2 color for axis and window background
	  	   1     1     1;     % 3 color for axis and window foreground
                   1     1     1;     % 4 color for non-interactive win and axis text 
		   1     0.5   0.5;   % 5 color for edit boxes (pink)
		   0     0     0;     % 6 color for edit box text & button labels
		   0.3   0.5   1;     % 7 color for Get Data! button
		   0     0     1;     % 8 color for text & axis lines that change
		   0.7   0     0;     % 9 whizzo -- the special color
		   1     0     0];    % 10 selection range box color
    
    browse('changecolor')
    
    % the time
    timetoggle = 1;
    set(prefs(2),'label','Time in Year/Yearday', ...
	'callback','browse(''timetoggle'',0)');
    browse('timetoggle',1)

    % selection ranges
    num_rang = zeros(8,1);
    ranges = nan*ones(4,2);
    
    % dataset and variable
    dset = nan;
    var = nan;
    scroll('dreset')
    scroll('vreset')
    
    % AXIS LIMITS
    axes_vals = [master_georange(1:2)+[-5 5] master_georange(3:4)+[-1 1] ...
	    master_zrange+[-50 0] master_timerange];

    % Geographic axis
    set(get(AXES(1),'zlabel'),'userdata',axes_vals(1:4))
    set(AXES(1), 'xlim', axes_vals(1:2), 'ylim', axes_vals(3:4))

    % the longitude (includes aspect ratio)
    set(prefs(1),'label','Start Longitude 0E', ...
	'callback','browse(''setlon'',360)');
    browse('setlon',0)
    
    % Depth axis
    set(get(AXES(2),'zlabel'),'userdata',[0 1 axes_vals(5:6)])
    set(AXES(2), 'xlim', [0 1], 'ylim', axes_vals(5:6))
    kids = get(AXES(2),'children');
    i = find(kids ~= range_boxes(2));
    delete(kids(i)); 
    xl = [0.01 0.99];
    set(range_boxes(2),'xdata',[xl(1:2) xl(2) xl(2) xl(2) xl(1) xl(1) xl(1)], ...
	'ydata', [ranges(3,1) ranges(3,1) ranges(3,1) ranges(3,2) ...
	    ranges(3,2) ranges(3,2) ranges(3,2) ranges(3,1)], ...
	'visible','on')

    % Time axis
    set(get(AXES(3),'zlabel'),'userdata',[axes_vals(7:8) 0 1])
    set(AXES(3),'xlim', axes_vals(7:8),'ylim',[0 1], ...
	'xtickmode','auto','xticklabelmode','auto')
    set(tstring(1),'string','Time in Years','color',dods_colors(4,:))
    set(tstring(2),'string','1 JAN 1800','color',dods_colors(8,:))

    % clear old labels and dataset plots
    if ~isempty(thandle), delete(thandle); thandle = []; end
    if ~isempty(lhandle), delete(lhandle); lhandle = []; end
    kids = get(AXES(3),'children');
    for i = 1:length(kids)
      if ~any(kids(i) == [range_boxes(3); tstring(:)])
	delete(kids(i));
      end
    end

    % check_level is 1Mb
    check_level = 1;

    % clims are 0 255
    color_limits = [0 255];
    set(AXES(1),'clim',color_limits)

    % change my mind on this:
    
%    % palettefile is avhrr
%    dir = which('browse');
%    dirsep = '/';
%    c = computer;
%    if strcmp(c(1:2),'PC')
%      dirsep = '\';
%    elseif strcmp(c(1:2),'MA')
%      dirsep = ':';
%    end
%    i = max(findstr(dir,dirsep));
%    dodsdir = dir(1:i);

    dodsdir = '';
    palettefile = [dodsdir 'avhrrpal.pal'];
    browse('paletteswap')
    
    browse('bsetrange')
    set(gui_buttons(39),'string','')
    refresh(browse_fig)
    return
  elseif strcmp(argin,'resolution')
    % set subsampling resolution, if possible
    dset_stride = available_resolutions(second_arg);
    set(ui_stride(second_arg),'checked','on')
    k = 1:length(available_resolutions);
    ii = find(k ~= second_arg);
    set(ui_stride(ii),'checked','off')
    return
  elseif strcmp(argin,'saveaxes')
    axes_vals = [get(AXES(1),'xlim') get(AXES(1),'ylim') ...
	    get(AXES(2),'ylim') get(AXES(3),'xlim')];
    return
  elseif strcmp(argin,'savedlg')
    if isempty(dodsdir)
      dir = which('browse');
      dirsep = '/';
      c = computer;
      if strcmp(c(1:2),'PC')
	dirsep = '\';
      elseif strcmp(c(1:2),'MA')
	dirsep = ':';
      end
      i = max(findstr(dir,dirsep));
      dodsdir = dir(1:i);
    end
    fname = [dodsdir 'browsopt.m'];
    if VERSION < 5
      % FIG = INPUTDLG(PromptString,DlgName,OKCallback,DefEditStr)
      OKCallback = ['Qmenu = gcf; browse(''saveopts'', ' ...
	    'get(findobj(Qmenu,''Style'',''edit''),''String''));' ...
	    'delete(Qmenu); clear Qmenu'];
      % this is couched in an eval to prevent error messages on startup
      eval([ 'save_fig = inputdlg(''Save options to m-file:'',', ...
	  '''DODS Browse: save options'', ', ...
	  'OKCallback, fname);'])
    else
      % additional check to make sure local inputdlg.m is NOT USED
      w = which('inputdlg.m','-all');
      s = size(w,1);
      if s > 1
	for i = 1:s
	  cmd = char(w(i));
	  if ~isempty(findstr(cmd,dodsdir))
	    disp('                ')
	    disp('    PLEASE RENAME OR REMOVE THE FILE ''inputdlg.m'' ')
	    disp(['    IN YOUR BROWSER SOURCE DIRECTORY: ' dodsdir])
	    return
	  end
	end
      else
	% just in case we ran into a local inputdlg, clear it before using
	clear inputdlg
      end
      % this must be couched in a string or Matlab 4 will break
      cmd = sprintf('%s', [ 'answer = inputdlg(''Save options to m-file:'', ', ...
	      '''DODS Browse: save options'', 1, {fname});']);
      eval(cmd)
      if ~isempty(answer)
	answer = char(answer);
	browse('saveopts',answer)
      end
    end
    return
  elseif strcmp (argin,'saveopts')
    fname = deblank(second_arg);
    if ~isempty(fname)
      % add a '.m' if necessary
      l = length(fname);
      if ~strcmp(fname(l-1:l),'.m')
	fname = [fname '.m'];
      end
      fid = fopen(fname,'w');
      if fid > -1
	% do save stuff (create browsopt.m)
	fprintf(fid,'%s\n','% DODS browse.m options file.  This is a matlab');
	fprintf(fid,'%s\n','% script file.  Customize by hand if you wish.');
        fprintf(fid,'\n');
	fprintf(fid,'%s\n','% Year in YEAR/MONTH/DAY or YEAR/YEARDAY');
	fprintf(fid,'%s%i%s\n','timetoggle = ',timetoggle,';');
        fprintf(fid,'\n');
	fprintf(fid,'%s\n', ...
	    '% COLORS: the color scheme. See browse.m line 237 for color usage.');
	fprintf(fid,'%s\n','dods_colors = [');
	fprintf(fid,'%g %g %g;\n', dods_colors');
	fprintf(fid,'];\n');
        fprintf(fid,'\n');
        fprintf(fid,'%s%i%s\n', 'fontsize = ', fontsize, ';');
        fprintf(fid,'\n');
	figsize = get(browse_fig,'position');
	fprintf(fid,'%s[%i %i %i %i];\n', 'figsize = ', figsize);
        fprintf(fid,'\n');
	fprintf(fid,'%s[%g %g %g %g %g %g %11.6f %11.6f];\n', ...
	    'axes_vals = ', axes_vals);
        fprintf(fid,'\n');
	fprintf(fid,'%s\n','% Selection ranges: Longitude, Latitude, Depth and Time');
	fprintf(fid,'%s\n','ranges = [');
	fprintf(fid,'%g %g\n',ranges');
	fprintf(fid,'%s\n','];');
        fprintf(fid,'\n');
	fprintf(fid,'%s\n','% Which were user-set.');
	fprintf(fid,'%s','num_rang = [');
	fprintf(fid,'%g ',num_rang');
	fprintf(fid,'%s\n',']'';');
        fprintf(fid,'\n');
        fprintf(fid, '%s\n', ...
	    '% COLOR LIMITS map these data values to limits of color table');
	fprintf(fid,'color_limits = [%g %g];\n', color_limits);
        fprintf(fid,'\n');
        fprintf(fid, '%s\n', ...
	    '% PALETTE FILE -- 255-color default palette.  A 3-column array');
	fprintf(fid,'%s\n','% of R G B values.  Values must lie between 0 and 1.');
	fprintf(fid,'%s%s%s\n', 'palettefile = ''', palettefile, ''';');
        fprintf(fid,'\n');
	fprintf(fid,'%s\n', ...
	    '% Threshold size in Mb of largest dataset to download automatically.');
	fprintf(fid,'%s%g%s\n', 'check_level = ', check_level, ';');
        fprintf(fid,'\n');
	fprintf(fid,'%s\n', ...
	    '% Available resolutions in multiples of the dataset stride.');
	fprintf(fid,'%s', 'available_resolutions = [');
	fprintf(fid,'%g ',available_resolutions);
	fprintf(fid,'%s\n', '];');
	fprintf(fid,'\n');
	fprintf(fid,'%s\n', ...
	    '% The location of the HTML version of the GUI user manual.');
	fprintf(fid,'manURL = ''%s'';\n', manURL);
        fprintf(fid,'\n');
	fclose(fid);
      else
	% HERE
	errordlg(['File ' fname ' unable to be opened. ', ...
		'Please check path and write permissions.'], ...
	    'DODS browser: unable to save options');
      end
    end
    return
  elseif strcmp(argin,'scrollfig')
    k = findobj(0,'type','figure','userdata','DODS variables');
    if isempty(k)
      scroll('vopen')
    else
      scroll_fig(1) = k;
    end
    k = findobj(0,'type','figure','userdata','DODS datasets');
    if isempty(k)
      scroll('dopen')
    else
      scroll_fig(2) = k;
    end
    
    p = get(scroll_fig(second_arg),'pos');
    x = 0;
    if strcmp(get(scroll_fig(second_arg),'visible'),'off')
      set(scroll_fig(second_arg),'visible','on')
      x = 1;
    end
    figure(scroll_fig(second_arg)); 
    if x
      set(scroll_fig(second_arg),'pos',p)
    end
    return
  elseif strcmp(argin,'setcolor')
    colors = [0 0 0; 0.5 0.5 0.5; 1 1 1; ...
	1 0 0; 0 1 0; 0 0 1; 1 1 0; 1 0 1; 0 1 1];
    fcn = round((second_arg-rem(second_arg,10))/10);
    i = rem(second_arg,10);
      if i > 0
	color = colors(i,:);
      end
    if fcn == 1 % set the foreground
      dods_colors(3,:) = color;
      dods_colors(4,:) = color;
    elseif fcn == 2 % set the backgrounds
      dods_colors(2,:) = color;
    elseif fcn == 3 % set the time labels
      dods_colors(8,:) = color;
    elseif fcn == 4 % set the range box color
      dods_colors(10,:) = color;
    elseif fcn == 5 % reset to default color scheme
      dods_colors = [0.702 0.702 0.702; % 1 vanilla: the default button color
	  0.5   0.5   0.5;   % 2 color for axis and window background
	  1     1     1;     % 3 color for axis and window foreground
	  1     1     1;     % 4 color for win and axis text 
	  1     0.5   0.5;   % 5 color for edit boxes
	  0     0     0;     % 6 color for edit box text
	  0.3   0.5   1;     % 7 color for Get Data! button
	  0     0     1;     % 8 color for text & axis lines that change
	  0.7   0     0;     % 9 whizzo -- the special color
	  1     0     0];    % 10 selection range box color
    end
    browse('changecolor')
    return
  elseif strcmp(argin,'setdset')
    % protect against incorrect display menus!
    % set current and previous datasets
    if isnan(dset)
      getxxx = '';
      archive = '';
      set(gui_buttons(1),'callback','browse(''getdata'')')
      set(gui_buttons(2),'string','')
      set(gui_buttons(54),'string','')
      set(gui_buttons(39),'string','')
      % NEW 
      set(gui_buttons(26:28),'visible','off')
      if ~isempty(ui_stride)
	for i = 1:length(ui_stride)
	  if any(findobj(ui_res,'type','uimenu') == ui_stride(i))
	    delete(ui_stride(i))
	  end
	end
      end
      return
    end

    % set output arguments of browse to match output of getxxx
    getxxx = deblank(master_getxxx(dset,:));
    archive = deblank(master_archives(dset,:));
    if exist(archive) == 2
      eval(archive)
    else
      if ~isnan(dset)
	% HERE
	disp('Metadata not found!')
      end
      dset = nan;
      archive = '';
      getxxx = '';
      set(gui_buttons(1),'callback','browse(''getdata'')')
      set(gui_buttons(2),'string','')
      set(gui_buttons(54),'string','')
      set(gui_buttons(39),'string','')
      scroll('datset')
      return
    end

    % SET THE RESOLUTION MENU
    if ~isempty(ui_stride)
      for i = 1:length(ui_stride)
	if any(findobj(ui_res,'type','uimenu') == ui_stride(i))
	  delete(ui_stride(i))
	end
      end
    end
    if ~isnan(master_resolutions(dset))
      l = length(available_resolutions);
      for i = 1:l
	res = available_resolutions(i);
        str1 = sprintf('%4.1f km', res*master_resolutions(dset));
        str2 = sprintf('browse(''resolution'',%i)',i);
        ui_stride(i) = uimenu(ui_res,'label',str1,'callback',str2);
      end
      browse('resolution',l)
    end

    if brs_old_dset ~= dset
      set(gui_buttons(2),'string','');
      set(gui_buttons(54),'string','');
    end
    
    % set the metadata
    if exist('Comments') == 1
      set(gui_buttons(39),'string',Comments)
    else
      set(gui_buttons(39),'string','')
    end
    
    % if there is only one variable, select it 

    if sum(variables) == 1
      brs_old_var = var;
      var = find(variables);
    end
    scroll('varset')

    if all(size(brs_old_var) == size(var))
      if all(brs_old_var ~= var)
	set(gui_buttons(2),'string','');
	set(gui_buttons(54),'string','');
      end
    end
    
    % draw dataset range info on maps
    figure(browse_fig)
    x = xrange('range', master_georange, [master_rangemin(dset,1) ...
	    master_rangemax(dset,1)]);
    y = [master_rangemin(dset,2) master_rangemax(dset,2)];
    if max(size(x) == 2)
      xl = [x(1:2) x(2) x(2) x(2) x(1) x(1) x(1)];
      yl = [y(1) y(1) y(1:2) y(2) y(2) y(2) y(1)];
    else
      % two boxes
      xl = [x(1:2) x(2) x(2) x(2) x(1) x(1) x(1) nan ...
	      x(3:4) x(4) x(4) x(4) x(3) x(3) x(3)];
      yl = [y(1) y(1) y(1:2) y(2) y(2) y(2) y(1) nan ...
	      y(1) y(1) y(1:2) y(2) y(2) y(2) y(1)];
    end
    
    subplot(AXES(1)); 
    h = line(xl,yl, 'color',datacolor(dset,:), ...
	'erasemode','none','clipping','on','visible','off'); drawnow
    i = plot(xl,yl, '*','color',datacolor(dset,:), ...
	'erasemode','none','clipping','on','visible','off'); drawnow
    % default to whole georange of dataset, politely 
    if sum(num_rang(1:4)) == 0
      % set y-range
      ranges(2,:) = y;
      
      % set x-range
      tmpx = xrange('range', [-180 180 -90 90], ...
	  [master_rangemin(dset,1) master_rangemax(dset,1)]);
      ranges(1,:) = tmpx;
      num_rang(1:4) = [1 1 1 1]';
      xl = xrange('range', master_georange, ...
	  [master_rangemin(dset,1) master_rangemax(dset,1)]);
      % if xl ever comes back with > 2 elements, there will
      % produce a bug here.
      xl = [xl(1:2) xl(2) xl(2) xl(2) xl(1) xl(1) xl(1)];
      yl = [ranges(2,1) ranges(2,1) ranges(2,1) ranges(2,2) ...
		ranges(2,2) ranges(2,2) ranges(2,2) ranges(2,1)];
      set(range_boxes(1),'xdata', xl, 'ydata', yl,'visible','off')

      if strcmp(get(gui_buttons(30),'string'),'View Text')
	set(range_boxes(1),'visible','on')
      end
      browse('bsetrange') % set edit box text 
    end
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      h = [h(:); i(:)];
      set(h,'visible','on')
    end

    figure(browse_fig); subplot(AXES(2)); 
    x = 0.90*dset/num_sets;
    yl = [master_rangemin(dset,3) master_rangemax(dset,3)];
    h = line([x x], yl, 'color',datacolor(dset,:),'erasemode','none', ...
	'clipping','on','visible','off'); drawnow
    i = plot([x x], yl, '*','color',datacolor(dset,:),'erasemode','none', ...
	'clipping','on','visible','off'); drawnow
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      set([h i], 'visible','on')
    end
    % default to whole depth of dataset. 
    % OVERRIDES USER-SET RANGES! RUDE! (Peter insisted.)
    if ~isnan(master_rangemin(dset,3)) & ~isnan(master_rangemax(dset,3))
      ranges(3,:) = [master_rangemin(dset,3) master_rangemax(dset,3)];
    end
    if ~isnan(ranges(3,1)) & ~isnan(ranges(3,2))
      num_rang(5:6) = [1 1]';
      set(gui_buttons(12),'String',sprintf(' %.2f',ranges(3,2)))
      set(gui_buttons(13),'String',sprintf(' %.2f',ranges(3,1)))
    end
    xl = [0.01 0.99];
    set(range_boxes(2),'xdata',[xl(1:2) xl(2) xl(2) xl(2) xl(1) xl(1) xl(1)], ...
	'ydata', [ranges(3,1) ranges(3,1) ranges(3,1) ranges(3,2) ...
	    ranges(3,2) ranges(3,2) ranges(3,2) ranges(3,1)])
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      set(range_boxes(2),'visible','on')
    end
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      h = [h(:); i(:)];
      set(h,'visible','on')
    end
      
    figure(browse_fig); subplot(AXES(3)); 
    xl = [master_rangemin(dset,4) master_rangemax(dset,4)];
    y = 0.90*dset/num_sets;
    h = line(xl, [y y], 'color',datacolor(dset,:),'erasemode','none', ...
	'clipping','on','visible','off'); drawnow
    i = plot(xl, [y y], '*','color',datacolor(dset,:),'erasemode','none', ...
	'clipping','on','visible','off'); drawnow
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      set([h i], 'visible','on')
    end

    if strcmp(get(gui_buttons(30),'string'),'View Text')
      h = [h(:); i(:)];
      set(h,'visible','on')
    end

    if VERSION < 5
      callbackstring = sprintf('browse(''getdata'',''cancel''); clear %s', ...
	  returnstring);
    else
      callbackstring = 'browse(''getdata'',''cancel'')';
    end
    set(gui_buttons(25),'callback',callbackstring)
    if sum(num_rang) == 8 & sum(isnan(ranges)) == 0
      callbackstring = sprintf('[%s] = browse(''getdata''); unpack', ...
	  returnstring);
      set(gui_buttons(1),'callback', callbackstring, ...
	'backgroundcolor',dods_colors(7,:))
      callbackstring = sprintf('[%s] = browse(''getdata'',''ok''); unpack', ...
	  returnstring);
      set(gui_buttons(24), 'callback',callbackstring)
    else
      set(gui_buttons(1),'callback','browse(''getdata'')')
      set(gui_buttons(24),'callback','')
    end
    return
  elseif strcmp(argin,'setlevel')
    x = get(gui_buttons(21),'string');
    if ~isempty(x)
      check_level = sscanf(x,'%g');
    end
    set(gui_buttons([19:21 29]),'visible','off')
    return
  elseif strcmp(argin,'setlon')
    % set the master georange
    offset = second_arg;
    if offset == 360
      callbackstring = 'browse(''setlon'',0)';
      set(prefs(1),'label','Start Longitude 180W','callback',callbackstring);
      master_georange = [0 360 -90 90];
    elseif offset == 0
      callbackstring = 'browse(''setlon'',360)';
      set(prefs(1),'label','Start Longitude 0E','callback',callbackstring);
      master_georange = [-180 180 -90 90];
    end
    % now turn off zoom -- saved axes values will be incorrect 
    subplot(AXES(1)); newzoom off; subplot(AXES(2)); newzoom off; 
    subplot(AXES(3)); newzoom off
    set(gui_buttons(5),'backgroundcolor', dods_colors(1,:));
    % reset axes all the way 'out'
    axes_vals = [master_georange(1:2)+[-5 5] master_georange(3:4)+[-1 1] ...
	    master_zrange+[-50 0] master_timerange];
    set(get(AXES(1),'zlabel'),'userdata',axes_vals(1:4))
    set(get(AXES(2),'zlabel'),'userdata',[0 1 axes_vals(5:6)])
    set(get(AXES(3),'zlabel'),'userdata',[axes_vals(7:8) 0 1])
    subplot(AXES(1))
    % set new coastline
    if isempty(dodsdir)
      dir = which('browse');
      dirsep = '/';
      c = computer;
      if strcmp(c(1:2),'PC')
	dirsep = '\';
      elseif strcmp(c(1:2),'MA')
	dirsep = ':';
      end
      i = max(findstr(dir,dirsep));
      dodsdir = dir(1:i);
    end
    fname = [dodsdir 'coastln'];
    eval(['load ' fname])
    x = coastlines(1,:); 
    x(coastinx) = x(coastinx)+offset;
    set(worldmap,'xdata',x); 
    clear coastlines
    
    % reset aspect ratio
    set(AXES(1),'xlim',axes_vals(1:2),'ylim',axes_vals(3:4));
    if VERSION < 5
      aspectstring = sprintf('set(AXES(1),%s,[%g 1])', ...
	  '''AspectRatio''', diff(axes_vals(1:2))/diff(axes_vals(3:4)));
    else
      aspectstring = sprintf('set(AXES(1), %s, [%i %i 1], %s, [1 1 1])', ...
	  '''PlotBoxAspectRatio''', ...
	  [diff(axes_vals(1:2)) diff(axes_vals(3:4))], ...
	  '''DataAspectRatio''');
    end
    eval(aspectstring)
 
    % I don't know why I thought this was necessary and it creates
    % problems, so get rid of it.
    
%    % get rid of plots and things
%    kids = get(AXES(1),'children');
%
%    % honor image_string sequence
%    if length(image_string) > 0
%      % skip the first image
%      h = []; l = 1;
%      while l < length(image_string)
%	k = image_string(l);
%	h = [h; image_string(l+1:l+k)];
%	l = l+k+1;
%      end
%      for i = 1:length(kids),
%	if ~any(kids(i) == [range_boxes(1); worldmap(:); h(:)])
%	  delete(kids(i))
%	end
%      end
%    else
%      for i = 1:length(kids),
%	if ~any(kids(i) == [range_boxes(1); worldmap(:)])
%	  delete(kids(i))
%	end
%      end
%    end
    if ranges(1,1) < ranges(1,2)
      x = ranges(1,:);
    else
      x = [ranges(1,2) ranges(1,1)+360];
    end
    x = xrange('range', master_georange, x);
    if max(size(x) > 2)
      % do not allow wraparound range selection
      if range_boxes(1) > 0
	set(range_boxes(1),'visible','off');
      end
      num_rang(1:2) = [0 0];
      set(gui_buttons(8:9),'string','')
      scroll('datset')
    else
      if range_boxes(1) > 0
	set(range_boxes(1),'xdata',[x(1:2) x(2) x(2) x(2) x(1) x(1) x(1)])
      end
      if ~isnan(x(1))
	set(gui_buttons(8),'String',sprintf(' %.2f',x(1)))
      end
      if ~isnan(x(2))
	set(gui_buttons(9),'String',sprintf(' %.2f',x(2)))
      end
    end
    return
  elseif strcmp(argin,'setrange'), 	% turn zoom off and stasel on
    figure(browse_fig)
    if all(get(gui_buttons(3),'backgroundcolor') == dods_colors(9,:))
      select(0);
      set(gui_buttons(3),'backgroundcolor',dods_colors(1,:))
    else
      subplot(AXES(1)); newzoom off; subplot(AXES(2)); newzoom off; 
      subplot(AXES(3)); newzoom off
      set(gui_buttons(5),'backgroundcolor',dods_colors(1,:))
      select(1);
      set(gui_buttons(3),'backgroundcolor',dods_colors(9,:))
    end
    return
  elseif strcmp(argin,'swapview')
    view = get(gui_buttons(30),'string');
    if strcmp(view,'View Text') % we are switching to text-only
      set([AXES(1:3) worldmap range_boxes(:)' tstring(:)'],'visible','off')
      if ~isempty(thandle)
	set(thandle,'visible','off')
      end
      if ~isempty(lhandle)
	set(lhandle,'visible','off')
      end
      lines = findobj(AXES(1:3),'type','line');
      lines = [lines; findobj(AXES(1:3),'type','image')];
      lines = [lines; findobj(AXES(1:3),'type','surface')];
      set(lines,'visible','off')
      set(gui_buttons(30),'string','View Plots')
      set(gui_buttons([3 5 6]),'visible','off')
      set(gui_buttons([2 8:17 31:59]),'visible','on')
    else % we are switching to graphic mode
      if sum(num_rang(1:4)) == 4
	set(range_boxes(1),'visible','on')
      end
      if sum(num_rang(5:6)) == 2
	set(range_boxes(2),'visible','on')
      end
      if sum(num_rang(7:8)) == 2
	set(range_boxes(3),'visible','on')
      end
      if ~isempty(thandle)
	set(thandle,'visible','on')
      end
      if ~isempty(lhandle)
	set(lhandle,'visible','on')
      end
      set([AXES(1:3) worldmap tstring(:)'],'visible','on')
      lines = findobj(browse_fig,'type','line');
      lines = [lines; findobj(browse_fig,'type','image')];
      lines = [lines; findobj(browse_fig,'type','surface')];
      % honor image_string sequence
      if length(image_string) > 0 & ~isempty(get(gui_buttons(6),'userdata'))
	set(gui_buttons(6),'visible','on')
	% skip the first image
	h = []; l = image_string(1)+2;
	while l < length(image_string)
	  k = image_string(l);
	  h = [h; image_string(l+1:l+k)];
	  l = l+k+1;
	end
	for i = 1:length(lines),
	  if ~any(lines(i) == [range_boxes(:); h])
	    set(lines(i),'visible','on')
	  end
	end
      else
	for i = 1:length(lines),
	  if ~any(lines(i) == range_boxes)
	    set(lines(i),'visible','on')
	  end
	end
      end
      set(gui_buttons([3 5]),'visible','on')
      set(gui_buttons([2 8:17 31:59]),'visible','off')
      set(gui_buttons(30),'string','View Text')
    end
    return
  elseif strcmp(argin,'timetoggle' )
    timetoggle = second_arg;
    if timetoggle == 0
      callbackstring = 'browse(''timetoggle'',1)';
      set(prefs(2),'label','Time in Year/Month/Day','callback',callbackstring);
    elseif timetoggle == 1
      callbackstring = 'browse(''timetoggle'',0)';
      set(prefs(2),'label','Time in Year/Yearday','callback',callbackstring);
    end
    timelbl(get(AXES(3),'xlim'))
    return
  elseif strcmp(argin,'trange');
    x = sscanf(get(gui_buttons(14),'string'),'%g');
    if ~isempty(x)
      ranges(4,1) = x;
      num_rang(7) = 1;
      lmo = [31 28 31 30 31 30 31 31 30 31 30 31];
      if rem(floor(ranges(4,1)),4) == 0
	if floor(ranges(4,1)) == 1900 	% 1900 was apparently not a leap year!
	  lyr = 365;
	else
	  lyr = 366;
	  lmo(2) = 29;
	end
      else
	lyr = 365;
      end
      range_day = floor((ranges(4,1)-floor(ranges(4,1)))*lyr(1))+1; % day of year
      t = min(find(range_day < cumsum(lmo)));
      if isempty(t)
	t = 12;
      end
      % day
      t(2) = range_day(1) - sum(lmo(1:t(1)-1));
      % hr
      t(3) = floor((((ranges(4,1)-floor(ranges(4,1)))*lyr(1)+1)-range_day(1))*24);
      % min
      t(4) = floor(((((ranges(4,1)-floor(ranges(4,1)))*lyr(1)+1)*24 - ...
	  range_day(1)*24)-t(3))*60);
      % sec
      t(5) = floor(((((ranges(4,1)-floor(ranges(4,1)))*lyr(1)+1)*24*60 - ...
	  range_day(1)*24*60)-t(3)*60)*60-t(4)*60);
      for i = 1:5;
	set(gui_buttons(39+i),'string',sprintf('%i',t(i)))
      end
    end
    x = sscanf(get(gui_buttons(15),'string'),'%g');
    if ~isempty(x)
      ranges(4,2) = x;
      num_rang(8) = 1;
      lmo = [31 28 31 30 31 30 31 31 30 31 30 31];
      if rem(floor(ranges(4,2)),4) == 0
	if floor(ranges(4,2)) == 1900 	% 1900 was apparently not a leap year!
	  lyr(2) = 365;
	else
	  lyr(2) = 366;
	  lmo(2) = 29;
	end
      else
	lyr(2) = 365;
      end
      range_day(2) = floor((ranges(4,2)-floor(ranges(4,2)))*lyr(2))+1; % day of year
      t = min(find(range_day(2) < cumsum(lmo)));
      if isempty(t)
	t = 12;
      end
      % day
      t(2) = range_day(2) - sum(lmo(1:t(1)-1));
      % hr
      t(3) = floor((((ranges(4,2)-floor(ranges(4,2)))*lyr(2)+1)-range_day(2))*24);
      % min
      t(4) = floor(((((ranges(4,2)-floor(ranges(4,2)))*lyr(2)+1)*24 - ...
	  range_day(2)*24)-t(3))*60);
      % sec
      t(5) = floor(((((ranges(4,2)-floor(ranges(4,2)))*lyr(2)+1)*24*60 - ...
	  range_day(2)*24*60)-t(3)*60)*60-t(4)*60);
      for i = 1:5;
	set(gui_buttons(44+i),'string',sprintf('%i',t(i)))
      end
    end
    if sum(num_rang(7:8)) == 2
      yl = [0.01 0.99];
      set(range_boxes(3),'xdata',[ranges(4,1:2) ranges(4,2) ranges(4,2) ...
	      ranges(4,2) ranges(4,1) ranges(4,1) ranges(4,1)], ...
	  'ydata', [yl(1) yl(1) yl(1:2) yl(2) yl(2) yl(2) yl(1)])
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	set(range_boxes(3),'visible','on')
      end
    end
    browse('gsetrange')
    scroll('datset')
    return
  elseif strcmp(argin,'update')
    % for safety's sake
    dset = nan;
    var = nan;
    archive = '';
    getxxx = '';
    
    % check that we can write to directory
    fname = [dodsdir 'dodstestfile'];
    fid = fopen(fname,'w');
    if fid > -1
      fclose(fid);
%      THIS IS COMMENTED OUT BECAUSE IT WILL NOT WORK ON ALL SYSTEMS      
%      % check that we have geturl
%      eval(['!which geturl > ' fname])
%      fid = fopen(fname,'r');
%      s = fscanf(fid,'%c');
%      if findstr(lower(s),'not found')
%	% HERE
%	disp(['Unable to find ''geturl'' command.  ', ...
%		'Please make sure it is in your path.'])
%	fclose(fid);
%	eval(['!rm ' fname])
%	return
%      end
      eval(['!rm ' fname])
    else
      % HERE
      disp('Unable to write to selected directory.  Please choose another.')
      return
    end

    if strcmp(second_arg, 'local')
      fnameLocal = 'MANIFEST.lcl';
      if exist(fnameLocal)
        updatlcl(fnameLocal);
      end

    else    
      % Fetch the manifest
      fname = [dodsdir 'DATASETS' dirsep 'MANIFEST'];
      arg = sprintf('%s%s', ...
  	  ['!geturl -v ' master_guiserver 'MANIFEST > '], ...
	  fname);
      eval(arg)
      if exist(fname) ~= 2
        % HERE
        disp('       Unable to retrieve new manifest')
        disp('       Please contact DODS support at bugs@dods.gso.uri.edu')
        return
      end
    
      % be polite: read the manifest and close the file
      fid = fopen(fname,'r');
      files = fscanf(fid,'%c');
      fclose(fid);
    
      dirsep = '/';
      c = computer;
      if strcmp(c(1:2),'PC')
        dirsep = '\';
      elseif strcmp(c(1:2),'MA')
        dirsep = ':';
      end
      
      if strcmp(second_arg,'all')
        master_archives = [];
        master_datasets = [];
        master_dataprops = [];
        master_getxxx = [];
        master_rangemax = [];
        master_rangemin = [];
        master_resolutions = [];
        master_variables = [];
        num_sets = 0;
        num_vars = 0;
      end
      update % execute update script

      fnameLocal = 'MANIFEST.lcl';
      if exist(fnameLocal)
        updatlcl(fnameLocal);
      end
    end

    return
  elseif strcmp(argin,'updatedlg')
    if isempty(dodsdir)
      dir = which('browse');
      dirsep = '/';
      c = computer;
      if strcmp(c(1:2),'PC')
	dirsep = '\';
      elseif strcmp(c(1:2),'MA')
	dirsep = ':';
      end
      i = max(findstr(dir,dirsep));
      dodsdir = dir(1:i);
    end
    fid = fopen('updatstr.m');
    if fid~=-1,
      % File opened successfully
      string = setstr((fread(fid))');
      fclose(fid);
    else
      % HERE
      disp('Unable to open update dialogue')
      return
    end
    k = findobj(0,'type','figure','userdata','DODS updatedlg');
    if ~isempty(k)
      figure(k)
      return
    end
    set(0,'units','pixels')
    scr_size = get(0,'ScreenSize'); scr_offset = scr_size(1:2); 
    scr_size = scr_size(3:4);
    % set up window characteristics
    fig_size = [round(scr_size(1)*0.3) round(scr_size(2)*0.3)];
    % minimum acceptable size
    fig_size(1) = max([fig_size(1) 380]);
    fig_size(2) = max([fig_size(2) 155]);
    fig_offset(1) = 100;
    fig_offset(2) = scr_size(2)*0.5;
    if fig_offset(2)+155 > scr_size(2),
      fig_offset(2) = scr_size(2)-155; 
    end
    h = figure('Name','Update dataset list?', 'numbertitle','off', ...
	'interruptible',switchon, ...
	'units','pixels', ...
	'resize','off',...
	'userdata','DODS updatedlg', ...
	'color',dods_colors(2,:), ...
	'position', [fig_offset fig_size]);
    uicontrol(h,'style','frame', ...
	'units','normalized', ...
	'position',[0 0 1 1], ...
	'backgroundcolor', dods_colors(1,:))
    uicontrol(h,'style','edit', ...
	'max',2, ...
	'units','normalized', ...
	'string',string, ...
	'position',[0 0.4 1 0.6], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:))
    uicontrol(h,'style','edit', ...
	'units','normalized', ...
	'string',dodsdir, ...
	'userdata','DODSDIR', ...
	'position',[0.02 0.3 0.96 0.1], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(5,:), ...
	'callback','browse(''dodsdir'')')
    uicontrol(h,'style','frame', ...
	'units','normalized', ...
	'position',[0 0 1 0.3], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:))
    callbackstring = sprintf('%s; delete(%i); %s', ...
	'browse(''dodsdir'')', h, ...
	'browse(''update'',''new'')');
    uicontrol(h,'style','pushbutton', ...
	'units','normalized', ...
	'string','New Only', ...
	'position',[0.03 0.05 0.18 0.1], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(7,:), ...
	'callback',callbackstring)
    callbackstring = sprintf('%s; delete(%i); %s', ...
	'browse(''dodsdir'')', h, ...
	'browse(''update'',''all'')');
    uicontrol(h,'style','pushbutton', ...
	'units','normalized', ...
	'string','Get ALL', ...
	'position',[0.28 0.05 0.18 0.1], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(7,:), ...
	'callback',callbackstring)
    callbackstring = sprintf('%s; delete(%i); %s', ...
	'browse(''dodsdir'')', h, ...
	'browse(''update'',''local'')');
    uicontrol(h,'style','pushbutton', ...
	'units','normalized', ...
	'string','Get Local', ...
	'position',[0.53 0.05 0.18 0.1], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(7,:)+[0.3 0.2 0], ...
	'callback',callbackstring)
    callbackstring = sprintf('delete(%i)',h);
    uicontrol(h,'style','pushbutton', ...
	'units','normalized', ...
	'string','Cancel', ...
	'position',[0.79 0.05 0.18 0.1], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback',callbackstring)
    return
  elseif strcmp(argin,'wesn');
    % get y-range: not complicated
    x = sscanf(get(gui_buttons(10),'string'),'%g');
    if ~isempty(x)
      if x < master_georange(3)
	x = master_georange(3);
	set(gui_buttons(10),'string',sprintf('%.3f',x));
      elseif x > master_georange(4)
	x = master_georange(4);
	set(gui_buttons(10),'string',sprintf('%.3f',x));
      end
      ranges(2,1) = x;
      num_rang(3) = 1;
    end
    x = sscanf(get(gui_buttons(11),'string'),'%g');
    if ~isempty(x)
      if x < master_georange(3)
	x = master_georange(3);
	set(gui_buttons(11),'string',sprintf('%.3f',x));
      elseif x > master_georange(4)
	x = master_georange(4);
	set(gui_buttons(11),'string',sprintf('%.3f',x));
      end
      ranges(2,2) = x;
      num_rang(4) = 1;
    end

    % get/set x-range: this is complicated
    x = sscanf(get(gui_buttons(8),'string'),' %g');
    if master_georange(1) == 0
      if ~isempty(x)
	if x < master_georange(1)
	  x = master_georange(1);
	  set(gui_buttons(8), 'string', sprintf('%.3f',x))
	elseif x > master_georange(2)
	  x = master_georange(2);
	  set(gui_buttons(8), 'string', sprintf('%.3f',x))
	end	  
	if (x >= 0) & (x < 180)
	  ranges(1,1) = x;
	elseif x >= 180
	  ranges(1,1) = x - 360;
	end
	temp_xrange(1) = x;
	num_rang(1) = 1;
      end
      x = sscanf(get(gui_buttons(9),'string'),'%g');
      if ~isempty(x)
	if x < master_georange(1)
	  x == master_georange(1);
	  set(gui_buttons(9), 'string', sprintf('%.3f',x))
	elseif x > master_georange(2)
	  x = master_georange(2);
	  set(gui_buttons(9), 'string', sprintf('%.3f',x))
	end	  
	if (x >= 0) & (x <= 180)
	  ranges(1,2) = x;
	elseif x > 180
	  ranges(1,2) = x - 360;
	end
	temp_xrange(2) = x;
	num_rang(2) = 1;
      end
      if all(ranges(1,:) == [0 0])
	ranges(1,:) = [-180 180];
      end
      xl = [temp_xrange temp_xrange(2) temp_xrange(2) ...
	    temp_xrange(2) temp_xrange(1) temp_xrange(1) temp_xrange(1)]; 
      yl = [ranges(2,1) ranges(2,1) ranges(2,1) ranges(2,2) ...
	    ranges(2,2) ranges(2,2) ranges(2,2) ranges(2,1)];
    else
      if ~isempty(x)
	if x < master_georange(1)
	  x = master_georange(1);
	  set(gui_buttons(8),'string', sprintf('%i',x))
	elseif x > master_georange(2)
	  x = master_georange(2);
	  set(gui_buttons(8),'string', sprintf('%i',x))
	end
	ranges(1,1) = x;
	num_rang(1) = 1;
      end
      x = sscanf(get(gui_buttons(9),'string'),'%g');
      if ~isempty(x)
	if x < master_georange(1)
	  x = master_georange(1);
	  set(gui_buttons(9),'string', sprintf('%i',x))
	elseif x > master_georange(2)
	  x = master_georange(2);
	  set(gui_buttons(9),'string', sprintf('%i',x))
	end
	ranges(1,2) = x;
	num_rang(2) = 1;
      end
      xl = [ranges(1,1:2) ranges(1,2) ranges(1,2)  ...
	    ranges(1,2) ranges(1,1) ranges(1,1) ranges(1,1)];
      yl = [ranges(2,1) ranges(2,1) ranges(2,1) ranges(2,2) ...
	    ranges(2,2) ranges(2,2) ranges(2,2) ranges(2,1)];
    end
    if sum(num_rang(1:4)) == 4
      set(range_boxes(1),'xdata', xl, 'ydata', yl, 'visible','off')
    end
    if strcmp(get(gui_buttons(30),'string'),'View Text')
      set(range_boxes(1),'visible','on')
    end
    % remove URL count
    browse('gsetrange')
    % check for valid datasets/variables
    scroll('datset')
    return
  elseif strcmp(argin,'zoom')
    if all(get(gui_buttons(5),'backgroundcolor') == dods_colors(9,:))
      set(gui_buttons(5),'backgroundcolor',dods_colors(1,:))
      subplot(AXES(1)); newzoom off; subplot(AXES(2)); newzoom off; 
      subplot(AXES(3)); newzoom off; 
    else
      select(0);
      set(gui_buttons(3),'backgroundcolor', ...
	  dods_colors(1,:)); set(gui_buttons(5), ...
	  'backgroundcolor',dods_colors(9,:))
      subplot(AXES(1)); newzoom on; subplot(AXES(2)); newzoom on; 
      subplot(AXES(3)); newzoom on; 
    end
    return
  elseif strcmp(argin,'zrange');
    % this is called
    x = sscanf(get(gui_buttons(12),'string'),'%g');
    if ~isempty(x)
      if x < master_zrange(1)
	x = master_zrange(1);
	set(gui_buttons(12),'string',sprintf('%.2f',x));
      elseif x > master_zrange(2)
	x = master_zrange(2);
	set(gui_buttons(12),'string',sprintf('%.2f',x));
      end
      ranges(3,2) = x;
      num_rang(5) = 1;
    end
    x = sscanf(get(gui_buttons(13),'string'),'%g');
    if ~isempty(x)
      if x < master_zrange(1)
	x = master_zrange(1);
	set(gui_buttons(13),'string',sprintf('%.2f',x));
      elseif x > master_zrange(2)
	x = master_zrange(2);
	set(gui_buttons(13),'string',sprintf('%.2f',x));
      end
      ranges(3,1) = x;
      num_rang(6) = 1;
    end
    if sum(num_rang(5:6)) == 2
      xl = [0.01 0.99];
      set(range_boxes(2),'xdata',[xl(1:2) xl(2) xl(2) xl(2) xl(1) xl(1) xl(1)], ...
	  'ydata', [ranges(3,1) ranges(3,1) ranges(3,1) ranges(3,2) ...
	      ranges(3,2) ranges(3,2) ranges(3,2) ranges(3,1)], 'visible', 'off')
      if strcmp(get(gui_buttons(30),'string'),'View Text')
	set(range_boxes(2),'visible','on')
      end
    end
    scroll('datset')
    return
  end % end of strcmp argin
  return
end
