%
%  Name: viewmode
% 
%  Usage: viewmode
% 
%   Description:
%     Interactive inspection
%     of Identified Modes
%

%
%  Version SWD970618
%
%  Author(s): Scott W. Doebling, doebling@lanl.gov
%	Modified by P. Cornwell, cornwell@lanl.gov
%
%  Institution: Los Alamos National Laboratory,
%		ESA-EA
%
%  Copyright (c) 1996-1997, The Regents of the University
%     	of California. (See top level of code for
%	full copyright statement.)

if exist('iviewm') ~= 1, iviewm = [1 10 24 0 0 0 330 30 0]; end


%  Estimate nscale for each mode

    geomrange = 0.1 * max(max(abs(Nodes)) - min(abs(Nodes)));

for i = 1:size(Phiplot,2),
   
    phimax = max(abs(Phiplot(:,i)));
    nscale(i) =  geomrange / phimax;
    
end

modemovie=[];

hviewm(1) = figure( ...
	'Name','DIAMOND: ViewModes', ...
	'NumberTitle','off', ...
   'Units','normal', ...
   'menubar','none',...
	'Position',[0.05 0.05 0.90 0.90]);

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

hviewm(2) =  axes('position',[0.1 0.1 0.7 0.7]);
rotate3d on

%
% Define Frame Around Mode Plot Option Controls
%

hviewm(3) = uicontrol('style','frame',...
		'units','normal',...
		'pos',[0.0 0.85 1. 0.25]);
   
%   
% hviewm(4:5) are defunct
%
   
hviewm(4) = uicontrol('position',[0 0 eps eps]);
hviewm(5) = uicontrol('position',[0 0 eps eps]);

%
%  Define mode scale factor box
%

hviewm(6) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.48 .86 .16 .04],...
   'string',sprintf('%6.3e',nscale(iviewm(1))),...
   'callback','nscale(iviewm(1)) = str2num(get(hviewm(6),''string''));');

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

%
%  Define Undef. Geom. Switch
%

hviewm(10) = uicontrol('style','checkbox',...
		'units','normal',...
		'position',[0.04 0.94 0.25 0.05],...
		'string','Show Undef. Geom',...
		'value',iviewm(4),...
		'callback',['iviewm(4) = get(hviewm(10),''value'');']);


hviewm(8) = uicontrol('position',[0 0 eps eps]);
%
%  Define Node Label Switch
%

hviewm(9) = uicontrol('style','checkbox',...
		'units','normal',...
		'position',[0.04 0.82 0.25 0.05],...
		'string','Show Labels',...
		'value',iviewm(5),...
		'callback',['iviewm(5) = get(hviewm(9),''value'');']);

%
%  Define Mode Interpolation Switch
%

hviewm(25) = uicontrol('style','checkbox',...
		'units','normal',...
		'position',[0.04 0.82 0.25 0.05],...
		'string','Interpolate DOF',...
		'value',iviewm(9),...
		'callback','iviewm(9) = get(hinterp,''value'');');



%
% Define Text box for Mode Number
%

hviewm(12) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.48 .94 .08 .04],...
   'string',iviewm(1),...
   'callback','eval(get(hviewm(16),''callback'')),');

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

hviewm(13) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.56 .94 .06 .04],...
        'string','prev', ...
  	'callback',['iviewm(1)=iviewm(1)-1;', ...
		'set(hviewm(12),''string'',num2str(iviewm(1)));', ...
       'eval(get(hviewm(16),''callback'')),']);

hviewm(14) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.62 .94 .06 .04],...
   'string','next', ...
   'callback',['iviewm(1)=iviewm(1)+1;', ...
        'set(hviewm(12),''string'',num2str(iviewm(1)));', ...
        'eval(get(hviewm(16),''callback'')),']);
  
%	  'if iviewm(1)>size(Phiplot,2),', ...
%	     'disp(''Mode out of range''),', ...
%	     'iviewm(1)=size(Phiplot,2);', ...
%	     'set(hviewm(12),''string'',num2str(iviewm(1)));', ...
%	  'else,', ...
%	    'set(hviewm(18),''visible'',''off'');', ...
%	    'set(hviewm(19),''visible'',''off'');', ...
%	    'set(hviewm(20),''visible'',''off'');', ...	    
%      'drawmode(Bars,Nodes,Shells,Phiplot,Freqplot,DOFvec,iviewm(1),iviewm(6),',...
%     '0,nscale(iviewm(1)),hviewm(2),1);', ...	    
%  'end;']);

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

hviewm(15) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.9 .94 .06 .04],...
        'string',num2str(iviewm(2)),...
	'callback','iviewm(2) = str2num(get(hviewm(15),''string''));');

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

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

