function viewmodesetup
%
%  Name: viewmodesetup
% 
%  Usage: viewmodesetup
% 
%   Description:
%     Sets up the figure for VIEWMODES
%

%
%  Version SWD970807
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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.hviewm(1) = figure( ...
	'Name','DIAMOND: ViewModes', ...
   'NumberTitle','off', ...
   'visible','off',...
   'Units','normal', ...
   'menubar','none',...
	'Position',[0.05 0.05 0.90 0.90]);

%%
%%
%%  Define Geometry Axes
%%
%%

HANDLES.hviewm(2) =  axes('position',[0.1 0.1 0.7 0.7],'dataaspectratio',[1 1 1]);

%
% Define Frame Around Mode Plot Option Controls
%

HANDLES.hviewm(3) = uicontrol('style','frame',...
		'units','normal',...
		'pos',[0.0 0.82 1. 0.28]);
   
%
%  Define mode scale factor box
%

HANDLES.hviewm(6) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.40 .86 .16 .04],...
   'callback',...
     ['switch VIEWMODES.ipltcmplx,',...
      'case ''Real'',',...
      'VIEWMODES.realscale{imode} = str2num(get(HANDLES.hviewm(6),''string''));',...
      'case ''Complex'',',...
      'VIEWMODES.complexscale{imode} = str2num(get(HANDLES.hviewm(6),''string''));',...
      'end,',...
      'eval(get(HANDLES.hviewm(16),''callback'')),']);

HANDLES.hviewm(7)=uicontrol('style','text',...
	'units','normal',...
	'pos',[.25 .86 .15 .04],...
    	'string','Mode Mag. Factor');

%
%  Define Undef. Geom. Switch
%

HANDLES.hviewm(10) = uicontrol('style','checkbox',...
		'units','normal',...
      'position',[.70 .90 .15 .04],...
		'string','Undef. Geom',...
      'callback',['VIEWMODES.iundef = get(HANDLES.hviewm(10),''value'');',...
            'eval(get(HANDLES.hviewm(16),''callback'')),']);


%
%  Define Node Label Switch
%

HANDLES.hviewm(9) = uicontrol('style','checkbox',...
		'units','normal',...
      'position',[.70 .86 .15 .04],...
		'string','Node Labels',...
      'callback',['GEOM.inodelab= get(HANDLES.hviewm(9),''value'');',...
            'eval(get(HANDLES.hviewm(16),''callback'')),']);
      
      
           
%
%  Active mode popup
%

HANDLES.hviewm(4) = uicontrol('style','popup',...
   'pos',[.40 .94 .16 .04],...
   'string','temp',...
   'callback',...
   ['imode = get(HANDLES.hviewm(4),''value'');',...
      'eval(get(HANDLES.hviewm(16),''callback'')),']);


%
% Define Text box for Mode Number
%

HANDLES.hviewm(12) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.40 .90 .16 .04],...
   'callback',...
   ['imode_t = str2num(get(HANDLES.hviewm(12),''string''));',...
		'if isempty(imode_t), disp(''Invalid Mode Number''),',...
  		'   set(HANDLES.hviewm(12),''string'',num2str(imode)),',...
		'elseif imode_t > MODES.nmodes, disp(''Invalid Mode Number''),',...
		'   set(HANDLES.hviewm(12),''string'',num2str(imode)),',...
		'elseif imode_t <= 0, disp(''Invalid Mode Number''),',...
		'   set(HANDLES.hviewm(12),''string'',num2str(imode)),',...
		'else,',...
		'   imode = imode_t;',...
      'end,',...
      'eval(get(HANDLES.hviewm(16),''callback'')),']);

HANDLES.hviewm(11)=uicontrol('style','text',...
	'units','normal',...
	'pos',[.25 .90 .15 .04],...
    	'string','Mode Number');

HANDLES.hviewm(13) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.56 .90 .06 .04],...
        'string','prev', ...
        'callback',...
        ['imode_t = imode-1;', ...
           'if imode_t == 0, disp(''Invalid Mode Number''),',...
           '    set(HANDLES.hviewm(12),''string'',num2str(imode)),',...
           ' else,',...
           '    imode = imode_t;',...
           'end,',...
           'eval(get(HANDLES.hviewm(16),''callback'')),']);

