function oaggui_menu_command ( action )

%  USAGE oaggui_menu_command (action)
%  In this function there are some command used in hopsGui for general 
%  purposes and managing of the interfaces objects (slider,edit, pushbutton,...) 
%
% The comands (action) are basically:
%
% openfile,.......Open the input file
% print_eps, print_lp
% print_ps_tall, print_ps,.......  Print in different ways
% exit
% new_variable,.......set the current variable
% settime, timeincrement,....... timedecrement set the current time
% rbvectoroverlay,....... Radio button to set or not overlay vetors
% rbmaskoverlay,.......Radio button to set or not overlay mask     
% rblabelcontours,....... Radio button to set or not label at contours
% rbautomaticontours,....... Radio button to set or not automatic contouring
% getmaxauto,getminauto,
% getintauto,.......Get information in case of manual contours
% velocity_settingsmenu,setarrowsampling,
% setarrowscale,setarrowcolor,
% setarrowreference,....... Set different values for drawing vectors
% fc_edit_depth,fc_slider_depth,
% fc_edit_iindex, fc_edit_jindex, 
% fc_slider_iindex, fc_slider_jindex, 
% fc_edit_kindex, 
% fc_slider_kindex,....... Manage the sliders for kindex,iindex and jindex
% setarrowrvariable,.......Set the vector field to be plotted
% getabsyear,getabsmonth,getabsday,getabshour,.......Get absolute time
%
% Pedro Velez (UIB-IEO), July 1999
%
global oaggui_obj
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  		
	
	
	
switch ( action )
case 'openfile'



     %When the file is open some values must be initialed

    	[filename,path] = uigetfile ( '*.nc', 'Select MexCdf Filename' );
	oaggui_obj{1}.filein = sprintf ( '%s%s', path, filename);	
	oaggui_obj{1}.ncid =ncmex ( 'open', oaggui_obj{1}.filein, 'nowrite' );
	%look which variables are present in the file
	oaggui_varmenu
	

	
	%Change the maximun and minimun values of the Slider in function of the	data
	set(oaggui_obj{1}.hslider_kindex,'Max',size(getnc(oaggui_obj{1}.filein,'zout',[-1 3],[-1 3],[-1 -1],1,1),1));
	set(oaggui_obj{1}.hslider_iindex,'Max',size(getnc(oaggui_obj{1}.filein,'grid2',[1 -1 1],[1 -1 1],1,1,2),1));
	set(oaggui_obj{1}.hslider_jindex,'Max',size(getnc(oaggui_obj{1}.filein,'grid2',[-1 1 2],[-1 1 2],1,1,2),1));



	%Time interval and maximun value for time
	temp01=getnc(oaggui_obj{1}.filein,'time');
	if size(temp01) == 1
	oaggui_obj{1}.time=-1;
	set(oaggui_obj{1}.edit_timestep,'visible','off')
	set(oaggui_obj{1}.text_timestep,'visible','off')
	set(oaggui_obj{1}.buttonl_timestep,'visible','off')
	set(oaggui_obj{1}.buttonb_timestep,'visible','off')			
	oaggui_obj{1}.timemax=0;	
	else
	oaggui_obj{1}.timemax=size(temp01);
	end



	


	

case 'print_eps'
	full_path_name='salida.ps';
        [filename,path] = ...
            uiputfile ( '*.eps', 'Select Filename For Encapsulated Postscript File' );
        full_path_name = sprintf ( '%s%s', path, filename );
        comm_str = sprintf ( 'print -dpsc2 -noui %s;\n',full_path_name );
        eval ( comm_str );
    


case 'print_lp'
	
	answer = inputdlg({'Print style','Printer Name', 'Other Options'},...
			   'Print Options',1,{'psc2','', '-noui'});
	if (size(answer,1)>0)
	    printstyle = char(answer(1));
	    printername = char(answer(2));
	    others = char(answer(3));
	    comm_str = sprintf( 'print -d%s -P%s %s -f%i ;\n',...
				printstyle, printername, others);
	    eval (comm_str );
	end


case 'print_ps_tall'
	orient tall
	full_path_name='salidatall.ps';
      [filename,path] = ...
            uiputfile ( '*.ps', 'Select Filename For Postscript File' );
        full_path_name = sprintf ( '%s%s', path, filename );
        comm_str = sprintf ( 'print -dpsc2 -noui %s;\n',full_path_name );
        eval ( comm_str );


case 'print_ps'
	full_path_name='salida.ps';
      [filename,path] = ...
            uiputfile ( '*.ps', 'Select Filename For Postscript File' );
        full_path_name = sprintf ( '%s%s', path, filename );
        comm_str = sprintf ( 'print -dpsc2 -noui %s;\n',full_path_name );
        eval ( comm_str );

case 'exit'
	  close all hidden
case 'new_variable'
        oaggui_obj{1}.variable = get ( gcbo, 'label' );
case 'rbmaskoverlay'	  
	set(oaggui_obj{1}.hfigure,'pointer','watch');	
	oaggui_obj{1}.drawmask=get(gcbo,'Value');
	if oaggui_obj{1}.drawmask==1
	if  strcmp('depth_contour',strrep(oaggui_obj{1}.action,' ','')) | strcmp('kindex_contour',strrep(oaggui_obj{1}.action,' ',''))
	eval(sprintf ( 'oaggui_contour_command %s\n','maskoverlay'));
	end
	end
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  			  	

	
case 'rblabelcontours'	  
	set(oaggui_obj{1}.hfigure,'pointer','watch');	
	oaggui_obj{1}.labelcontours=get(gcbo,'Value');
	if  ~isempty(oaggui_obj{1}.action) 
	eval(sprintf ( 'oaggui_contour_command %s\n',oaggui_obj{1}.action));
	end
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  		
case 'rbautomaticontours'
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  
	oaggui_obj{1}.cautomatic=get(gcbo,'Value');
	if  ~isempty(oaggui_obj{1}.action) 
	eval(sprintf ( 'oaggui_contour_command %s\n',oaggui_obj{1}.action));
	end
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  			  		
	
