function peigui_mainmenu()

% This function open the main window of the hopsgui sofware

global peigui_obj

% ----------------------------------------------------------------------
% Controls for figure and the parents
% ----------------------------------------------------------------------



figure_= figure('Units','normalized','DefaultUicontrolUnits','Normalized', .... 
	'Color',[1 1 1], ...
	'InvertHardcopy','off', ...
	'NumberTitle','off',....
	'MenuBar','none', ...
	'PaperType','a4letter', ...
	'Name','PeiGui', ...	
	'Position',[0.404688 0.21875 0.578906 0.595703]);
	

peigui_obj{1}.hfigure=figure_;

axes1_ = axes('Parent',figure_, ...
	'Units','normalized', ...
	'Box','on', ...
	'CameraUpVector',[0 1 0], ...
	'FontName','times', ...
	'Layer','top', ...
	'Position',[0.08 0.25 .80 0.65], ...
	'Tag','Axes1', ...
	'Color',[1 1 1], ...	
	'XColor',[0 0 0], ...
	'YColor',[0 0 0], ...
	'ZColor',[0 0 0], ...
        'xtick',[], 'ytick',[]);
 	
	
axes2_ = axes('Parent',figure_, ...
	'Units','normalized', ...
	'Box','on', ...
	'CameraUpVector',[0 1 0], ...
	'FontName','times', ...
	'Layer','top', ...
	'Color',[1 1 1], ...		
	'Position',[0.89 0.25 .05 0.65], ...
	'Tag','Axes1', ...
	'XColor',[0 0 0], ...
	'YColor',[0 0 0], ...
	'ZColor',[0 0 0], ...
        'xtick',[], 'ytick',[]);
	
peigui_obj{1}.haxes1=axes1_;  %Main axes handle
peigui_obj{1}.haxes2=axes2_;  %Colorbar axes handle

c = text('Parent',axes1_, ...
	'Color',[0 0 0], ...
	'FontName','times', ...
	'HandleVisibility','callback', ...
	'HorizontalAlignment','center', ...
	'Position',[0.5 -0.0471014 0], ...
	'Tag','Text1', ...
	'VerticalAlignment','cap');
	
set(get(c,'Parent'),'XLabel',c);
c = text('Parent',axes1_, ...
	'Color',[0 0 0], ...
	'FontName','times', ...
	'HandleVisibility','callback', ...
	'HorizontalAlignment','center', ...
	'Position',[-0.0354559 0.501208 0], ...
	'Rotation',90, ...
	'Tag','Text2', ...
	'VerticalAlignment','baseline');
	
set(get(c,'Parent'),'YLabel',c);
c = text('Parent',axes1_, ...
	'Color',[0 0 0], ...
	'FontName','times', ...
	'HandleVisibility','callback', ...
	'HorizontalAlignment','right', ...
	'Position',[-0.0586107 1.08333 0], ...
	'Tag','Text3', ...
	'Visible','on');
	
set(get(c,'Parent'),'ZLabel',c);
c = text('Parent',axes1_, ...
	'Color',[0 0 0], ...
	'FontName','times', ...
	'HandleVisibility','callback', ...
	'HorizontalAlignment','left', ...
	'Position',[0.08 1.01812 0], ...
	'Tag','UpperTitleAxis', ...
	'VerticalAlignment','bottom');
%set(get(c,'Parent'),'Title',c);

peigui_obj{1}.htextaxes=c;



% ----------------------------------------------------------------------
% Uicontrols for the iindex slider
% ----------------------------------------------------------------------

text_iindex_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.25 0.05 0.08 0.04], ...
	'String','Iindex:', ...
	'Style','text', ...
	'Tag','StaticTextIindex');
edit_iindex_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[1 1 1], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.33 0.05 0.07 0.04], ...
	'String',num2str(peigui_obj{1}.iindex), ...
	'Style','edit', ...
	'Tag','EditTextIindex', ...
	'Callback','peigui_menu_command fc_edit_iindex; peigui_contour_command iindex_contour', ...	
	'Value',30);
