function plottool
%   Name: plottool
%
%   Usage: plottool
%
%   Description: Creates the palette of plot attribute tools 
%     

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

hplttl(1) = figure('units','pixels','position',[450 40 300 300],...
			'menubar','none','numbertitle','off','resize','off',...
         'name','Diamond: Plot Tools','visible','off',...
             'closerequestfcn','errordlg(''Do not attempt to close DIAMOND windows improperly'')');

top=.95;
left=.05;
btnwd=.25;
btnht=.1;
spacing=.01;


%  =================
%  Axis Limits Boxes
%  =================

btnnum=0;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd/2 btnht];

%
% fmin button
%
hplttl(2)=uicontrol(hplttl(1), ...
	'style','text', ...
	'units','normal', ...
	'pos',btnpos, ...
   'string','xmin');
btnpos = btnpos + [btnwd/2 0 btnwd/2 0];
hplttl(3)=uicontrol(hplttl(1), ...
   'style','edit', ...
	'units','normal', ...
	'string','xmin', ...
   'pos',btnpos, ...
   'back','w', ...
   'call',['fminm_t=str2num(get(HANDLES.hplttl(3),''string''));', ...
      ' if isempty(fminm_t), disp(''Invalid Min. Freq.''),',...
      '    set(HANDLES.hplttl(3),''string'',num2str(fminm)),',...
		' elseif fminm_t >= DISPLAY{iaxes}.xlim(2), disp(''Invalid Min. Freq.''),',...
		'    set(HANDLES.hplttl(3),''string'',num2str(fminm)),',...
		' elseif fminm_t < 0, disp(''Invalid Min. Freq.''),',...
  		'    fminm = 0; set(HANDLES.hplttl(3),''string'',num2str(fminm)),',...
		' else,',...
		'    fminm = fminm_t;',...
      ' end,',...
      'for itemp = iaxesvec,',...
      '   set(DISPLAY{itemp}.haxes,''Xlim'',[fminm DISPLAY{itemp}.xlim(2)]),',...
      '   DISPLAY{itemp}.xlim = get(DISPLAY{itemp}.haxes,''xlim'');',...
      '   plotdisplay(itemp),',...
      'end,',...
      'configplttl(iaxes,inds),',...
      'figure(HANDLES.hplttl(1)),']);

%
% fmax button
%
btnnum=1;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd/2 btnht];

hplttl(4)=uicontrol(hplttl(1), ...
	'style','text', ...
	'units','normal', ...
	'pos',btnpos, ...
   'string','xmax');
btnpos = btnpos + [btnwd/2 0 btnwd/2 0];
hplttl(5)=uicontrol(hplttl(1), ...
   'style','edit', ...
	'units','normal', ...
	'string','xmax',...
   'pos',btnpos, ...
   'back','w', ...
   'call',['fmaxm_t=str2num(get(HANDLES.hplttl(5),''string''));', ...
      ' if isempty(fmaxm_t), disp(''Invalid Max. Freq.''),',...
  		'    set(HANDLES.hplttl(5),''string'',num2str(fmaxm)),',...
		' elseif fmaxm_t <= DISPLAY{iaxes}.xlim(1), disp(''Invalid Max. Freq.''),',...
		'    set(HANDLES.hplttl(5),''string'',num2str(fmaxm)),',...
		' elseif fmaxm_t > max(DISPLAY{iaxes}.xvec), disp(''Invalid Max. Freq.''),',...
  		'    fmaxm = max(DISPLAY{iaxes}.xvec); set(HANDLES.hplttl(5),''string'',num2str(fmaxm)),',...
		' else,',...
		'    fmaxm = fmaxm_t;',...
		' end,',...
      'for itemp = iaxesvec,',...
      '   set(DISPLAY{itemp}.haxes,''Xlim'',[DISPLAY{itemp}.xlim(1) fmaxm]),',...
      '   DISPLAY{itemp}.xlim = get(DISPLAY{itemp}.haxes,''xlim'');',...
      '   plotdisplay(itemp),',...
      'end,',...
      'configplttl(iaxes,inds),',...
      'figure(HANDLES.hplttl(1)),']);

