%
%  Script: ERAconv.m
% 
%  Usage: ERAconv.m
% 
%  Description:
%    Puts Frequency and Damping into a matrix
%    Freq is a column vector of frequencies
%    Dampings a column vector of damping
%
%  Version SWD970402
%
%  Author(s): Phillip Cornwell, cornwell@lanl.gov
%             Erik Straser, estraser@lanl.gov
%
%  Institution: Los Alamos National Laboratory, ESA-EA
%
%  Copyright (c) 1996, The Regents of the University
%     	of California.

global hera;
global herac;

hERAconv=figure( ...
    'Name','ERA Convergence Studies', ...
    'NumberTitle','off', ...
    'unit','normal',...
    'Position',[0.05 0.05 0.75 0.75], ...
    'menubar','none');

hERAconva=axes('position',[.1 .2 .7 .7],'visible','off');
    
%%====================================
%% For the ERA window
%%====================================
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];
herac(1)=uicontrol(hERAconv, ...
        '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];
herac(1)=uicontrol(hERAconv, ...
      'style','push', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','on', ...      
      'string','Hankel H(0)', ...
      'callback',['q=str2num(get(herac(3),''string''));', ...
		  'd=str2num(get(herac(5),''string''));', ...
 		  '[S0] = mkhank0(G,nlines,fs,q,d);',...
		  'axes(hERAconva); showall(hERAconva); semilogy(S0),',...
                  'xlabel(''Number of Poles'');',...
		  'global hera herac;',...
		  'set(herac([6:12 15:16]),''visible'',''on''),']);

%
%  q
%
btnnum=2;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.65 btnht];
herac(2)=uicontrol(hERAconv, ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','on', ...      
      'string','q');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
herac(3)=uicontrol(hERAconv, ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','on', ...      
      'string',get(onHndlVector(5),'string'), ...
      'callback',['global hera herac;', ... 
	          'q=str2num(get(herac(3),''string''));', ...
	          'value = get(herac(3),''string'');', ...
		  'set(hera(5),''string'',value)']);

%
%  d
%
btnnum=3;
ypos=top-(btnnum-1)*(btnht);
btnpos=[left ypos-btnht btnwd*.65 btnht];
herac(4)=uicontrol(hERAconv, ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','on', ...      
      'string','d');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
herac(5)=uicontrol(hERAconv, ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','on', ...      
      'string',get(onHndlVector(7),'string'), ...
      'callback',['global hera herac;', ... 
                  'd=str2num(get(herac(5),''string''));', ...
	          'value = get(herac(5),''string'');', ...
		  'set(hera(7),''string'',value)']);

%
%  Poles
%
%  Select X axis value off of plot using mouse
btnnum=4;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
herac(15)=uicontrol(hERAconv, ...
        'style','pushbutton', ...
        'units','normalized', ...
        'pos',btnpos, ...
  	'visible','off', ...
	'string',' Poles', ...
	'callback',['global hera;',... 
                    '[f1,temp] = ginput(1);',...
		    'set(herac(16),''string'',num2str(2*ceil(f1/2)));',...
		    'set(herac(10),''string'',num2str(2*ceil(f1/2)));',...
		    'set(hera(9),  ''string'',num2str(2*ceil(f1/2)));']);
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
herac(16)=uicontrol(hERAconv, ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','?');

%
%  Run vine plot
%
btnnum=5;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
herac(6)=uicontrol(hERAconv, ...
      'style','push', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','Run Vine', ...
      'callback',['nxlow=str2num(get(herac(8),''string''));', ...
	'nxhigh=str2num(get(herac(10),''string''));', ...
	'dnx=2*ceil(str2num(get(herac(12),''string''))/2);', ...
        'set(herac(12),''string'',num2str(dnx));',...        
        '[H0,H1,Y,U0,S0,V0,fs_out,nresp,nref] = makehank(G,nlines,fs,q,d);',...
        'axes(hERAconva); cla;', ...
	'title(''Vine Plot''); xlabel(''Frequency (Hz)''), ylabel(''Model Order'');', ...
        'set(hERAconva,''yscale'',''lin''),',...
	'axis([cf-sp/2 cf+sp/2 nxlow nxhigh+dnx]),',...
	'vineplot(H0,H1,Y,U0,S0,V0,q,d,fs_out,nref,nresp,nxhigh,nxlow,dnx,hERAconva,respDOF,refDOF);']);

%
%  nx_low
%
btnnum=6;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
herac(7)=uicontrol(hERAconv, ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','nx_min');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
herac(8)=uicontrol(hERAconv, ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','10');

%
%  nx_high
%
btnnum=7;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
herac(9)=uicontrol(hERAconv, ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','nx_max');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
herac(10)=uicontrol(hERAconv, ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','?');

%
%  delta_nx
%
btnnum=8;
ypos=ypos-btnht;
btnpos=[left ypos-btnht btnwd*.65 btnht];
herac(11)=uicontrol(hERAconv, ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','delta nx');
btnpos=[left+.65*btnwd ypos-btnht btnwd*.35 btnht];
herac(12)=uicontrol(hERAconv, ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','off', ...      
      'string','?');

%
%  Close window
%
btnnum=13;
ypos=top-(btnnum-1)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
herac(13)=uicontrol(hERAconv, ...
      'style','push', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'visible','on', ...      
      'string','Close',...
      'callback','set(hERAconv,''visible'',''off'')');
