function modmenu
%
%  Name: modmenu
% 
%  Usage: modmenu
% 
%  Description:
%    Initializes modal analysis menus
%

%  Version SWD970904
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 MODES

%%=============================================
%% Menu Items for modal analysis
%%=============================================

%=======================================
% Load/Save menu
%========================================
HANDLES.hmmenu{2}(1)=uimenu(HANDLES.hfigdmnd,'Label','Load/Save','enable','on');
HANDLES.hmmenu{2}(2)=uimenu(HANDLES.hmmenu{2}(1),'Label','Load');
HANDLES.hmmenu{2}(3)= uimenu(HANDLES.hmmenu{2}(2),'Label','Data');
uimenu(HANDLES.hmmenu{2}(3),'Label','Primary','Callback', ...
   ['[filename,pathname,error]=loadfile(0,pathname);', ...
      'if error==0,',...
      '   disp(''Loading Primary Data...''),',...
      '	 loaddata(pathname,filename,1);',...
      '   disp(''Done Loading Primary Data''),',...
      'end']);
uimenu(HANDLES.hmmenu{2}(3),'Label','Secondary','Callback', ...
   ['[filename,pathname,error]=loadfile(0,pathname);', ...
      'if error==0,',...
      'disp(''Loading Secondary Data...''),',...
      'loaddata(pathname,filename,2);',...
		'disp(''Done Loading Secondary Data''),',...
		' end']);
uimenu(HANDLES.hmmenu{2}(2),'Label','Modes','Callback', ...
   ['[filename,pathname,error]=loadfile(1,pathname);', ...
      'if error==0,',...
      '   disp(''Loading Modes...''),',...
      '   loadmodes(pathname,filename),', ...
      '   set(HANDLES.hmmenu{6}(1),''enable'',''on''),',...
      '   disp(''Done Loading Modes''),',...
      'end;']);             
uimenu(HANDLES.hmmenu{2}(2),'Label','Geometry','Callback', ...
   ['[filename,pathname,error]=loadfile(2,pathname);', ...
      'if error==0,',...
      '   disp(''Loading Geometry...''),',...
      '   loadgeom(pathname,filename),',...
      '   disp(''Done Loading Geometry''),',...
     'end;']);
HANDLES.hmmenu{2}(2)=uimenu(HANDLES.hmmenu{2}(1),'Label','Save');
uimenu(HANDLES.hmmenu{2}(2),'Label','Data','Callback', ...
   ['[filename,pathname,error]=savefile(0,pathname);', ...
      'if error==0,',...
      '   disp(''Saving Primary Data...''),',...
      '	 savedata(pathname,filename,1);',...
      '   disp(''Done Saving Primary Data''),',...
      'end;']);
uimenu(HANDLES.hmmenu{2}(2),'Label','Modes','Callback', ...
   ['[filename,pathname,error]=savefile(1,pathname);', ...
      'if error==0,',...
      '   disp(''Saving Modes...''),',...
      '   savemodes(pathname,filename),',...
      '   disp(''Done Saving Modes''),',...
      'end,']);
uimenu(HANDLES.hmmenu{2}(2),'Label','Geometry','Callback', ...
   ['[filename,pathname,error]=savefile(2,pathname);', ...
      'if error==0,',...
      '   disp(''Saving Geometry...''),',...
      '   savegeom(pathname,filename),',...
      '   disp(''Done Saving Geometry''),',...
      'end,']);
uimenu(HANDLES.hmmenu{2}(1),'label','List Filenames','callback',...
   ['disp('' ''),',...
    'for i = 1:length(DATA),',...
    ' if isfield(DATA{i},''filename''), disp([''Data File #'',num2str(i),'': '',DATA{i}.pathname,DATA{i}.filename]), end,',...
    'end,',...
    'if isfield(MODES,''filename''), disp([''Modes File: '',MODES.pathname,MODES.filename]), end,',...
    'if isfield(GEOM,''filename''), disp([''Geometry File: '',GEOM.pathname,GEOM.filename]), end,',...
    'drawnow,']);
    


