image thumbnail

XPC_DISPLAY_LOGGED_DATA

by

 

28 Nov 2004 (Updated )

xpc_display_logged_data is a GUI for quick display of logged data.

xpc_display_logged_data.m
function varargout = xpc_display_logged_data(varargin)
% XPC_DISPLAY_LOGGED_DATA display logged data from example Model xpcosc.mdl
% 
%  The XPC_DISPLAY_LOGGED_DATA gui is an Example of a User Interface to
%  view the aquired data of a xPC Target Application generated.
%  These GUI does check if a Target Application is connected and while 
%  trying to visualize the aquired data, does check if the Application is
%  still running. If so waits until it stopped. 
%  Read and visualized data then in the GUI zoomed in and out and through
%  the Print Button, the User is able to make a JPG-File Screenshot of the
%  axis content of the Data.
% 
%  These Interface is tested and runnable under R13sp1 and R4.0.
% 
%  Needed Files:      * xpc_display_logged_data.m
%
%
%  SYNTAX: >> xpc_display_logged_data
% 
% 
%  See also: XPC_COMMAND_CENTER XPC_QUICK_REFERENCE XPC_OPENWWWINTERFACE


%% AUTHOR    : Frank Gonzalez-Morphy 
%% $DATE     : 25-June-2004 09:36:02 $ 
%% $Revision : 1.4.7 $ 
%% DEVELOPED : 7.0.0.19920 (R14) 
%% FILENAME  : xpc_command_center.m


% Last Modified by GUIDE v2.5 15-Aug-2004 16:14:55


% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @xpc_display_logged_data_OpeningFcn, ...
                   'gui_OutputFcn',  @xpc_display_logged_data_OutputFcn, ...
                   'gui_LayoutFcn',  @xpc_display_logged_data_LayoutFcn, ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before xpc_display_logged_data is made visible.
function xpc_display_logged_data_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for xpc_display_logged_data
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes xpc_display_logged_data wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% #########################
WB = waitbar(0,'Please wait, search for Target Connection ...');   % Process Bar
for i=1:800, % computation here %
    waitbar(i/1000)
end
if (strcmp(xpctargetping, 'success'))
    % set(tag_txt_app,'String',tg.Application)
    tgob = xpc;
    set(handles.tag_txt_app,'String',tgob.Application)
    handles.xpcobject.tgob = tgob;
    guidata(hObject,handles)
else
    set(handles.tag_txt_app, 'BackgroundColor', 'red', ...
        'ForegroundColor' , 'white', 'String', 'NONE CONNECTION')
    set(handles.tag_txt_title, 'String', 'Close, check TCP/IP Connection and Open again!', ...
        'ForegroundColor', 'red')
    set(handles.tag_btn_close, 'BackgroundColor', 'red', 'ForegroundColor' , 'white')
    set(handles.tag_btn_print, 'Enable', 'Off')
    set(handles.tag_btn_zoom, 'Enable', 'Off')
    set(handles.tag_btn_grid, 'Enable', 'Off')
    set(handles.tag_btn_data, 'Enable', 'Off')
end
close(WB)



