function eraconvsetup
%
%  Name: eraconvsetup
% 
%  Usage: eraconvsetup
% 
%  Description:
%    Initializes the window for era convergence studies
%

%  Version SWD970908
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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

HANDLES.herac(1)=figure( ...
   'Name','ERA Convergence Studies', ...
   'NumberTitle','off', ...
   'visible','off',...
   'unit','normal',...
   'Position',[0.05 0.05 0.75 0.75], ...
   'menubar','none',...
   'closerequestfcn','errordlg(''Do not attempt to close DIAMOND windows improperly'')');

HANDLES.herac(2)=axes('position',[.1 .2 .7 .7],'visible','off');

top=.95;
left=.84;
btnwd=.15;
btnht=.06;
spacing=.01;

%====================================
% Set up the console frame
%=====================================
frmborder=0.01;
ypos=.05-frmborder;
frmpos=[left-frmborder ypos btnwd+2*frmborder .9+2*frmborder];
HANDLES.herac(3)=uicontrol(HANDLES.herac(1), ...
   'Style','Frame', ...
   'units','normalized', ...
   'visible','on', ...
   'Position',frmpos, ...
   'BackgroundColor',[.5 .5 .5]);

%==================================
% Set up buttons
%==================================
%
% Generate Hankel matrices button
%
btnnum=1;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANLDES.herac(4)=uicontrol(HANDLES.herac(1), ...
   'style','push', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','on', ...      
   'string','Plot Hankel SV', ...
   'callback',...
   ['makehank,',...
      'axes(HANDLES.herac(2)); semilogy(diag(MODES.eraparam.S0)),',...
      'xlabel(''Number of Poles''), ylabel(''Singular Value''),',...
      'set(HANDLES.herac([9:17]),''visible'',''on''),']);

%
%  q
%
btnnum=2;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.65 btnht];
HANDLES.herac(5)=uicontrol(HANDLES.herac(1), ...
   'style','text', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','on', ...      
   'string','q');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
HANDLES.herac(6)=uicontrol(HANDLES.herac(1), ...
   'style','edit', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','on', ...      
   'string',' ', ...
   'callback',...
   ['MODES.eraparam.q = str2num(get(HANDLES.herac(6),''string''));']);

%
%  d
%
btnnum=3;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.65 btnht];
HANDLES.herac(7)=uicontrol(HANDLES.herac(1), ...
   'style','text', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','on', ...      
   'string','d');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
HANDLES.herac(8)=uicontrol(HANDLES.herac(1), ...
   'style','edit', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','on', ...      
   'string',' ', ...
   'callback',...
   ['MODES.eraparam.d = str2num(get(HANDLES.herac(8),''string''));']);

%
%  Poles
%
btnnum=4;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
HANDLES.herac(9)=uicontrol(HANDLES.herac(1), ...
   'style','pushbutton', ...
   'units','normalized', ...
   'pos',btnpos, ...
   'visible','off', ...
   'string',' Poles', ...
   'callback',...
   ['[f1,temp] = ginput(1);',...
      'MODES.eraparam.nx = num2str(2*ceil(f1/2));',...
      'set(HANDLES.herac(10),''string'',MODES.eraparam.nx);']);

btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
HANDLES.herac(10)=uicontrol(HANDLES.herac(1), ...
   'style','edit', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string',' ',...
   'callback',...
   ['MODES.eraparam.nx = 2*ceil(str2num(get(HANDLES.herac(10),''string''))/2);',...
      'set(HANDLES.herac(10),''string'',MODES.eraparam.nx);']);
%
%  Run vine plot
%
btnnum=5;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.herac(11)=uicontrol(HANDLES.herac(1), ...
   'style','push', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string','Run Vine', ...
   'callback',...
   ['axes(HANDLES.herac(2)); cla;', ...
      'title(''Vine Plot''); xlabel(''Frequency (Hz)''), ylabel(''Model Order'');', ...
      'set(HANDLES.herac(2),''yscale'',''lin''),',...
      'axis([DATA{1}.cf-DATA{1}.sp/2 DATA{1}.cf+DATA{1}.sp/2 MODES.eraparam.nxlow MODES.eraparam.nxhigh + MODES.eraparam.dnx]),',...
      'vineplot,']);

%
%  nx_low
%
btnnum=6;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
HANDLES.herac(12)=uicontrol(HANDLES.herac(1), ...
   'style','text', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string','nx_min');

btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
HANDLES.herac(13)=uicontrol(HANDLES.herac(1), ...
   'style','edit', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string','10',...
   'callback',...
   ['temp = 2*ceil(str2num(get(HANDLES.herac(13),''string''))/2);',...
      'if isempty(temp), disp(''Error: Invalid Minimum Nx Value''),',...
      'elseif temp < 0, disp(''Error: Invalid Minimum Nx Value''),',...
      'elseif temp > MODES.eraparam.nxhigh, disp(''Error: Invalid Minimum Nx Value''),',...
      'else, MODES.eraparam.nxlow = temp;',...
      'end,',...
      'set(HANDLES.herac(13),''string'',num2str(MODES.eraparam.nxlow)),']);

%
%  nx_high
%
btnnum=7;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
HANDLES.herac(14)=uicontrol(HANDLES.herac(1), ...
   'style','text', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string','nx_max');

btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
HANDLES.herac(15)=uicontrol(HANDLES.herac(1), ...
   'style','edit', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string','100',...
   'callback',...
   ['temp = 2*ceil(str2num(get(HANDLES.herac(15),''string''))/2);',...
      'if isempty(temp), disp(''Error: Invalid Maximum Nx Value''),',...
      'elseif temp < MODES.eraparam.nxlow, disp(''Error: Invalid Maximum Nx Value''),',...
      'else, MODES.eraparam.nxhigh = temp;',...
      'end,',...
      'set(HANDLES.herac(15),''string'',num2str(MODES.eraparam.nxhigh)),']);

%
%  delta_nx
%
btnnum=8;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
HANDLES.herac(16)=uicontrol(HANDLES.herac(1), ...
   'style','text', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string','delta nx');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
HANDLES.herac(17)=uicontrol(HANDLES.herac(1), ...
   'style','edit', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','off', ...      
   'string','10',...
   'callback',...
   ['temp = 2*ceil(str2num(get(HANDLES.herac(17),''string''))/2);',...
      'if isempty(temp), disp(''Error: Invalid Nx Increment Value''),',...
      'elseif temp > (MODES.eraparam.nxhigh - MODES.eraparam.nxlow), disp(''Error: Invalid Nx Increment Value''),',...
      'else, MODES.eraparam.dnx = temp;',...
      'end,',...
      'set(HANDLES.herac(17),''string'',num2str(MODES.eraparam.dnx)),']);

%
%  Close window
%
btnnum=13;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.herac(18)=uicontrol(HANDLES.herac(1), ...
   'style','push', ...
   'unit','normalized', ...
   'position',btnpos, ...
   'visible','on', ...      
   'string','Close',...
   'callback',...
   ['set(HANDLES.herab(5),''string'',num2str(MODES.eraparam.q)),',...
      'set(HANDLES.herab(7),''string'',num2str(MODES.eraparam.d)),',...
      'set(HANDLES.herab(9),''string'',num2str(MODES.eraparam.nx)),',...   
      'set(HANDLES.herac(1),''visible'',''off'')']);


return