function [hplot] = plotbtns(figNumber)
% Function: plotbtns.m
% 
% Usage: hplot = plotbtns(figNumber);
% 
% Description:
%    Initializes the Data Plot Window
%    Handles and graphics elements.
%    Returns a vector to those elements.
%
% Version SWD970519
%
% 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=.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];
hplot(1)=uicontrol(figNumber, ...
        'Style','Frame', ...
        'units','normalized', ...
        'Position',frmpos, ...
        'Visible','off', ...
        'BackgroundColor',[.5 .5 .5]);

%====================================
% Set up the plot axes (1 for single, 2 for upper/lower)
%=====================================

%Big Single Axes
hplot(13) = axes('position',[.1 .22 .7 .7]);

%Upper Twin Axes
hplot(14) = axes('position',[.1 .62 .7 .3]);

%Lower Twin Axes
hplot(15) = axes('position',[.1 .22 .7 .3]);

set(hplot(13:15),'Visible','off');

%====================================
% Set up the plot legend
%=====================================

hplot(16) = axes('position',[0.1 0.0 0.7 0.15]);
set(hplot(16),'visible','off')

%====================================
% Set up the buttons
%=====================================

%
%  To make it an upper and lower plot
%
btnnum=2;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(7)=uicontrol(figNumber, ...
      'style','push', ...
      'units','normalized', ...
      'position',btnpos, ...
      'string','Upper/Lower', ...
      'value',0, ...
      'visible','off', ...
      'Callback',[' if strcmp(get(onHndlVector(7),''string''),''Upper/Lower''),',...
			'   hidebtns(onHndlVector([2 5 6 12])),',...
			'   hideall(onHndlVector(13)),',...
			'   showall(onHndlVector(14)),',...
                  '   showall(onHndlVector(15)),',...
			'   iyscale = 2; iylog = 0;',...
			'   set(hplttl(14),''value'',iyscale),',...
			'   set(hplttl(15),''value'',iylog),',...
			'   nn=3; iyscale = 2; iylog=0;',...
			'   haxes = onHndlVector(nn+12);',... 
			'   set(hplttl(16),''value'',2),',...
			'   eval(get(hplttl(16),''call'')),',...
			'   iyscale = 1; iylog = 1;',...
			'   set(hplttl(14),''value'',iyscale),',...
			'   set(hplttl(15),''value'',iylog),',...
			'   nn=2; iyscale = 1; iylog=1;',...
			'   haxes = onHndlVector(nn+12);',...
			'   set(hplttl(16),''value'',2),',...
			'   eval(get(hplttl(16),''call'')),',... 
			'   set(onHndlVector(8),''value'',1);',...
			'   set(onHndlVector(7),''string'',''Single''),',...
			'   showall(onHndlVector(8)),',...
			'else,',...
			'   showall(onHndlVector(13)),',...
			'   hideall(onHndlVector(14)),',...
                  '   hideall(onHndlVector(15)),',...
			'   nn=1;',...
			'   haxes = onHndlVector(nn+12);',...
			'   set(hplttl(16),''value'',2),',...
			'   eval(get(hplttl(16),''call'')),',...
			'   set(onHndlVector(7),''string'',''Upper/Lower''),',...
			'   hideall(onHndlVector(8)),',...
			'   showbtns(onHndlVector([2 5 6 12])),',...
			'end,']);

%
%  To choose the upper or lower plot
%
btnnum=3;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(8)=uicontrol(figNumber, ...
      'style','popup', ...
      'units','normalized', ...
      'position',btnpos, ...
      'string','Upper|Lower', ...
      'value',1, ...
      'visible','off', ...
      'Callback',['nn=get(onHndlVector(8),''value'') + 1;',...
			'haxes = onHndlVector(nn+12);']);

% Empty Handles
%
%
hplot(9)=uicontrol('position',[0 0 eps eps]);
hplot(10)=uicontrol('position',[0 0 eps eps]);
hplot(11)=uicontrol('position',[0 0 eps eps]);

