VERSION = version; VERSION = str2num(VERSION(1));
if VERSION < 5
  interruptstring = 'yes';
else
  interruptstring = 'on';
end
% set up button chars
labels = [' Style  ';' StaSel ';'Sel All ';' Zoom   ';
    ' Grid   ';' Sta  ID';'  Prop  ';'  Plot  ';' Clear  ';'  Sigma ';
    '  Maps  ';'Add Prop';'LoadData';'SaveOpts';' QUIT   '];
call = str2mat('hydroplt(''setstyle'')', ...
    'hydroplt(''stasel'')', ...
    'hydroplt(''selall'')', 'hydroplt(''zoom'')', ...
    'hydroplt(''grid'')', 'hydroplt(''staid'')', ...
    'hydroplt(''prop'')','hydroplt(''plot'')');
backs = str2mat('hydroplt(''clear'')', ...
    'hydroplt(''sigmas'')','hydroplt(''maps'')',...
    'hydroplt(''addprop'')', 'hydroplt(''load'')',...
    'hydroplt(''save'')', 'hydroplt(''QUIT'')');
callbacks = str2mat(call,backs);

% let's get serious; get screen params to set up windows
scr_size = get(0,'ScreenSize'); scr_offset = scr_size(1:2); 
scr_size = scr_size(3:4);

% window the first: button window: put in lower left corner
fig_size = [round(scr_size(1)*0.10) round(scr_size(2)*0.7)];
% minimum acceptable size
if VERSION < 5
  fig_size(1) = max([fig_size(1) 130]);
  fig_size(2) = max([fig_size(2) 360]);
else
  fig_size(1) = max([fig_size(1) 154]);
  fig_size(2) = max([fig_size(2) 360]);
end
fig_offset = scr_offset;
%
sta_menu = figure('NumberTitle','off', ...
    'Name','STAPLOT', ...
    'units','pixels' ,...
    'Position',[fig_offset fig_size],...
    'interruptible',interruptstring, ...
    'resize','on',...
    'color',[0 0.5 0.5], ...
    'visible','off');
if VERSION > 4
  set(sta_menu,'menubar','none')
end

% because of the incredibly stupid way that 'uimenu' and 'popupmenu'
% have been configured, the COLOR menu, MUST come at the top of the page
% and it MUST be a uimenu, not a regular uicontrol button.  Sheesh!
ui_colors = uimenu('label','Color');
if VERSION < 5
  for i = 1:length(colornames)
    callbackstring = sprintf('''hydroplt(''''setcolor'''', %2i)''',i);
    if strcmp(deblank(lower(colornames(i,:))),'black')
      uimenu(ui_colors, ...
	  'Label',colornames(i,:), ...
	  'backgroundcolor',[1 1 1], ...
	  'foregroundcolor',plotcolors(i,:), ...
	  'callback',eval(callbackstring))
    else
      uimenu(ui_colors, ...
	  'Label',colornames(i,:), ...
	  'backgroundcolor',[0 0 0], ...
	  'foregroundcolor',plotcolors(i,:), ...
	  'callback',eval(callbackstring))
    end
  end
else
  for i = 1:length(colornames)
    callbackstring = sprintf('''hydroplt(''''setcolor'''', %2i)''',i);
    uimenu(ui_colors, ...
	'Label',colornames(i,:), ...
	'foregroundcolor',plotcolors(i,:), ...
	'callback',eval(callbackstring))
  end
end
drawnow

% ********PULLDOWN UIMENU PLOTTING CONTROLS*****************
ui_plot = uimenu('label','Plot Ctrl');

callbackstring = 'hydroplt(''plotcontrol'',1)';
uimenu(ui_plot,'label','xlims','callback',callbackstring);

callbackstring = 'hydroplt(''plotcontrol'',2)';
uimenu(ui_plot,'label','ylims','callback',callbackstring);

callbackstring = 'hydroplt(''plotcontrol'',3)';
uimenu(ui_plot,'label','zlims','callback',callbackstring);

callbackstring = 'hydroplt(''plotcontrol'',4)';
uimenu(ui_plot,'label','xticks','callback',callbackstring);

callbackstring = 'hydroplt(''plotcontrol'',5)';
uimenu(ui_plot,'label','yticks','callback',callbackstring);

callbackstring = 'hydroplt(''plotcontrol'',6)';
uimenu(ui_plot,'label','zticks','callback',callbackstring);

callbackstring = 'hydroplt(''setview'',2)';
uimenu(ui_plot,'label','2-D','callback',callbackstring);

callbackstring = 'hydroplt(''setview'',3)';
uimenu(ui_plot,'label','3-D','callback',callbackstring);
      
callbackstring = 'hydroplt(''flipud'')';
uimenu(ui_plot,'label','Flipud','callback',callbackstring);
      
% set up the real plot control edit buttons
P_CTRL = zeros(6,2);
      
P_CTRL(1,1) = uicontrol('style','edit','units','normalized', ...
    'position',[0.01 0.935 0.75 0.065], ...
    'horizontalalign','left', ...
    'visible','off', ...
    'callback', 'pltctrl(''lmcallback'', 1)');
P_CTRL(1,2) = uicontrol('style','push','units','normalized', ...
    'position',[0.76 0.935 0.23 0.065], ...
    'string','X', ...
    'visible','off', ...
    'backgroundcolor',[1 0 0], ...
    'callback','pltctrl(''dismiss'', 1)');
P_CTRL(2,1) = uicontrol('style','edit','units','normalized', ...
    'position',[0.01 0.935 0.75 0.065], ...
    'horizontalalign','left', ...
    'visible','off', ...
    'callback', 'pltctrl(''lmcallback'', 2)');
