function viewmode
%
%  Name: viewmode
% 
%  Usage: viewmode
% 
%   Description:
%     Configures and enables the VIEWMODE window
%     for inspecting identified modes
%

%
%  Version SWD970805
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 VIEWMODES GEOM MODES imode

%  Estimate Scaling factor for each mode

geomrange = 0.1 * max(max(abs(GEOM.Nodes(:,2:4))) - min(abs(GEOM.Nodes(:,2:4))));

for i = 1:MODES.nmodes,
   
    phicmax = max(abs(MODES.residue{i}));
    VIEWMODES.complexscale{i} =  geomrange / phicmax;
    phirmax = max(abs(MODES.modalvector{i}));
    VIEWMODES.realscale{i} =  geomrange / phirmax;

end

%  Clear out the movie and turn off movie controls

VIEWMODES.modemovie=[];

set(HANDLES.hviewm(18),'visible','off'),
set(HANDLES.hviewm(19),'visible','off'), 
set(HANDLES.hviewm(20),'visible','off'),

%  Define active mode number if necessary, and draw it

if isempty(imode)
   imode = 1;
elseif imode < 1 | imode > MODES.nmodes,
   imode = 1;
end

set(HANDLES.hviewm(12),'string',num2str(imode))
set(HANDLES.hviewm(4),'string',buildfreqpopup)
set(HANDLES.hviewm(4),'value',imode)


if ~isfield(VIEWMODES,'iundef'),
   VIEWMODES.iundef = 0;
end
set(HANDLES.hviewm(10),'value',VIEWMODES.iundef)

if ~isfield(GEOM,'inodelab'),
   GEOM.inodelab = 0;
end
set(HANDLES.hviewm(9),'value',GEOM.inodelab)

if ~isfield(VIEWMODES,'ipltcmplx'),
   VIEWMODES.ipltcmplx = 'Real';
end

switch VIEWMODES.ipltcmplx
case 'Real', set(HANDLES.hviewm(22),'value',1)
case 'Complex', set(HANDLES.hviewm(22),'value',2)
end

if ~isfield(VIEWMODES,'ianim'),
   VIEWMODES.ianim = 10;
end
set(HANDLES.hviewm(15),'string',num2str(VIEWMODES.ianim))

if ~isfield(VIEWMODES,'ifps'),
   VIEWMODES.ifps = 24;
end
set(HANDLES.hviewm(20),'string',num2str(VIEWMODES.ifps))

%  Initialize and configure the mode shape line colors
if ~isfield(GEOM,'nodelnco'),
   GEOM.nodelnco = 'g';
end

switch GEOM.nodelnco,
case 'y', set(HANDLES.hviewm(26),'value',1)
case 'b', set(HANDLES.hviewm(26),'value',2)
case 'r', set(HANDLES.hviewm(26),'value',3)
case 'g', set(HANDLES.hviewm(26),'value',4)
end

if ~isfield(GEOM,'barlnco'),
   GEOM.barlnco = 'y';
end

switch GEOM.barlnco,
case 'y', set(HANDLES.hviewm(28),'value',1)
case 'b', set(HANDLES.hviewm(28),'value',2)
case 'r', set(HANDLES.hviewm(28),'value',3)
case 'g', set(HANDLES.hviewm(28),'value',4)
end

if ~isfield(GEOM,'undefgeomco'),
   GEOM.undefgeomco = 'b';
end

switch GEOM.undefgeomco,
case 'y', set(HANDLES.hviewm(30),'value',1)
case 'b', set(HANDLES.hviewm(30),'value',2)
case 'r', set(HANDLES.hviewm(30),'value',3)
case 'g', set(HANDLES.hviewm(30),'value',4)
end

GEOM.nodelabsz = 14;
GEOM.ibarlab = 0;
GEOM.barlnst = '-';
GEOM.barlabsz = 14;

drawmode(0)  % Zero indicates zero phase delay (phase delay used for animation)
modetitle    % Add a title to the mode plot
   
%  Make the viewmodes window visible

set(HANDLES.hviewm(1),'visible','on')
figure(HANDLES.hviewm(1))
rotate3d on

return