%
% ymin button
%
btnnum=2;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd/2 btnht];
hplttl(6)=uicontrol(hplttl(1), ...
	'style','text', ...
	'units','normal', ...
	'pos',btnpos, ...
    	'string','ymin');
btnpos = btnpos + [btnwd/2 0 btnwd/2 0];
hplttl(7)=uicontrol(hplttl(1), ...
     	'style','edit', ...
	'units','normal', ...
	'string','ymin', ...
	'pos',btnpos, ...
        'back','w', ...
        'call',['yminm = DISPLAY{1}.ylim(1);',...
        'ymaxm = DISPLAY{1}.ylim(2);',...
        'yminm_t=str2num(get(HANDLES.hplttl(7),''string''));', ...
		' if isempty(yminm_t), disp(''Invalid Lower Limit''),',...
  		'    set(HANDLES.hplttl(7),''string'',num2str(yminm)),',...
		' elseif yminm_t >= DISPLAY{iaxes}.ylim(2), disp(''Invalid Lower Limit''),',...
		'    set(HANDLES.hplttl(7),''string'',num2str(yminm)),',...
		' else,',...
		'    yminm = yminm_t;',...
		' end,',...
	   ' for iaxes = iaxesvec,',...
      '   set(DISPLAY{iaxes}.haxes,''ylim'',[yminm DISPLAY{iaxes}.ylim(2)]),',...
      '   DISPLAY{iaxes}.ylim = get(DISPLAY{iaxes}.haxes,''ylim'');',...
      'end,',...
      'configplttl(iaxes,inds),',...
      'figure(HANDLES.hplttl(1)),']);

%
% ymax button
%
btnnum=3;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd/2 btnht];
hplttl(8)=uicontrol(hplttl(1), ...
	'style','text', ...
	'units','normal', ...
	'pos',btnpos, ...
    	'string','ymax');
btnpos = btnpos + [btnwd/2 0 btnwd/2 0];
hplttl(9)=uicontrol(hplttl(1), ...
     	'style','edit', ...
	'units','normal', ...
	'string','ymax', ...
	'pos',btnpos, ...
        'back','w', ...
	'call',['yminm = DISPLAY{1}.ylim(1);',...
      'ymaxm = DISPLAY{1}.ylim(2);',...
      'ymaxm_t=str2num(get(HANDLES.hplttl(9),''string''));', ...
		' if isempty(ymaxm_t), disp(''Invalid Upper Limit''),',...
  		'    set(HANDLES.hplttl(9),''string'',num2str(ymaxm)),',...
		' elseif ymaxm_t <= DISPLAY{iaxes}.ylim(1), disp(''Invalid Upper Limit''),',...
		'    set(HANDLES.hplttl(9),''string'',num2str(ymaxm)),',...
		' else,',...
		'    ymaxm = ymaxm_t;',...
		' end,',...
	   ' for iaxes = iaxesvec,',...
      '   set(DISPLAY{iaxes}.haxes,''ylim'',[DISPLAY{iaxes}.ylim(1) ymaxm]),',...
      '   DISPLAY{iaxes}.ylim = get(DISPLAY{iaxes}.haxes,''ylim'');',...
      'end,',...
      'configplttl(iaxes,inds),',...
      'figure(HANDLES.hplttl(1)),']);

%
%  Close Button
%
btnpos = [1-spacing-btnwd 0.01 btnwd btnht];
hplttl(10) = uicontrol(hplttl(1),...
	'style','push',...
	'units','normal',...
	'position',btnpos,...
	'string','Close',...
	'call','set(HANDLES.hplttl(1),''visible'',''off'')');


%
%  Line Style Editor Label and frame
left = 0.06;
btnnum=4;
btnpos = [0.05 0.0 btnwd*1.5+0.02 0.50];
uicontrol(hplttl(1),...
	'style','frame',...
        'back',[0.5 0.5 0.5], ...
	'position',btnpos);
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.5 btnht];
uicontrol(hplttl(1),...
	'style','Text',...
	'units','normal',...
        'back',[0.5 0.5 0.5], ...
	'position',btnpos,...
	'string','Line Style Editor');

