Index: /issm/branches/trunk-jpl-ad2/src/m/plot/applyoptions.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/applyoptions.m	(revision 18291)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/applyoptions.m	(revision 18292)
@@ -139,4 +139,10 @@
 %colorbar
 if getfieldvalue(options,'colorbar',1)==1,
+	if getfieldvalue(options,'rgb',0),
+		%this is an rgb plot, very different type of colorbar!
+		rgbcolorbar(options);
+		colorbar off
+		return;
+	end
 	if exist(options,'colorbarcornerposition'),
 		c=colorbar(getfieldvalue(options,'colorbarcornerposition'),'peer',gca);
@@ -240,5 +246,4 @@
 else
 	%do nothing
-
 end
 
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/plot_gl.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/plot_gl.m	(revision 18292)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/plot_gl.m	(revision 18292)
@@ -0,0 +1,111 @@
+function plotgl(md,optionslist)
+scriptsdir=['~/issm-projects/visl/externalicelab/fem'];
+
+%check on existing of webgl directory: 
+if ~exist('.webgl','dir'),
+	prepare_gl(md,checkplotoptions(md,optionslist{1}));
+end
+	
+options=optionslist{1};
+options=checkplotoptions(md,options);
+
+%keep present directory: 
+presentdir=pwd;
+
+%Setup unique directory in present dir: 
+directory=['.webgl'];
+database=['./generic/'];
+cd(directory);
+
+%copy editables.js file
+copyfile([scriptsdir '/generic/editables.js'],'./generic/editables.js');
+
+%Deal with title: 
+if exist(options,'title')
+	title=getfieldvalue(options,'title');
+else
+	title='';
+end
+replacestringinfile('./generic/editables.js','Generic Plot',title);
+
+%height scaling:
+replacestringinfile('./generic/editables.js','var height_scaling = 60.0;',['var height_scaling = ' num2str(getfieldvalue(options,'height_scaling',60)) ';']);
+
+%high resolution: 
+if ~getfieldvalue(options,'highres',0);
+	replacestringinfile('./generic/editables.js','var hdBackgroundImageFileName = experiment_name + "/radar_hd.png";','var hdBackgroundImageFileName = "";');
+end
+
+%ocean zero threshold: 
+replacestringinfile('./generic/editables.js','var ocean_threshold = .001;',['var ocean_threshold = ' num2str(getfieldvalue(options,'ocean_threshold',.001)) ';']);
+
+%Deal with mesh and results {{{
+	
+	fid=fopen([database 'model_coords.js'],'w');
+
+	%write index:
+	fprintf(fid,'<!-- index{{{-->\n');
+	fprintf(fid,'var index=[');
+	for i=1:md.mesh.numberofelements-1,
+		fprintf(fid,'[%i, %i, %i],',md.mesh.elements(i,1),md.mesh.elements(i,2),md.mesh.elements(i,3));
+	end
+	fprintf(fid,'[%i, %i, %i]];\n',md.mesh.elements(end,1),md.mesh.elements(end,2),md.mesh.elements(end,3));
+	fprintf(fid,'<!--}}}-->\n');
+	writejsfield(fid,'x',md.mesh.x,md.mesh.numberofvertices);
+	writejsfield(fid,'y',md.mesh.y,md.mesh.numberofvertices);
+	writejsfield(fid,'surface',md.geometry.surface,md.mesh.numberofvertices);
+
+	%Deal with data: 
+	datastring='';
+	caxis1string='';
+	caxis2string='';
+	labelstring='';
+	unitstring='';
+	zoom=getfieldvalue(options,'zoom',-.25);
+	for i=1:length(optionslist),
+		options=optionslist{i}; options=checkplotoptions(md,options);
+		data=getfieldvalue(options,'data');
+		caxis=getfieldvalue(options,'caxis',[min(data(:)) max(data(:))]);
+		label=getfieldvalue(options,'label','');
+		if strcmpi(label,''),
+			%create generic label: 
+			label=['data' num2str(i)];
+		end
+		unit=getfieldvalue(options,'unit','');
+		if strcmpi(unit,''),
+			%create generic unit: 
+			unit='SI';
+		end
+
+		if i<length(optionslist),
+			datastring=[datastring '"data' num2str(i) '",'];
+			caxis1string=[caxis1string num2str(caxis(1)) ','];
+			caxis2string=[caxis2string num2str(caxis(2)) ','];
+			labelstring=[labelstring '"' label '"' ','];
+			unitstring=[unitstring '"' unit '"' ','];
+		else
+			datastring=[datastring '"data' num2str(i) '"' ];
+			caxis1string=[caxis1string num2str(caxis(1))];
+			caxis2string=[caxis2string num2str(caxis(2))];
+			labelstring=[labelstring '"' label '"'];
+			unitstring=[unitstring '"' unit '"'];
+		end
+		writejsfield(fid,['data' num2str(i)],data,md.mesh.numberofvertices);
+	end
+	replacestringinfile('./generic/editables.js','"V"',labelstring);
+	replacestringinfile('./generic/editables.js','"velocity"',datastring);
+	replacestringinfile('./generic/editables.js','var data_min_array = [-9999',['var data_min_array = [' caxis1string]);
+	replacestringinfile('./generic/editables.js','var data_max_array = [9999',['var data_max_array = [' caxis2string]);
+	replacestringinfile('./generic/editables.js','"m/yr"',unitstring);
+	replacestringinfile('./generic/editables.js','initialZoomFactor = -.20;',['initialZoomFactor = ' num2str(zoom) ';']);
+	
+
+
+	fclose(fid);
+% }}}
+
+%Open browser with results: 
+web('./generic.html','-browser');
+
+%Come back to present directory: 
+cd(presentdir);
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/plot_manager.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/plot_manager.m	(revision 18291)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/plot_manager.m	(revision 18292)
@@ -159,4 +159,10 @@
 end
 