slider_iindex_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Max',44, ...
	'Min',1, ...	
	'Position',[0.25 0.01 0.15 0.04], ...
	'Style','slider', ...
	'Tag','SliderIindex', ...
	'Callback','peigui_menu_command fc_slider_iindex; peigui_contour_command iindex_contour', ...		
	'Value',peigui_obj{1}.iindex);
	
peigui_obj{1}.hedit_iindex=edit_iindex_;
peigui_obj{1}.hslider_iindex=slider_iindex_;

% ----------------------------------------------------------------------
% Uicontrols for the jindex slider
% ----------------------------------------------------------------------


text_jindex_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.40 0.05 0.08 0.04], ...
	'String','Jindex:', ...
	'Style','text', ...
	'Tag','StaticTextJindex');
edit_jindex_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[1 1 1], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.48 0.05 0.07 0.04], ...
	'String',num2str(peigui_obj{1}.jindex), ...
	'Style','edit', ...
	'Tag','EditTextJindex', ...
	'Callback','peigui_menu_command fc_edit_jindex; peigui_contour_command jindex_contour', ...
	'Value',peigui_obj{1}.jindex);
slider_jindex_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Min',1, ...
	'Max',60, ...
	'Position',[0.40 0.01 0.15 0.04], ...
	'Style','slider', ...
	'Tag','SliderJindex', ...
	'Callback','peigui_menu_command fc_slider_jindex; peigui_contour_command jindex_contour', ...	
	'Value',peigui_obj{1}.jindex);
	
peigui_obj{1}.hedit_jindex=edit_jindex_;
peigui_obj{1}.hslider_jindex=slider_jindex_;


% ----------------------------------------------------------------------
% Uicontrols for the jindex slider
% ----------------------------------------------------------------------


text_kindex_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.55 0.05 0.08 0.04], ...
	'String','kindex:', ...
	'Style','text', ...
	'Tag','StaticTextJindex');
edit_kindex_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[1 1 1], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.63 0.05 0.07 0.04], ...
	'String',num2str(peigui_obj{1}.jindex), ...
	'Style','edit', ...
	'Tag','EditTextkindex', ...
	'Callback','peigui_menu_command fc_edit_kindex; peigui_contour_command kindex_contour', ...
	'Value',peigui_obj{1}.jindex);
slider_kindex_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Min',1, ...
	'Max',60, ...
	'Position',[0.55 0.01 0.15 0.04], ...
	'Style','slider', ...
	'Tag','Sliderkindex', ...
	'Callback','peigui_menu_command fc_slider_kindex; peigui_contour_command kindex_contour', ...	
	'Value',peigui_obj{1}.kindex);
	
peigui_obj{1}.hedit_kindex=edit_kindex_;
peigui_obj{1}.hslider_kindex=slider_kindex_;


% ----------------------------------------------------------------------
% Uicontrols for the depth slider
% ----------------------------------------------------------------------


text_depth_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.009+0.75 0.05 0.10 0.04], ...
	'String','Depth:', ...
	'Style','text', ...
	'Tag','StaticTextdepth');

edit_depth_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[1 1 1], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.11+0.75 0.05 0.1 0.04], ...
	'String',num2str(peigui_obj{1}.depth), ...
	'Style','edit', ...
	'Tag','EditTextDepth', ...
	'Callback','peigui_menu_command fc_edit_depth; peigui_contour_command depth_contour', ...
	'Value',-100);
	
slider_depth_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Max',-0.01, ...
	'Min',-5000., ...
	'Position',[0.009+0.75 0.01 0.2 0.04], ...
	'Style','slider', ...
	'Tag','SliderDepth', ...
	'Callback','peigui_menu_command fc_slider_depth; peigui_contour_command depth_contour', ...
	'Value',-100.);
	

peigui_obj{1}.hedit_depth=edit_depth_;
peigui_obj{1}.hslider_depth=slider_depth_;

% ----------------------------------------------------------------------
% Uicontrols for the time step slider
% ----------------------------------------------------------------------


text_timestep_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.70196 0.70196 0.70196], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.65+0.06 0.1 0.10 0.04], ...
	'String','Time Step', ...
	'Style','text', ...
	'Tag','time step label');


