Index: /issm/trunk/src/m/classes/public/plot/parse_options.m
===================================================================
--- /issm/trunk/src/m/classes/public/plot/parse_options.m	(revision 837)
+++ /issm/trunk/src/m/classes/public/plot/parse_options.m	(revision 838)
@@ -116,6 +116,6 @@
 smooth_values=findarg(optionstring,'smooth');
 if ~isempty(smooth_values),
-	if strcmpi(smooth_values.value,'yes'),
-		options_struct.smooth=0;
+	if strcmpi(smooth_values.value,'on'),
+		options_struct.smooth=1;
 	else
 		options_struct.smooth=smooth_values.value;
@@ -395,5 +395,5 @@
 	options_struct.highres=highresvalues.value;
 else
-	options_struct.highres=NaN;
+	options_struct.highres=0;
 end
 
@@ -407,5 +407,5 @@
 	end
 else
-	options_struct.windowsize=NaN;
+	options_struct.windowsize=1;
 end
 
@@ -419,5 +419,5 @@
 	end
 else
-	options_struct.alpha=NaN;
+	options_struct.alpha=1.5; %Rignot setting.
 end
 	
@@ -628,4 +628,4 @@
 	options_struct.border=bordervalues(1).value;
 else
-	options_struct.border=NaN;
-end
+	options_struct.border=0;
+end
Index: /issm/trunk/src/m/classes/public/plot/plot_overlay.m
===================================================================
--- /issm/trunk/src/m/classes/public/plot/plot_overlay.m	(revision 837)
+++ /issm/trunk/src/m/classes/public/plot/plot_overlay.m	(revision 838)
@@ -7,60 +7,109 @@
 %   See also: PLOTMODEL
 