%
%  Line Selector popup
%
btnnum=5;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.5 btnht];
hplttl(11) = uicontrol(hplttl(1),...
	'style','popup',...
	'units','normal',...
	'position',btnpos,...
	'string','Primary Line | Secondary Line',...
	'value',1,...
   'callback',[' inds = get(HANDLES.hplttl(11),''value'');',...
               ' configplttl(iaxes,inds),']);

%
%  Line Style Popup
%
btnnum=6;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.5 btnht];
hplttl(12) = uicontrol(hplttl(1),...
	'style','popup',...
	'units','normal',...
	'position',btnpos,...
	'string','Solid|Dashed|Dotted|No Line',...
	'value',1,...
   'callback',...
       ['switch get(HANDLES.hplttl(12),''value''),',...
          'case 1, DISPLAY{iaxes}.lnst{inds} = ''- ''; ',...
          'case 2, DISPLAY{iaxes}.lnst{inds} = ''--''; ',...
          'case 3, DISPLAY{iaxes}.lnst{inds} = '': ''; ',...
          'case 4, DISPLAY{iaxes}.lnst{inds} = ''none''; ',...
        'end,',...
        'set(DISPLAY{iaxes}.hline{inds},''linestyle'',DISPLAY{iaxes}.lnst{inds});',...
        'set(DISPLAY{iaxes}.hplttextln{inds},''linestyle'',DISPLAY{iaxes}.lnst{inds} );']);


%
%  Line Color Popup
%
btnnum=7;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.5 btnht];
hplttl(13) = uicontrol(hplttl(1),...
	'style','popup',...
	'units','normal',...
	'position',btnpos,...
	'string','Yellow|Blue|Red|Green',...
	'value',1,...
   'callback',...
         ['switch get(HANDLES.hplttl(13),''value''),',...
          'case 1, DISPLAY{iaxes}.lnco{inds} = ''y''; ',...
          'case 2, DISPLAY{iaxes}.lnco{inds} = ''b''; ',...
          'case 3, DISPLAY{iaxes}.lnco{inds} = ''r''; ',...
          'case 4, DISPLAY{iaxes}.lnco{inds} = ''g''; ',...
        'end,',...
        'set(DISPLAY{iaxes}.hline{inds},''color'',DISPLAY{iaxes}.lnco{inds});'...
        'set(DISPLAY{iaxes}.hplttextln{inds},''color'',DISPLAY{iaxes}.lnco{inds} );']);


   
%
%  Line Style Popup
%
btnnum=8;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.5 btnht];
hplttl(26) = uicontrol(hplttl(1),...
	'style','popup',...
	'units','normal',...
	'position',btnpos,...
	'string','No Marker|Circle|Dot|Plus|Star',...
	'value',1,...
   'callback',...
      ['switch get(HANDLES.hplttl(26),''value''),',...
          'case 1, DISPLAY{iaxes}.marker{inds} = ''none''; ',...
          'case 2, DISPLAY{iaxes}.marker{inds} = ''o''; ',...
          'case 3, DISPLAY{iaxes}.marker{inds} = ''.''; ',...
          'case 4, DISPLAY{iaxes}.marker{inds} = ''+''; ',...
          'case 5, DISPLAY{iaxes}.marker{inds} = ''*''; ',...
        'end,',...
        'set(DISPLAY{iaxes}.hline{inds},''marker'',DISPLAY{iaxes}.marker{inds});'...
        'set(DISPLAY{iaxes}.hplttextln{inds},''marker'',DISPLAY{iaxes}.marker{inds} );']);

%
%  y-axis plot scaling
%
btnnum=5;
left = 0.65;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.2 btnht];
hplttl(14) = uicontrol(hplttl(1),...
	'style','popup',...
	'units','normal',...
	'position',btnpos,...
	'string','MAG|PHASE|REAL|IMAG',...
	'value',1,...
	'callback', ...
      ['switch get(HANDLES.hplttl(14),''value''),',...
      '  case 1, DISPLAY{iaxes}.iyscale = ''MAG'';',...
      '  case 2, DISPLAY{iaxes}.iyscale = ''PHASE'';',...
      '  case 3, DISPLAY{iaxes}.iyscale = ''REAL'';',...
      '  case 4, DISPLAY{iaxes}.iyscale = ''IMAG'';',...
      'end,',...
      'defdisplay(iaxes), plotdisplay(iaxes),',...
      'configplttl(iaxes,inds),',...
      ' figure(HANDLES.hplttl(1)),']);
