function plotbtns
% Function: plotbtns.m
% 
% Usage: plotbtns
% 
% Description:
%    Initializes the Data Plot Window
%    Handles and graphics elements.
%    Returns a vector to those elements.
%
% Version SWD970819
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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=.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.hplotb(1)=uicontrol(HANDLES.hfigdmnd, ...
        '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
HANDLES.hplotb(13) = axes('position',[.1 .22 .7 .7]);

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

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

set(HANDLES.hplotb(13:15),'Visible','off');

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

HANDLES.hplotb(16) = axes('position',[0.1 0.0 0.7 0.15]);
set(HANDLES.hplotb(16),'visible','off','xlim',[0 1],'ylim',[0 1])

%====================================
% 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];
HANDLES.hplotb(7)=uicontrol(HANDLES.hfigdmnd, ...
      'style','push', ...
      'units','normalized', ...
      'position',btnpos, ...
      'string','Upper/Lower', ...
      'value',0, ...
      'visible','off', ...
      'Callback',[' if strcmp(get(HANDLES.hplotb(7),''string''),''Upper/Lower''),',...
			'   hidebtns(HANDLES.hplotb([2 5 6 12])),',...
			'   hideall(HANDLES.hplotb(13)),',...
			'   showall(HANDLES.hplotb(14)),',...
         '   showall(HANDLES.hplotb(15)),',...
         '   iaxesvec = [1 2];',...
         '   DISPLAY{1}.haxes = HANDLES.hplotb(14);',...
         '   if length(DISPLAY)~=2,',...
         '      DISPLAY{2} = DISPLAY{1};',...
         '      DISPLAY{2}.haxes = HANDLES.hplotb(15);',...
         '   end,',... 
         '   plotdisplay(1),',...
         '   plotdisplay(2),',...
         '   plotlegend,',...
         '   configplttl(1,1), iaxes = 1;',...
         '   set(HANDLES.hplotb(7),''string'',''Single Plot''),',...
         'else,',...
         '   DISPLAY{1}.haxes = HANDLES.hplotb(13);',...
         '   iaxesvec = 1;',...
         '   iaxes = 1;',...
         '   plotdisplay(1),',...
         '   plotlegend,',...
         '   configplttl(1,1),',...
        	'   showall(HANDLES.hplotb(13)),',...
			'   hideall(HANDLES.hplotb(14)),',...
         '   hideall(HANDLES.hplotb(15)),',...
         '   set(HANDLES.hplotb(7),''string'',''Upper/Lower''),',...
         '   showbtns(HANDLES.hplotb([2 5 6 12])),',...
			'end,']);

%
% Add Secondary Data
%
btnnum=1;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.hplotb(12)=uicontrol(HANDLES.hfigdmnd, ...
      'style','push', ...
      'position',btnpos, ...
      'string','Add Secondary', ...
      'visible','off', ...
      'Callback',['if strcmp(get(HANDLES.hplotb(12),''string''),''Add Secondary''),',...
         'DISPLAY{iaxes}.ioverlay = 1;',...
         'setndsdef(iaxes,1,2),',...
         'DISPLAY{iaxes}.idatafile{2} = 2;',...
         'DISPLAY{iaxes}.lnst{2} = ''--'';',...
         'DISPLAY{iaxes}.lnco{2} = ''r'';',...
         'DISPLAY{iaxes}.marker{2} = ''none'';',...
         'DISPLAY{iaxes}.lnlab{2} = ''Secondary Data'';',...
         'defspecdatavec(iaxes), defdisplay(iaxes), plotdisplay(iaxes),',...
         'plotlegend, inds = 1; configplttl(iaxes,inds),',...
         'set(HANDLES.hplotb(12),''string'',''Del Secondary''),',...
         'hidebtns(HANDLES.hplotb([2 5 6 7])),',...
       'else,',...
         'indsvec = 1;',...
         'inds = 1;',...
         'plotdisplay(iaxes),',...
         'configplttl(iaxes,1),',...
         'plotlegend,',...
         'set(HANDLES.hplotb(12),''string'',''Add Secondary''),',...
         'showbtns(HANDLES.hplotb([2 5 6 7])),',...
	    'end,']);

%
%  Overlay Synthesis Button
%