-%2d plots only
-if ~strcmpi(md.type,'2d'),
-	error('plot_overlay error message: only 2d plots allowed');
+
+%check that buildoverlay has not already been called
+redo=1;
+if (ischar(data) & isstruct(md.mesh2grid_parameters) & ismember(data,mesh2grid_parameters)),
+	choice=input(['mesh2grid has already been called for the parameter ''' data '''. Do you want to call it again (y/n)?'],'s');
+	if strcmp(choice,'y')
+		disp('use previous mesh2grid result');
+		redo=0;
+	end
 end
 
-%highres?
-if ~isnan(options_structure.highres),
-	highres=options_structure.highres;
+if redo
+	%process mesh and data
+	[x y z elements is2d]=processmesh(md,options_structure);
+	[data isongrid]=processdata(md,data,options_structure);
+
+	%apply caxis if required
+	if ~isnan(options_structure.caxis),
+		data(find(data<options_structure.caxis(1)))=options_structure.caxis(1);
+		data(find(data>options_structure.caxis(2)))=options_structure.caxis(2);
+	end
+
+	%check is2d
+	if ~is2d, 
+		error('buildoverlay error message: overlay not supported for 3d meshes, project on a layer');
+	end
+
+	%Ok, first we need to recover the radar map.
+	md=radarpower(md,options_structure.highres);
+
+	writefile('contours.exp',md.domainoutline);
+	contours=expread('contours.exp',0);
+	contours=contours(1); %just keep the outer domain outline.
+	delete('contours.exp');
+
+	%use mesh2grid solution to get an gridded data to display using imagesc
+	if isongrid,
+		interpolation='node';
+	else
+		interpolation='element';
+	end
+	data_mesh2grid=GriddataMeshToGrid(elements,x,y,contours,data,min(x),max(y),...
+		(max(x)-min(x))/length(md.sarxm),(max(y)-min(y))/length(md.sarym),length(md.sarym),length(md.sarxm),...
+		interpolation,'average',options_structure.windowsize);
 else
-	highres=0;
+	%process mesh and data
+	[x y z elements is2d]=processmesh(md,options_structure);
+	[data isongrid]=processdata(md,data,options_structure);
+
+	%get previous result
+	data_mesh2grid=mesh2grid_results(find(ismember(data,mesh2grid_parameters)));
 end
 
-%alpha?
-if ~isnan(options_structure.alpha),
-	transparency=options_structure.alpha;
-else
-	transparency=1.5; %Rignot setting.
-end
+%Ok, we have two images, double format: 
+radar=md.sarpwr;
 
-%smoothing?
-if strcmpi(options_structure.smooth,'yes') & length(data)==md.numberofelements
-	smoothing=1;
-else
-	smoothing=0;
-end
+%nullify NaN in results
+data_mesh2grid(find(isnan(data_mesh2grid)))=0;
 
-if ~isnan(options_structure.windowsize),
-	windowsize=options_structure.windowsize;
-else
-	windowsize=1;
-end
+%Build hsv color image from radar and results
+transparency=options_structure.alpha;
+border=options_structure.border;
 
-%border?
-if ~isnan(options_structure.border),
-	border=options_structure.border;
-else
-	border=0;
-end
+%intensity
+v=radar/max(max(radar));
 
-[image_rgb xm ym]=buildoverlay(md,data,transparency,highres,smoothing,windowsize,border);
+%hue
+%cut results under 1.5, and log
+data_mesh2grid(find(data_mesh2grid<1.5))=1.5;
+h=bytscl(log(data_mesh2grid))/(255+1); %1 offset on colormap
+
+%saturation
+s=(0.5+data_mesh2grid/125)/transparency;s(find(s>1))=1;s(find(s<0))=0;
+s(find(data_mesh2grid==1.5))=0;
+
+%Include border
+v((1:border),:)=0;  v((end-border+1:end),:)=0; v(:,1:border)=0;v(:,(end-border+1:end))=0;
+
+%Transform hsv to rgb
+image_hsv=zeros(size(data_mesh2grid,1),size(data_mesh2grid,2),3);
+image_hsv(:,:,1)=h;
+image_hsv(:,:,2)=s;
+image_hsv(:,:,3)=v;
+image_rgb=hsv2rgb(image_hsv);
 
 %Select plot area 
 subplot(width,width,i);
 
-if ~isnan(options_structure.unitmultiplier),
-	xm=xm*options_structure.unitmultiplier;
-	ym=ym*options_structure.unitmultiplier;
-end
-
 %Plot: 
-imagesc(xm,ym,image_rgb);set(gca,'YDir','normal');
+imagesc(md.sarxm,md.sarym,image_rgb);set(gca,'YDir','normal');
 
 %Apply options, without colorbar and without grid
+if ~isnan(options_structure.fontsize),
+	fontsize=options_structure.fontsize;
+else
+	fontsize=14;
+end
+if isnan(options_structure.axis),
+	options_structure.axis='equal off';
+end
+if isnan(options_structure.colorbarpos),
+	options_structure.colorbarpos=[0.82 0.65 0.03 0.2];
+end
 iscolorbar=(options_structure.colorbar==1 | isnan(options_structure.colorbar));
 options_structure.colorbar=0;
-
 applyoptions(md,data,options_structure);
 
@@ -69,18 +118,12 @@
 
 	%create colorbar with correct colors and position
-	colorbar_rgb=buildoverlaycolorbar(md,data,transparency);
+	colorbar_rgb=buildoverlaycolorbar(md,data,options_structure.alpha);
 	colorbar_handle=colorbar; 
 	colorbar_image_handle=get(colorbar_handle,'Children'); 
 	set(colorbar_image_handle,'CData',colorbar_rgb);
-	if ~isnan(options_structure.colorbarpos),
-		set(colorbar_handle,'Position',options_structure.colorbarpos);
-	else
-		set(colorbar_handle,'Position',[0.82 0.65 0.03 0.2])
-	end
+	set(colorbar_handle,'Position',options_structure.colorbarpos);
 
 	%modify ticks.
-	if isfield(struct(md),data) data=eval(['md.' data ';']); end
 	data(find(data<1.5))=1.5;
-	
 	scalestring=get(colorbar_handle,'YTickLabel');
 	scalevalues=get(colorbar_handle,'YTick');
@@ -91,15 +134,9 @@
 	for i=1:numvalues,
 		fraction=(scalevalues(i)-scaleminmax(1))/(scaleminmax(2)-scaleminmax(1));
-		scalevalues(i)=round_ice(exp(min(log(data))+(max(log(data))-min(log(data)))*fraction),1);
+		scalevalues(i)=round_ice(exp(min(log(data))+(max(log(data))-min(log(data)))*fraction),2);
 		scalestring=[scalestring; sprintf('%8.4g',scalevalues(i))];
 	end
 	set(colorbar_handle,'YTickLabel',scalestring);
 	set(colorbar_handle,'YColor','y');
-	set(colorbar_handle,'FontSize',14);
+	set(colorbar_handle,'FontSize',fontsize);
 end
-
-%take axis off
-axis off;
-
-%put axis equal
-axis equal;