%
%  Y axis log scaling
%
btnnum=5.5;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.2 btnht*0.5];
hplttl(15) = uicontrol(hplttl(1),...
	'style','check',...
	'units','normal',...
	'position',btnpos,...
	'string','Log Scale',...
	'value',1,...
	'callback',[' DISPLAY{iaxes}.iylog = get(HANDLES.hplttl(15),''value'');',...
      ' switch  DISPLAY{iaxes}.iylog,',...
      '  case 0, set(DISPLAY{iaxes}.haxes,''yscale'',''linear''),',...
      '  case 1, set(DISPLAY{iaxes}.haxes,''yscale'',''log''),',...
      ' end,']);


btnnum=6.2;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*0.75 btnht*0.7];
hplttl(27)= uicontrol(hplttl(1), ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','Ensemble #');
btnpos=[left+btnwd*0.75 ypos-btnht btnwd*0.45 btnht*0.7];
hplttl(28)=uicontrol(hplttl(1), ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','1', ...
      'back','white', ...
      'callback',...
      ['iavg=str2num(get(HANDLES.hplttl(28),''string''));',...
         'if isempty(iavg), disp(''Ensemble # out of Range''),',...
         '    iavg = 1; set(HANDLES.hplttl(28),''string'',num2str(iavg)),',...
			'elseif iavg > size(DATA{DISPLAY{iaxes}.idatafile{inds}}.G,4), disp(''Ensemble # out of Range''),',...
			'    iavg = size(DATA{DISPLAY{iaxes}.idatafile{inds}}.G,4); set(HANDLES.hplttl(28),''string'',num2str(iavg)),',...
			'elseif iavg < 1, disp(''Ensemble # out of Range''),',...
  			'    iavg = 1; set(HANDLES.hplttl(28),''string'',num2str(iavg)),',...
           'end,',...
      'DISPLAY{iaxes}.iavg{inds}=iavg;',...
      'defspecdatavec(iaxes), defdisplay(iaxes), plotdisplay(iaxes),',...
      'plotlegend,',...
      'figure(HANDLES.hplttl(1)),']);




%
% CMIF/SISO/MIF/APS button
%
btnnum=2;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.2 btnht];
hplttl(16)=uicontrol(hplttl(1), ...
      'style','popup', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','SISO|CMIF|MIF|APS|MvMIF', ...
      'callback',...
      ['dellegend,',...
      'for itemp = indsvec,',...
      '   switch get(HANDLES.hplttl(16),''value''),',...
      '   case 1, DISPLAY{iaxes}.displayfun{itemp} = ''SISO'';',...
      '   case 2, DISPLAY{iaxes}.displayfun{itemp} = ''CMIF'';',...
      '   case 3, DISPLAY{iaxes}.displayfun{itemp} = ''MIF'';',...
      '   case 4, DISPLAY{iaxes}.displayfun{itemp} = ''APS'';',...
      '   case 5, DISPLAY{iaxes}.displayfun{itemp} = ''MvMIF'';',...
      '   end,',...
      'end,',...
      'defdisplay(iaxes), plotdisplay(iaxes),',...
      'configplttl(iaxes,inds),',...
      'plotlegend,',...
      'figure(HANDLES.hplttl(1)),']);