%=======================================
% Geometry menu
%========================================
HANDLES.hmmenu{3}(1)=uimenu(HANDLES.hfigdmnd,'Label','Geometry/DOF','enable','on');
uimenu(HANDLES.hmmenu{3}(1),'Label','Edit Geometry','Callback','editgeom');
uimenu(HANDLES.hmmenu{3}(1),'Label','Edit DOF List','Callback','makedof');

%=======================================
% Data menu
%========================================
HANDLES.hmmenu{4}(1)=uimenu(HANDLES.hfigdmnd,'Label','Plot Data','enable','off');
uimenu(HANDLES.hmmenu{4}(1),'Label','Spectral and Time Data','Callback',[ ...
      'set(HANDLES.hfigdmnd,''name'',''Diamond:  Modal Analysis (Plot Spectral and Time Data)'');', ...
      'plotwindow']);
uimenu(HANDLES.hmmenu{4}(1),'Label','Multi-plot of FRF Magnitudes','Callback','mplot1');

%=======================================
% Identify Modes menu
%========================================
HANDLES.hmmenu{5}(1)=uimenu(HANDLES.hfigdmnd,'Label','Identify Modes','enable','off');
HANDLES.hmmenu{5}(2) = uimenu(HANDLES.hmmenu{5}(1),'Label','Complex-to-Real Conv. Method');
HANDLES.hmmenu{5}(3) = uimenu(HANDLES.hmmenu{5}(2),'Label','Real Part', ...
   'callback',['MODES.ic2rmeth = ''Real Part'';', ...
      'set(HANDLES.hmmenu{5}(3),''checked'',''on''),',...
      'set(HANDLES.hmmenu{5}(4),''checked'',''off''),',...
      'set(HANDLES.hmmenu{5}(8),''checked'',''off''),',...
      'residues2modes,']);
HANDLES.hmmenu{5}(8) = uimenu(HANDLES.hmmenu{5}(2),'Label','Imag Part', ...
   'callback',['MODES.ic2rmeth = ''Imag Part'';', ...
      'set(HANDLES.hmmenu{5}(3),''checked'',''off''),',...
      'set(HANDLES.hmmenu{5}(4),''checked'',''off''),',...
      'set(HANDLES.hmmenu{5}(8),''checked'',''on''),',...
      'residues2modes,']);
HANDLES.hmmenu{5}(4) = uimenu(HANDLES.hmmenu{5}(2),'Label','Phase Rounding', ...
   'callback',['MODES.ic2rmeth = ''Phase Rounding'';', ...
      'set(HANDLES.hmmenu{5}(3),''checked'',''off''),',...
      'set(HANDLES.hmmenu{5}(4),''checked'',''on''),',...
      'set(HANDLES.hmmenu{5}(8),''checked'',''off''),',...
      'residues2modes,']);
HANDLES.hmmenu{5}(5) = uimenu(HANDLES.hmmenu{5}(1),'Label','Spectral Function to Fit');
HANDLES.hmmenu{5}(6) = uimenu(HANDLES.hmmenu{5}(5),'Label','FRF','callback',...
   ['MODES.ispecfunfit = ''FRF'';',...
      'set(HANDLES.hmmenu{5}(6),''checked'',''on''),',...
      'set(HANDLES.hmmenu{5}(7),''checked'',''off''),']);
HANDLES.hmmenu{5}(7) = uimenu(HANDLES.hmmenu{5}(5),'Label','CPS','callback',...
   ['MODES.ispecfunfit = ''CPS'';',...
      'set(HANDLES.hmmenu{5}(6),''checked'',''off''),',...
      'set(HANDLES.hmmenu{5}(7),''checked'',''on''),']);
uimenu(HANDLES.hmmenu{5}(1),'Label','Operating Shapes','separator','on','Callback',[ ...
      'set(HANDLES.hfigdmnd,''name'',''Diamond:  Modal Analysis (Operating Shapes)'');', ...
      'drawnow,',...
      'if ~isstruct(GEOM), warndlg(''Warning: NO GEOMETRY DEFINED. YOU CANNOT VIEW MODE SHAPES.''), end,',...
      'drawnow, pause(3), opshapewindow']);