btnnum=9;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.hplotb(2)=uicontrol(HANDLES.hfigdmnd, ...
      'style','push', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','Add Synthesis', ...
      'visible','off', ...
      'Callback',['if strcmp(get(HANDLES.hplotb(2),''string''),''Add Synthesis''),',...
         '  DISPLAY{iaxes}.ioverlay = 3;',...
         '  setndsdef(iaxes,1,2),',...
         '  DISPLAY{iaxes}.lnst{2} = ''--'';',...
         '  DISPLAY{iaxes}.lnco{2} = ''r'';',...
         '  DISPLAY{iaxes}.marker{2} = ''none'';',...
         '  DISPLAY{iaxes}.lnlab{2} = ''Modal Synthesis'';',...
         '  defspecdatavec(iaxes), defdisplay(iaxes), plotdisplay(iaxes),',...
         '  plotlegend, inds = 1; configplttl(iaxes,inds),',...
         '  set(HANDLES.hplotb(2),''string'',''Del Synthesis''),',...
         '  hidebtns(HANDLES.hplotb([5 6 7 12])),',...
         'else,',...
         '  indsvec = 1;',...
         '  inds = 1;',...
         '  plotdisplay(iaxes),',...
         '  configplttl(iaxes,1),',...
         '  plotlegend,',...
         '  set(HANDLES.hplotb(2),''string'',''Add Synthesis''),',...
         '  showbtns(HANDLES.hplotb([5 6 7 12])),',...
         'end,']);
 
 
%
%  Plot Tools button
%

btnnum=0;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.hplotb(4) = uicontrol(HANDLES.hfigdmnd,...
	'style','push',...
	'position',btnpos,...
	'string','Plot Tools',...
	'call','set(HANDLES.hplttl(1),''visible'',''on''),figure(HANDLES.hplttl(1))');

%
% Add statistics
%
btnnum=10;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd btnht];
HANDLES.hplotb(5)=uicontrol(HANDLES.hfigdmnd, ...
      'style','push', ...
      'position',btnpos, ...
      'string','Add Statistics', ...
      'visible','off', ... 
      'Callback',...
        ['if strcmp(get(HANDLES.hplotb(5),''string''),''Add Statistics''),',...
         '   DISPLAY{iaxes}.inumsig = get(HANDLES.hplotb(6),''value'');',...
         '   DISPLAY{iaxes}.ioverlay = 2;',...
         '   [DATA{1}.mag1sig,DATA{1}.phs1sig,DATA{1}.coh1sig,DATA{1}.cps1sig] = genstat(DATA{1}.G(:,:,:,DISPLAY{iaxes}.iavg{inds}),DATA{1}.Gxy(:,:,:,DISPLAY{iaxes}.iavg{inds}),DATA{1}.Coh(:,:,:,DISPLAY{iaxes}.iavg{inds}),DATA{1}.navg);',...
         '   setndsdef(iaxes,1,2),',...
         '   setndsdef(iaxes,2,3),',...
         '   DISPLAY{iaxes}.lnst{2} = ''none'';',...
         '   DISPLAY{iaxes}.lnco{2} = ''g'';',...
         '   DISPLAY{iaxes}.marker{2} = ''.'';',...
         '   DISPLAY{iaxes}.lnst{3} = ''none'';',...
         '   DISPLAY{iaxes}.lnco{3} = ''g'';',...
         '   DISPLAY{iaxes}.marker{3} = ''.'';',...
         '   switch DISPLAY{iaxes}.inumsig,',...
         '   case 1, DISPLAY{iaxes}.lnlab{2} = ''+1 Sigma''; DISPLAY{iaxes}.lnlab{3} = ''-1 Sigma'';',...
         '   case 2, DISPLAY{iaxes}.lnlab{2} = ''+2 Sigma''; DISPLAY{iaxes}.lnlab{3} = ''-2 Sigma'';',...
         '   end,',...
         '   defspecdatavec(iaxes), defdisplay(iaxes), plotdisplay(iaxes),',...
         '   plotlegend,',...
         '   inds = 1; configplttl(iaxes,inds),',...
         '   set(HANDLES.hplotb(5),''string'',''Del Statistics''),',...
         '   hidebtns(HANDLES.hplotb([2 6 7 12])),',...
         'else,',...
         '   inds = 1;',...
         '   indsvec = 1;',...
         '   inds = 1;',...
         '   plotdisplay(iaxes),',...
         '   configplttl(iaxes,1),',...
         '   plotlegend,',...
         '   set(HANDLES.hplotb(5),''string'',''Add Statistics''),',...
         '   showbtns(HANDLES.hplotb([2 6 7 12])),',...
			'end,']);

%
% 1 sigma / 2 sigma popup
%

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

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

return