case 'getmaxauto'
      oaggui_obj{1}.cmax=str2num(get(gcbo,'String'));
	

case 'getminauto'
      oaggui_obj{1}.cmin=str2num(get(gcbo,'String'));

case 'getintauto'
      oaggui_obj{1}.cint=str2num(get(gcbo,'String'));



case 'fc_edit_iindex'
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  	
	oaggui_obj{1}.iindex=fix(str2num(get(oaggui_obj{1}.hedit_iindex,'String')));
	set(oaggui_obj{1}.hslider_iindex,'Value',oaggui_obj{1}.iindex);
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  			
	
	
case 'fc_edit_jindex'
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  	
	oaggui_obj{1}.jindex=fix(str2num(get(oaggui_obj{1}.hedit_jindex,'String')));
	set(oaggui_obj{1}.hslider_jindex,'Value',oaggui_obj{1}.jindex);
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  			
	
case 'fc_slider_iindex'
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  	
	oaggui_obj{1}.iindex=fix(get(oaggui_obj{1}.hslider_iindex,'Value'));
	set(oaggui_obj{1}.hedit_iindex,'String',num2str(oaggui_obj{1}.iindex));	
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  		

	
case 'fc_slider_jindex'
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  	
	oaggui_obj{1}.jindex=fix(get(oaggui_obj{1}.hslider_jindex,'Value'));
	set(oaggui_obj{1}.hedit_jindex,'String',num2str(oaggui_obj{1}.jindex));
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  		


case 'fc_edit_kindex'
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  	
	oaggui_obj{1}.kindex=fix(str2num(get(oaggui_obj{1}.hedit_kindex,'String')));
	set(oaggui_obj{1}.hslider_kindex,'Value',oaggui_obj{1}.kindex);
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  			

case 'fc_slider_kindex'
	set(oaggui_obj{1}.hfigure,'pointer','watch');		  	
	oaggui_obj{1}.kindex=fix(get(oaggui_obj{1}.hslider_kindex,'Value'));
	set(oaggui_obj{1}.hedit_kindex,'String',num2str(oaggui_obj{1}.kindex));
	set(oaggui_obj{1}.hfigure,'pointer','arrow');		  		



case 'getabsyear'	
	oaggui_obj{1}.absyear=str2num(get(gcbo,'String'));


case 'getabsmonth'	
	oaggui_obj{1}.absmonth=str2num(get(gcbo,'String'));

case 'getabsday'	
	oaggui_obj{1}.absday=str2num(get(gcbo,'String'));

case 'getabshour'	
	oaggui_obj{1}.abshour=str2num(get(gcbo,'String'));
case 'settime'	  

      oaggui_obj{1}.time=str2num(get(oaggui_obj{1}.edit_timestep,'String'));
	if ( oaggui_obj{1}.time > oaggui_obj{1}.timemax )
	    oaggui_obj{1}.time = oaggui_obj{1}.timemax;
	  disp(sprintf ( '>>>>>There are just %d  time steps \n',oaggui_obj{1}.timemax));	    
	  set(oaggui_obj{1}.edit_timestep,'String',num2str(oaggui_obj{1}.time))
	return;  
      end
      if ( oaggui_obj{1}.time < 1 )
	    oaggui_obj{1}.time = 1;
          set(oaggui_obj{1}.edit_timestep,'String',num2str(oaggui_obj{1}.time))	    
	return;  	    
      end
      if  ~isempty(oaggui_obj{1}.action) 	  
	eval(sprintf ( 'oaggui_contour_command %s\n', oaggui_obj{1}.action)) ;
	end

	
case 'timeincrement'

	  oaggui_obj{1}.time=round(str2num(get(oaggui_obj{1}.edit_timestep,'String')))+1;
	  %Check if the time is smaller than 1
	  if ( oaggui_obj{1}.time > oaggui_obj{1}.timemax )
		    oaggui_obj{1}.time = oaggui_obj{1}.timemax;
	  disp(sprintf ( '>>>>>There are just %d  time steps \n',oaggui_obj{1}.timemax));	    
	  return;  	  
  	  end
	  set(oaggui_obj{1}.edit_timestep,'String',num2str(oaggui_obj{1}.time));
	  if  ~isempty(oaggui_obj{1}.action) 	  
	  eval(sprintf ( 'oaggui_contour_command %s\n', oaggui_obj{1}.action)) ;
	  end


case 'timedecrement'

	  oaggui_obj{1}.time=round(str2num(get(oaggui_obj{1}.edit_timestep,'String')))-1;
	  %Check if the time is smaller than 1
	  if ( oaggui_obj{1}.time == 0 )
	    oaggui_obj{1}.time = 1;
	  return;  
	  end
	  set(oaggui_obj{1}.edit_timestep,'String',num2str(oaggui_obj{1}.time));
	  if  ~isempty(oaggui_obj{1}.action) 	  
	  eval(sprintf ( 'oaggui_contour_command %s\n', oaggui_obj{1}.action)) ;
	  end

  	

end
if ~strcmp('exit',strrep(action,' ',''))
set(oaggui_obj{1}.hfigure,'pointer','arrow');
end
return;