P_CTRL(2,2) = uicontrol('style','push','units','normalized', ...
    'position',[0.76 0.935 0.23 0.065], ...
    'string','X', ...
    'visible','off', ...
    'backgroundcolor',[1 0 0], ...
    'callback','pltctrl(''dismiss'', 2)');
P_CTRL(3,1) = uicontrol('style','edit','units','normalized', ...
    'position',[0.01 0.935 0.75 0.065], ...
    'horizontalalign','left', ...
    'visible','off', ...
    'callback', 'pltctrl(''lmcallback'', 3)');
P_CTRL(3,2) = uicontrol('style','push','units','normalized', ...
    'position',[0.76 0.935 0.23 0.065], ...
    'string','X', ...
    'visible','off', ...
    'backgroundcolor',[1 0 0], ...
    'callback','pltctrl(''dismiss'', 3)');
P_CTRL(4,1) = uicontrol('style','edit','units','normalized', ...
    'position',[0.01 0.935 0.75 0.065], ...
    'horizontalalign','left', ...
    'visible','off', ...
    'callback', 'pltctrl(''tccallback'', 4)');
P_CTRL(4,2) = uicontrol('style','push','units','normalized', ...
    'position',[0.76 0.935 0.23 0.065], ...
    'string','X', ...
    'visible','off', ...
    'backgroundcolor',[1 0 0], ...
    'callback','pltctrl(''dismiss'', 4)');
P_CTRL(5,1) = uicontrol('style','edit','units','normalized', ...
    'position',[0.01 0.935 0.75 0.065], ...
    'horizontalalign','left', ...
    'visible','off', ...
    'callback', 'pltctrl(''tccallback'', 5)');
P_CTRL(5,2) = uicontrol('style','push','units','normalized', ...
    'position',[0.76 0.935 0.23 0.065], ...
    'string','X', ...
    'visible','off', ...
    'backgroundcolor',[1 0 0], ...
    'callback','pltctrl(''dismiss'', 5)');
P_CTRL(6,1) = uicontrol('style','edit','units','normalized', ...
    'position',[0.01 0.935 0.75 0.065], ...
    'horizontalalign','left', ...
    'visible','off', ...
    'callback', 'pltctrl(''tccallback'', 6)');
P_CTRL(6,2) = uicontrol('style','push','units','normalized', ...
    'position',[0.76 0.935 0.23 0.065], ...
    'string','X', ...
    'visible','off', ...
    'backgroundcolor',[1 0 0], ...
    'callback','pltctrl(''dismiss'', 6)');
% ***********************************************************************

posit = [0.01 1.0 0.98 0.065];
for i = 1:length(labels)
  posit = [posit(1) posit(2)-0.066 posit(3) posit(4)];
  uicontrol('style','push','string',labels(i,:),...
      'units', 'normalized', 'position', posit, ...
      'callback',callbacks(i,:), 'interruptible', interruptstring)
  drawnow
end

kids = get(sta_menu,'children');
for i = 1:length(kids);
  if strcmp(get(kids(i),'type'),'uicontrol')
    set(kids(i),'units','normalized');
    if strcmp(get(kids(i),'type'),'uicontrol')
      s = deblank(fliplr(deblank(fliplr(get(kids(i),'string')))));
      if strcmp(s,'Style')
	B_HANDLES(1) = kids(i);
	set(B_HANDLES(1),'Style','Popup','String',...
	    plotstyle)
	drawnow
      elseif strcmp(s,'StaSel')
	B_HANDLES(2) = kids(i);
	set(B_HANDLES(2),'Style','Radio')
	drawnow
      elseif strcmp(deblank(s),'Sel All')
	B_HANDLES(3) = kids(i);
	if ~isempty(sections)
	  s = size(sections);
	  buttonstring = ['Sel All'];
	  for i = 1:s(1)
	    newstring = ['section ' num2str(i)];
	    buttonstring = str2mat(buttonstring, newstring);
	  end
	end
	set(B_HANDLES(3),'Style','Popup', 'String', ...
	    buttonstring)
	drawnow
      elseif strcmp(s,'Prop')
	B_HANDLES(4) = kids(i);
	set(B_HANDLES(4),'Style','Popup','String',...
	    proplist)
	drawnow
      elseif strcmp(s,'Plot')
	B_HANDLES(5) = kids(i);
	set(B_HANDLES(5),'Style','Popup','String',...
	    'XY Plot|XYZ Plot|ContFill|ContLine')
	drawnow
      elseif strcmp(s,'Clear')
	B_HANDLES(6) = kids(i);
	set(B_HANDLES(6),'Style','Popup','String',...
	    'Cl Fig|Cl Sta|Cl Iso|Cl Txt')
	drawnow
      elseif strcmp(s,'Maps')
	B_HANDLES(7) = kids(i);
	label = str2mat('Worldmap',batlist);
	set(B_HANDLES(7),'Style','Popup','String',label)
	drawnow
      elseif strcmp(s,'Sigma')
	B_HANDLES(8) = kids(i);
	set(B_HANDLES(8),'style','popup','String',...
	    'Sigma_0|Sigma_1|Sigma_2|Sigma_3|Sigma_4')
	iso_handles = [];
      elseif strcmp(s,'Add Prop')
	B_HANDLES(11) = kids(i);
	set(B_HANDLES(11),'style','popup','String',...
	    'Add prop|Del prop')
      elseif strcmp(s,'LoadData')
	B_HANDLES(9) = kids(i);
	set(B_HANDLES(9),'style','popup','String',...
	    'Load data|Append data')
      elseif strcmp(s,'SaveOpts')
	B_HANDLES(10) = kids(i);
	set(B_HANDLES(10),'style','popup','String',...
	    'SaveOpts|SaveData')
      end
    end
  end
end
% now uncover the figure
set(sta_menu,'visible','on');

