function [hera] = erabtns(figNumber)
% Function: erabtns.m
% 
% Usage: hera = erabtns(figNumber);
% 
% Description:
%    Initializes the ERA Window
%    Handles and graphics elements.
%    Returns a vector to those elements.
%
% Version SWD970331
%
% Author(s): Erik Straser, estraser@lanl.gov
%	modified by Scott W. Doebling, doebling@lanl.gov
%
% Institution: Los Alamos National Laboratory, ESA-EA
%
% Copyright (c) 1996-1997, The Regents of the University
%     	of California.

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];
hera(1)=uicontrol(figNumber, ...
        '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];
hera(2)=uicontrol(figNumber, ...
      '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];
hera(3)=uicontrol(figNumber, ...
 	'style','push', ...
	'position',btnpos, ...
	'string','Run ERA', ...
	'callback',[ ...
		'iopDOF=get(onHndlVector(22),''value'');',...
		'q=str2num(get(onHndlVector(5),''string''));', ...
		'd=str2num(get(onHndlVector(7),''string''));', ...
		'nx=str2num(get(onHndlVector(9),''string''));', ...
		'[A,B,C,D,fs_out,emac_era,msv_era]=era(G,nlines,fs,nx,q,d);', ...
		'[phic_resp_t,phic_ref_t,freq_t,damp_t,emac_t,mpc_resp_t,',...
		   'mpc_ref_t,cmi_resp_t,cmi_ref_t,msv] = era2mode(A,B,C,fs_out,emac_era,msv_era,respDOF,refDOF);',...
		'ifilt=0;',...
		'if iopDOF == 1,',...
		'textin=ERAtext(freq_t,damp_t,emac_t,mpc_resp_t,cmi_resp_t);', ...
		'else, textin=ERAtext(freq_t,damp_t,emac_t,mpc_ref_t,cmi_ref_t);',...
		'end,',...
		'set(onHndlVector(24),''string'',textin);']);
	
%
%  q
%
btnnum=3.5;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.6 btnht];
hera(4)=uicontrol(figNumber, ...
      'style','text', ...
      'position',btnpos, ...
      'string','q');

btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
hera(5)=uicontrol(figNumber, ...
      'style','edit', ...
      'position',btnpos, ...
      'string','1');

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

btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
hera(7)=uicontrol(figNumber, ...
      'style','edit', ...
      'position',btnpos, ...
      'string','1');

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

btnpos=[left+.6*btnwd ypos-btnht btnwd*.4 btnht];
hera(9)=uicontrol(figNumber, ...
      'style','edit', ...
      'position',btnpos, ...
      'string','1');


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

btnnum=7;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd btnht];
hera(10)=uicontrol(figNumber, ...
      'style','push', ...
      'position',btnpos, ...
      'string','Run Filter', ...
      'callback',[ ...
	'f_limits(1)=str2num(get(onHndlVector(12),''string''));', ...
	'f_limits(2)=str2num(get(onHndlVector(14),''string''));', ...
	'mqi_limits(1)=str2num(get(onHndlVector(16),''string''));', ...
	'mqi_limits(2)=str2num(get(onHndlVector(18),''string''));', ...
	'mqi_limits(3)=str2num(get(onHndlVector(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(hmmenu(6),''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(onHndlVector(24),''string'',textin);']);

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

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

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

%
%  Listbox for ERA results
%

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


%
% hera(21) and hera(23) are defunct
%

hera(21) = uicontrol('position',[0 0 eps eps]);


%
% Title for ERA Results Box
%

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

%
%  Input/Output mode shape selector
%

btnnum=14;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd btnht];
hera(22)=uicontrol(figNumber, ...
      'style','popup', ...
      'position',btnpos, ...
      'Value',1,...
      'string','Resp DOF|Ref DOF', ...
       'callback',[...
		'iopDOF=get(onHndlVector(22),''value'');',...
		'if ifilt == 0,',...
		'if iopDOF == 1,',...
		'textin=ERAtext(freq_t,damp_t,emac_t,mpc_resp_t,cmi_resp_t);', ...
		'else, textin=ERAtext(freq_t,damp_t,emac_t,mpc_ref_t,cmi_ref_t);',...
		'end,',...
		'elseif 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,',...
      'end,',...
      'set(onHndlVector(24),''string'',textin);']);
%
%  Monte Carlo Analysis Setup Button
%

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

set(hera,'visible','off')

return