function Handles = loopstruct(ConfigNumber,AxisHandle,Render)
%LOOPSTRUCT  Draws feedback loop configuration.
%
%   Handles = LOOPSTRUCT(ConfigID,AxisHandle,Render) draws the loop
%   configuration with number CONFIGID in the axis with handle AXISHANDLE. 
%   Available RENDERs include
%     1) 'plain':  just the loop topology sketch
%     2) 'signal': include signal names
%
%   The axis limits will be set from 0-1 along both axes to ensure the 
%   loop structure scales appropriately. Any children on the axis are 
%   deleted before the new feedback configuration is drawn. 

%   Author(s): Karen D. Gondoly
%              P. Gahinet 3/00
%   Copyright 1986-2002 The MathWorks, Inc. 
%   $Revision: 1.15 $  $Date: 2002/04/10 04:42:37 $

% Defaults
if nargin<3,
    Render = 'plain';
end

% Draw it
Handles = LocalDrawStruct(AxisHandle,ConfigNumber,Render);


%---------------------Internal Functions-----------------------

%%%%%%%%%%%%%%%%%%%%%%%
%%% LocalDrawStruct %%% 
%%%%%%%%%%%%%%%%%%%%%%%
function Handles = LocalDrawStruct(AxisHandle,ConfigNumber,Render)   
% Draws the current feedback structure

SignalFlag = strcmp(Render(1),'s');

% Delete all children
kids = get(AxisHandle,'Children');
delete(kids(ishandle(kids)))

% Initialize
set(AxisHandle,'Ylim',[0 1],'Xlim',[0 .9+.1*SignalFlag],...
    'XlimMode','manual','YlimMode','manual');
Handles = struct('OpenLine',[],'ClosedLine',[],'FilterLine',[], ...
    'SumPoint1',[], 'SumPoint2',[], ...
    'FilterPatch',[],'FilterText',[],'CompPatch',[],'CompText',[],...
    'SensorPatch',[],'SensorText',[],'PlantPatch',[],'PlantText',[],...
    'Signals',[]);

ColorC = [1 0.45 0.45];
ColorF = [0 0.85 0];
ColorG = [1 1 .8];