+%Are we rendering on a browser? 
+if exist(options,'webgl'),
+	plot_gl(md,data,options);
+	return;
+end
+
 %Figure out if this is a semi-transparent plot.
 if exist(options,'googlemaps'),
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/plot_unit.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/plot_unit.m	(revision 18291)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/plot_unit.m	(revision 18292)
@@ -54,6 +54,11 @@
 			patch( 'Faces',[C A D],'Vertices', [x y z],'FaceVertexCData',data(:),'FaceColor','interp','EdgeColor',edgecolor);
 		else
+			%do we have several columns to data, in which case we are dealing with an rgb plot?
 			A=elements(:,1); B=elements(:,2); C=elements(:,3); 
-			patch( 'Faces', [A B C], 'Vertices', [x y z],'FaceVertexCData', data(:),'FaceColor','interp','EdgeColor',edgecolor);
+			if size(data,2)==3,
+				patch( 'Faces', [A B C], 'Vertices', [x y z],'FaceVertexCData', data,'FaceColor','interp','EdgeColor',edgecolor);
+			else
+				patch( 'Faces', [A B C], 'Vertices', [x y z],'FaceVertexCData', data(:),'FaceColor','interp','EdgeColor',edgecolor);
+			end
 		end
 
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/plotmodel.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/plotmodel.m	(revision 18291)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/plotmodel.m	(revision 18292)
@@ -34,7 +34,12 @@
 
 	%Create figure 
