function peigui_menu_command ( action )

%  USAGE peigui_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 peigui_obj
set(peigui_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' );
	peigui_obj{1}.filein = sprintf ( '%s%s', path, filename);	
	peigui_obj{1}.ncid =ncmex ( 'open', peigui_obj{1}.filein, 'nowrite' );
	%look which variables are present in the file
	peigui_varmenu
	

	
	%Change the maximun and minimun values of the Slider in function of the	data
	set(peigui_obj{1}.hslider_depth,'Min',min(min(getnc(peigui_obj{1}.filein,'tbath'))));
	set(peigui_obj{1}.hslider_iindex,'Max',getnc(peigui_obj{1}.filein,'imt'));
	set(peigui_obj{1}.hslider_jindex,'Max',getnc(peigui_obj{1}.filein,'jmt'));


	set(peigui_obj{1}.hslider_kindex,'Max',getnc(peigui_obj{1}.filein,'km'));
	set(peigui_obj{1}.hslider_depth,'Value',fix((min(min(getnc(peigui_obj{1}.filein,'tbath')))+max(max(getnc(peigui_obj{1}.filein,'tbath'))))/2))
	set(peigui_obj{1}.hedit_depth,'String',num2str(fix((min(min(getnc(peigui_obj{1}.filein,'tbath')))+max(max(getnc(peigui_obj{1}.filein,'tbath'))))/2)))	
	

	%set title in the figure
	peigui_obj{1}.titlrun=deblank(getnc(peigui_obj{1}.filein,'titleic')');


	
	%Time interval and maximun value for time
	temp01=getnc(peigui_obj{1}.filein,'time');
	if size(temp01) == 1
	peigui_obj{1}.time=1;
	set(peigui_obj{1}.edit_timestep,'visible','off')
	set(peigui_obj{1}.text_timestep,'visible','off')
	set(peigui_obj{1}.buttonl_timestep,'visible','off')
	set(peigui_obj{1}.buttonb_timestep,'visible','off')			
	
	peigui_obj{1}.timemax=0;	
	else
	peigui_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'
        peigui_obj{1}.variable = get ( gcbo, 'label' );
case 'settime'	  
      peigui_obj{1}.time=str2num(get(peigui_obj{1}.edit_timestep,'String'));
	if ( peigui_obj{1}.time > peigui_obj{1}.timemax )
	    peigui_obj{1}.time = peigui_obj{1}.timemax;
	    
	  disp(sprintf ( '>>>>>There are just %d  time steps \n',peigui_obj{1}.timemax));	    
	  set(peigui_obj{1}.edit_timestep,'String',num2str(peigui_obj{1}.time))
	return;  
      end
      if ( peigui_obj{1}.time < 1 )
	    peigui_obj{1}.time = 1;
          set(peigui_obj{1}.edit_timestep,'String',num2str(peigui_obj{1}.time))	    
	return;  	    
      end
      if  ~isempty(peigui_obj{1}.action) 	  
	eval(sprintf ( 'peigui_contour_command %s\n', peigui_obj{1}.action)) ;
	end

	
case 'timeincrement'

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


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

		
case 'rbvectoroverlay'	  

	peigui_obj{1}.drawvectors=get(gcbo,'Value');
	if peigui_obj{1}.drawvectors == 1
        if strcmp('depth_contour',strrep(peigui_obj{1}.action,' ',''))	
	    eval(sprintf ( 'peigui_vector_command %s\n','depth_vector'));
	  elseif strcmp('kindex_contour',strrep(peigui_obj{1}.action,' ',''))	
	    eval(sprintf ( 'peigui_vector_command %s\n','k_vector'));
      end
	elseif strcmp('depth_contour',strrep(peigui_obj{1}.action,' ','')) | strcmp('kindex_contour',strrep(peigui_obj{1}.action,' ',''))
	delete(peigui_obj{1}.hvectors1)
	delete(peigui_obj{1}.hvectors2)
	delete(peigui_obj{1}.hvectors3)
	end


case 'rbmaskoverlay'	  

	peigui_obj{1}.drawmask=get(gcbo,'Value');
	if peigui_obj{1}.drawmask==1
	if  strcmp('depth_contour',strrep(peigui_obj{1}.action,' ','')) | strcmp('kindex_contour',strrep(peigui_obj{1}.action,' ',''))
	eval(sprintf ( 'peigui_contour_command %s\n','maskoverlay'));
	end
	end
	set(peigui_obj{1}.hfigure,'pointer','arrow');		  			  	

	
case 'rblabelcontours'	  
	set(peigui_obj{1}.hfigure,'pointer','watch');	
	peigui_obj{1}.labelcontours=get(gcbo,'Value');
	if  ~isempty(peigui_obj{1}.action) 
	eval(sprintf ( 'peigui_contour_command %s\n',peigui_obj{1}.action));
	end


case 'rblinecontours'	  

	peigui_obj{1}.linecontours=get(gcbo,'Value');
	if  ~isempty(peigui_obj{1}.action) 
	eval(sprintf ( 'peigui_contour_command %s\n',peigui_obj{1}.action));
	end

case 'rbautomaticontours'

	peigui_obj{1}.cautomatic=get(gcbo,'Value');
	if  ~isempty(peigui_obj{1}.action) 
	eval(sprintf ( 'peigui_contour_command %s\n',peigui_obj{1}.action));
	end

	
case 'getmaxauto'
      peigui_obj{1}.cmax=str2num(get(gcbo,'String'));
	

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

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


case 'velocity_settingsmenu'
	eval(sprintf ( 'peigui_velocity_settingsmenu \n'));	

case 'setarrowsampling'

	peigui_obj{1}.isub=round(str2num(get(gcbo,'String')));
	delete(peigui_obj{1}.hvectors1)
	delete(peigui_obj{1}.hvectors2)
	delete(peigui_obj{1}.hvectors3)
	figure(peigui_obj{1}.hfigure)
	hold on		
	eval(sprintf ( 'peigui_vector_command %s\n',peigui_obj{1}.vectoraction));
	hold off

	
case 'setarrowscale'

	peigui_obj{1}.fac=str2num(get(gcbo,'String'));
	delete(peigui_obj{1}.hvectors1)
	delete(peigui_obj{1}.hvectors2)
	delete(peigui_obj{1}.hvectors3)
	figure(peigui_obj{1}.hfigure)
	hold on		
	eval(sprintf ( 'peigui_vector_command %s\n',peigui_obj{1}.vectoraction));
	hold off

	

case 'setarrowcolor'

	peigui_obj{1}.vectorcolor=get(gcbo,'String');
	delete(peigui_obj{1}.hvectors1)
	delete(peigui_obj{1}.hvectors2)
	delete(peigui_obj{1}.hvectors3)
	figure(peigui_obj{1}.hfigure)
	hold on		
	eval(sprintf ( 'peigui_vector_command %s\n',peigui_obj{1}.vectoraction));
	hold off

	
	
case 'setarrowreference'

	peigui_obj{1}.refvector=str2num(get(gcbo,'String'));
	delete(peigui_obj{1}.hvectors1)
	delete(peigui_obj{1}.hvectors2)
	delete(peigui_obj{1}.hvectors3)
	figure(peigui_obj{1}.hfigure)
	hold on		
	eval(sprintf ( 'peigui_vector_command %s\n',peigui_obj{1}.vectoraction));
	hold off


	
case 'fc_edit_depth'

	peigui_obj{1}.depth=round(str2num(get(peigui_obj{1}.hedit_depth,'String')));
	set(peigui_obj{1}.hslider_depth,'Value',peigui_obj{1}.depth);

	
case 'fc_slider_depth'

	peigui_obj{1}.depth=round(get(peigui_obj{1}.hslider_depth,'Value'));
	set(peigui_obj{1}.hedit_depth,'String',num2str(peigui_obj{1}.depth));


case 'fc_edit_iindex'

	peigui_obj{1}.iindex=fix(str2num(get(peigui_obj{1}.hedit_iindex,'String')));
	set(peigui_obj{1}.hslider_iindex,'Value',peigui_obj{1}.iindex);

	
	
case 'fc_edit_jindex'

	peigui_obj{1}.jindex=fix(str2num(get(peigui_obj{1}.hedit_jindex,'String')));
	set(peigui_obj{1}.hslider_jindex,'Value',peigui_obj{1}.jindex);

	
case 'fc_slider_iindex'

	peigui_obj{1}.iindex=fix(get(peigui_obj{1}.hslider_iindex,'Value'));
	set(peigui_obj{1}.hedit_iindex,'String',num2str(peigui_obj{1}.iindex));	


	
case 'fc_slider_jindex'

	peigui_obj{1}.jindex=fix(get(peigui_obj{1}.hslider_jindex,'Value'));
	set(peigui_obj{1}.hedit_jindex,'String',num2str(peigui_obj{1}.jindex));



case 'fc_edit_kindex'

	peigui_obj{1}.kindex=fix(str2num(get(peigui_obj{1}.hedit_kindex,'String')));
	set(peigui_obj{1}.hslider_kindex,'Value',peigui_obj{1}.kindex);


case 'fc_slider_kindex'

	peigui_obj{1}.kindex=fix(get(peigui_obj{1}.hslider_kindex,'Value'));
	set(peigui_obj{1}.hedit_kindex,'String',num2str(peigui_obj{1}.kindex));


case 'setarrowrvariable'
	choice=get(gcbo,'Value');
	if choice==1, peigui_obj{1}.vectorvar='vtot';
	elseif choice==2, peigui_obj{1}.vectorvar='vclin';
	elseif choice==3, peigui_obj{1}.vectorvar='vgeo';	
	end


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


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

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

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



end

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

return;