uimenu(HANDLES.hmmenu{5}(1),'Label','ERA','Callback',[ ...
      'set(HANDLES.hfigdmnd,''name'',''Diamond:  Modal Analysis (ERA)'');', ...
      'erawind']);
uimenu(HANDLES.hmmenu{5}(1),'Label','Complex Exponential','Callback',[ ...
      'set(HANDLES.hfigdmnd,''name'',''Diamond:  Modal Analysis (Complex Exponential)'');', ... 
      'cewind']);
uimenu(HANDLES.hmmenu{5}(1),'Label','Rational Polynomial','Callback',[ ...
      'set(HANDLES.hfigdmnd,''name'',''Diamond:  Modal Analysis (Rational Polynomial)'');', ...
      'ratpwindow']);
uimenu(HANDLES.hmmenu{5}(1),'Label','NL Least Squares','Callback','disp(''This item is not operational yet'')',...
   'enable','off');

%=======================================
% Analyze Modes menu
%========================================
HANDLES.hmmenu{6}(1) = uimenu(HANDLES.hfigdmnd,'label','Analyze Modes','enable','off');
uimenu(HANDLES.hmmenu{6}(1),'Label','Analysis Tools',...
   'Callback','anmodwindow');
uimenu(HANDLES.hmmenu{6}(1),'Label','Plot Mode Shapes',...
   'Callback',...
   ['if isstruct(GEOM),',...
    '   viewmode,',...
    'else,',...
    '   warndlg(''Cannot Plot Mode Shapes: No Geometry Present''),',...
    'end,']);

uimenu(HANDLES.hmmenu{6}(1),'label','Clear Modes (NO UNDO!)',...
   'callback',['for i = MODES.nmodes:-1:1, deletemode(i), end,',...
      ' set(HANDLES.hmmenu{6}(1),''enable'',''off''),',...
      'disp(''MODES CLEARED''),']);

%=======================================
% Nonlinear Analysis menu
%========================================
HANDLES.hmmenu{17}(1) = uimenu(HANDLES.hfigdmnd,'label','Nonlinear Analysis','enable','off');
uimenu(HANDLES.hmmenu{17}(1),'Label','Prob Density Function Fit',...
   'Callback','pdffwindow');
uimenu(HANDLES.hmmenu{17}(1),'Label','Time-Frequency Analysis',...
   'Callback','timefreqwindow');
%
%  Set the checkmarks for the complex-to-real conversion method
%

if exist('MODES.ic2rmeth') ~= 1,
   MODES.ic2rmeth = 'Imag Part';
end

switch MODES.ic2rmeth,
case 'Real Part'
   set(HANDLES.hmmenu{5}(3),'checked','on')
   set(HANDLES.hmmenu{5}(4),'checked','off')
   set(HANDLES.hmmenu{5}(8),'checked','off')
case 'Imag Part'
   set(HANDLES.hmmenu{5}(3),'checked','off')
   set(HANDLES.hmmenu{5}(4),'checked','off')
   set(HANDLES.hmmenu{5}(8),'checked','on')
case 'Phase Rounding'
   set(HANDLES.hmmenu{5}(3),'checked','off')
   set(HANDLES.hmmenu{5}(4),'checked','on')
   set(HANDLES.hmmenu{5}(8),'checked','off')
end

%
%  Set the checkmarks to select the spectral funtion for curve fitting
%

if exist('MODES.ispecfunfit') ~= 1,
   MODES.ispecfunfit = 'FRF';
end

switch MODES.ispecfunfit
case 'FRF'
   set(HANDLES.hmmenu{5}(6),'checked','on')
   set(HANDLES.hmmenu{5}(7),'checked','off')
case 'CPS'
   set(HANDLES.hmmenu{5}(6),'checked','off')
   set(HANDLES.hmmenu{5}(7),'checked','on')
end

return