-	f=figure(figurenumber);clf;
-	if strcmpi(getfieldvalue(options.list{1},'visible','on'),'off'),
-		set(f,'Visible','Off');
+	if ~exist(options.list{1},'webgl'),
+		f=figure(figurenumber);clf;
+		if strcmpi(getfieldvalue(options.list{1},'visible','on'),'off'),
+			set(f,'Visible','Off');
+		end
+	else
+		plot_gl(md,options.list);
+		return;
 	end
 
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/prepare_gl.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/prepare_gl.m	(revision 18292)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/prepare_gl.m	(revision 18292)
@@ -0,0 +1,235 @@
+function prepare_gl(md,options)
+
+%scripts to be picked up from directory:
+scriptsdir=['~/issm-projects/visl/externalicelab/fem'];
+if strcmpi(md.mesh.hemisphere','s'),
+	triangulation='/Users/larour/ModelData/BamberDEMAntarctica1km/triangulated/triangulation_15.mat';
+	radar_image='/Users/larour/ModelData/BamberDEMAntarctica1km/triangulated/radar.png';
+elseif strcmpi(md.mesh.hemisphere','n'),
+	triangulation='/u/astrid-r1b/ModelData/HowatDEMGreenland2012/triangulated/triangulation_15.mat';
+	radar_image='/u/astrid-r1b/ModelData/HowatDEMGreenland2012/triangulated/radar.png';
+else
+	error('prepare_gl error usage: ''hemisphere'' should be set to ''s'' or ''n''');
+end
+
+%keep present directory: 
+presentdir=pwd;
+
+%Setup unique directory in present dir: 
+directory='.webgl';
+mkdir(directory);
+cd(directory);
+
+%Copy scripts needed:
+copyfile([scriptsdir '/css'],'./css');
+copyfile([scriptsdir '/../css/main.css'],'./css');
+copyfile([scriptsdir '/images'],'./images');
+copyfile([scriptsdir '/obj'],'./obj');
+copyfile([scriptsdir '/src'],'./src');
+copyfile([scriptsdir '/js'],'./js');
+copyfile([scriptsdir '/generic'],'./generic');
+copyfile([scriptsdir '/generic.html'],'.');
+
+
+database=['./generic/'];
+
+%Write triangulation to disk {{{
+tr=load(triangulation);
+
+%write x0, x1, y0 and y1
+fid=fopen([database '/image_coords.js'],'w');
+fprintf(fid,'var x0=%g;\n',tr.x0);
+fprintf(fid,'var x1=%g;\n',tr.x1);
+fprintf(fid,'var y0=%g;\n',tr.y0);
+fprintf(fid,'var y1=%g;\n',tr.y1);
+fclose(fid);
+
+%copy image locally: 
+system(['cp ' radar_image ' ' database '/radar.png']);
+	
+%write triangulation and surface to disk: 
+fid=fopen([database '/surface_triangulation.js'],'w');
+
+%write index:
+fprintf(fid,'<!-- index_surface{{{-->\n');
+fprintf(fid,'var index_surface=[');
+for i=1:length(tr.index)-1,
+	fprintf(fid,'[%i, %i, %i],',tr.index(i,1),tr.index(i,2),tr.index(i,3));
+end
+fprintf(fid,'[%i, %i, %i]];\n',tr.index(end,1),tr.index(end,2),tr.index(end,3));
+fprintf(fid,'<!--}}}-->\n');
+%write x:
+fprintf(fid,'<!-- x_surface{{{-->\n');
+fprintf(fid,'var x_surface=[');
+for i=1:length(tr.x)-1,
+	fprintf(fid,'%g,',tr.x(i,1));
+end
+fprintf(fid,'%g];\n',tr.x(end,1));
+fprintf(fid,'<!--}}}-->\n');
+
+%write y:
+fprintf(fid,'<!-- y_surface{{{-->\n');
+fprintf(fid,'var y_surface=[');
+for i=1:length(tr.y)-1,
+	fprintf(fid,'%g,',tr.y(i,1));
+end
+fprintf(fid,'%g];\n',tr.y(end,1));
+fprintf(fid,'<!--}}}-->\n');
+
+%write surface:
+fprintf(fid,'<!-- surface_surface{{{-->\n');
+fprintf(fid,'var surface_surface=[');
+for i=1:length(tr.surface)-1,
+	fprintf(fid,'%g,',tr.surface(i));
+end
+fprintf(fid,'%g];\n',tr.surface(end));
+fprintf(fid,'<!--}}}-->\n');
+
+fclose(fid);
+%}}}
+%Write high-res Greenland triangulation to disk  {{{
+if getfieldvalue(options,'highres',0);
+	x0=min(md.mesh.x);
+	x1=max(md.mesh.x);
+	y0=min(md.mesh.y);
+	y1=max(md.mesh.y);
+	dx=x1-x0;
+	dy=y1-y0;
+	factor=.25;
+
+	x0=x0-factor*dx;
+	x1=x1+factor*dx;
+	y1=y1+factor*dy;
+	y0=y0-factor*dy;
+
+	%write x0, x1, y0 and y1
+	fid=fopen([database '/image_coords_highdef.js'],'w');
+	fprintf(fid,'var x0_hd=%g;\n',x0);
+	fprintf(fid,'var x1_hd=%g;\n',x1);
+	fprintf(fid,'var y0_hd=%g;\n',y0);
+	fprintf(fid,'var y1_hd=%g;\n',y1);
+	fclose(fid);
+
+
+	%extract image
+	eval(['!gdal_translate -quiet -projwin ' num2str(x0) ' ' num2str(y1) ' ' num2str(x1) ' ' num2str(y0) ' ' geotiff_name_hd ' radar_hd.tif']);
+
+	%convert to png: 
+	system('convert radar_hd.tif radar_hd.png  && rm -rf radar_hd.tif');
+
+	%get width: 
+	[status,width]=system(['convert radar_hd.png -format %w info:']); width=str2num(width);
+
+	%get height: 
+	[status,height]=system(['convert radar_hd.png -format %h info:']); height=str2num(height);
+
+	%get these a powers of 2: 
+	width=2^(nextpow2(width));
+	height=2^(nextpow2(height));
+
+	%change size of image: 
+	system(['convert -geometry ' num2str(width) 'x' num2str(height) '! radar_hd.png radar_hd.png']);
+
+	system(['mv radar_hd.png ' database '/radar_hd.png']);
+
+	%create square mesh initially: 
+	md_temp=squaremesh(model,1,1,100,100);
+
+	%scale:
+	md_temp.mesh.x=x0+md_temp.mesh.x*(x1-x0);
+	md_temp.mesh.y=y0+md_temp.mesh.y*(y1-y0);
+
+	%now refine to better capture surface:
+	hmax=500000;
+	hmin=500;
+	err=2;
+	sobs=InterpFromGridToMesh(x_m,y_m,surface,md_temp.mesh.x,md_temp.mesh.y,0);
+	md_temp=bamg(md_temp,'hmax',hmax,'hmin',hmin,'gradation',10,'field',sobs,'err',err,'splitcorner',1,'KeepVertices',0);
+	sobs=InterpFromGridToMesh(x_m,y_m,surface,md_temp.mesh.x,md_temp.mesh.y,0);
+
+	%write triangulation and surface to disk: 
+	fid=fopen([database '/surface_triangulation_hd.js'],'w');
+
+	%write index:
+	fprintf(fid,'<!-- index_surface_hd{{{-->\n');
+	fprintf(fid,'var index_surface_hd=[');
+	for i=1:md_temp.mesh.numberofelements-1,
+		fprintf(fid,'[%i, %i, %i],',md_temp.mesh.elements(i,1),md_temp.mesh.elements(i,2),md_temp.mesh.elements(i,3));
+	end
+	fprintf(fid,'[%i, %i, %i]];\n',md_temp.mesh.elements(end,1),md_temp.mesh.elements(end,2),md_temp.mesh.elements(end,3));
+	fprintf(fid,'<!--}}}-->\n');
+	%write x:
+	fprintf(fid,'<!-- x_surface_hd{{{-->\n');
+	fprintf(fid,'var x_surface_hd=[');
+	for i=1:md_temp.mesh.numberofvertices-1,
+		fprintf(fid,'%g,',md_temp.mesh.x(i,1));
+	end
+	fprintf(fid,'%g];\n',md_temp.mesh.x(end,1));
+	fprintf(fid,'<!--}}}-->\n');
+
+	%write y:
+	fprintf(fid,'<!-- y_surface_hd{{{-->\n');
+	fprintf(fid,'var y_surface_hd=[');
+	for i=1:md_temp.mesh.numberofvertices-1,
+		fprintf(fid,'%g,',md_temp.mesh.y(i,1));
+	end
+	fprintf(fid,'%g];\n',md_temp.mesh.y(end,1));
+	fprintf(fid,'<!--}}}-->\n');
+
+	%write surface:
+	fprintf(fid,'<!-- surface_surface_hd{{{-->\n');
+	fprintf(fid,'var surface_surface_hd=[');
+	for i=1:md_temp.mesh.numberofvertices-1,
+		fprintf(fid,'%g,',sobs(i));
+	end
+	fprintf(fid,'%g];\n',sobs(end));
+	fprintf(fid,'<!--}}}-->\n');
+
+	fclose(fid);
+else
+	delete([database '/radar_hd.png']);
+	delete([database '/image_coords_highdef.js']);
+	delete([database '/surface_triangulation_hd.js']);
+	
+end
+% }}}
+%Deal with contour {{{
+	
+	fid=fopen([database '/contour_coords.js'],'w');
+
+	contour_x=md.mesh.x(md.mesh.segments(:,1));
+	contour_y=md.mesh.y(md.mesh.segments(:,1));
+	contour_surface=md.geometry.surface(md.mesh.segments(:,1));
+
+	%write contour_x:
+	fprintf(fid,'<!-- contour_x{{{-->\n');
+	fprintf(fid,'var contour_x=[');
+	for i=1:length(contour_x)-1,
+		fprintf(fid,'%g,',contour_x(i));
+	end
+	fprintf(fid,'%g];\n',contour_x(end));
+	fprintf(fid,'<!--}}}-->\n');
+
+	%write contour_y:
+	fprintf(fid,'<!-- contour_y{{{-->\n');
+	fprintf(fid,'var contour_y=[');
+	for i=1:length(contour_y)-1,
+		fprintf(fid,'%g,',contour_y(i));
+	end
+	fprintf(fid,'%g];\n',contour_y(end));
+	fprintf(fid,'<!--}}}-->\n');
+
+	%write contour_surface:
+	fprintf(fid,'<!-- contour_surface{{{-->\n');
+	fprintf(fid,'var contour_surface=[');
+	for i=1:length(contour_surface)-1,
+		fprintf(fid,'%g,',contour_surface(i));
+	end
+	fprintf(fid,'%g];\n',contour_surface(end));
+	fprintf(fid,'<!--}}}-->\n');
+
+	fclose(fid);
+% }}}
+
+%Come back to present directory: 
+cd(presentdir);
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/processdata.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/processdata.m	(revision 18291)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/processdata.m	(revision 18292)
@@ -62,5 +62,12 @@
 %quiver?
 if datasize(2)>1,
-	datatype=3;
+	
+	%rgb plot or quiver plot? 
+	if getfieldvalue(options,'rgb',0),
+		datatype=2;
+		return;
+	else
+		datatype=3;
+	end
 
 	%check number of columns, add zeros if necessary,
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/rgbcolorbar.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/rgbcolorbar.m	(revision 18292)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/rgbcolorbar.m	(revision 18292)
@@ -0,0 +1,65 @@
+function rgbcolorbar(options)
+%RGBCOLORBAR - this is a triangular colorbar, three corners representing red=1, green=0, blue=0, 
+%  red=0, green=1, blue=0 and red=0, green=0, blue=1. The rest of the triangle is colorbar corresponding to 
+%  the r,g,b triple using patch type coloring. We build a triagngular mesh to do this!
+%
+%   Usage:
+%      rgbcolorbar(options)
+%
+%   See also: PLOTMODEL
+
+	%first, urn classic colorbar off
+	colorbar off;
+
+	%create simple triangle mesh: 
+	a.x=[0 1 .5 0];
+	a.y=[0 0 .5*tand(60) 0];
+	a.density=1;
+	expwrite(a,'rgbcolor.exp');
+	md=triangle(model,'rgbcolor.exp',.005);
+	delete rgbcolor.exp
+
+	x1=a.x(1); x2=a.x(2); x3=a.x(3);
+	y1=a.y(1); y2=a.y(2); y3=a.y(3);
+
+	x3x1=x1-x3;
+	y3y1=y1-y3;
+	x3x2=x2-x3;
+	y3y2=y2-y3;
+	delta=x2*y3-y2*x3-x1*y3+y1*x3+x1*y2-y1*x2;
+
+	r=zeros(md.mesh.numberofvertices,1);
+	g=zeros(md.mesh.numberofvertices,1);
+	b=zeros(md.mesh.numberofvertices,1);
+	
+	for i=1:md.mesh.numberofvertices,
+		
+		x0=md.mesh.x(i);
+		y0=md.mesh.y(i);
+
+		%first area coordinate
+		r(i)=(y3y2*(x0-x3)-x3x2.*(y0-y3))./delta;
+		%second area coordinate
+		g(i)=(x3x1.*(y0-y3)-y3y1.*(x0-x3))./delta;
+		%third area coordinate
+		b(i)=1-r(i)-g(i);
+	end
+	
+	%keep handle to current axes before creating one.
+	current=gca;
+
+	%now position a patch: 
+	position=getfieldvalue(options,'colorbarpos',[.9 .3 .1 .1]);
+	axes('position',position);
+	t=patch( 'Faces', [md.mesh.elements(:,1) md.mesh.elements(:,2) md.mesh.elements(:,3)], 'Vertices', [md.mesh.x md.mesh.y zeros(md.mesh.numberofvertices,1)],'FaceVertexCData', [r g b], 'FaceColor','interp','EdgeColor','none');axis square off;
+
+	%deal wih titles: 
+	titles=getfieldvalue(options,'colorbartitle',{'','',''});
+	fontsize=getfieldvalue(options,'fontsize',12);
+
+	text(x1,y1-.1,titles{1},'FontSize',fontsize);
+	text(x2-.1,y2-.1,titles{2},'FontSize',fontsize);
+	text(x3,y3+.05,titles{3},'FontSize',fontsize);
+
+	%reestablish axes
+	axes(current);
Index: /issm/branches/trunk-jpl-ad2/src/m/plot/writejsfield.m
===================================================================
--- /issm/branches/trunk-jpl-ad2/src/m/plot/writejsfield.m	(revision 18292)
+++ /issm/branches/trunk-jpl-ad2/src/m/plot/writejsfield.m	(revision 18292)
@@ -0,0 +1,29 @@
+function writejsfield(fid,name,variable,nods)
+%WRITEJSFIELD - write variable to javascript file 
+%
+%   Usage:
+%      writejsfield(fid,name,variable)
+%
+
+	%write array:
+	if size(variable,2)==1,
+		fprintf(fid,'<!-- %s{{{-->\n',name);
+		fprintf(fid,'var %s=[',name);
+		for i=1:nods-1,
+			fprintf(fid,'%g,',variable(i));
+		end
+		fprintf(fid,'%g];\n',variable(end));
+		fprintf(fid,'<!--}}}-->\n');
+	else
+		%multi-sized array: 
+		fprintf(fid,'<!-- %s{{{-->\n',name);
+		fprintf(fid,'var %s={}\n',name);
+		for i=1:size(variable,2),
+			fprintf(fid,'%s["%i"]=[',name,i);
+			for j=1:nods-1,
+				fprintf(fid,'%g,',variable(j,i));
+			end
+			fprintf(fid,'%g];\n',variable(end,i));
+		end
+		fprintf(fid,'<!--}}}-->\n');
+	end