%---Add new cases to add new feedback structures
switch ConfigNumber
case 1
    % Tracking loop, compensator in forward path
    yr = .7+.02*SignalFlag;
    Handles.Lines = [...
          line([0.05 .8],[.65 .65],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle);...
          patch([.13 .15 .13 .13],[.625 .65 .675 .625],-9*ones(1,4),'k','Parent',AxisHandle);...
          patch([.78 .8 .78 .78],[.625 .65 .675 .625],-9*ones(1,4),'k','Parent',AxisHandle);...
          line([.3 .3 yr yr],[.65 .2 .2 .65],-10*ones(1,4),'Color',[0 0 0],'Parent',AxisHandle);...
          patch([.55 .57 .57 .55],[.2 .175 .225 .2],-9*ones(1,4),'k','Parent',AxisHandle);...
          patch([.29 .3 .31 .29],.61+[-.05 0 -.05 -.05],-9*ones(1,4),'k','Parent',AxisHandle)];    
    Handles.SumPoint = patch([.292 .292 .308 .308 .292],[.625 .675 .675 .625 .625],-9*ones(1,5),'k',...
       'Parent',AxisHandle);
    Handles.Filter = [...
          patch([.15 .25 .25 .15 .15],[.5 .5 .8 .8 .5],-8*ones(1,5),ColorF,'Parent',AxisHandle);...
          text(.18,.65,'F','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    Handles.Compensator = [...
          patch([.35 .45 .45 .35 .35],[.5 .5 .8 .8 .5],-8*ones(1,5),ColorC,'Parent',AxisHandle);...
          text(.38,.65,'C','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    Handles.Plant = [...
          patch([.55 .65 .65 .55 .55],[.5 .5 .8 .8 .5],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
          text(.58,.65,'G','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    Handles.Sensor = [...
          patch([.45 .55 .55 .45 .45],[.05 .05 .35 .35 .05],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
          text(.48,.2,'H','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    if SignalFlag
        Handles.Signals = [...
                text(0.02,.65,'r','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                text(0.83,.65,'y','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                text(0.49,.55,'u','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line([.5 .5],[.85 .65],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle) ; ... ...
                patch([.49 .51 .5 .49],[.7 .7 .65 .7],-9*ones(1,4),'k','Parent',AxisHandle); .....
                text(0.49,.92,'du','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line([.7 .7],[.85 .65],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle); ...
                patch([.69 .71 .70 .69],[.7 .7 .65 .7],-9*ones(1,4),'k','Parent',AxisHandle); ...                
                text(0.69,.92,'dy','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line([.35 .35],[.2 0.05],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle); ...
                patch([.34 .35 .36 .34],[.15 .2 .15 .15],-9*ones(1,4),'k','Parent',AxisHandle); .....                
                text(.345,0,'n','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    end
    
    
case 2,
    % Tracking loop, compensator in return path
    Handles.Lines = [...
          line([0.05 .8],[.65 .65],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle);...
          patch([.13 .15 .13 .13],[.625 .65 .675 .625],-9*ones(1,4),'k','Parent',AxisHandle);...
          patch([.78 .8 .78 .78],[.625 .65 .675 .625],-9*ones(1,4),'k','Parent',AxisHandle);...
          line([.3 .3 .7 .7],[.65 .2 .2 .65],-10*ones(1,4),'Color',[0 0 0],'Parent',AxisHandle);...
          patch([.65 .67 .67 .65],[.2 .175 .225 .2],-9*ones(1,4),'k','Parent',AxisHandle);...
          patch([.29 .3 .31 .29],.61+[-.05 0 -.05 -.05],-9*ones(1,4),'k','Parent',AxisHandle)];        
    Handles.SumPoint = patch([.292 .292 .308 .308 .292],[.625 .675 .675 .625 .625],-9*ones(1,5),'k',...
       'Parent',AxisHandle);
    Handles.Filter = [...
          patch([.15 .25 .25 .15 .15],[.5 .5 .8 .8 .5],-8*ones(1,5),ColorF,'Parent',AxisHandle);...
          text(.18,.65,'F','Parent',AxisHandle,'Tag','FilterText','FontSize',7,'Color',[0 0 0])];
    Handles.Plant = [...
          patch([.45 .55 .55 .45 .45],[.5 .5 .8 .8 .5],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
          text(.48,.65,'G','Parent',AxisHandle,'Tag','PlantText','FontSize',7,'Color',[0 0 0])];
    Handles.Compensator = [...
          patch([.35 .45 .45 .35 .35],[.05 .05 .35 .35 .05],-8*ones(1,5),ColorC,'Parent',AxisHandle);...
          text(.38,.2,'C','Parent',AxisHandle,'Tag','CompText','FontSize',7,'Color',[0 0 0])];
    Handles.Sensor = [...
          patch([.55 .65 .65 .55 .55],[.05 .05 .35 .35 .05],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
          text(.58,.2,'H','Parent',AxisHandle,'Tag','SensorText','FontSize',7,'Color',[0 0 0])];
    if SignalFlag
       Handles.Signals = [...
                text(0.02,.65,'r','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                text(0.83,.65,'y','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                text(0.4,.56,'u','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line([.36 .36],[.85 .65],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle) ; ...
                patch([.35 .37 .36 .35],[.7 .7 .65 .7],-9*ones(1,4),'k','Parent',AxisHandle); ...                
                text(0.35,.92,'du','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]); ...
                line([.65 .65],[.85 .65],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle) ; ...
                patch([.64 .66 .65 .64],[.7 .7 .65 .7],-9*ones(1,4),'k','Parent',AxisHandle); ...                                
                text(0.64,.92,'dy','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line([.5 .5],[.2 0.05],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle) ; ...
                patch([.49 .5 .51 .49],[.15 .2 .15 .15],-9*ones(1,4),'k','Parent',AxisHandle); .....                                
                text(.495,0,'n','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    end

    
case 3
   % Tracking loop, compensator in forward path, feedforward filter
   yr = .7+.02*SignalFlag;
   Handles.Lines = [...
         line([0.05  .8],[0.57 0.57],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle);...
         patch([.27 .29 .27 .27],[.545 .57 .595 .545],-9*ones(1,4),'k','Parent',AxisHandle);...
         patch([.78 .80 .78 .78],[.545 .57 .595 .545],-9*ones(1,4),'k','Parent',AxisHandle);...  
         line([.3  .3  yr yr],[.57 .2 .2 .57],-10*ones(1,4),'Color',[0 0 0],'Parent',AxisHandle);...
         patch([.55 .57 .57 .55],[.2 .175 .225 .2],-9*ones(1,4),'k','Parent',AxisHandle);...
         patch([.29 .3 .31 .29],.53+[-.05 0 -.05 -.05],-9*ones(1,4),'k','Parent',AxisHandle);...
         line([.12 .12 .15  NaN .25  .5  .5],[.57 .82 .82  NaN .82  .82 .57],-10*ones(1,7),...
         'Color',[0 0 0],'Parent',AxisHandle);...
         patch([ .49 .51 .5 .49], [.675 .675 .625 .675],-9*ones(1,4),'k','Parent',AxisHandle)];    % last two = prefilter
   Handles.SumPoint = [...
         patch([.292 .292 .308 .308 .292],[.545 .595 .595 .545 .545],-9*ones(1,5),'k','Parent',AxisHandle);...
         patch([.492 .492 .508 .508 .492],[.545 .595 .595 .545 .545],-9*ones(1,5),'k','Parent',AxisHandle)];
   Handles.Filter = [...
         patch([.15 .25 .25 .15 .15],[0.65 0.65 0.95 0.95 0.65],-8*ones(1,5),ColorF,'Parent',AxisHandle);...
         text(.17,.8,'F','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
   Handles.Compensator = [...
         patch([.35 .45 .45 .35 .35],[.42 .42 .72 .72 .42],-8*ones(1,5),ColorC,'Parent',AxisHandle);...
         text(.38,.57,'C','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
   Handles.Plant = [...
         patch([.55 .65 .65 .55 .55],[.42 .42 .72 .72 .42],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
         text(.58,.57,'G','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
   Handles.Sensor = [...
         patch([.45 .55 .55 .45 .45],[.05 .05 .35 .35 .05],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
         text(.48,.2,'H','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
   if SignalFlag
      Handles.Signals = [...
            text(0.02,.65,'r','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
            text(0.83,.65,'y','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
            text(0.49,.45,'u','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
            line([.53 .53 .5],[.85 .65 .6],'Color',[0 0 0],'Parent',AxisHandle) ; ...                
            text(0.515,.92,'du','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
            line([.7 .7],[.85 .57],-10*ones(1,2),...
            'Color',[0 0 0],'Parent',AxisHandle) ; ...
            patch(0.05+[.64 .66 .65 .64],-0.06+[.7 .7 .65 .7],-9*ones(1,4),'k','Parent',AxisHandle); ...                                                
            text(0.69,.92,'dy','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
            line([.35 .35],[.2 0.05],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle) ; ...
            patch([.34 .35 .36 .34],[.15 .2 .15 .15],-9*ones(1,4),'k','Parent',AxisHandle); ...                                            
            text(.345,0,'n','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
   end
    
    
case 4,
% Tracking loop, compensator in forward path, feedback filter
    yr = .7+.02*SignalFlag;
    Handles.Lines = [...
          line([0.05 .8],[.8 .8],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle);...
          patch([.17 .19 .17 .17],[.825 .8 .775 .825],-9*ones(1,4),'k','Parent',AxisHandle);...
          patch([.8 .82 .8 .8],[.825 .8 .775 .825],-9*ones(1,4),'k','Parent',AxisHandle);...
          line([.2 .2 yr  yr NaN .64 .59 .64],...
          [.8 .2 .2 .8  NaN .17 .2  .23],-10*ones(1,8),'Color',[0 0 0],'Parent',AxisHandle);...
          patch([.65 .67 .67 .65],[.2 .175 .225 .2],-9*ones(1,4),'k','Parent',AxisHandle);...
          patch([.19 .2 .21 .19],.76+[-.05 0 -.05 -.05],-9*ones(1,4),'k','Parent',AxisHandle);...
          line([.4 .4 ],[.8 .2  ],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle);...
          patch([.4 .39 .41 .4],[.76 .71 .71 .76],-9*ones(1,4),'k','Parent',AxisHandle)];
    Handles.SumPoint = [...
          patch([.192 .192 .208 .208 .192],[.775 .825 .825 .775 .775],-9*ones(1,5),'k','Parent',AxisHandle);...
          patch([.392 .392 .408 .408 .392],[.775 .825 .825 .775 .775],-9*ones(1,5),'k','Parent',AxisHandle)];
    Handles.Filter = [...
           patch([.35 .45 .45 .35 .35],[.25 .25 .55 .55 .25],-8*ones(1,5),ColorF,'Parent',AxisHandle);...
           text(.38,.4,'F','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];    
    Handles.Compensator = [...
          patch([.25 .35 .35 .25 .25],[.65 .65 .95 .95 .65],-8*ones(1,5),ColorC,'Parent',AxisHandle);...
          text(.28,.8,'C','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    Handles.Plant = [...
          patch([.55 .65 .65 .55 .55],[.65 .65 .95 .95 .65],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
          text(.58,.8,'G','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    Handles.Sensor = [...
          patch([.55 .65 .65 .55 .55],[.05 .05 .35 .35 .05],-8*ones(1,5),ColorG,'Parent',AxisHandle);...
          text(.58,.2,'H','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    if SignalFlag
        Handles.Signals = [...
                text(0.1,.9,'r','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                text(0.81,.9,'y','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                text(0.49,.9,'u','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line([.4 .4],[1.05 .82],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle) ; ...
                patch([ .4 .41 .39 .4],[ .85 .9 .9 .85],-9*ones(1,4),'k','Parent',AxisHandle); ...
                text(0.39,1.12,'du','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line( [.7 .7],[1.05 .80],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle) ; ...
                patch([.7 .71 .69 .7],[ .82 .87 .87 .82],-9*ones(1,4),'k','Parent',AxisHandle); ...
                text(0.69,1.12,'dy','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0]) ; ...
                line( [.45 .45],[.2 0.05],-10*ones(1,2),'Color',[0 0 0],'Parent',AxisHandle); ...
                patch([.45 .46 .44 .45],[.19 .14 .14 .19],-9*ones(1,4),'k','Parent',AxisHandle); ...                    
                text(.445,0,'n','Parent',AxisHandle,'FontSize',7,'Color',[0 0 0])];
    end
    

case 5, % was 3
    Handles.OpenLine = line([.2 .8 .76 NaN .8 .76 NaN .31 .35 .31 NaN 0.1 .35 NaN .31 .35 .31], ...
        [.65 .65 .68 NaN .65 .62 NaN .62 .65 .68 NaN .75 .75 NaN .72 .75 .78],...
        'Color',[0 0 0],'Parent',AxisHandle);
    Handles.ClosedLine = line([.2 .2 .7 .7 NaN .59 .55 .59],...
        [.65 .2 .2 .65 NaN .17 .2 .23],...
        'Color',[0 0 0],'Parent',AxisHandle,'Tag','ClosedLine');
    Handles.CompPatch=patch([.35 .45 .45 .35 .35],[.5 .5 .85 .85 .5],'c',...
        'Parent',AxisHandle,'Tag','CompPatch');
    Handles.CompText=text(.375,.675,'C','Parent',AxisHandle,'Tag','CompText','FontSize',7);
    Handles.PlantPatch=patch([.55 .65 .65 .55 .55],[.5 .5 .8 .8 .5],'y', ...
        'Parent',AxisHandle,'Tag','PlantPatch');
    Handles.PlantText=text(.575,.65,'G','Parent',AxisHandle,'Tag','PlantText','FontSize',7);
    Handles.SensorPatch=patch([.45 .55 .55 .45 .45],[.05 .05 .35 .35 .05],'y', ...
        'Parent',AxisHandle,'Tag','SensorPatch');
    Handles.SensorText=text(.475,.2,'H','Parent',AxisHandle,'Tag','SensorText','FontSize',7);
    
case 6, % was 4
    % Small gain problem formulation set-up, see p1-32 of Robust TB manual
    % or P/K set-up in mu p3-20
    Handles.OpenLine = line([.15 .75 .69 NaN .75 .69 NaN .36 .41 .36], ...
        [.75 .75 .78 NaN .75 .72 NaN .72 .75 .78],'Color',[0 0 0],'Parent',AxisHandle);
    Handles.ClosedLine = line([.4 .25 .25 .65 .65 .5 NaN .54 .5 .54],...
        [.65 .65 .2 .2 .65 .65 NaN .17 .2 .23],...
        'Color',[0 0 0],'Parent',AxisHandle,'Tag','ClosedLine');
    Handles.PlantPatch=patch([.4 .5 .5 .4 .4],[.5 .5 .85 .85 .5],'y', ...
        'Parent',AxisHandle,'Tag','PlantPatch');
    Handles.PlantText=text(.425,.675,'G','Parent',AxisHandle,'Tag','PlantText','FontSize',7);
    Handles.CompPatch=patch([.4 .5 .5 .4 .4],[.05 .05 .35 .35 .05],'c', ...
        'Parent',AxisHandle,'Tag','CompPatch');
    Handles.CompText=text(.425,.2,'C','Parent',AxisHandle,'Tag','CompText','FontSize',7);
    
end % switch ConfigNumber





%%%%%%%%%%%%%%%%%%%%%%%
%%% LocalOpenStruct %%% %---Opens the Feedback Structure Window
%%%%%%%%%%%%%%%%%%%%%%%
function a = LocalOpenStruct(ParentFig,OldStructNum,SISOflag);

StdColor = get(0,'DefaultFigureColor');
PointsToPixels = 72/get(0,'ScreenPixelsPerInch');
StdUnit = 'points';

CurrentVal = zeros(1,4);
CurrentVal(OldStructNum)=1;

if SISOflag,
   FigWidth = 170;
   NumConfig = 2;
else
   FigWidth = 300;
   NumConfig = 4;   
end

a = figure('Color',StdColor, ...
   'MenuBar','none', ...
   'WindowStyle','modal',...
   'Name',xlate('Feedback Structures'), ...
   'NumberTitle','off', ...
   'IntegerHandle','off', ...
   'Resize','off', ...
   'Unit','point', ...
   'Position',[86.25 93.75 FigWidth 180],...
   'visible','off',...
   'Tag','ConfigFig');

ConfigText = [{'Compensator in the Forward path'};
   {'Compensator in the Feedback path'};{' '};{' '}];

b = uicontrol('Parent',a, ...
   'Units',StdUnit, ...
   'Position',[102 215 113.25 12], ...
   'backgroundcolor',StdColor, ...
   'FontWeight','bold', ...
   'String','Select a configuration', ...
   'Style','text');

for ct=1:NumConfig,
   
   t = uicontrol('Parent',a, ...
      'Units',StdUnit,...
      'style','text', ...
      'FontWeight','bold', ...
      'FontSize',8,...
      'string',ConfigText{ct}, ...
      'BackgroundColor',StdColor, ...
      'Position',[12+(150*floor(ct/3)) 163-(74*rem(ct+1,2)) 150 12]);
   
   b = axes('Parent',a, ...
      'Units',StdUnit, ...
      'Box','on', ...
      'CameraUpVector',[0 1 0], ...
      'Color',[1 1 1], ...
      'Position',[33.75+(144.75*floor(ct/3)) 109-(74*rem(ct+1,2)) 108 50], ...
      'Tag',['Config',num2str(ct),'Axes'], ...
      'XColor',[0 0 0], ...
      'XTickMode','manual', ...
      'YColor',[0 0 0], ...
      'YLimMode','manual', ...
      'YTickMode','manual', ...
      'ZColor',[0 0 0]);
   
   Handles = LocalDrawStruct(b,ct);
   
   ConfigButton(ct) = uicontrol('Parent',a, ...
      'Units',StdUnit, ...
      'BackgroundColor',[0.8 0.8 0.8], ...
      'Position',[12+(150*floor(ct/3)) 134-(74*rem(ct+1,2)) 15 15], ...
      'Style','radiobutton', ...
      'Callback','rlfcn(''radiocallback'');', ...
      'Tag',['Config',num2str(ct),'Button'], ...
      'Value',CurrentVal(ct));
end

if SISOflag,
   set(ConfigButton(1),'UserData',ConfigButton(2));
   set(ConfigButton(2),'UserData',ConfigButton(1));
else
   set(ConfigButton(1),'UserData',ConfigButton(2:4));
   set(ConfigButton(2),'UserData',ConfigButton([1,3:4]));
   set(ConfigButton(3),'UserData',ConfigButton([1:2,4]));
   set(ConfigButton(4),'UserData',ConfigButton(1:3));
end

b = uicontrol('Parent',a, ...
   'Units',StdUnit, ...
   'Position',[5 5 50 20], ...
   'String','Help', ...
   'Callback','loopstruct(''help'',gcbf);', ...
   'Tag','HelpButton');
b = uicontrol('Parent',a, ...
   'Units','points', ...
   'Position',[FigWidth/2-25 5 50 20], ...
   'String','OK', ...
   'Callback','loopstruct(''apply'',gcbf);', ...
   'Tag','OKButton');
b = uicontrol('Parent',a, ...
   'Units',StdUnit, ...
   'Position',[FigWidth-55 5.25 50 20], ...
   'String','Cancel', ...
   'UserData',ParentFig,...
   'Callback','loopstruct(''close'',gcbf);', ...
   'Tag','CancelButton');

set(a,'visible','on',...
   'UserData',struct('Parent',ParentFig,'StructNum',OldStructNum, ...
   'ConfigButtons',ConfigButton));