% --- Outputs from this function are returned to the command line.
function varargout = xpc_display_logged_data_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in tag_btn_data.
function tag_btn_data_Callback(hObject, eventdata, handles)
% hObject    handle to tag_btn_data (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% ############
% set( ... in der Figure Umgebung data speichern/bergeben ... !!!
if isfield(handles,'xpcobject')
    tg = handles.xpcobject.tgob;
    WarnF = openwarnfig;
    faceclr = get(handles.tag_btn_tgstatus, 'BackgroundColor');
    while strcmp(tg.Status,'running')
        set(handles.tag_btn_tgstatus, 'BackgroundColor', 'red', ...
            'String' , 'Running', ...
            'ForegroundColor' , 'White')
        pause(2)
        %%tg = xpc;  % ???? ist dieses notwendig, um stndig nachzuschahuen ???
        %tg_status = tg.Status;
    end
    close(WarnF)
    set(handles.tag_btn_tgstatus, 'BackgroundColor', faceclr, ...
        'String', '')
    try
        tg_t = tg.TimeLog; 
        tg_o = tg.OutputLog;
        plot(tg_t, tg_o(:,1), 'LineWidth', 2); 
        grid; 
        hold('on'); 
        plot(tg_t, tg_o(:,2),'r', 'LineWidth', 2)
    catch
        disp(' None Data has been Logged. Start and Stop Target.')
        beep
    end
else  % none existent field
    msgbox(' Error while Reading. None Target Connection or valid xPC Object',' :: Reading Data ...','error')
%     disp(' :: None Target Connection or valid Object.')
end


% --- Executes on button press in tag_btn_grid.
function tag_btn_grid_Callback(hObject, eventdata, handles)
% hObject    handle to tag_btn_grid (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% doc grid   
% doc zoom % toggle between ON / OFF
% get(handles.tag_btn_grid)
grid  % toggle between ON / OFF

% hObject
% handles
% hObject =
%   152.0029
% >> handles = 
%                figure1: 186.0032
%          tag_btn_print: 202.0040
%            tag_txt_xpc: 97.0094
%             tag_txt_fg: 96.0094
%            tag_txt_app: 95.0094
%        tag_txt_appname: 94.0094
%          tag_btn_close: 93.0095
%           tag_btn_zoom: 16.0038
%           tag_btn_grid: 15.0029
%           tag_btn_data: 14.0032
%          tag_txt_title: 13.0032
%         tag_frame_plot: 12.0032
%     tag_frame_applname: 11.0032
%                 frame4: 10.0037
%      tag_frame_control: 201.0040
%               tag_axes: 187.0032
%                 output: 186.0032


% --- Executes on button press in tag_btn_print.
function tag_btn_print_Callback(hObject, eventdata, handles)
% hObject    handle to tag_btn_print (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

ax = handles.tag_axes;
% Create a new figure for Saving and Printing
HelperFig = figure('Name',' Helper Printing Window', 'Visible', 'Off');   
% axes                  % Create an axes object in the figure
% copy axes into the new figure
newax = copyobj(ax,HelperFig); 
% newax = copyobj(HelperFig,ax); 
% new_handle = copyobj(h,gca);
% If you would like to have the axes cover a larger area of the figure window rather
% than the original size as in the subplot, then change it's Position value:
set(newax, 'units', 'normalized', 'position', [0.13 0.11 0.775 0.815]);

FN = jpg_printing(HelperFig);

close(HelperFig)
% FN = jpg_printing(handles.to_print_fig);
% FN = jpg_printing(handles.tag_axes)
% FN = jpg_printing(HFig_s)
% jpg_printing
if ~isempty(FN)
    handles.jpg = FN;
    guidata(hObject, handles)
end

% ------------------------------------------------------------
function figh = openwarnfig
figh = dialog('Name', ' :: Logged Data Viewer :: ', ...
    'Position', [614   508   333   115]);
txt = uicontrol(figh, 'Style', 'Text', ...
    'String', 'Please wait, till Target has stopped !', ...
    'Position', [15 45 300 30], 'FontSize', 14);
movegui(figh, 'center')

                      
% By GUIDE created Graphical Structure ...


% --- Creates and returns a handle to the GUI figure. 
function h1 = xpc_display_logged_data_LayoutFcn(policy)
% policy - create a new figure or use a singleton. 'new' or 'reuse'.

persistent hsingleton;
if strcmpi(policy, 'reuse') & ishandle(hsingleton)
    h1 = hsingleton;
    return;
end

appdata = [];
appdata.GUIDEOptions = struct(...
    'active_h', [], ...
    'taginfo', struct(...
    'figure', 2, ...
    'axes', 2, ...
    'text', 8, ...
    'pushbutton', 6, ...
    'frame', 5), ...
    'override', 0, ...
    'release', 13, ...
    'resize', 'none', ...
    'accessibility', 'callback', ...
    'mfile', 1, ...
    'callbacks', 1, ...
    'singleton', 1, ...
    'syscolorfig', 1, ...
    'lastSavedFile', 'D:\work\2Do_Check\MATLABcentral\_Frank_Contributions\xpc_display_logged_data\xpc_display_logged_data.m', ...
    'blocking', 0);
appdata.lastValidTag = 'figure1';
appdata.GUIDELayoutEditor = [];

h1 = figure(...
'Units','characters',...
'PaperUnits',get(0,'defaultfigurePaperUnits'),...
'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
'IntegerHandle','off',...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'MenuBar','none',...
'Name',' :: Logged Data Viewer :: - v1.4',...
'NumberTitle','off',...
'PaperPosition',get(0,'defaultfigurePaperPosition'),...
'PaperSize',[20.98404194812 29.67743169791],...
'PaperType',get(0,'defaultfigurePaperType'),...
'Position',[103.8 21.8461538461539 140 39.6153846153846],...
'Renderer',get(0,'defaultfigureRenderer'),...
'RendererMode','manual',...
'Resize','off',...
'HandleVisibility','callback',...
'Tag','figure1',...
'UserData',[],...
...'Behavior',get(0,'defaultfigureBehavior'),...
'Visible','on',...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_axes';

h2 = axes(...
'Parent',h1,...
'Units','characters',...
'Position',[42.2 4.15384615384616 90.2 30],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
...'LooseInset',[18.2 4.35769230769231 13.3 2.97115384615385],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','tag_axes',...
...'Behavior',get(0,'defaultaxesBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

h3 = get(h2,'title');

set(h3,...
'Parent',h2,...
'Color',[0 0 0],...
'HorizontalAlignment','center',...
'Position',[0.5 1.01666666666667 1.00005459937205],...
'VerticalAlignment','bottom',...
'HandleVisibility','off');  %, ...
...'Behavior',struct());

h4 = get(h2,'xlabel');

set(h4,...
'Parent',h2,...
'Color',[0 0 0],...
'HorizontalAlignment','center',...
'Position',[0.497782705099778 -0.0602564102564105 1.00005459937205],...
'VerticalAlignment','cap',...
'HandleVisibility','off');  %, ...
...'Behavior',struct());

h5 = get(h2,'ylabel');

set(h5,...
'Parent',h2,...
'Color',[0 0 0],...
'HorizontalAlignment','center',...
'Position',[-0.0631929046563193 0.496153846153846 1.00005459937205],...
'Rotation',90,...
'VerticalAlignment','bottom',...
'HandleVisibility','off');  %,...
...'Behavior',struct());

h6 = get(h2,'zlabel');

set(h6,...
'Parent',h2,...
'Color',[0 0 0],...
'HorizontalAlignment','right',...
'Position',[-0.468957871396896 1.17820512820513 1.00005459937205],...
'HandleVisibility','off',...
...'Behavior',struct(),...
'Visible','off');

appdata = [];
appdata.lastValidTag = 'tag_frame_control';

h7 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'ListboxTop',0,...
'Position',[2 3.30769230769232 33.2 33.9230769230769],...
'String','',...
'Style','frame',...
'Tag','tag_frame_control',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'frame4';

h8 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'BackgroundColor',[0.501960784313725 0.501960784313725 0.501960784313725],...
'ListboxTop',0,...
'Position',[5.6 12.5384615384615 25.8 8.46153846153846],...
'String',{  '' },...
'Style','frame',...
'Tag','frame4',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_frame_applname';

h9 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'BackgroundColor',[0.501960784313725 0.501960784313725 0.501960784313725],...
'ListboxTop',0,...
'Position',[3.4 31.3846153846154 30 2.69230769230769],...
'String',{  '' },...
'Style','frame',...
'Tag','tag_frame_applname',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_frame_plot';

h10 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'BackgroundColor',[0.501960784313725 0.501960784313725 0.501960784313725],...
'ListboxTop',0,...
'Position',[5.6 21.4615384615385 25.8 8.46153846153846],...
'String',{  '' },...
'Style','frame',...
'Tag','tag_frame_plot',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_txt_title';

h11 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'FontSize',12,...
'FontWeight','bold',...
'ListboxTop',0,...
'Position',[42.2 34.6923076923077 90 2.38461538461538],...
'String','Display of Logged Real-Time Application Data',...
'Style','text',...
'Tag','tag_txt_title',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_btn_data';

h12 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'Callback','xpc_display_logged_data(''tag_btn_data_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[7.6 26.6153846153846 21.6 2],...
'String','Read Targetdata',...
'TooltipString','Reads the saved Data from Target Application',...
'Tag','tag_btn_data',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_btn_grid';

h13 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'Callback','xpc_display_logged_data(''tag_btn_grid_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[7.6 18.3076923076923 21.6 2],...
'String','Grid   ON/OFF',...
'TooltipString','Show the Grid at the Axis; Toggle between ON and OFF Status',...
'Tag','tag_btn_grid',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_btn_zoom';

h14 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'Callback','zoom',...
'ListboxTop',0,...
'Position',[7.6 15.7692307692308 21.6 2],...
'String','Zoom   ON/OFF',...
'TooltipString','Zoom functionality of display axis; Toggle between ON and OFF Status',...
'Tag','tag_btn_zoom',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_btn_close';

h15 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'Callback','closereq',...
'ListboxTop',0,...
'Position',[7.6 5.23076923076924 21.6 2],...
'String','Close',...
'TooltipString','Close these Window',...
'Tag','tag_btn_close',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_txt_appname';

h16 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'FontSize',9,...
'FontWeight','bold',...
'ListboxTop',0,...
'Position',[4.8 34.2307692307692 27.2 1.76923076923077],...
'String','Application Name',...
'Style','text',...
'TooltipString','Actual application on Target',...
'Tag','tag_txt_appname',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_txt_app';

h17 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'ListboxTop',0,...
'Position',[4.4 32.0769230769231 28 1.15384615384615],...
'String','-none-',...
'Style','text',...
'TooltipString','Shows the Name of Loaded Appliaction',...
'Tag','tag_txt_app',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_txt_fg';

h18 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'FontAngle','italic',...
'ListboxTop',0,...
'Position',[105 0.692307692307701 28 1.15384615384615],...
'String','Frank Gonzalez-Morphy',...
'Style','text',...
'TooltipString','eM: f.gonzalez@mathworks.de - The MathWorks GmbH',...
'Tag','tag_txt_fg',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_txt_xpc';

h19 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'FontWeight','bold',...
'ListboxTop',0,...
'Position',[0.2 1.00000000000001 35 1.38461538461538],...
'String','xPC Target Applications',...
'Style','text',...
'Tag','tag_txt_xpc',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_btn_print';

h20 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'Callback','xpc_display_logged_data(''tag_btn_print_Callback'',gcbo,[],guidata(gcbo))',...
'ListboxTop',0,...
'Position',[7.6 13.2307692307692 21.6 2],...
'String','PRINT',...
'TooltipString','Does the current axis view print in a JPG File',...
'Tag','tag_btn_print',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'txt_tip';

h21 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'HorizontalAlignment','left',...
'ListboxTop',0,...
'Position',[41.6 1.00000000000001 57.6 1.15384615384615],...
'String','TIP: Left Mouse Doubleclick to Zoom 100% out !!',...
'Style','text',...
'TooltipString','TIP: Left Mouse Doubleclick to Zoom 100% out !!',...
'Tag','txt_tip',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'tag_btn_tgstatus';

h22 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'BackgroundColor',[0.501960784313725 0.501960784313725 0.501960784313725],...
'FontSize',10,...
'FontWeight','bold',...
'ForegroundColor',[1 1 1],...
'Position',[7.6 24.0769230769231 21.6 1.53846153846154],...
'String','',...
'Style','text',...
'TooltipString','Show the Status of Target, if runing or stopped',...
'Tag','tag_btn_tgstatus',...
...'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );


hsingleton = h1;


% --- Set application data first then calling the CreateFcn. 
function local_CreateFcn(hObject, eventdata, createfcn, appdata)

if ~isempty(appdata)
   names = fieldnames(appdata);
   for i=1:length(names)
       name = char(names(i));
       setappdata(hObject, name, getfield(appdata,name));
   end
end

if ~isempty(createfcn)
   eval(createfcn);
end


% --- Handles default GUIDE GUI creation and callback dispatch
function varargout = gui_mainfcn(gui_State, varargin)


%   GUI_MAINFCN provides these command line APIs for dealing with GUIs
%
%      XPC_DISPLAY_LOGGED_DATA, by itself, creates a new XPC_DISPLAY_LOGGED_DATA or raises the existing
%      singleton*.
%
%      H = XPC_DISPLAY_LOGGED_DATA returns the handle to a new XPC_DISPLAY_LOGGED_DATA or the handle to
%      the existing singleton*.
%
%      XPC_DISPLAY_LOGGED_DATA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in XPC_DISPLAY_LOGGED_DATA.M with the given input arguments.
%
%      XPC_DISPLAY_LOGGED_DATA('Property','Value',...) creates a new XPC_DISPLAY_LOGGED_DATA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".

%   Copyright 1984-2004 The MathWorks, Inc.
%   $Revision: 1.4.6.8 $ $Date: 2004/04/15 00:06:57 $

gui_StateFields =  {'gui_Name'
                    'gui_Singleton'
                    'gui_OpeningFcn'
                    'gui_OutputFcn'
                    'gui_LayoutFcn'
                    'gui_Callback'};
gui_Mfile = '';
for i=1:length(gui_StateFields)
    if ~isfield(gui_State, gui_StateFields{i})
        error('Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile);        
    elseif isequal(gui_StateFields{i}, 'gui_Name')
        gui_Mfile = [gui_State.(gui_StateFields{i}), '.m'];
    end
end

numargin = length(varargin);

if numargin == 0
    % XPC_DISPLAY_LOGGED_DATA
    % create the GUI
    gui_Create = 1;
elseif isequal(ishandle(varargin{1}), 1) && ispc && iscom(varargin{1}) && isequal(varargin{1},gcbo)
    % XPC_DISPLAY_LOGGED_DATA(ACTIVEX,...)    
    vin{1} = gui_State.gui_Name;
    vin{2} = [get(varargin{1}.Peer, 'Tag'), '_', varargin{end}];
    vin{3} = varargin{1};
    vin{4} = varargin{end-1};
    vin{5} = guidata(varargin{1}.Peer);
    feval(vin{:});
    return;
elseif ischar(varargin{1}) && numargin>1 && isequal(ishandle(varargin{2}), 1)
    % XPC_DISPLAY_LOGGED_DATA('CALLBACK',hObject,eventData,handles,...)
    gui_Create = 0;
else
    % XPC_DISPLAY_LOGGED_DATA(...)
    % create the GUI and hand varargin to the openingfcn
    gui_Create = 1;
end

if gui_Create == 0
    varargin{1} = gui_State.gui_Callback;
    if nargout
        [varargout{1:nargout}] = feval(varargin{:});
    else
        feval(varargin{:});
    end
else
    if gui_State.gui_Singleton
        gui_SingletonOpt = 'reuse';
    else
        gui_SingletonOpt = 'new';
    end
    
    % Open fig file with stored settings.  Note: This executes all component
    % specific CreateFunctions with an empty HANDLES structure.
    
    % Do feval on layout code in m-file if it exists
    if ~isempty(gui_State.gui_LayoutFcn)
        gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
        % openfig (called by local_openfig below) does this for guis without
        % the LayoutFcn. Be sure to do it here so guis show up on screen.
        movegui(gui_hFigure,'onscreen')
    else
        gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);            
        % If the figure has InGUIInitialization it was not completely created
        % on the last pass.  Delete this handle and try again.
        if isappdata(gui_hFigure, 'InGUIInitialization')
            delete(gui_hFigure);
            gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);            
        end
    end
    
    % Set flag to indicate starting GUI initialization
    setappdata(gui_hFigure,'InGUIInitialization',1);

    % Fetch GUIDE Application options
    gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
    
    if ~isappdata(gui_hFigure,'GUIOnScreen')
        % Adjust background color
        if gui_Options.syscolorfig 
            set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
        end

        % Generate HANDLES structure and store with GUIDATA
        guidata(gui_hFigure, guihandles(gui_hFigure));
    end
    
    % If user specified 'Visible','off' in p/v pairs, don't make the figure
    % visible.
    gui_MakeVisible = 1;
    for ind=1:2:length(varargin)
        if length(varargin) == ind
            break;
        end
        len1 = min(length('visible'),length(varargin{ind}));
        len2 = min(length('off'),length(varargin{ind+1}));
        if ischar(varargin{ind}) && ischar(varargin{ind+1}) && ...
                strncmpi(varargin{ind},'visible',len1) && len2 > 1
            if strncmpi(varargin{ind+1},'off',len2)
                gui_MakeVisible = 0;
            elseif strncmpi(varargin{ind+1},'on',len2)
                gui_MakeVisible = 1;
            end
        end
    end
    
    % Check for figure param value pairs
    for index=1:2:length(varargin)
        if length(varargin) == index
            break;
        end
        try set(gui_hFigure, varargin{index}, varargin{index+1}), catch break, end
    end

    % If handle visibility is set to 'callback', turn it on until finished
    % with OpeningFcn
    gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
    if strcmp(gui_HandleVisibility, 'callback')
        set(gui_hFigure,'HandleVisibility', 'on');
    end
    
    feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
    
    if ishandle(gui_hFigure)
        % Update handle visibility
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
        
        % Make figure visible
        if gui_MakeVisible
            set(gui_hFigure, 'Visible', 'on')
            if gui_Options.singleton 
                setappdata(gui_hFigure,'GUIOnScreen', 1);
            end
        end

        % Done with GUI initialization
        rmappdata(gui_hFigure,'InGUIInitialization');
    end
    
    % If handle visibility is set to 'callback', turn it on until finished with
    % OutputFcn
    if ishandle(gui_hFigure)
        gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
        if strcmp(gui_HandleVisibility, 'callback')
            set(gui_hFigure,'HandleVisibility', 'on');
        end
        gui_Handles = guidata(gui_hFigure);
    else
        gui_Handles = [];
    end
    
    if nargout
        [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    else
        feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    end
    
    if ishandle(gui_hFigure)
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
    end
end    

function gui_hFigure = local_openfig(name, singleton)

% openfig with three arguments was new from R13. Try to call that first, if
% failed, try the old openfig.
try 
    gui_hFigure = openfig(name, singleton, 'auto');
catch
    % OPENFIG did not accept 3rd input argument until R13,
    % toggle default figure visible to prevent the figure
    % from showing up too soon.
    gui_OldDefaultVisible = get(0,'defaultFigureVisible');
    set(0,'defaultFigureVisible','off');
    gui_hFigure = openfig(name, singleton);
    set(0,'defaultFigureVisible',gui_OldDefaultVisible);
end

Contact us