%
% Choose Primary or Secondary Data Set
%
btnnum=1;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(12)=uicontrol(figNumber, ...
      'style','push', ...
      'position',btnpos, ...
      'string','Add Secondary', ...
      'visible','off', ...
      'Callback',['if strcmp(get(onHndlVector(12),''string''),''Add Secondary''),',...
			' nds=2;', ...
			' lnst = [''- '';''--''];',...
		      ' lnco = [''y'';''r''];',...
			' set(hplttl(11),''string'',''Primary Data|Secondary Data''),',...
			' set(hplttl(14:20),''visible'',''off''),',...
			' hidebtns(onHndlVector([2 5 6 7])),',...
			' set(onHndlVector(12),''string'',''Del Secondary''),',...
			'else,',...
			' nds=1; iptline=1;', ...
			' lnst = lnst(1,:);',...
		      ' lnco = lnco(1,:);',...
			' set(hplttl(11),''string'',''Primary Data''),',...
			' set(hplttl(11),''value'',iptline),',...
			' set(hplttl(14:20),''visible'',''on''),',...
			' showbtns(onHndlVector([2 5 6 7])),',...
			' set(onHndlVector(12),''string'',''Add Secondary''),',...
			'end,',...
			'if strcmp(name,''CMIF''),', ...
				'set(hplttl(16),''value'',1),',...
				'eval(get(hplttl(16),''call'')),',...
			'else,',...
				'eval(get(hplttl(14),''call'')),',...
		   	'end,']);

%
%  Overlay Synthesis Button
%

btnnum=9;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(2)=uicontrol(figNumber, ...
      'style','push', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','Add Synthesis', ...
      'visible','off', ...
       'callback',['if strcmp(get(onHndlVector(2),''string''),''Add Synthesis''),',...
			'if exist(''G1syn'')~=1,',...
		   'disp(''Computing Synthesized FRFs...''),',...
		   ' if ipltcmplx == 1, G1syn = synFRF(Freq,Damp,phir_resp,phir_ref,freq,respDOF,refDOF);',...
		   ' elseif ipltcmplx==2, G1syn = synFRF(Freq,Damp,phic_resp,phic_ref,freq,respDOF,refDOF);',...
		   ' end,',...
		   'end,',...
		   'if strcmp(name,''CMIF''),',...
		         'toplotsyn=cmif(G1syn,nlines);',...
			   'respstr = -1;',...
			   'refstr = -1;',...
		   'else,',...
		   '  dataisyn=G1syn((iresp-1)*nlines+1:nlines*iresp,iref);', ...
 		   '  eval([''toplotsyn='',plotopt,''(dataisyn);'']);', ...
		   '  respstr = num2str(iresp);',...
		   '  refstr = num2str(iref);',...
		   'end,',...
	 	   'lnst = [''- '';''--''];',...
		   'lnco = [''y'';''r''];',...
		   'set(hplttl(11),''string'',''Primary Data|Synthesized Data''),',...
				' set(hplttl(14:20),''visible'',''off''),',...
		   'modplot(haxes,freq,fminm,fmaxm,toplotsyn,nn,iylog,2,name,lnst,lnco,nfunc);', ...
 		   'dataleg(hlegax,2,respstr,refstr,''Synthesized'',lnst,lnco);',...
			' hidebtns(onHndlVector([12 5 6 7])),',...
			' set(onHndlVector(2),''string'',''Del Synthesis''),',...
	'else,',...
		' nds=1; iptline=1;', ...
			' lnst = lnst(1,:);',...
		      ' lnco = lnco(1,:);',...
			' set(hplttl(11),''string'',''Primary Data''),',...
			' set(hplttl(11),''value'',iptline),',...
			' set(hplttl(14:20),''visible'',''on''),',...
			' showbtns(onHndlVector([12 5 6 7])),',...
			' set(onHndlVector(2),''string'',''Add Synthesis''),',...
			'if strcmp(name,''CMIF''),', ...
				'set(hplttl(16),''value'',1),',...
				'eval(get(hplttl(16),''call'')),',...
			'else,',...
				'eval(get(hplttl(14),''call'')),',...
		   	'end,',...
	'end,']);

btnnum=8;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(3)=uicontrol(figNumber, ...
	'style','popupmenu', ...
	'units','normal', ...
	'visible','off', ...
	'string','Real|Complex', ...
	'position',btnpos,...
	'callback','ipltcmplx = get(onHndlVector(3),''value''); clear G1syn');



%
%  Plot Tools button
%

btnnum=0;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(4) = uicontrol(figNumber,...
	'style','push',...
	'position',btnpos,...
	'string','Plot Tools',...
	'call',['defhline,',...
		'  if exist(''iptline'')~=1, iptline =1; end,',...
		'set(hplttl(11),''value'',iptline),',...
		'eval(get(hplttl(11),''call'')),',...
		'set(hplttl(1),''visible'',''on''),figure(hplttl(1))']);

