function pltctrl(argin,n)
global P_CTRL F_HANDLES B_HANDLES
%
% implement plot uicontrols and dismiss them when done
%
pix = get(0,'children'); 		% check for live plots
kids = [];
for i = 1:length(pix)
  if isstrcmp(get(pix(i),'userdata'),'staplot')
    kids = [kids pix(i)];
  end
end
for i = 1:length(kids) 		% find most recent plot that's a staplot plot
  if any(kids(i) == F_HANDLES)
    curr_ax = get(kids(i),'currentaxes');
    break
  end
end

if isstrcmp(argin,'lmcallback')
  % we are changing axis limits
  nl = [];
  if ~isempty(n)
    snl = get(P_CTRL(n,1), 'string');
    nl = sscanf(snl,'%g',2);
  end
  if n == 1
    if length(nl) == 2;
      set(curr_ax,'xlim',nl);
    end
  elseif n == 2
    if length(nl) == 2;
      set(curr_ax,'ylim',nl);
    end
  elseif n == 3
    if length(nl) == 2;
      set(curr_ax,'zlim',nl);
    end
  end
elseif strcmp(argin,'tccallback')
  % we are changing tick values
  nt = [];
  if ~isempty(n)
    snt = get(P_CTRL(n,1), 'string');
    if any(isdigit(snt))
      nt = sscanf(snt,'%g',inf);
      nt = sort(nt);
    else
      if strcmp(deblank(lower(snt)),'auto')
	nt = 'auto';
      end
    end
  end
  if n == 4
    if length(nt) == 1
      lims = get(curr_ax,'xlim');
      set(curr_ax,'xtick',lims(1):nt:lims(2))
    else
      if isstrcmp('auto',nt)
	set(curr_ax,'xtickmode','auto')
      else
	set(curr_ax,'xtick',nt)
      end
    end
  elseif n == 5
    if length(nt) == 1
      lims = get(curr_ax,'ylim');
      set(curr_ax,'ytick',lims(1):nt:lims(2))
    else
      if isstrcmp('auto',nt)
	set(curr_ax,'ytickmode','auto')
      else
	set(curr_ax,'ytick',nt)
      end
    end
  elseif n == 6
    if length(nt) == 1
      lims = get(curr_ax,'zlim');
      set(curr_ax,'ztick',lims(1):nt:lims(2))
    else
      if isstrcmp('auto',nt)
	set(curr_ax,'ztickmode','auto')
      else
	set(curr_ax,'ztick',nt)
      end
    end
  end
elseif strcmp(argin,'dismiss')
  if ~isempty(n);
    set(P_CTRL(n,1),'visible','off');
    set(P_CTRL(n,2),'visible','off');
    set(B_HANDLES(1),'visible','on');
  end
end
