function [out1,out2,out3,out4,out5,out6,out7,out8,out9,out10,out11,out12,out13,out14,out15,out16]=dispmenu(argin1, argin2, argin3, argin4, argin5, argin6, argin7, argin8, argin9, argin10, argin11, argin12, argin13)
%
% DISPMENU      Part of the DODS data browser.
%
%            Deirdre Byrne, The Island Institute, 29 April 1997
%                 dbyrne@islandinstitute.org
%

% The preceding empty line is important.

% DISPLAY_MENU are the buttons.  19 and 27 are 'OK' and 'CANCEL'
% 
% 
% $Id: dispmenu.m,v 1.13 2000/03/23 02:53:17 dbyrne Exp $

% $Log: dispmenu.m,v $
% Revision 1.13  2000/03/23 02:53:17  dbyrne
%
%
% Rewrote unpack.m from scratch.  Much shorter, better commented,
% more robust now.  In particular, it now checks for blank names,
% zero-size arguments, removes these all handily, and distinguishes
% between the potential number of plots and the returned number
% of URLs.  Plotscript.m and dispmenu.m changed accordingly to
% use num_plots instead of num_urls.  -- dbyrne 00/03/22
%
% Revision 1.12  2000/03/17 08:39:55  dbyrne
%
%
% Fixed a small bug that had 'Z:' label invisible when it shouldn't be.
%
% Revision 1.11  1999/07/19 22:38:22  dbyrne
%
%
% Fixed a bug that carried over datarange from previous datasets!  Nasty.
% dbyrne 99/07/19
%
% Revision 1.10  1999/07/19 19:02:51  dbyrne
%
%
% Dataset scroll window is now modal -- will not show other datasets once
% one is chosen.  Also, dataset name colors changed to black for unselected,
% and choice of black or light gray once selected (depending on dataset color).
%
% Fixed a bug in plotscript that was using an incorrect index into the
% data range (used in scaling images).
%
% dbyrne 99/07/19
%
% Revision 1.9  1999/05/13 03:09:53  dbyrne
%
%
% Added Acknowledge and Data_Use_Policy to archive.m.  Fixed getxxx functions
% to use dodsmsg instead of stdout for errors/info.  Made ChangeLog so that it's
% in Emacs format.  All changes for release 3.0.0 -- dbyrne 99/05/12
%
% Revision 1.17  1998/11/09 12:47:04  root
% Fixed small things in display.
%
% Revision 1.16  1998/09/12 20:54:51  root
% *** empty log message ***
%
% Revision 1.15  1998/09/12 15:28:40  root
% Made modifications necessary to let display menu be called numerous times.
%
% Revision 1.14  1998/09/08 20:35:52  dbyrne
% fixed bug with variablelist
%
% fixed bug in 'cancel' button callback
%
% Revision 1.13  1998/09/08 16:12:46  dbyrne
% more changes from browse_display_choices to browse_dispchoices
%
% Revision 1.12  1998/09/08 16:04:21  dbyrne
% browse_get_variables and browse_display_choices too long for v4. Changed
% them to browse_getvariables and browse_dispchoices
%
% Revision 1.11  1998/09/08 08:55:07  dbyrne
% Changed name of callback function from 'clearvars' to 'clrvars'.
%
% Revision 1.10  1998/09/04 11:32:29  dbyrne
% fixing so it can be called from browser uimenu
%
% Revision 1.9  1998/09/03 20:32:40  dbyrne
% CLeaning up multivariable plot items.
%
% Revision 1.8  1998/09/03 20:00:10  dbyrne
% Enabled clearvars function in callback for 'ok' button.
%
% Revision 1.7  1998/09/03 19:09:25  dbyrne
% Modified to allow x,y plots to plot on browser.
%
% Revision 1.6  1998/09/02 16:44:52  dbyrne
% this is now called by unpack in main workspace.
%
% Revision 1.5  1998/09/01 07:05:45  dbyrne
% who knows
%
% Revision 1.4  1998/08/27 14:30:38  dbyrne
% Making sure 'get data' button reappears each time necessary
%
% Revision 1.3  1998/08/25 15:16:46  dbyrne
% % tried to add a 'CANCEL' button. still some bugs. DAB 98/08/25
%
% Revision 1.2  1998/08/20 12:49:29  dbyrne
% % changes to allow for multiple variables in scroll.m
%
% Revision 1.1  1998/05/17 14:10:45  dbyrne
% *** empty log message ***
%
% Revision 1.2  1997/10/14 02:41:17  tom
% Modified behavior of display info menu.
%
% Revision 1.1.1.1  1997/09/22 14:13:53  tom
% Imported Matlab GUI sources to CVS
%

% these are shared with browse
global display_fig display_choices
global dods_colors switchon switchoff

% these are local
global display_menu
global lon_val lat_val display_args get_variables display_num_plots
global display_axes_vals display_sizes display_names
global display_count display_georange display_palette
global display_depthname displaydata_range display_index
global browse_fig browse_clear_button display_colorlimits 
global display_datarangeindex display_num_plots

