function erabtns
% Function: erabtns.m
% 
% Usage: erabtns
% 
% Description:
%    Initializes the ERA Window
%    Handles and graphics elements.
%    Returns a vector to those elements.

%
% Version SWD970904
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global HANDLES

top=.95;
left=.83;
btnwd=.16;
btnht=.04;
spacing=.01;

%====================================
% Set up the console frame
%=====================================
frmborder=0.01;
ypos=.03-frmborder;
frmpos=[left-frmborder ypos btnwd+2*frmborder .94+2*frmborder];
HANDLES.herab(1)=uicontrol(HANDLES.hfigdmnd, ...
   'Style','Frame', ...
   'units','normalized', ...
   'visible','off', ...
   'Position',frmpos, ...
   'BackgroundColor',[.5 .5 .5]);

%==================================
% Set up buttons
%==================================
%
% Convergence button
%
btnnum=1;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.herab(2)=uicontrol(HANDLES.hfigdmnd, ...
   'style','push', ...
   'position',btnpos, ...
   'string','Convergence', ...
   'callback','eraconv');


%==================================
% Set up buttons
%==================================
%
% Run era
%
btnnum=2.5;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.herab(3)=uicontrol(HANDLES.hfigdmnd, ...
   'style','push', ...
   'position',btnpos, ...
   'string','Run ERA', ...
   'callback',...
   ['[A,B,C,emac_era,msv_era] = era;', ...
      'era2mode(A,B,C,MODES.eraparam.fs_out,emac_era,msv_era,DATA{1}.respDOF,DATA{1}.refDOF);',...
      'eratext,',...
      'set(HANDLES.hmmenu{6}(1),''enable'',''on''),']);
%
%  q
%
btnnum=3.5;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(4)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','q');

btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(5)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','1',...
   'callback',...
   ['MODES.eraparam.q = str2num(get(HANDLES.herab(5),''string''));']);

%
%  d
%
btnnum=4.5;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(6)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','d');

btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(7)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','1',...
   'callback',...
   ['MODES.eraparam.d = str2num(get(HANDLES.herab(7),''string''));']);


%
%  Poles (a.k.a nx)
%
btnnum=5.5;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(8)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','Poles');

btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(9)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','1',...
   'callback',...
   ['MODES.eraparam.nx = str2num(get(HANDLES.herab(9),''string''));']);



%==================================
% Filter button
%==================================

btnnum=7;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.herab(10)=uicontrol(HANDLES.hfigdmnd, ...
   'style','push', ...
   'position',btnpos, ...
   'string','Run Filter', ...
   'callback',[ ...
      'f_limits(1)=str2num(get(HANDLES.herab(12),''string''));', ...
      'f_limits(2)=str2num(get(HANDLES.herab(14),''string''));', ...
      'mqi_limits(1)=str2num(get(HANDLES.herab(16),''string''));', ...
      'mqi_limits(2)=str2num(get(HANDLES.herab(18),''string''));', ...
      'mqi_limits(3)=str2num(get(HANDLES.herab(20),''string''));', ...
      '[phic_resp,phic_ref,Freq,Damp,emac,mpc_resp,mpc_ref,cmi_resp,cmi_ref]',...
      '=modefilt(phic_resp_t,phic_ref_t,freq_t,damp_t,emac_t,mpc_resp_t,mpc_ref_t,',...
      'cmi_resp_t,cmi_ref_t,f_limits,mqi_limits,0);',...
      'set(HANDLES.hmmenu{6}(1),''enable'',''on''),',...	
      'ifilt = 1;',...
      'if iopDOF == 1,',...
      'textin=ERAtext(Freq,Damp,emac,mpc_resp,cmi_resp);', ...
      'else, textin=ERAtext(Freq,Damp,emac,mpc_ref,cmi_ref);',...
      'end,',...
      'set(HANDLES.herab(24),''string'',textin);']);

%
%  Fmin
%
btnnum=8;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(11)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','Fmin');
btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(12)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','0');
%
%  Fmax
%
btnnum=9;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(13)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','Fmax');
btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(14)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','1');
%
%  EMAC
%
btnnum=10;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(15)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','EMAC');
btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(16)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','.5');

%
%  MPC
%
btnnum=11;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(17)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','MPC');
btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(18)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','.5');

%
%  CMI
%
btnnum=12;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
HANDLES.herab(19)=uicontrol(HANDLES.hfigdmnd, ...
   'style','text', ...
   'position',btnpos, ...
   'string','CMI');
btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
HANDLES.herab(20)=uicontrol(HANDLES.hfigdmnd, ...
   'style','edit', ...
   'position',btnpos, ...
   'string','.5');

%
%  Delete Mode
%

btnnum=16.5;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.herab(21) = uicontrol('style','push',...
   'units','normal',...
   'pos',btnpos,...
   'string','Delete Mode',...
   'callback',...
   ['deletemode(get(HANDLES.herab(24),''value'')-1),',...
      'if MODES.nmodes == 0, hideallbtns, set(HANDLES.hmmenu{6}(1),''enable'',''off''), set(HANDLES.hviewm(1),''visible'',''off''), drawnow,',...
      'else,',...
      ' if imode > 1, imode = imode -1; else imode = 1; end,',...
      ' eratext,',...
      'end,']);


%
%  Listbox for ERA results
%

HANDLES.herab(24)=uicontrol(HANDLES.hfigdmnd,...
   'style','listbox','position',[.05 .05 .7 .84], ...
   'fontname','courier',...
   'backgroundcolor',[.8 .8 .8]);


%
% Title for ERA Results Box
%

HANDLES.herab(23) = uicontrol(HANDLES.hfigdmnd,...
   'style','text',...
   'position',[0.225 0.90 0.35 0.05],...
   'String','ERA RESULTS LIST');

%
%  Monte Carlo Analysis Setup Button
%

btnnum=15.5;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.herab(25)=uicontrol(HANDLES.hfigdmnd, ...
   'style','pushbutton', ...
   'position',btnpos, ...
   'string','Monte Carlo', ...
   'callback',...
   ['set(hmctl(1),''visible'',''on''), figure(hmctl(1)),']);

set(HANDLES.herab,'visible','off')

return