%
% Add statistics
%
btnnum=10;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(5)=uicontrol(figNumber, ...
      'style','push', ...
      'position',btnpos, ...
      'string','Add Statistics', ...
      'visible','off', ... 
	'Callback',['if strcmp(get(onHndlVector(5),''string''),''Add Statistics''),',...
			' isigm = get(onHndlVector(6),''value'');',...
			' if isigm == 1,',...
			'   pstr = ''+1 Sigma'';',...
			'   mstr = ''-1 Sigma'';',...
			' else,',...
			'   pstr = ''+2 Sigma'';',...
			'   mstr = ''-2 Sigma'';',...
			' end,',...
			' lnst = [''- '';''. '';''. ''];',...
		      ' lnco = [''y'';''r'';''g''];',...
			' set(hplttl(11),''string'',[''Primary Data|'',pstr,''|'',mstr]),',...
			' set(hplttl(14:20),''visible'',''off''),',...
			' hidebtns(onHndlVector([12 2 7])),',...
			' set(hplttl(16),''value'',1),',...
			' if exist(''navg1'') ~=1 , navg1 = input(''Number of Averages?''); end,',...
			' if exist(''mag1sig'') ~= 1,',...
			'   fprintf(1,''Generating Data Statistics...''),',...	
			'   [mag1sig,phs1sig,coh1sig,cps1sig,real1sig,imag1sig] = genstat(G1,Gxy1,Coh1,navg1);',...
			'   fprintf(1,''done\n''),',...
			' end,',...
			'if nfunc==1,',...
			' if iyscale == 1,',...
			'    set(hplttl(16),''value'',2),',...
      		'    eval(get(hplttl(16),''call'')),',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot + isigm*mag1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,2,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,2,-1,-1,pstr,lnst,lnco);',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot - isigm*mag1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,3,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,3,-1,-1,mstr,lnst,lnco);',...
			' elseif iyscale == 2,',...
      		'    eval(get(hplttl(14),''call'')),',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot + isigm*phs1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,2,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,2,-1,-1,pstr,lnst,lnco);',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot - isigm*phs1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,3,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,3,-1,-1,mstr,lnst,lnco);',...
			' elseif iyscale == 3,',...
			'    eval(get(hplttl(14),''call'')),',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot + isigm*real1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,2,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,2,-1,-1,pstr,lnst,lnco);',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot - isigm*real1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,3,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,3,-1,-1,mstr,lnst,lnco);',...
			' elseif iyscale == 4,',...
			'    eval(get(hplttl(14),''call'')),',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot + isigm*imag1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,2,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,2,-1,-1,pstr,lnst,lnco);',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot - isigm*imag1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,3,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,3,-1,-1,mstr,lnst,lnco);',...
			' end,',...
			'elseif nfunc==2,',...
			'    eval(get(hplttl(14),''call'')),',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot + isigm*coh1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,2,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,2,-1,-1,pstr,lnst,lnco);',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot - isigm*coh1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,3,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,3,-1,-1,mstr,lnst,lnco);',...
			'elseif nfunc==3,',...
			'    set(hplttl(16),''value'',2),',...
      		'    eval(get(hplttl(16),''call'')),',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot + isigm*cps1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,2,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,2,-1,-1,pstr,lnst,lnco);',...
			'    modplot(haxes,freq,fminm,fmaxm,toplot - isigm*cps1sig((iresp-1)*nlines+1:nlines*iresp,iref),nn,iylog,3,name,lnst,lnco,nfunc);', ...
 		   	'    dataleg(hlegax,3,-1,-1,mstr,lnst,lnco);',...
			'end,',...
			' defhline,',...
			' set(onHndlVector(5),''string'',''Del Statistics''),',...
			'else,',...
			' nds=1; iptline=1;', ...
			' lnst = lnst(1,:);',...
		      ' lnco = lnco(1,:);',...
			' set(hplttl(11),''string'',''Primary Data''),',...
			' set(hplttl(11),''value'',iptline),',...
			' set(hplttl(14:20),''visible'',''on''),',...
			' if strcmp(name,''CMIF''),',...
				'set(hplttl(16),''value'',1),',...
				'eval(get(hplttl(16),''call'')),',...
			' else,',...
				'eval(get(hplttl(14),''call'')),',...
		   	' end,',...
			' set(onHndlVector(5),''string'',''Add Statistics''),',...
			' showbtns(onHndlVector([12 2 7])),',...
			'end,']);

%
% 1 sigma / 2 sigma popup
%

btnnum=11;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
hplot(6)=uicontrol(figNumber, ...
      'style','popup', ...
      'position',btnpos, ...
	'value',1,...
      'string','+/- 1 Sigma| +/- 2 Sigma');

set(hplot,'visible','off')

return











