function  f_moni(cmd_string)
%  f_moni
%
% this function creates the figure for monitoring the variables
% it then plots the variables


global h_fig_moni  h_ax_cv  h_ax_mv  h_ax_dv  is_exit  is_run

% catalog of handles for the objects in f_moni
% handle(1) = uicontrol (h_fig_moni, 'style', 'toggle',...
%     'tooltipstring','start/stop simulation',...
% handle(2) = uicontrol (h_fig_moni, 'style', 'pushbutton',...
%     'tooltipstring','EXIT the program',...
num_handles = 2; % record the number of uicontrol handles
handle = linspace(0,0,num_handles); % initialize an array to hold the handles

switch cmd_string

case 'initialize' % create the figure

    % check for existence of the disturbance box
    set(0,'showhiddenhandles','on') % make all figures detectable
    h_figs = get(0,'children');  % get handles of existing figures
    set(0,'showhiddenhandles','off') % protect the GUIs again
    fig_exists = 0; 
    for fig = h_figs'
        fig_exists = strcmp(get(fig,'name'),'Monitor');
        if fig_exists
            figure(fig) % bring to front of screen
            return % no need to initialize; exit function
        end % if fig_exists
    end % for fig = h_figs'
    
    
	% create figure and frame
	h_fig_moni = figure ('position',[650 50 600 600],...
        'resize', 'off',...
        'menubar', 'none',...
        'name', 'Monitor');
	%     'handlevisibility','callback',...
	% uicontrol (h_fig_dist, 'style', 'frame',...
	%     'position', [10 10 780 580]);
	
	% create axes
	h_ax_cv = axes(...
        'units','pixels',...
        'box','on',...
        'position', [50 390 500 130 ]);
	title('controlled variable')
	
	h_ax_mv = axes(...
        'units','pixels',...
        'box','on',...
        'position', [50 220 500 130 ]);
	title('manipulated variable')
	
	h_ax_dv = axes(...
        'units','pixels',...
        'box','on',...
        'position', [50 50 500 130 ]);
	title('disturbance variable')

	% create toggle switch for starting the simulation
	handle(1) = uicontrol (h_fig_moni, 'style', 'toggle',...
        'tooltipstring','START/STOP simulation',...
        'string', 'START',...
        'value',0,...
        'callback','f_moni(''start-stop'')',...
        'position', [150 560 70 30]);
	is_run = 'no';
	
	% create pushbutton for exiting the program
	handle(2) = uicontrol (h_fig_moni, 'style', 'pushbutton',...
        'tooltipstring','EXIT the program',...
        'string', 'EXIT',...
        'value',0,...
        'callback','f_moni(''exit'')',...
        'position', [400 560 70 30]);
	is_exit = 'no'
	
    	% finally, store the handles in the figure's userdata area
	set(h_fig_moni,'userdata',handle);

case 'start-stop' % callback for the start/stop button
    handle = get(h_fig_moni,'userdata'); % get the handles for the uicontrols
    if get(handle(1),'value') == 1
        is_run = 'ys'; % user has requested that simulation run
        set(handle(1),'string','STOP'); % display STOP on the button
    else
        is_run = 'no';
        set(handle(1),'string','START');
    end %     if get(handle(1),'value') == 1
    
case 'exit' % callback for the exit button
    handle = get(h_fig_moni,'userdata'); % get the handles for the uicontrols
    if get(handle(2),'value') == 1
        is_exit = 'ys';
    else
        is_exit = 'no';
    end %    if get(handle(2),'value') == 1

end  % switch cmd_string