edit_timestep_= uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[1 1 1], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.79+0.06 0.1 0.07 0.04], ...
	'String','1', ...
	'Style','edit', ...
	'callback',' peigui_menu_command settime', ...	
	'Tag','peigui time edit', ...
	'Value',1);

peigui_obj{1}.text_timestep=text_timestep_; %Handle for the edit time box
peigui_obj{1}.edit_timestep=edit_timestep_; %Handle for the edit time box


buttonl_timestep_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.7 0.7 0.7], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.75+0.06 0.1 0.04 0.04], ...
	'String','<', ...
	'callback','peigui_menu_command timedecrement', ...
	'Tag','time step back one');

buttonb_timestep_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.7 0.7 0.7], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.56+.3+0.06 0.1 0.04 0.04], ...
	'String','>', ...
	'callback','peigui_menu_command timeincrement', ...	
	'Tag','time step forward one');
	

peigui_obj{1}.buttonl_timestep=buttonl_timestep_; 
peigui_obj{1}.buttonb_timestep=buttonb_timestep_; 


% ----------------------------------------------------------------------
% Controls file menu
% ----------------------------------------------------------------------


menufile_= uimenu('Parent',figure_, ...
	'Label','File', ...
	'Tag','peigui file menu');
	

menufile_open_ = uimenu('Parent',menufile_, ...
	'Callback','peigui_menu_command openfile', ...
	'Label','Open file', ...
	'Tag','peigui figure open nc file');


menufile_print_ps_ = uimenu('Parent',menufile_, ...
	'Callback','peigui_menu_command print_ps', ...
	'Label','Print to Ps', ...
	'Tag','peigui figure print postscript');

menufile_print_ps_tall_ = uimenu('Parent',menufile_, ...
	'Callback','peigui_menu_command print_ps_tall', ...
	'Label','Print to Ps, Tall', ...
	'Tag','peigui figure print tall postscript');
	
	
menufile_print_eps_ = uimenu('Parent',menufile_, ...
	'Callback','peigui_menu_command print_eps',...
	'Label','Print to Eps', ...
	'Tag','peigui figure print encapsulated postscrip');
	
menufile_print_lp_= uimenu('Parent',menufile_, ...
	'Callback','peigui_menu_command print_lp', ...
	'Label','Print to Printer', ...
	'Tag','peigui figure print to printer');	

menufile_exit_= uimenu('Parent',menufile_, ...
	'Callback','peigui_menu_command exit', ...
	'Label','Exit', ...
	'Tag','peigui figure exit');	


% ----------------------------------------------------------------------
% Controls Variable menu (The children are described in peigui_menuvar.m)
% ----------------------------------------------------------------------


menuvar_= uimenu('Parent',figure_, ...
	'Label','Variables', ...
	'Tag','peigui file menu');





peigui_obj{1}.hmenuvar=menuvar_; % hmenuvar handle for the menu of the variables


% ----------------------------------------------------------------------
% Controls Radio buttons for:
% 	contour labeling
% 	Overlay vectors 
% 	Overlay land mask
% ----------------------------------------------------------------------


automacont_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'Callback','peigui_menu_command rbautomaticontours', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.20+0.03 0.15 0.21 0.04], ...
	'String','Automatic Contour', ...
	'Style','checkbox', ...
	'Value',peigui_obj{1}.cautomatic,...
	'Tag','Checkbox1');


automaxtext_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.43 0.1 0.08 0.04], ...
	'String','Max', ...
	'Style','Text');

automaxedit_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'Callback',' peigui_menu_command getmaxauto', ...
	'BackgroundColor',[1 1 1], ...	
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.51 0.1 0.1 0.04], ...
	'Style','edit', ...
	'String',num2str(peigui_obj{1}.cmax), ...
	'Tag','Checkbox1');
	
automintext_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.25 0.1 0.08 0.04], ...
	'String','Min', ...
	'Style','Text');

autominedit_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'Callback',' peigui_menu_command getminauto', ...
	'BackgroundColor',[1 1 1], ...	
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.33 0.1 0.1 0.04], ...
	'Style','edit', ...
	'String',num2str(peigui_obj{1}.cmin), ...
	'Tag','Checkbox1');
	