% protect against starting up without Browse figure being ready
if isempty(findobj(0,'type','figure','userdata','DODS'))
  return
end

if isstr(argin1)
  if strcmp(argin1,'startup')
    % prevent multiple startups
    k = get(0,'children');
    for i = 1:length(k),
      if strcmp(get(k(i),'userdata'),'DODS display')
	close(k(i)); clear display_menu
      end
    end
    k = get(0,'units');
    set(0,'units','pixels')
    scr_size = get(0,'ScreenSize'); scr_offset = scr_size(1:2); 
    scr_size = scr_size(3:4);
    set(0,'units',k)
    % set up window characteristics
    fig_size = [round(scr_size(1)*0.3) round(scr_size(2)*0.5)];
    % minimum acceptable size
    fig_size(1) = max([fig_size(1) 440]);
    fig_size(2) = max([fig_size(2) 480]);
    fig_offset(1) = 100;
    fig_offset(2) = scr_size(2)*0.5;
    if fig_offset(2)+480 > scr_size(2),
      fig_offset(2) = scr_size(2)-600; 
    end
    display_menu = zeros(27,1);
    display_choices = zeros(12,1);
    buttonpos = [0.01 0.95 0.5 0.05];
    indent = 0.05;
    buttonsep = 0.05;
    display_fig = figure('numbertitle','off', ...
	'Name','Display acquired data?', ...
	'visible','off', ...
	'interruptible',switchoff, ...
	'units','pixels', ...
	'resize','off',...
	'userdata','DODS display', ...
	'color',dods_colors(1,:), ...
	'position', [fig_offset fig_size]);
    uicontrol(display_fig,'style','frame', ...
	'units','normalized', ...
	'position',[0 0 1 1], ...
	'backgroundcolor', dods_colors(1,:))

    display_menu(1) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','Display Acquired Data', ...
	'position',buttonpos, ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(1)');
  
    display_menu(17) = uicontrol(display_fig, 'style', 'text', ...
	'visible','off', ...
	'units','normalized', ...
	'string','as', ...
	'horiz', 'left', ...
	'position', buttonpos + [indent -buttonsep -indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:));
  
    display_menu(3) = uicontrol(display_fig,'style','popup', ...
	'visible','off', ...
	'value',1, ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','Points | Lines | Contour | Image | Pcolor | Quiver', ...
	'position', buttonpos+[indent -2*buttonsep -4*indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(3)');
  
    display_menu(25) = uicontrol(display_fig,'style','popup', ...
	'visible','off', ...
	'value',1, ...
	'units','normalized', ...
	'horiz', 'center', ...
	'string', ...
	'default | yellow | cyan | magenta | red | green | blue | black | white ', ...
	'position', buttonpos+[8*indent -2*buttonsep -7*indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(25)');
  
    display_menu(26) = uicontrol(display_fig,'style','popup', ...
	'visible','off', ...
	'value',1, ...
	'units','normalized', ...
	'horiz', 'center', ...
	'string','+ | o | x | * | . | -', ...
	'position', buttonpos+[11*indent -2*buttonsep -8*indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(26)');
  
    display_menu(20) = uicontrol(display_fig,'style','text', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'right', ...
	'string','X:', ...
	'position', buttonpos+[indent-0.04 -3*buttonsep-0.015 -0.46 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:));
    display_menu(4) = uicontrol(display_fig,'style','popup', ...
	'visible','off', ...
	'units','normalized', ...
	'value',1, ...
	'horiz', 'left', ...
	'string','', ...
	'position', buttonpos+[indent -3*buttonsep-0.01 -4*indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(4)');
  
    display_menu(21) = uicontrol(display_fig,'style','text', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'right', ...
	'string','Y:', ...
	'position', buttonpos+[indent-0.04 -4*buttonsep-0.025 -0.46 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:));
    display_menu(5) = uicontrol(display_fig,'style','popup', ...
	'visible','off', ...
	'units','normalized', ...
	'value',1, ...
	'horiz', 'left', ...
	'string','', ...
	'position', buttonpos+[indent -4*buttonsep-0.02 -4*indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(5)');
  
    display_menu(22) = uicontrol(display_fig,'style','text', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'right', ...
	'string','Z:', ...
	'position', buttonpos+[indent-0.04 -5*buttonsep-0.035 -0.46 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:));
    display_menu(6) = uicontrol(display_fig,'style','popup', ...
	'visible','off', ...
	'units','normalized', ...
	'value',1, ...
	'horiz', 'left', ...
	'string','', ...
	'position', buttonpos+[indent -5*buttonsep-0.03 -4*indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(6)');
  
    display_menu(23) = uicontrol(display_fig,'style','text', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'right', ...
	'string','V:', ...
	'position', buttonpos+[10*indent-0.04 -5*buttonsep-0.035 -0.46 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:));
    display_menu(24) = uicontrol(display_fig,'style','popup', ...
	'visible','off', ...
	'units','normalized', ...
	'value',1, ...
	'horiz', 'left', ...
	'string','', ...
	'position', buttonpos+[10*indent -5*buttonsep-0.03 -4*indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(24)');
  
    buttonpos = buttonpos + [0 -0.04 0 0];
    display_menu(18) = uicontrol(display_fig, 'style', 'text', ...
	'visible','off', ...
	'units','normalized', ...
	'string','on', ...
	'horiz', 'left', ...
	'position', buttonpos + [indent -6*buttonsep -indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:));
  
    display_menu(7) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','Browse Window', ...
	'position', buttonpos+[indent -7*buttonsep -indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(7)');
  
    display_menu(13) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','First Returned Dataset (first URL)', ...
	'position', buttonpos+[2*indent -8*buttonsep 0.1 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(13)');
  
    display_menu(14) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','All Returned Data (all URLs)', ...
	'position', buttonpos+[2*indent -9*buttonsep 0.1 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(14)');
  
    display_menu(8) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','Other Windows', ...
	'position', buttonpos+[indent -10*buttonsep -indent 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(8)');
  
    display_menu(9) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','Use an existing window', ...
	'position', buttonpos+[2*indent -11*buttonsep 0 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(9)');
  
    display_menu(15) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','First returned dataset (first URL)', ...
	'position', buttonpos+[3*indent -12*buttonsep 0.1 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(15)');
    
    display_menu(16) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','ALL returned data (all URLs)', ...
	'position', buttonpos+[3*indent -13*buttonsep 0.1 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(16)');
    
    display_menu(10) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','Open New Window(s)', ...
	'position', buttonpos+[2*indent -14*buttonsep 0 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(10)');
  
    display_menu(11) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','One window for ALL returned data', ...
	'position', buttonpos+[3*indent -15*buttonsep 0.1 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(11)');
      
    display_menu(12) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','One window per dataset', ...
	'position', buttonpos+[3*indent -16*buttonsep 0.1 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(12)');
  
    display_menu(2) = uicontrol(display_fig,'style','radio', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'left', ...
	'string','Do Not Display', ...
	'position', buttonpos+[0 -17*buttonsep 0 0], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:), ...
	'callback', 'dispmenu(2)');

    callbackstring = sprintf('%s; %s; %s; %s', ...
	'browse_dispchoices = dispmenu(19); ', ...
	[ 'if browse_dispchoices(1) == 1,', ...
	  'plotscript; end'], ...
	'set(browse_clear_button,''enable'',''on'')', ...
	'clrvars');
    display_menu(19) =  uicontrol(display_fig,'style','push', ...
	'visible','off', ...
	'units','normalized', ...
	'horiz', 'center', ...
	'string','OK', ...
	'callback',callbackstring, ...
	'position', buttonpos+[0.2 -18.5*buttonsep -0.3 0.02], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(9,:)); drawnow

    % the callback for this button is reset in browse.m
    display_menu(27) =  uicontrol(display_fig,'style','push', ...
	'visible','on', ...
	'units','normalized', ...
	'horiz', 'center', ...
	'string','Cancel', ...
	'callback','dispmenu(27); clrvars', ...
	'position', buttonpos+[0.6 -18.5*buttonsep -0.3 0.02], ...
	'foregroundcolor', dods_colors(6,:), ...
	'backgroundcolor', dods_colors(1,:)); drawnow
    return
  elseif strcmp(argin1,'display')
  % *************************************************************************
    % if the window has been killed, make a new one before going on
    if isempty(findobj(0,'type','figure','userdata','DODS display'))
      dispmenu('startup')
    end
    if nargin > 1
      display_args = argin2;
      display_datarangeindex = argin3;
      get_variables = argin4;
      display_num_plots = argin5;
    end

    set(display_menu([1:18 20:26]),'visible','off')
    set(display_menu(19),'visible','on')
    if display_num_plots > 1
      set(display_menu([7 8:10]),'value',0)
      set(display_menu(13:14),'visible','on','value',0)
      set(display_menu(19),'visible','on')
    elseif display_num_plots == 1
      set(display_menu([11 12 15 16 13 14]),'visible','off','value',0)
      display_choices(5:6) = [0 0]';
      set(display_menu(19),'visible','on')
    end

    if all(size(display_args) > 0)
      lat_val = 0; lon_val = 0;
      for i = 1:size(display_args(:,1))
	if strcmp(deblank(display_args(i,:)), 'Longitude') 
	  lon_val = i;
	elseif strcmp(deblank(display_args(i,:)), 'Latitude') 
	  lat_val = i;
	end	
      end
      
      set(display_menu(1),'visible','on','value',1)
      set(display_menu(2),'visible','on','value',0)
      set(display_menu(3),'visible','on','value',4)
      display_choices(2) = 4;
      set(display_menu(22),'visible','on')
      % default to "Yes, Display data"
      display_choices(1) = 1;
      set(display_menu(17:18),'visible','on')
      
      buttonwidth = size(display_args,2)*0.023+0.044; % make it wide enough
      set(display_menu(20:21),'visible','on')
      p = get(display_menu(4),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(4),'position',p)
      p = get(display_menu(5),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(5),'position',p)
      p = get(display_menu(6),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(6),'position',p)
      p = get(display_menu(24),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(24),'position',p)
      % first default -- x & y args are 1st returned variable on the list
      set(display_menu(4),'string', display_args,'visible','on','value',1)
      set(display_menu(5),'string', display_args,'visible','on','value',1)
      % set the default z-variable to the first selected variable
      for j = 1:size(get_variables, 1)
	for i = 1:size(display_args, 1)
	  if strcmp(deblank(get_variables(j,:)), ...
		deblank(display_args(i,:)))
	    break
	  end
	end
      end
      set(display_menu(6),'string', display_args, ...
	  'visible','on','value', i); display_choices(9) = i;
      
      set(display_menu(24),'string', display_args, ...
	  'visible','off','value', 1); display_choices(10) = 0;
      set(display_menu(23:26),'visible','off')
      set(display_menu(22),'visible','off','string','Z:')
      
      if lat_val > 0 			% default to lon,lat coords if possible
	set(display_menu(5), 'visible','on', ...
	    'value',lat_val); display_choices(8) = lat_val; % default yarg is lat
	if lon_val 			% WE CAN USE BROWSER!
	  set(display_menu(7),'visible','on','value',1);
	  set(display_menu(8),'visible','on','value',0);
	  set(display_menu(22),'visible','on')
	  if display_num_plots > 1
	    set(display_menu(13),'visible','on','value',0)
	    set(display_menu(14),'visible','on','value',1)
	    display_choices(5) = 1;
	  else
	    set(display_menu([13 14]),'visible','off','value',0)
	    display_choices(5) = 0;
	  end
	  set(display_menu(4),'visible','on', ...
	      'value', lon_val); display_choices(7) = lon_val; % default xarg is lon
	  set(display_menu([9:12 15 16]),'visible','off','value',0);
	  display_choices([3 4 6]) = [0 0 0]';
	else
	  % need to set up what would happen if lat exists but no Lon
	  display_choices([3:4 7:8]) = [1 1 1 1]';
	  set(display_menu([8 10]),'visible','on','value',1);
	  set(display_menu(9),'visible','on','value',0);
	  set(display_menu([7 13 14]),'visible','off','value',0);
	  set(display_menu([15 16]),'visible','off','value',0)
	  if display_num_plots > 1
	    set(display_menu(12),'visible','on','value',1);
	    set(display_menu(11),'visible','on','value',0)
	    display_choices([5:6]) = [1 1]';
	  else
	    set(display_menu(11:12),'visible','off','value',0);
	    display_choices([5:6]) = [0 0]';
	  end
	end
      else % cannot use browse window because no Latitude
	display_choices([3:4 7:8]) = [1 1 1 1]';
	set(display_menu([8 10]),'visible','on','value',1);
	set(display_menu(9),'visible','on','value',0);
	set(display_menu([7 13 14]),'visible','off','value',0);
	set(display_menu([15 16]),'visible','off','value',0)
	if display_num_plots > 1
	  set(display_menu(12),'visible','on','value',1);
	  set(display_menu(11),'visible','on','value',0)
	  display_choices([5:6]) = [1 1]';
	else
	  set(display_menu(11:12),'visible','off','value',0);
	  display_choices([5:6]) = [0 0]';
	end
      end % end of check for latitude
      if display_num_plots > 1 & display_choices(3) == 0
	set(display_menu(13),'visible','on','value',0)
	set(display_menu(14),'visible','on','value',1)
	display_choices(5) = 1;
	set(display_menu(19),'visible','on')
      else
	set(display_menu([13 14]),'visible','off','value',0)
	display_choices(5) = 0;
      end
    else % WE HAVE NO RETURNED VARIABLES AND CANNOT PLOT
      display_choices = zeros(12,1);
      set(display_menu([1:18 20:23]),'visible','off')
      set(display_menu(24),'visible','off','value',0)
      set(display_menu(19),'visible','on')
    end
    % *************************************************************************
  elseif strcmp(argin1,'displayfrombrowse')
    % if the window has been killed, make a new one before going on
    if isempty(findobj(0,'type','figure','userdata','DODS display'))
      dispmenu('startup')
    end
    if nargin > 1
      display_axes_vals = argin2;
      display_sizes = argin3;
      display_names = argin4;
      display_count = argin5;
      display_georange = argin6;
      display_depthname = argin7;
      displaydata_range = argin8;
      display_index = argin9;
      browse_fig = argin10;
      display_palette = argin11;
      browse_clear_button = argin12;
      display_colorlimits = argin13;
    end
    callbackstring = sprintf('%s; %s; %s; %s', ...
	[ '[browse_dispchoices, browse_axes_vals, browse_sizes, ', ...
	'browse_names, browse_count, browse_georange, ', ...
	'browse_depth_name, browse_data_range, browse_index,', ...
	'browse_figure, browse_palette, browse_num_plots, ', ...
	'browse_clear_button, browse_dispargs, ', ...
	'browse_color_limits, browse_datarangeindex] = dispmenu(19)'], ...
	[ 'if browse_dispchoices(1) == 1,', ...
	'plotscript; end'], ...
        'set(browse_clear_button,''enable'',''on'')', ...
        'clrvars');
    set(display_menu(19),'callback',callbackstring)
    set(display_menu([1:18 20:26]),'visible','off')
    set(display_menu(19),'visible','on')
    if display_num_plots > 1
      set(display_menu([7 8:10]),'value',0)
      set(display_menu(13:14),'visible','on','value',0)
      set(display_menu(19),'visible','on')
    elseif display_num_plots == 1
      set(display_menu([11 12 15 16 13 14]),'visible','off','value',0)
      display_choices(5:6) = [0 0]';
      set(display_menu(19),'visible','on')
    end

    if all(size(display_args) > 0)
      lat_val = 0; lon_val = 0;
      for i = 1:size(display_args(:,1))
	if strcmp(deblank(display_args(i,:)), 'Longitude') 
	  lon_val = i;
	elseif strcmp(deblank(display_args(i,:)), 'Latitude') 
	  lat_val = i;
	end	
      end
      
      set(display_menu(1),'visible','on','value',1)
      set(display_menu(2),'visible','on','value',0)
      set(display_menu(3),'visible','on','value',4)
      display_choices(2) = 4;
      set(display_menu(22),'visible','on')
      % default to "Yes, Display data"
      display_choices(1) = 1;
      set(display_menu(17:18),'visible','on')
      
      buttonwidth = size(display_args,2)*0.023+0.044; % make it wide enough
      set(display_menu(20:21),'visible','on')
      p = get(display_menu(4),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(4),'position',p)
      p = get(display_menu(5),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(5),'position',p)
      p = get(display_menu(6),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(6),'position',p)
      p = get(display_menu(24),'position'); p = [p(1:2) buttonwidth p(4)];
      set(display_menu(24),'position',p)
      % first default -- x & y args are 1st returned variable on the list
      set(display_menu(4),'string', display_args,'visible','on','value',1)
      set(display_menu(5),'string', display_args,'visible','on','value',1)
      % set the default z-variable to the first selected variable
      for j = 1:size(get_variables, 1)
	for i = 1:size(display_args, 1)
	  if strcmp(deblank(get_variables(j,:)), ...
		deblank(display_args(i,:)))
	    break
	  end
	end
      end
      set(display_menu(6),'string', display_args, ...
	  'visible','on','value', i); display_choices(9) = i;
      
      set(display_menu(24),'string', display_args, ...
	  'visible','off','value', 1); display_choices(10) = 0;
      set(display_menu(23:26),'visible','off')
      
      if lat_val > 0 			% default to lon,lat coords if possible
	set(display_menu(5), 'visible','on', ...
	    'value',lat_val); display_choices(8) = lat_val; % default yarg is lat
	if lon_val 			% WE CAN USE BROWSER!
	  set(display_menu(7),'visible','on','value',1);
	  set(display_menu(8),'visible','on','value',0);
	  set(display_menu(22),'visible','on')
	  if display_num_plots > 1
	    set(display_menu(13),'visible','on','value',0)
	    set(display_menu(14),'visible','on','value',1)
	    display_choices(5) = 1;
	  else
	    set(display_menu([13 14]),'visible','off','value',0)
	    display_choices(5) = 0;
	  end
	  set(display_menu(4),'visible','on', ...
	      'value', lon_val); display_choices(7) = lon_val; % default xarg is lon
	  set(display_menu([9:12 15 16]),'visible','off','value',0);
	  display_choices([3 4 6]) = [0 0 0]';
	else
	  % need to set up what would happen if lat exists but no Lon
	  display_choices([3:4 7:8]) = [1 1 1 1]';
	  set(display_menu([8 10]),'visible','on','value',1);
	  set(display_menu(9),'visible','on','value',0);
	  set(display_menu([7 13 14]),'visible','off','value',0);
	  set(display_menu([15 16]),'visible','off','value',0)
	  if display_num_plots > 1
	    set(display_menu(12),'visible','on','value',1);
	    set(display_menu(11),'visible','on','value',0)
	    display_choices([5:6]) = [1 1]';
	  else
	    set(display_menu(11:12),'visible','off','value',0);
	    display_choices([5:6]) = [0 0]';
	  end
	end
      else % cannot use browse window because no Latitude
	display_choices([3:4 7:8]) = [1 1 1 1]';
	set(display_menu([8 10]),'visible','on','value',1);
	set(display_menu(9),'visible','on','value',0);
	set(display_menu([7 13 14]),'visible','off','value',0);
	set(display_menu([15 16]),'visible','off','value',0)
	if display_num_plots > 1
	  set(display_menu(12),'visible','on','value',1);
	  set(display_menu(11),'visible','on','value',0)
	  display_choices([5:6]) = [1 1]';
	else
	  set(display_menu(11:12),'visible','off','value',0);
	  display_choices([5:6]) = [0 0]';
	end
      end % end of check for latitude
      if display_num_plots > 1 & display_choices(3) == 0
	set(display_menu(13),'visible','on','value',0)
	set(display_menu(14),'visible','on','value',1)
	display_choices(5) = 1;
	set(display_menu(19),'visible','on')
      else
	set(display_menu([13 14]),'visible','off','value',0)
	display_choices(5) = 0;
      end
    else % WE HAVE NO RETURNED VARIABLES AND CANNOT PLOT
      display_choices = zeros(12,1);
      set(display_menu([1:18 20:23]),'visible','off')
      set(display_menu(24),'visible','off','value',0)
      set(display_menu(19),'visible','on')
    end
  elseif strcmp(argin1,'resetcallback')
    callbackstring = sprintf('%s; %s; %s; %s', ...
	'browse_dispchoices = dispmenu(19); ', ...
	[ 'if browse_dispchoices(1) == 1,', ...
	'plotscript; end'], ...
        'set(browse_clear_button,''enable'',''on'')', ...
        'clrvars');
    set(display_menu(19),'callback',callbackstring)
    return
  end 
  set(display_fig,'visible','on')
  % *************************************************************************
elseif ~isstr(argin1)
  if argin1 == 1
    if get(display_menu(1),'value') == 1
      set(display_menu(2),'value',0)
%         right here ---v
      set(display_menu([1 3 17]),'visible','on')
      set(display_menu(19),'visible','off')
      display_choices(1) = 1;
    else
      set(display_menu(2),'value',1)
%         right here ---v
      set(display_menu([1 3:18 20:24]),'visible','off')
      display_choices = zeros(12,1);
      set(display_menu(3:6),'value',1) % this resets text
%      set(display_menu(3:6),'value',0) % this resets value
      set(display_menu(19),'visible','on')
      display_choices(1) = 0;
    end
  elseif argin1 == 3
    % ----------------------------- SELECT PLOT TYPE -----------------------
    v = get(display_menu(3),'value');
    display_choices(2) = v;
    set(display_menu(18),'visible','on')
    if display_choices(2) < 3 
      % ---------------------LINE OR SYMBOL PLOT---------
      display_choices(9) = 0;
      set(display_menu(22:23),'visible','off')
      set(display_menu([6 24]),'visible','off','value',0)
      % set default linestyles
      if display_choices(2) == 1
	set(display_menu(25:26),'visible','on','value',1)
	display_choices([11 12]) = [1 1]'; % default to (multi, '+')
      elseif display_choices(2) == 2
	set(display_menu(25),'visible','on','value',2)
	set(display_menu(26),'visible','off','value',6)
	display_choices([11 12]) = [2 6]'; % default to (yellow, '-')
      end
      set(display_menu([5 8 21]),'visible','on')
      if all(size(display_args) > 0) % we get to specify an x-argument
	set(display_menu(4:5),'string',display_args,'visible','on')
	if lon_val > 0
	  display_choices(7) = lon_val;
	  set(display_menu(4),'value',lon_val)
	else
	  display_choices(7) = 1;
	  set(display_menu(4),'value',1)
	end
	if lat_val > 0
	  display_choices(8) = lat_val;
	  set(display_menu(5),'value',lat_val)
	else
	  display_choices(8) = 1;
	  set(display_menu(5),'value',1)
	end
	if display_choices(7) == lon_val & display_choices(8) == lat_val ...
	  & all([lon_val lat_val] > 0)
	  set(display_menu(7:8),'visible','on')
	else
	  display_choices(3) = 1;
	  set(display_menu(8),'visible','on')
	  set(display_menu([7 13 14]),'visible','off','value',0)
	end
      else % WE HAVE NO RETURNED VARIABLES AND CANNOT PLOT
	display_choices = zeros(12,1);
	set(display_menu([1 2 7:18 20:23]),'visible','off','value',0)
	set(display_menu([3:6 24:26]),'visible','off','value',1)
	set(display_menu(19),'visible','on')
      end
      % --------------------------------------------------
    else % contour, image, pcolor or quiver plot
      set(display_menu(6),'visible','on')
      if display_choices(9) > 0 & display_choices(9) <= ...
	    size(display_args,1) 
	set(display_menu(6),'value',display_choices(9))
      else
	set(display_menu(6),'value',1)
      end
      set(display_menu(22),'visible','on','string','Z:')
      set(display_menu(23),'visible','off')
      set(display_menu(24:26),'visible','off','value',1)
      if display_choices(2) == 6 % QUIVER PLOT
	display_choices(10) = 0;
	set(display_menu(22),'string','U:')
	set(display_menu(23),'visible','on')
	set(display_menu(24),'string', display_args, ...
	    'visible','on','value', 1);
	display_choices(10) = 1;
	set(display_menu(25), 'visible','on','value', 2);
	display_choices(11) = 2; % default to yellow
      end
	
      if all(size(display_args) > 0)
	set(display_menu(20:21),'visible','on')
	set(display_menu(4:5),'string',display_args,'visible','on')
	if lon_val > 0
	  display_choices(7) = lon_val;
	  set(display_menu(4),'value',lon_val)
	else
	  display_choices(7) = 1;
	  set(display_menu(4),'value',1)
	end
	if lat_val > 0
	  display_choices(8) = lat_val;
	  set(display_menu(5),'value',lat_val)
	else
	  display_choices(8) = 1;
	  set(display_menu(5),'value',1)
	end
	if display_choices(7) == lon_val & display_choices(8) == lat_val ...
	  & all([lon_val lat_val] > 0)
	  set(display_menu(7:8),'visible','on')
	else
	  display_choices(3) = 1;
	  set(display_menu(8),'visible','on')
	  set(display_menu([7 13 14]),'visible','off','value',0)
	end
      else % WE HAVE NO RETURNED VARIABLES AND CANNOT PLOT
	display_choices = zeros(12,1);
	set(display_menu([1:18 24]),'visible','off','value',0)
	set(display_menu([20:23]),'visible','off')
	set(display_menu(19),'visible','on')
      end
    end
    % ------------------------------------------------------------------ 
  elseif argin1 == 25
    display_choices(11) = get(display_menu(25),'value');
  elseif argin1 == 26
    display_choices(12) = get(display_menu(26),'value');
  elseif argin1 == 4
    display_choices(7) = get(display_menu(4),'value');
    if display_choices(7) ~= lon_val & display_choices(3) == 0
      display_choices(3) = 1;
      set(display_menu(8:10),'visible','on')
      set(display_menu(8),'value',1)
      set(display_menu([7 13 14]),'visible','off','value',0)
      if display_num_plots > 1
      else
	set(display_menu([11:12 15:16]),'visible','off','value',0)
	display_choices(5:6) = [0 0]';
      end
    elseif display_choices(7) ~= lon_val & display_choices(3) == 1
      set(display_menu([7 13 14]),'visible','off','value',0)
    elseif (display_choices(7) == lon_val) & ...
	  (display_choices(8) == lat_val) & ...
	  (display_choices(2) >= 3)
      % if is was selected, leave it selected ... if not, leave it
      set(display_menu(7),'visible','on') 
    end
  elseif argin1 == 5    
    display_choices(8) = get(display_menu(5),'value');
    if display_choices(8) ~= lat_val & display_choices(3) == 0
      display_choices(3) = 1;
      set(display_menu([7 13 14]),'visible','off','value',0)
      set(display_menu(8:10),'visible','on')
      set(display_menu(8),'value',1)
      if display_num_plots > 1
      else
	set(display_menu([11:12 15:16]),'visible','off','value',0)
	display_choices(5:6) = [0 0]';
      end
    elseif display_choices(8) ~= lat_val & display_choices(3) == 1
      set(display_menu([7 13 14]),'visible','off','value',0)
    elseif (display_choices(7) == lon_val) & ...
	  (display_choices(8) == lat_val) & ...
	  (display_choices(2) >= 3) & ...
	  all([lon_val lat_val] > 0)
      % if is was selected, leave it selected ... if not, leave it
      set(display_menu(7),'visible','on') 
    end
  elseif argin1 == 6
    display_choices(9) = get(display_menu(6),'value');
  elseif argin1 == 24
    display_choices(10) = get(display_menu(24),'value');
  elseif argin1 == 7
    if get(display_menu(7),'value') == 1
      set(display_menu([8:12 15:16]),'value',0); 
      set(display_menu([9:12 15:16]),'visible','off')
      if display_num_plots > 1,
	set(display_menu(13:14),'visible','on'); 
	set(display_menu(19),'visible','off')
      else,
	set(display_menu(13:14),'value',0) 
	set(display_menu(19),'visible','on')
	display_choices(5) = 0;
      end
      display_choices([3 4 6]) = [0 0 0]';
    else
      set(display_menu(8),'value',1); 
      set(display_menu(13:14),'visible','off','value',0)
      set(display_menu(9:10),'visible','on','value',0)
      if display_num_plots > 1,
	set(display_menu(19),'visible','off')
      else,
	set(display_menu(19),'visible','on')
	display_choices(5) = 0;
      end
      display_choices(3) = 1;
    end
  elseif argin1 == 13
    if get(display_menu(13),'value') == 1
      set(display_menu(14),'value',0)
      set(display_menu(19),'visible','on')
      display_choices(5) = 0;
    else
      set(display_menu(14),'value',1)
      set(display_menu(19),'visible','on')
      display_choices(5) = 1;
    end
  elseif argin1 == 14
    if get(display_menu(14),'value') == 1
      set(display_menu(13),'value',0)
      set(display_menu(19),'visible','on')
      display_choices(5) = 1;
    else
      set(display_menu(13),'value', 1)
      set(display_menu(19),'visible','on')
      display_choices(5) = 0;
    end
  elseif argin1 == 8
    if get(display_menu(8),'value') == 1
      set(display_menu([7 13 14]),'value',0)
      set(display_menu([13:14 19]),'visible','off')
      set(display_menu(9:10),'visible','on')
      display_choices(3) = 1;
    else
      if (display_choices(7) == lon_val) & ...
	    (display_choices(8) == lat_val) & ...
	    all([lon_val lat_val])
	set(display_menu(7),'value',1,'visible','on')
	set(display_menu([9:12 15:16]),'visible','off','value',0)
	if display_num_plots > 1
	  set(display_menu(19),'visible','off')
	  set(display_menu(13:14),'visible','on','value',0)
	  display_choices([3:4]) = [0 0]';
	else
	  set(display_menu(19),'visible','off')
	  display_choices([3:5]) = [0 0 0]';
	end
      else
	set(display_menu(8),'value',1)
	set(display_menu(8:10),'visible','on')
	display_choices(3) = 1;
      end
    end
  elseif argin1 == 9
    if get(display_menu(9),'value') == 1
      set(display_menu(10:12),'value',0)
      set(display_menu(11:12),'visible','off')
      if display_num_plots > 1
	set(display_menu(15:16),'visible','on')
	set(display_menu(19),'visible','off')
      else
	set(display_menu(15:16),'value',0)
	set(display_menu(19),'visible','on')
	display_choices(5) = 0;
      end
      display_choices([4 6]) = [0 0]';
    else
      set(display_menu(10),'value',1)
      set(display_menu(11:12),'visible','on')
      set(display_menu(15:16),'visible','off','value',0)
      if display_num_plots > 1
	set(display_menu(19),'visible','off')
      else
	set(display_menu(19),'visible','on')
	display_choices(5) = 0;
      end
      display_choices(4) = 1;
    end
  elseif argin1 == 15
    if get(display_menu(15),'value') == 1
      set(display_menu(16),'value',0)
      set(display_menu(19),'visible','on')
      display_choices(5) = 0;
    else
      set(display_menu(16),'value',1)
      set(display_menu(19),'visible','on')
      display_choices(5) = 1;
    end
  elseif argin1 == 16
    if get(display_menu(16),'value') == 1
      set(display_menu(15),'value',0)
      set(display_menu(19),'visible','on')
      display_choices(5) = 1;
    else
      set(display_menu(15),'value',1)
      set(display_menu(19),'visible','on')
      display_choices(5) = 0;
    end
  elseif argin1 == 10
    if get(display_menu(10),'value') == 1
      set(display_menu([9 15 16]),'value',0) 
      set(display_menu([15:16]),'visible','off')
      if display_num_plots > 1, 
	set(display_menu(11:12),'visible','on')
	set(display_menu(19),'visible','off')
      else,
	set(display_menu(11:12),'value',0)
	set(display_menu(19),'visible','on')
	display_choices(6) = 0;
      end
      display_choices([4 5]) = [1 1]';
    else
      set(display_menu(9),'value',1) 
      set(display_menu([11:12]),'visible','off','value',0)
      set(display_menu([15:16]),'visible','on')
      if display_num_plots > 1, 
	set(display_menu(19),'visible','off')
      else,
	set(display_menu(19),'visible','on')
	display_choices(6) = 0;
      end
      display_choices(4) = 0;
    end
  elseif argin1 == 11;
    if get(display_menu(11),'value') == 1
      set(display_menu(12),'value',0)
      set(display_menu(19),'visible','on')
      display_choices(6) = 0;
    else
      set(display_menu(12),'value',1)
      set(display_menu(19),'visible','on')
      display_choices(6) = 1;
    end
  elseif argin1 == 12 
    if get(display_menu(12),'value') == 1
      set(display_menu(11),'value',0)
      set(display_menu(19),'visible','on')
      display_choices(6) = 1;
    else
      set(display_menu(11),'value',1)
      set(display_menu(19),'visible','on')
      display_choices(6) = 0;
    end
  elseif argin1 == 2
    if get(display_menu(2),'value') == 1
      display_choices = zeros(12,1); 
      set(display_menu([1 7:16]),'value',0)
      set(display_menu([3:6 24:26]),'value',1) % reset pulldownmenus
      set(display_menu([3:18 20:26]),'visible','off')
      set(display_menu(19),'visible','on')
    else
      % all the stuff that comes under display_menu(1)
      set(display_menu(2),'value',0)
      set(display_menu(1),'value',1)
      set(display_menu([1 3 17]),'visible','on')
      set(display_menu(19),'visible','off')
      display_choices(1) = 1;
    end
  elseif argin1 == 19
    set(display_fig,'visible','off')
    out1 = display_choices;
    out2 = display_axes_vals;
    out3 = display_sizes;
    out4 = display_names;
    out5 = display_count;
    out6 = display_georange;
    out7 = display_depthname;
    out8 = displaydata_range;
    out9 = display_index;
    out10 = browse_fig;
    out11 = display_palette;
    out12 = display_num_plots;
    out13 = browse_clear_button;
    out14 = display_args;
    out15 = display_colorlimits;
    out16 = display_datarangeindex;
    return
  elseif argin1 == 27
    set(display_fig,'visible','off')
    browse('getdata','cancel')
    return
  end
end
