function sumboard
%SUMBOARD Creates the ident figure.

%	L. Ljung 4-4-94
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.12 $  $Date: 1995/05/24 11:51:11 $

global XIDhw XIDposd XIDposm XIDsbmen XIDplotprefs
global XIDplotw XIDsumb  XIDlayout XIDstatus XIDcounters XIDsessions
XIDplotw=-ones(16,3);
XIDcounters=[8,16,0,0];
layout
s1='iduipoin(1);';s2='iduipoin(1);iduistat(''Compiling ...'');eval(''';
s3='iduipoin(2);';s4='''),iduipoin(2);';
mStdButtonWidth=0.8*mStdButtonWidth;
H0 = mEdgeToFrame;                % Mimimum measurement
Voff = 5*mEdgeToFrame;            % Uicontrol vertical/horizontal offset
CBWH = [1.8*mStdButtonWidth mStdButtonHeight];
PUWH = [1.8*mStdButtonWidth CBWH(2)];

% Make axes have appealling "golden" ratio
AxisW = (CBWH(1)-Voff)/2;
AWH = AxisW*[1 2/(1+sqrt(5))];

% Define figure width and height
FigW = 3*CBWH(1) + PUWH(1) + Voff + 4*mFrameToText;
FigH = 4*AWH(2) + 8*CBWH(2) + mFrameToText + 5*H0 + 6*Voff;

DefUIBgC = get(0,'DefaultUIcontrolBackgroundColor');
comp = computer;
if all(comp(1:2)=='PC'),
   DefUIBgC = [.7 .7 .7];
end
figname=idlaytab('figname',16);
scrsize=get(0,'screensize');

fprintf('.') 
Plotcolors=idlayout('plotcol');
axescolor=Plotcolors(5,:);
fig = figure('Unit','pix','Position',[10 scrsize(4)-FigH-10 FigW FigH], ...
 'Color',DefUIBgC,'MenuBar','none','ColorMap',[],'NextPlot','new', ...
 'NumberTitle','off','Name',figname,'backingstore','on',...
 'DefaultAxesBox','on','DefaultAxesColor',DefUIBgC, ...
 'DefaultAxesDrawMode','fast','DefaultAxesUnit','pixel', ...
 'DefaultAxesYTick',[],'DefaultAxesYTickLabels',[], ...
 'DefaultAxesXTick',[],'DefaultAxesXTickLabels',[], ...
 'DefaultTextFontSize',8, ...
 'DefaultTextHorizontalAlignment','center',...
 'DefaultAxesXColor',axescolor, 'DefaultAxesYColor',axescolor, ...
 'DefaultAxesZColor',axescolor, ...
 'Visible','off','tag','sitb16');     
XIDsumb(1)=fig;
fprintf('.') 
    [label,acc]=menulabel('&File');
f = uimenu(fig,'Label',label);
    [label,acc]=menulabel('&Open session... ^o');
    XIDsbmen(1)=uimenu(f,'Label',label,'Accel',acc,'callback',...
      [s2,'iduisess(''''load'''');',s4],'tag','open');
    [label,acc]=menulabel('&Close session');
    XIDsbmen(3)=uimenu(f,'Label',label,'Accel',acc,'callback',...
       [s2,'iduiedit(''''new'''');',s4],'interruptible','yes',...
       'enable','off'); 
    [label,acc]=menulabel('&Save session ^s');
    XIDsbmen(4)=uimenu(f,'Label',label,'Accel',acc,'tag','save',...
    'callback',[s2,'iduisess(''''save'''');',s4],'enable','off','separator','on');
    [label,acc]=menulabel('Save session &as...');
    XIDsbmen(5)=uimenu(f,'Label',label,'tag','saveas',... 
        'callback',[s2,'iduisess(''''save_as'''');',s4],'enable','off');
    [label,acc]=menulabel(['&1 ',deblank(XIDsessions(1,:))]);
    XIDsbmen(6)=uimenu(f,'Label',label,...
      'userdata',deblank(XIDsessions(1,:)),'tag',deblank(XIDsessions(2,:)),...
        'separator','on',... 
        'callback',[s2,'iduisess(''''direct'''',6);',s4],'enable','on' );
    [label,acc]=menulabel(['&2 ',deblank(XIDsessions(3,:))]);
    XIDsbmen(7)=uimenu(f,'Label',label,...
      'userdata',deblank(XIDsessions(3,:)),'tag',deblank(XIDsessions(4,:)),...
        'callback',[s2,'iduisess(''''direct'''',7);',s4],'enable','on' );
    [label,acc]=menulabel(['&3 ',deblank(XIDsessions(5,:))]);
    XIDsbmen(8)=uimenu(f,'Label',label,...
      'userdata',deblank(XIDsessions(5,:)),'tag',deblank(XIDsessions(6,:)),...
        'callback',[s2,'iduisess(''''direct'''',8);',s4],'enable','on' );
    [label,acc]=menulabel(['&4 ',deblank(XIDsessions(7,:))]);
    XIDsbmen(9)=uimenu(f,'Label',label,...
      'userdata',deblank(XIDsessions(7,:)),'tag',deblank(XIDsessions(8,:)),...
        'callback',[s2,'iduisess(''''direct'''',9);',s4],'enable','on' );
    
    [label,acc]=menulabel('&Exit ident^w');
    uimenu(f,'Label',label,'Accel',acc,'callback',...
  [s1,'iduiedit(''close_all'');',s3],'interruptible','yes','separator','on'); 

    [label,acc]=menulabel('&Options');
o = uimenu(fig,'Label',label);
    [label,acc]=menulabel('E&xtra model/data board ^x');
    uimenu(o,'Label',label,'Accel',acc,'callback',...
     [s1,'iddmtab;',s3]);
    [label,acc]=menulabel('&Empty trash');
    XIDsbmen(10)=uimenu(o,'label',label,'enable','off',...
              'callback',[s1,'iduiwast(''kill'');',s3],'tag','trashmenu');
    [label,acc]=menulabel('&Save preferences');
    uimenu(o,'Label',label,'separator','on','interruptible','yes',...
              'callback',[s1,'idlaytab(''save'');idlaytab(''savepf'');',s3]);
    [label,acc]=menulabel('&Default preferences');
    uimenu(o,'label',label,'callback',[s1,'idlaytab(''def'');',s3],...
          'interruptible','yes');
    [label,acc]=menulabel('&Window');    
w = uimenu(fig,'Label',label,'callback','winmenu','Tag','winmenu');
    winmenu(fig);
    [label,acc]=menulabel('&Help');
h = uimenu(fig,'Label',label);
    [label,acc]=menulabel('&System Identification');
    uimenu(h,'Label',label,'callback',...
             'iduihelp(''sitbgui.hlp'',''Help: The Big Picture'');')
    [label,acc]=menulabel('&Interactive demo');
    uimenu(h,'Label',label,'callback','iduidemo(0);') 
    [label,acc]=menulabel('&Using ident');
    uimenu(h,'Label',label,'callback',...
             'iduihelp(''idmw.hlp'',''Help: ident'');')
    [label,acc]=menulabel('&Help topics');
    uimenu(h,'Label',label,'callback',...
             'iduihelp(''idhtop.hlp'',''Help: File menu'');')
    [label,acc]=menulabel('&Don''t miss this');
    uimenu(h,'Label',label,'callback',...
             'iduihelp(''iduidmt.hlp'',''Help: Import data and models'');')

% Define a bunch of constants for offsets
H1 = mFrameToText;                % Left corner of Data Views checkbox
H2 = H1 + AxisW + Voff;           % Left corner of right axis under Data
H3 = H2 + AxisW + mFrameToText;   % Left corner of center column popup
H4 = H3 + PUWH(1) + mFrameToText; % Left corner of Model Views checkbox
H5 = H4 + AxisW + Voff;           % Left corner of 2nd axis under Models
H6 = H5 + AxisW + Voff;           % Left corner of 3rd axis under Models
H7 = H6 + AxisW + Voff;           % Left corner of 4th axis under Models

% Preallocate some memory
Text     = zeros(6,1);
CheckBox = zeros(8,1);
Axis     = zeros(28,1);
Popup    = zeros(4,1);
V1 = H0;

% Create the status line
StatusW = FigW -2*H0;
Text(1) = uicontrol(fig,'Style','text','String','Status line is here.', ...
 'BackgroundColor',DefUIBgC, ...
 'Position',[H0 V1 StatusW CBWH(2)]);
XIDstatus(16)=Text(1);
% Make Checkboxes and Popups
V3 = V1 + CBWH(2) + 2*H0;;
V4 = V3 + CBWH(2) + Voff;
V5 = V4 + CBWH(2) + Voff;
V6 = V5 + CBWH(2) + Voff;
CheckBox(1) = uicontrol('Style','check','String','Time plot', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H1 V6 CBWH]);
CheckBox(2) = uicontrol('Style','check','String','Data spectra', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H1 V5 CBWH]);

CheckBox(3) = uicontrol('Style','check','String','Model output', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H4 V6 CBWH]);
CheckBox(4) = uicontrol('Style','check','String','Model resids', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H4 V5 CBWH]);

CheckBox(5) = uicontrol('Style','check','String','Transient resp', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H6 V6 CBWH]);
CheckBox(6) = uicontrol('Style','check','String','Frequency resp', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H6 V5 CBWH]);
CheckBox(7) = uicontrol('Style','check','String','Zeros and poles', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H6 V4 CBWH]);
CheckBox(8) = uicontrol('Style','check','String','Noise spectrum', ...
 'HorizontalAlignment','left','BackgroundColor',DefUIBgC, ...
 'Position',[H6 V3 CBWH]);
XIDplotw([1 13 3 6 5 2 4 7],2)=CheckBox(1:8);
% Make a Close button.  Actually adds some symmetry
Push = uicontrol('Style','push','String','Exit','Position',[H1 V3 CBWH], ...
 'Callback',[s1,'iduiedit(''close_all'');',s3],'interruptible','yes',...
  'backgroundcolor',DefUIBgC);

% Make Data Views and Model Views text
V7 = V6 + CBWH(2) + H0;
Text(2) = uicontrol(fig,'Style','text','String','Data Views', ...
 'BackgroundColor',DefUIBgC, ...
 'Position',[H1 V7 CBWH]);
Text(3) = uicontrol(fig,'Style','text','String','Model Views', ...
 'BackgroundColor',DefUIBgC, ...
 'Position',[H5 V7 CBWH]);
SpecialAWH = AWH;%[(1+sqrt(5))/2 1]*(2*CBWH(2)+Voff);

Axis(26) = axes('Position',...
     [H4+CBWH(1)/4 V5-SpecialAWH(2)-H0 SpecialAWH],'tag','selva','color','k');
Text(4)=get(Axis(26),'xlabel');
set(Text(4),'string','Validation Data','color','k')

text('pos',[0.5 0],'units','norm','tag','name',...
                      'verticalalignment','bottom');
line('color','w','vis','off','erasemode','normal','tag',...
             'selline');
XIDhw(4,1)=Axis(26);

% Make To Workspace icon
ToWSBottom = V6;
ToWSLeft = H3+(CBWH(1)-AWH(1))/2;
Axis(27) = axes('Position',[ToWSLeft ToWSBottom AWH],'Color',DefUIBgC, ...
 'XColor','k','YColor','k','Zcolor','k', ...
 'DefaultTextColor','k','tag','expor');
text(.5,.7,'To')
text(.5,.3,'Workspace')

% Make empty trashcan icon

TrashWH = 1.5*[20 30];
TrashLeft = H3 + (CBWH(1)-TrashWH(1))/2;
TrashBottom = V3 + 3*Voff;
Axis(28) = axes('Position',[TrashLeft TrashBottom TrashWH], ...
 'Box','off','Color',DefUIBgC,'xcolor',DefUIBgC,'ycolor',DefUIBgC, ...
 'zcolor','k',...
 'Xlim',[0 50],'Ylim',[0 100],'NextPlot','new','tag','waste');
text(25,-25,'Trash','Color','k')
xd = [18  18  32 32  0  0 50 50 32 NaN  1 1 49 49 NaN 10 12 12 10 NaN ...
      20 22 22 20 NaN 30 32 32 30 NaN 40 42 42 40];
yd = [95 100 100 95 95 90 90 95 95 NaN 90 0  0 90 NaN 80 75 15 10 NaN ...
      80 75 15 10 NaN 80 75 15 10 NaN 80 75 15 10];
lem = line(xd,yd,'Color','k','tag','empty');
% Here's a non-empty trashcan
xd = [18  18  32 32  0  0 50 50 32 NaN 10  0  0 10 40 50 50 40 NaN ...
      12  7  7 12 NaN ...
      22 17 17 22 NaN 28 33 33 28 NaN 38 43 43 38];
yd = [95 100 100 95 95 90 90 95 95 NaN 90 70 20  0  0 20 70 90 NaN ...
      80 70 20 10 NaN ...
      80 70 20 10 NaN 80 70 20 10 NaN 80 70 20 10];
lf = line(xd,yd,'Color','k','vis','off','tag','full');
fprintf('.') 

% Create the data and model axes
V2 = V7 + CBWH(2) + Voff + mFrameToText/2;
VVL = V2; % Level of lowermost axes
kd=8;km=16;map=idlayout('colors');
HPOS=[H1 H2 H3 H4 H5 H6 H7];
for i=4:-1:1,
   Axis(6*(i-1)+1) = axes('Position',[H2 V2 AWH],'NextPlot','add',...
      'tag',['data ',int2str(kd)]);
   text('pos',[0.5 0],'units','norm','tag','name',...
                      'verticalalignment','bottom');
   line('color',map(kd,:),'vis','off','erasemode','normal','tag',...
             'dataline0');kd=kd-1;
   Axis(6*(i-1)+2) = axes('Position',[H1 V2 AWH],'NextPlot','add',...
      'tag',['data ',int2str(kd)]);
   text('pos',[0.5 0],'units','norm','tag','name',...
                      'verticalalignment','bottom');
   line('color',map(kd,:),'vis','off','erasemode','normal','tag',...
             'dataline0');kd=kd-1;
   for kpos=6:-1:3
      Axis(6*(i-1)+kpos) = axes('Position',[HPOS(kpos+1) V2 AWH],...
        'NextPlot','add','tag',['model',int2str(km)]);
      text('pos',[0.5 0],'units','norm','tag','name',...
                      'verticalalignment','bottom');
      line('color',map(km,:),'vis','off','erasemode','normal','tag',...
             'modelline0');km=km-1;
   end
   V2 = V2 + AWH(2) + Voff;
end
VVU = V2 - AWH(2) -Voff; % Level of uppermost icon axes
fprintf('.') 

Axis(30) = axes('position',get(Axis(4),'pos'),'vis','off');
a1 = text('Unit','norm','Position',[1.05 1.3], ...
 'Rotation',-90, ...
 'String','-->','Color','k', ...
 'FontSize',12,'FontWeight','bold','FontName','arial');
Axis(31) = axes('position',get(Axis(2),'pos'),'vis','off');
a2 = text('Unit','norm','Position',[1.05 1.3], ...
 'Rotation',-90, ...
 'String','-->','Color','k', ...
 'FontSize',12,'FontWeight','bold','FontName','arial');

% Make Data and Model popup and Operations text
V2 = V2 - Voff + 2*H0 + CBWH(2);
Popup(1) = uicontrol(fig,'Style','popup', ...
 'String','Data|Import...|Example...', ...
 'Position',[H1 V2 CBWH], ...
 'BackgroundColor',DefUIBgC, ...
 'Callback',[s2,'iduipop(''''data'''');',s4]);
Popup(2) = uicontrol(fig,'Style','popup','String','Models|Import...', ...
 'Position',[H5 V2 CBWH], ...
 'BackgroundColor',DefUIBgC, ...
 'Callback',[s2,'iduipop(''''model'''');',s4]);
Voper = V2-CBWH(2)-H0;
Text(6) = uicontrol(fig,'Style','text','String','Operations', ...
 'BackgroundColor',DefUIBgC, ...
 'Position',[H3 Voper CBWH]);

% Make popups and Current data axis
Vpop1   = VVU + AWH(2)/4;%Voper - H0 - AWH(2);
VCDaxes = Vpop1 - CBWH(2) - 1.25*AWH(2);
Vpop2   = VVL + AWH(2)/4;%VCDaxes -3*CBWH(2);
Pop3Str = ['<-- Preprocess|Select channels...|Select range...|'...
           'Remove means|Remove trends|Filter...|Resample...|Quick start'];
Popup(3) = uicontrol('Style','popup','String',Pop3Str, ...
 'HorizontalAlignment','left', ...
 'Position',[H3 Vpop1 CBWH], ...
 'BackgroundColor',DefUIBgC, ...
 'Callback',[s2,'iduipop(''''preprocess'''');',s4]);
Pop4Str = [' Estimate -->|Parametric models...|' ...
 'Spectral model...|Correlation model...|Quick start'];
Popup(4) = uicontrol('Style','popup','String',Pop4Str, ...
 'HorizontalAlignment','left', ...
 'Position',[H3 Vpop2 CBWH], ...
 'BackgroundColor',DefUIBgC, ...
 'Callback',[s2,'iduipop(''''estimate'''');',s4]);
XIDplotw(16,1)=Popup(4);
XIDplotw(15,2)=Popup(3);
XIDplotw(14,2)=Popup(2);
set(XIDplotw(16,1),'userdata',str2mat('[]','[]',int2str(1)));
    % usd(1) is cra-filter order usd(2) is spa-M usd(3) is spa-method
Axis(25) = axes('Position',[H3+(CBWH(1)-AWH(1))/2 VCDaxes AWH], ...
            'NextPlot','add','tag','seles','color','k');
text('pos',[0.5 0],'units','norm','tag','name',...
                      'verticalalignment','bottom','color','w');
line('vis','off','erasemode','normal','tag',...
             'selline');
Text(5)=get(Axis(25),'xlabel');
set(Text(5),'string','Working Data','color','k')
XIDhw(3,1) =Axis(25);

Axis(29) = axes('Position',[H3+(CBWH(1)-AWH(1))/2 VCDaxes AWH],'vis','off');
t1 = text('Unit','normal','Position',[-.1 .5],'String','--->', ...
 'HorizontalAlignment','right','Color','k', ...
 'FontSize',12,'FontWeight','bold','FontName','arial');
t2 = text('Unit','normal','Position',[.6 1.4],'String','-->', ...
 'HorizontalAlignment','center', ...
 'VerticalAlignment','bottom','Color','k','Rotation',90, ...
 'FontSize',12,'FontWeight','bold','FontName','arial');
t3 = text('Unit','normal','Position',[.6 -.8],'String','-->', ...
 'HorizontalAlignment','center', ...
 'VerticalAlignment','top','Color','k','Rotation',-90, ...
 'FontSize',12,'FontWeight','bold','FontName','arial');

if isempty(XIDplotprefs)
   pd=idlayout('plotdefs');pd=pd(:);
   pd=pd*ones(1,15);
else
  pd=XIDplotprefs;
end 

set(XIDplotw(1,2),'callback',[s2,'iduipw(1);',s4],'userdata',int2str(pd(12,1)));
set(XIDplotw(14,2),'userdata',int2str(pd(12,14)));
set(XIDplotw(2,2),'callback',[s2,'iduipw(2);',s4],...
 'UserData',str2mat(int2str(pd(2,2)),int2str(pd(3,2)),int2str(pd(1,2)),'[]'));
set(XIDplotw(3,2),'callback',[s2,'iduipw(3);',s4],...
 'UserData',str2mat(int2str(pd(4,3)),int2str(pd(5,3)),'[]',int2str(pd(6,3))));
set(XIDplotw(4,2),'callback',[s2,'iduipw(4);',s4]);
set(XIDplotw(5,2),'callback',[s2,'iduipw(5);',s4],...
      'UserData',str2mat(int2str(pd(8,5)),num2str(pd(9,5)),int2str(pd(7,5))));
set(XIDplotw(6,2),'callback',[s2,'iduipw(6);',s4],...
       'UserData',num2str(pd(10,6)));
set(XIDplotw(7,2),'callback',[s2,'iduipw(7);',s4],...
 'UserData',str2mat(int2str(pd(2,7)),int2str(pd(3,7)),int2str(pd(1,7)),'[]'));
set(XIDplotw(13,2),'userdata',...
     str2mat(int2str(pd(2,13)),int2str(pd(3,13)),...
             int2str(pd(1,13)),'[]',int2str(pd(11,13))),...
      'callback',[s2,'iduipw(13);',s4]);
set(XIDplotw(15,2),'userdata',...
     str2mat(int2str(pd(2,15)),int2str(pd(3,15)),int2str(pd(1,15)),'[]',...
            int2str(pd(11,15))));

set(XIDplotw([1:7,13],2),'visible','on','enable','off');


fprintf('.') 
% Make all the uicontrols and axes normalized

set([Text; CheckBox; Axis; Popup; Push],'Unit','norm')
XIDposd=[];XIDposm=[];
for ka=0:3
   XIDposd=[XIDposd;get(Axis(ka*6+1),'pos');get(Axis(ka*6+2),'pos')];
   for kk=3:6, XIDposm=[XIDposm;get(Axis(ka*6+kk),'pos')];end
end

% Make the figure visible

fprintf('.')
fprintf(' done. \n')
iduistat('Ready to start. Try the Data popup.')
set(XIDsumb(1),'windowbuttondownfcn',...
   ['iduipoin(1);[dat,dat_n,dat_i,do_com]=',...
   'idmwwb;eval(do_com);clear dat dat_n dat_i do_com,iduipoin(2);'],...
  'KeyPressfcn',[s2,'iduikeyp;',s4])
if length(XIDlayout)>15
         if XIDlayout(16,3)
            eval('set(wb,''pos'',XIDlayout(16,1:4))','')
         end
end

set(XIDsumb(1),'vis','on')

% end sumboard