autointedit_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'Callback',' peigui_menu_command getintauto', ...
	'BackgroundColor',[1 1 1], ...	
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.61 0.1 0.1 0.04], ...
	'Style','edit', ...
	'String',num2str(peigui_obj{1}.cint), ...
	'Tag','Checkbox1');

	

peigui_obj{1}.hautominedit=autominedit_;
peigui_obj{1}.hautomaxedit=automaxedit_;
peigui_obj{1}.hautointedit=autointedit_;

vectoverlay_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'Callback','peigui_menu_command rbvectoroverlay', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.01 0.13+0.04 0.21 0.04], ...
	'String','Overlay Arrows', ...
	'Style','checkbox', ...
	'Value',peigui_obj{1}.drawvectors,...
	'Tag','Checkbox1');

maskoverlay_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'Callback','peigui_menu_command rbmaskoverlay', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.01 0.13 0.21 0.04], ...
	'String','Overlay Land Mask', ...
	'Style','checkbox', ...
	'Value',peigui_obj{1}.drawmask,...
	'Tag','Checkbox1');


linecontours_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'Callback','peigui_menu_command rblinecontours', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.01 0.13-0.04 0.21 0.04], ...
	'String','Contour Lines', ...
	'Style','checkbox', ...
	'Value',peigui_obj{1}.linecontours,...
	'Tag','Checkbox1');


labelcontours_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'Callback','peigui_menu_command rblabelcontours', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.01 0.13-0.08 0.21 0.04], ...
	'String','Contour Labels', ...
	'Style','checkbox', ...
	'Value',peigui_obj{1}.labelcontours,...
	'Tag','Checkbox1');



zoom_ = uicontrol('Parent',figure_, ...
	'Units','normalized', ...
	'BackgroundColor',[0.701961 0.701961 0.701961], ...
	'Callback','zoom', ...
	'FontName','times', ...
	'FontSize',12, ...
	'Position',[0.04 0.01 0.12 0.04], ...
	'String','Zoom', ...
	'Style','checkbox', ...
	'Value',peigui_obj{1}.labelcontours,...
	'Tag','Checkbox1');



% ----------------------------------------------------------------------
% Controls Variable menu (The children are described in peigui_menuvar.m)
% ----------------------------------------------------------------------


menudefault_= uimenu('Parent',figure_, ...
	'Label','Default Values', ...
	'Tag','peigui file menu');

velsettings_= uimenu('Parent',menudefault_, ...
	'Callback','peigui_menu_command velocity_settingsmenu', ...
	'Label','Velocity Settings');

abssettings_= uimenu('Parent',menudefault_, ...
	'Callback','peigui_abstimegui', ...
	'Label','Absolute time');



menuanimation_= uimenu('Parent',figure_, ...
	'Label','Animation');

animations_= uimenu('Parent',menuanimation_, ...
	'Callback','peigui_animatioguide', ...
	'Label','Make New');
animationsold_= uimenu('Parent',menuanimation_, ...
	'Callback','peigui_animationsaved', ...
	'Label','Play Saved');
	

% ----------------------------------------------------------------------
% Colorscale Variable menu 
% ----------------------------------------------------------------------


menudcolorscale_= uimenu('Parent',figure_, ...
	'Label','ColorScale', ...
	'Tag','hslice file menu');


mc6_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(white)', ...
	'Label','White-No color');

mc1_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(gray)', ...
	'Label','Gray');

mc2_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(copper)', ...
	'Label','Copper');

mc3_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(jet)', ...
	'Label','Jet');

mc4_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(hsv)', ...
	'Label','Hsv');

mc5_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(prism)', ...
	'Label','Prism');

mc6_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(hot)', ...
	'Label','Hot');

mc6_= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(bone)', ...
	'Label','Bone');
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(pink)', ...
	'Label','Pink');
	
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(flag)', ...
	'Label','Flag');
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(lines)', ...
	'Label','lines');
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(cool)', ...
	'Label','cool');
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(autumn)', ...
	'Label','autumn');
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(spring)', ...
	'Label','spring');
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(winter)', ...
	'Label','winter');
mc= uimenu('Parent',menudcolorscale_, ...
	'Callback','colormap(summer)', ...
	'Label','summer');