HANDLES.hviewm(14) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.62 .90 .06 .04],...
   'string','next', ...
   'callback',...
   ['imode_t=imode+1;', ...
      'if imode_t > MODES.nmodes, disp(''Invalid Mode Number''),',...
		'   set(HANDLES.hviewm(12),''string'',num2str(imode)),',...
      ' else,',...
      '    imode = imode_t;',...
      'end,',...
      'eval(get(HANDLES.hviewm(16),''callback'')),']);


HANDLES.hviewm(5) = uicontrol('style','push',...
   'units','normal',...
   'pos',[.56 .86 .12 .04],...
   'string','Delete Mode',...
   'callback',...
   ['deletemode(imode),',...
      'if MODES.nmodes == 0, hideallbtns, set(HANDLES.hmmenu{6}(1),''enable'',''off''), set(HANDLES.hviewm(1),''visible'',''off''), drawnow,',...
      '  else,',...
      'if imode > 1, imode = imode -1; else imode = 1; end,',...
      'set(HANDLES.hviewm(4),''string'',buildfreqpopup),',...
      'eval(get(HANDLES.hviewm(16),''callback'')),',...
      'end,']);


%
% Define Text box for Number of Anim. Cycles
%

HANDLES.hviewm(15) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.9 .94 .06 .04],...
   'string',10,...
	'callback','VIEWMODES.ianim = str2num(get(HANDLES.hviewm(15),''string''));');

	uicontrol('style','text',...
	'units','normal',...
	'pos',[.7 .94 .2 .04],...
    	'string','# of Anim. Cycles');

%%
%%
%%  Define the Plot Mode Button
%%
%%

HANDLES.hviewm(16) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.85 .90 .10 .04],...
        'string','Plot',...
        'callback',...
        ['set(HANDLES.hviewm(12),''string'',num2str(imode)),',...
           'set(HANDLES.hviewm(4),''value'',imode);',...
           'switch VIEWMODES.ipltcmplx,',...
           'case ''Real'', set(HANDLES.hviewm(22),''value'',1),',...
           'case ''Complex'', set(HANDLES.hviewm(22),''value'',2),',...
           'end,',...
           'set(HANDLES.hviewm(18),''visible'',''off'');', ...
           'set(HANDLES.hviewm(19),''visible'',''off'');', ...
           'set(HANDLES.hviewm(20),''visible'',''off'');', ...
           'VIEWMODES.modemovie = [];',...
           'set(HANDLES.hviewm(2),''xlimmode'',''auto'',''ylimmode'',''auto'',''zlimmode'',''auto''),',...
           'drawmode(0),', ...
           'modetitle,',...
           'set(HANDLES.hviewm(2),''xlimmode'',''manual'',''ylimmode'',''manual'',''zlimmode'',''manual''),']);

%%
%%
%%  Define the Animate Mode Button
%%
%%

HANDLES.hviewm(17) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.85 .85 .10 .04],...
        'string','Animate',...
	'callback',...
   ['set(HANDLES.hviewm(18),''visible'',''off'');', ...
      'VIEWMODES.modemovie = animmode;',...
      'set(HANDLES.hviewm(18),''visible'',''on'');', ...
      'set(HANDLES.hviewm(19),''visible'',''on'');', ...
      'set(HANDLES.hviewm(20),''visible'',''on'');', ...
      'movie(VIEWMODES.modemovie,VIEWMODES.ianim,VIEWMODES.ifps);']);


%%
%%  Define the Replay Animation Button
%%
%%

HANDLES.hviewm(18) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.75 .66 .25 .04],...
   'string','Replay Animation',...
   'callback','movie(VIEWMODES.modemovie,VIEWMODES.ianim,VIEWMODES.ifps);');


%%
%%  Define the Frames per second Button
%%
%%
HANDLES.hviewm(19)=uicontrol('style','text', ...
      	'units','normal', ...
	'pos',[.75 .62 .20 .04], ...
	'string','Frames per second');

