function oaggui_contour_command ( action )
%  USAGE oaggui_contour_command(action)
%  In this function there are some command used in oagGui for contouring
%
% The comands (action) are basically:
% depth_contour,......Do depth contours
% jindex_contour,......Do jindex contours
% iindex_contour,......Do iindex contours
% kindex_contour,......Do kindex contours
% maskoverlay,......Overlay land mask
%
% Pedro Velez (UIB-IEO), July 1999
global oaggui_obj

switch ( action )
        
%%%%Jindex contouring%%%%%
case 'jindex_contour'
oaggui_obj{1}.action = action;


	[field,x,y,z]=oaggui_jslice(oaggui_obj{1}.filein, ...
	oaggui_obj{1}.jindex,....
	oaggui_obj{1}.time,...
	oaggui_obj{1}.variable);
	
	%Checking automatic limits or not
	if oaggui_obj{1}.cautomatic == 1
		minmax=extrem(field);
		vector=nice([minmax],2)';
		levels=min(vector):(vector(2)-vector(1)):max(vector);
		oaggui_obj{1}.cmin=minmax(1);
		oaggui_obj{1}.cmax=minmax(2);
		oaggui_obj{1}.cint=vector(2)-vector(1);
		
		%I Change the windows of the max, min, interval
		set(oaggui_obj{1}.hautominedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cmin)));
		set(oaggui_obj{1}.hautomaxedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cmax)));
		set(oaggui_obj{1}.hautointedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cint)));
		vector=nice([minmax],2)';
		levels=min(vector):(vector(2)-vector(1)):max(vector);
		
	else
		minmax(1)=oaggui_obj{1}.cmin;
		minmax(2)=oaggui_obj{1}.cmax;
		levels=oaggui_obj{1}.cmin:oaggui_obj{1}.cint:oaggui_obj{1}.cmax;
		
	end	

  %Contouring
	caxis([minmax]);  
	axes(oaggui_obj{1}.haxes1)
	if oaggui_obj{1}.labelcontours==1 
	extcontour(x,z,field',levels,'fill','fontsize',10,'fontname','times');
	else
	extcontour(x,z,field',levels,'fill');
	end
	
	axes(oaggui_obj{1}.haxes1)
	%caxis([minmax]);colorbar(oaggui_obj{1}.haxes2)
	caxis([minmax]);hopscolorbar(levels,oaggui_obj{1}.haxes2,oaggui_obj{1}.haxes1)	
	axes(oaggui_obj{1}.haxes1)

  %set title in the axes

    date=gregorian(getnc(oaggui_obj{1}.filein,'time',[oaggui_obj{1}.time],[oaggui_obj{1}.time]));

      title(sprintf ('%s for %s at j=%3d, %s \n %s', ....
	  oaggui_obj{1}.variable,...
	  oaggui_obj{1}.titlrun, oaggui_obj{1}.jindex, ...
    	  datestr(datenum(date(1),date(2),date(3),date(4),date(5),date(6)),0), ...
	  oaggui_obj{1}.filein), ...
	  'Parent',oaggui_obj{1}.haxes1,...
	  'Units','normalized','position',[0 1.0], ...
	  'horizontalalignment','left','interpreter','none');
	ylabel('Depth')

	

%%%%Iindex contouring%%%%
case 'iindex_contour'
oaggui_obj{1}.action = action;

      [field,x,y,z]=oaggui_islice(oaggui_obj{1}.filein,...
	oaggui_obj{1}.iindex,...
	oaggui_obj{1}.time,...
	oaggui_obj{1}.variable);
  
	%Checking automatic limits or not
	if oaggui_obj{1}.cautomatic == 1
		minmax=extrem(field);
		vector=nice([minmax],2)';
		levels=min(vector):(vector(2)-vector(1)):max(vector);
		oaggui_obj{1}.cmin=minmax(1);
		oaggui_obj{1}.cmax=minmax(2);
		oaggui_obj{1}.cint=vector(2)-vector(1);
		
		%I Change the windows of the max, min, interval
		set(oaggui_obj{1}.hautominedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cmin)));
		set(oaggui_obj{1}.hautomaxedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cmax)));
		set(oaggui_obj{1}.hautointedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cint)));
		vector=nice([minmax],2)';
		levels=min(vector):(vector(2)-vector(1)):max(vector);
		
	else
		minmax(1)=oaggui_obj{1}.cmin;
		minmax(2)=oaggui_obj{1}.cmax;
		levels=oaggui_obj{1}.cmin:oaggui_obj{1}.cint:oaggui_obj{1}.cmax;
		
	end	
  
  %Contouring
	caxis([minmax]);  
	axes(oaggui_obj{1}.haxes1)
	if oaggui_obj{1}.labelcontours==1 
	extcontour(y,z,field',levels,'fill','label','k','fontsize',10,'fontname','times');
	else
	extcontour(y,z,field',levels,'fill');
	end
	axes(oaggui_obj{1}.haxes1)
	%caxis([minmax]);colorbar(oaggui_obj{1}.haxes2)
	caxis([minmax]);hopscolorbar(levels,oaggui_obj{1}.haxes2,oaggui_obj{1}.haxes1)		
	axes(oaggui_obj{1}.haxes1)	
  
 
   %set title in the axes
   
     date=gregorian(getnc(oaggui_obj{1}.filein,'time',[oaggui_obj{1}.time],[oaggui_obj{1}.time])) ;
      title(sprintf ('%s for %s at i=%3d, %s \n %s', ....
	  oaggui_obj{1}.variable,...
	  oaggui_obj{1}.titlrun, oaggui_obj{1}.iindex, ...
  	  datestr(datenum(date(1),date(2),date(3),date(4),date(5),date(6)),0), ...
	  oaggui_obj{1}.filein), ...
	  'Parent',oaggui_obj{1}.haxes1,...
	  'Units','normalized','position',[0 1.0], ...
	  'horizontalalignment','left','interpreter','none');


   	ylabel('Depth') 



%%%%kindex contouring%%%%
case 'kindex_contour'
oaggui_obj{1}.action = action;


	%Reading data
      [field,x,y,z]=oaggui_kslice(oaggui_obj{1}.filein,...
	oaggui_obj{1}.kindex,...
	oaggui_obj{1}.time,...
	oaggui_obj{1}.variable);
	
	%Checking automatic limits or not
	if oaggui_obj{1}.cautomatic == 1
		minmax=extrem(field);
		vector=nice([minmax],2)';
		levels=min(vector):(vector(2)-vector(1)):max(vector);
		oaggui_obj{1}.cmin=minmax(1);
		oaggui_obj{1}.cmax=minmax(2);
		oaggui_obj{1}.cint=vector(2)-vector(1);
		
		%I Change the windows of the max, min, interval
		set(oaggui_obj{1}.hautominedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cmin)));
		set(oaggui_obj{1}.hautomaxedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cmax)));
		set(oaggui_obj{1}.hautointedit,'String',deblank(sprintf('%8.5g',oaggui_obj{1}.cint)));
		vector=nice([minmax],2)';
		levels=min(vector):(vector(2)-vector(1)):max(vector);
		
	else
		minmax(1)=oaggui_obj{1}.cmin;
		minmax(2)=oaggui_obj{1}.cmax;
		levels=oaggui_obj{1}.cmin:oaggui_obj{1}.cint:oaggui_obj{1}.cmax;
		
	end	
  
	%Contouring
	caxis([minmax]);
	axes(oaggui_obj{1}.haxes1)
	if oaggui_obj{1}.labelcontours==1 
	extcontour(x,y,field,levels,'fill','label','k','fontsize',10,'fontname','times');
	else
	extcontour(x,y,field,levels,'fill');
	end
	axes(oaggui_obj{1}.haxes1)
	%caxis([minmax]);colorbar(oaggui_obj{1}.haxes2)
	caxis([minmax]);hopscolorbar(levels,oaggui_obj{1}.haxes2,oaggui_obj{1}.haxes1)		
	axes(oaggui_obj{1}.haxes1)	


	%setting the correct aspectratio
	set(oaggui_obj{1}.haxes1,'dataaspectratio', ...
	[1 cos(getnc(oaggui_obj{1}.filein,'rlatd')*pi/180.) 1]);
  
  
    date=gregorian(getnc(oaggui_obj{1}.filein,'time',[oaggui_obj{1}.time],[oaggui_obj{1}.time]));

  	%set title in the axes
      title(sprintf ('%s for %s at %4d metres, %s \n %s', ....
	  oaggui_obj{1}.variable,...
	  oaggui_obj{1}.titlrun, z, ...
	  datestr(datenum(date(1),date(2),date(3),date(4),date(5),date(6)),0), ...
	  oaggui_obj{1}.filein), ...
	  'Parent',oaggui_obj{1}.haxes1,...
	  'Units','normalized','position',[0 1.0], ...
	  'horizontalalignment','left','interpreter','none');

	xlabel('Longitude')
	ylabel('Latitude')

	%check if we add the current vectors.
      if oaggui_obj{1}.drawvectors == 1 
	oaggui_vector_command ('k_vector')
	end


	%check if we add the land mask.
      if oaggui_obj{1}.drawmask == 1 
	oaggui_contour_command ('maskoverlay')
	end


%%%%Mask Overlay%%%%
case 'maskoverlay'

	%Reading data
	
	x=getnc(oaggui_obj{1}.filein,'grid2',[-1 -1 1],[-1 -1 1],1,1,2);
	y=getnc(oaggui_obj{1}.filein,'grid2',[-1 -1 2],[-1 -1 2],1,1,2);
      land=getnc(oaggui_obj{1}.filein,'mask',[-1 -1],[-1 -1],1,1,1);
	
	  [m,n]=size(x);
	  for i=1:m-1
        for j=1:n-1
	    if land(i,j) == 0
	      patch([x(i,j) x(i+1,j) x(i+1,j+1) x(i,j+1)],...
             [y(i,j) y(i+1,j) y(i+1,j+1) y(i,j+1)],'k','linestyle','none');
          end
	  end
	  end





end


return;