hviewm(16) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.82 .90 .15 .04],...
        'string','Plot',...
        'callback',['iviewm(1) = str2num(get(hviewm(12),''string''));',...
           'set(hviewm(6),''string'',sprintf(''%6.3e'',nscale(iviewm(1)))),',...
	  'if iviewm(1)>size(Phiplot,2),', ...
	     'disp(''Mode out of range''),', ...
	     'iviewm(1)=size(Phiplot,2);', ...
	     'set(hviewm(12),''string'',num2str(iviewm(1)));', ...
	  'else,', ...
	    'set(hviewm(18),''visible'',''off'');', ...
	    'set(hviewm(19),''visible'',''off'');', ...
       'set(hviewm(20),''visible'',''off'');', ...
       'set(hviewm(2),''dataaspectratio'',[1 1 1]),',...
	    'drawmode(Bars,Nodes,Shells,Phiplot,Freqplot,DOFvec,iviewm(1),iviewm(6),',...
       'iviewm(4),nscale(iviewm(1)),hviewm(2),1);', ...
	    'if ipltcmplx == 1, labstr = ''Real Mode Shape'';',...
	    'elseif ipltcmplx==2, labstr = ''Complex Mode Shape'';',...
       'end,',...
       'exstr = get(get(hviewm(2),''title''),''string'');',...
       'ht = title([exstr blanks(5) labstr]);',...
	  'end;']);


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

hviewm(17) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.82 .85 .15 .04],...
        'string','Animate',...
	'callback',['iviewm(1) = str2num(get(hviewm(12),''string''));',...
     'set(hviewm(18),''visible'',''off'');',...
     'set(hviewm(2),''dataaspectratio'',[1 1 1]), axes(hviewm(2)), axis manual,',...
     'modemovie=animmode(Bars,Nodes,Shells,Phiplot,Freqplot,DOFvec,iviewm(1),iviewm(6),0,iviewm(4),iviewm(5),hviewm(2),nscale(iviewm(1)));',...
	  'set(hviewm(18),''visible'',''on'');', ...
	  'set(hviewm(19),''visible'',''on'');', ...
	  'set(hviewm(20),''visible'',''on'');', ...
	  'movie(modemovie,iviewm(2),iviewm(3));']);


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

hviewm(18) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.75 .66 .25 .04],...
        'string','Replay Animation',...
	'callback',['iviewm(3)=str2num(get(hviewm(20),''string''));', ...
		'movie(modemovie,iviewm(2),iviewm(3))']);

if isempty(modemovie), set(hviewm(18),'visible','off'), end

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

hviewm(20) = uicontrol('style','edit',...
	'units','normal',...
	'pos',[.95 .62 .05 .04],...
        'string',num2str(iviewm(3)),...
	'callback','iviewm(3) = str2num(get(hviewm(20),''string''));');

if isempty(modemovie), 
   set(hviewm(19),'visible','off'), 
   set(hviewm(20),'visible','off'),
end

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

hviewm(21) = uicontrol('style','push',...
	'units','normal',...
	'pos',[.725 .01 .25 .04],...
        'string','Exit ViewModes',...
	'callback','clear modemovie; close(hviewm(1))');

%
% Mode type popup (real/complex)
%

hviewm(22)=uicontrol('style','popupmenu', ...
	'units','normal', ...
	'string','Real|Complex', ...
	'position',[.82 .80 .15 .04],...
	'value',ipltcmplx,...
	'callback',['iopDOF=get(hviewm(23),''value'');',...
		    'ipltcmplx = get(hviewm(22),''value'');',...
		    'asphiplt']);

%
%  Input/Output mode shape selector
%

hviewm(23)=uicontrol('style','popup', ...
      'unit','normalized', ...
      'position',[.82 .60 .15 .04],...
      'Value',iopDOF,...
      'string','Resp DOF|Ref DOF', ...
      'callback',['iopDOF=get(hviewm(23),''value'');',...
		  'ipltcmplx = get(hviewm(22),''value'');',...
		  'asphiplt']);



hviewm(24) = uicontrol('style','push',...
		'units','normal',...
		'pos',[0.82 0.75 0.15 0.04],...
		'string','Print',...
		'callback','disp(''Printing Mode Shape...''), print');

%%
%%  Draw the geometry already in the workspace
%%

%if iviewm(4)==1,
   
%   updtgeom('--',[0 0 0],Nodes,Bars,Shells,hviewm(2),14,[]);
   
%end

%%
%%  Disable inappropriate mode shape options
%%

if exist('phir_resp') ~=1 & exist('phir_ref')~=1 & exist('phir_resp_t')~=1 & exist('phir_ref_t')~=1,
	set(hviewm(22),'visible','off')
end

if (exist('phic_resp') ~=1 & exist('phic_resp_t')~=1) | (exist('phic_ref') ~=1 & exist('phic_ref_t')~=1),
	set(hviewm(23),'visible','off')
end

%%
%%  Disable the interpolation and node label switches
%%

set(hviewm(25),'visible','off')
set(hviewm(9),'visible','off')

drawnow

return