HANDLES.hviewm(20) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.95 .62 .05 .04],...
        'string',24,...
	'callback','VIEWMODES.ifps = str2num(get(HANDLES.hviewm(20),''string''));');

%%
%%
%%  Define the Exit Button
%%
%%

HANDLES.hviewm(21) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.725 .01 .25 .04],...
        'string','Exit ViewModes',...
	'callback','VIEWMODES.modemovie = []; set(HANDLES.hviewm(1),''visible'',''off'')');

%
% Mode type popup (real/complex)
%

HANDLES.hviewm(22)=uicontrol('style','popupmenu', ...
	'units','normal', ...
	'string','Real|Complex', ...
	'position',[.85 .80 .10 .04],...
	'value',1,...
   'callback',...
   ['switch get(HANDLES.hviewm(22),''value''),',...
      'case 1, VIEWMODES.ipltcmplx = ''Real'';',...
      'case 2, VIEWMODES.ipltcmplx = ''Complex'';',...
      'end,',...
      'eval(get(HANDLES.hviewm(16),''callback'')),']);

HANDLES.hviewm(24) = uicontrol('style','push',...
		'units','normal',...
		'pos',[0.85 0.75 0.10 0.04],...
		'string','Print',...
      'callback','errordlg(''Sorry, print function not operative'')');
   
%   
%  Color selectors
%

HANDLES.hviewm(25)=uicontrol('style','text', ...
	'units','normal', ...
   'string','Node Color', ...
   'horizontalalignment','right',...
	'position',[.02 .94 .10 .04]);

HANDLES.hviewm(26)=uicontrol('style','popupmenu', ...
	'units','normal', ...
	'position',[.13 .95 .10 .04],...
	'string','Yellow|Blue|Red|Green',...
	'value',1,...
   'callback',...
         ['switch get(HANDLES.hviewm(26),''value''),',...
          'case 1, GEOM.nodelnco = ''y''; ',...
          'case 2, GEOM.nodelnco = ''b''; ',...
          'case 3, GEOM.nodelnco = ''r''; ',...
          'case 4, GEOM.nodelnco = ''g''; ',...
          'end,',...
          'eval(get(HANDLES.hviewm(16),''callback'')),']);
   
    
HANDLES.hviewm(27)=uicontrol('style','text', ...
	'units','normal', ...
   'string','Bar Color', ...
   'horizontalalignment','right',...
	'position',[.02 .89 .10 .04]);

HANDLES.hviewm(28)=uicontrol('style','popupmenu', ...
	'units','normal', ...
	'position',[.13 .90 .10 .04],...
	'string','Yellow|Blue|Red|Green',...
	'value',1,...
   'callback',...
         ['switch get(HANDLES.hviewm(28),''value''),',...
          'case 1, GEOM.barlnco = ''y''; ',...
          'case 2, GEOM.barlnco = ''b''; ',...
          'case 3, GEOM.barlnco = ''r''; ',...
          'case 4, GEOM.barlnco = ''g''; ',...
          'end,',...
          'eval(get(HANDLES.hviewm(16),''callback'')),']);
    
HANDLES.hviewm(29)=uicontrol('style','text', ...
	'units','normal', ...
   'string','Undef. Color', ...
   'horizontalalignment','right',...
	'position',[.02 .84 .10 .04]);

HANDLES.hviewm(30)=uicontrol('style','popupmenu', ...
	'units','normal', ...
	'position',[.13 .85 .10 .04],...
	'string','Yellow|Blue|Red|Green',...
	'value',1,...
   'callback',...
         ['switch get(HANDLES.hviewm(30),''value''),',...
          'case 1, GEOM.undefgeomco = ''y''; ',...
          'case 2, GEOM.undefgeomco = ''b''; ',...
          'case 3, GEOM.undefgeomco = ''r''; ',...
          'case 4, GEOM.undefgeomco = ''g''; ',...
          'end,',...
          'eval(get(HANDLES.hviewm(16),''callback'')),']);

return
