function h1=gui_pop_set(fig,tag,root,action_mfile);
%
% Call h1=gui_pop_set(fig,tag,root,action_mfile);
%
% For character string root, finds root in popupmenu options and sets value accordingly.
% For cell array root, sets popupmenu options to root and makes sure value is OK.
% For numeric root, sets popupmenu value to root.
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
h1=findobj(fig,'Tag',tag);
files=get(h1,'String');
if iscell(root),
    val=get(h1,'Value');
    set(h1,'String',root);
    if val>length(root) | val<1, set(h1,'Value',1); end
elseif isnumeric(root) & ~isempty(root),
    set(h1,'Value',root);
else
    jfile=find(strcmp(files,root)); nfile=length(jfile);
	if nfile>0,
        set(h1,'Value',jfile);
        if nfile>1, 
            disp(['NOTE: >1 instance of root found in gui_pop_set: Tag = ',tag,'; root = ',root]); 
        end
	else,
        set(h1,'Value',1);
        if ~isempty(root),
            disp(['WARNING: Popupmenu string: ',root,' not found in Tag: ',tag]);
            disp(['         Popupmenu list = ']); disp(char(files));
        end
	end
end
%
if nargin>=4 & ~isempty(action_mfile),
    str=[action_mfile,'(''',tag,''');']; eval(str);
end