%
%  To choose which Response DOF to plot
%
btnnum=3;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*0.6 btnht];
hplttl(17)= uicontrol(hplttl(1), ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','Resp');
btnpos=[left+btnwd*0.6 ypos-btnht btnwd*0.6 btnht];
hplttl(18)=uicontrol(hplttl(1), ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','1', ...
      'back','white', ...
       'callback',['iresp=str2num(get(HANDLES.hplttl(18),''string''));',...
			' if isempty(iresp), disp(''Resp # out of Range''),',...
  			'    iresp = 1; set(HANDLES.hplttl(18),''string'',num2str(iresp)),',...
			'elseif iresp > size(DATA{DISPLAY{iaxes}.idatafile{inds}}.respDOF,1), disp('' Resp # out of Range''),',...
			'    iresp = size(DATA{DISPLAY{iaxes}.idatafile{inds}}.respDOF,1); set(HANDLES.hplttl(18),''string'',num2str(iresp)),',...
			'elseif iresp < 1, disp(''Resp # out of Range''),',...
  			'    iresp = 1; set(HANDLES.hplttl(18),''string'',num2str(iresp)),',...
           'end,',...
      'DISPLAY{iaxes}.iresp{inds}=iresp;',...
      'defdisplay(iaxes), plotdisplay(iaxes),',...
      'plotlegend,',...
      'figure(HANDLES.hplttl(1)),']);


%
%  To choose which Reference DOF to plot
%
btnnum=4;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*0.6 btnht];
hplttl(19)=uicontrol(hplttl(1), ...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','Ref');
btnpos=[left+btnwd*0.6 ypos-btnht btnwd*0.6 btnht];
hplttl(20)=uicontrol(hplttl(1), ...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','1', ...
      'back','white', ...
       'callback',['iref=str2num(get(HANDLES.hplttl(20),''string''));',...
			' if isempty(iref), , disp(''Ref # out of Range''),',...
  			'    iref = 1; set(HANDLES.hplttl(20),''string'',num2str(iref)),',...
			' elseif iref > size(DATA{DISPLAY{iaxes}.idatafile{inds}}.refDOF,1), disp(''Ref # out of Range''),',...
			'    iref = size(DATA{DISPLAY{iaxes}.idatafile{inds}}.refDOF,1); set(HANDLES.hplttl(20),''string'',num2str(iref)),',...
			' elseif iref < 1, disp(''Ref # out of Range''),',...
  			'    iref = 1; set(HANDLES.hplttl(20),''string'',num2str(iref)),',...
			'end,',...
	      'DISPLAY{iaxes}.iref{inds}=iref;',...
      'defdisplay(iaxes), plotdisplay(iaxes),',...
      'plotlegend,',...
      ' figure(HANDLES.hplttl(1)),']);

%
%  Plot axis selector
%
btnnum=0;
left = 0.65;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.2 btnht];
hplttl(24) = uicontrol(hplttl(1),...
	'style','popup',...
	'units','normal',...
	'position',btnpos,...
	'string','Upper|Lower',...
	'value',1,...
	'callback',['iaxes = get(HANDLES.hplttl(24),''value'');'...
                  'configplttl(iaxes,inds),']);
         

%
% Spectral Function Selector
%
btnnum=1;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht btnwd*1.2 btnht];
hplttl(25)=uicontrol(hplttl(1), ...
      'style','popup', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','FRF|Coherence|CPS|PSD Resp|PSD Ref|Time History', ...
      'callback',...
      ['dellegend,',...
      'for itemp = indsvec,',...
      '    switch get(HANDLES.hplttl(25),''value''),',...
      '    case 1, DISPLAY{iaxes}.specfun{itemp} = ''FRF'';',...
      '    case 2, DISPLAY{iaxes}.specfun{itemp} = ''Coherence'';',...
      '    case 3, DISPLAY{iaxes}.specfun{itemp} = ''CPS'';',...
      '    case 4, DISPLAY{iaxes}.specfun{itemp} = ''PSD Resp'';',...
      '    case 5, DISPLAY{iaxes}.specfun{itemp} = ''PSD Ref'';',...
      '    case 6, DISPLAY{iaxes}.specfun{itemp} = ''Time History'';',...
      '    end,',...
      'end,',...
      'defspecdatavec(iaxes), defdisplay(iaxes), plotdisplay(iaxes),',...
      'configplttl(iaxes,inds),',...
      'plotlegend,',...
      'figure(HANDLES.hplttl(1)),']);

         
HANDLES.hplttl = hplttl;

return