Index: ../trunk-jpl/src/m/plot/writejsfile.m
===================================================================
--- ../trunk-jpl/src/m/plot/writejsfile.m	(revision 0)
+++ ../trunk-jpl/src/m/plot/writejsfile.m	(revision 19013)
@@ -0,0 +1,59 @@
+function writejsfile(filename,model,keyname)
+%WRITEJSFILE - write model file to javascript database
+%
+%   Usage:
+%      writejsfile(filename,model,keyname)
+%
+
+	nods=length(model.x);
+	nel=size(model.index,1);
+	nx=length(model.contourx1);
+	
+	fid=fopen(filename,'w');
+
+	fprintf(fid,'model = {};\n');
+	fprintf(fid,'model["title"]="%s";\n',model.title);
+	fprintf(fid,'model["initialZoomFactor"]=%s;\n',model.initialZoomFactor);
+	
+	%write index:
+	fprintf(fid,'<!-- model["index"]{{{-->\n');
+	fprintf(fid,'model["index"]=[');
+	for i=1:nel-1,
+		fprintf(fid,'[%i, %i, %i],',model.index(i,1),model.index(i,2),model.index(i,3));
+	end
+	fprintf(fid,'[%i, %i, %i]];\n',model.index(end,1),model.index(end,2),model.index(end,3));
+	fprintf(fid,'<!--}}}-->\n');
+	
+	writejsfield(fid,'model["x"]',model.x,nods);
+	writejsfield(fid,'model["y"]',model.y,nods);
+	writejsfield(fid,'model["z"]',model.z,nods);
+	writejsfield(fid,'model["surface"]',model.surface,nods);
+	writejsfield(fid,'model["contourx1"]',model.contourx1,nx);
+	writejsfield(fid,'model["contoury1"]',model.contoury1,nx);
+	writejsfield(fid,'model["contourz1"]',model.contourz1,nx);
+	writejsfield(fid,'model["contourx2"]',model.contourx2,nx);
+	writejsfield(fid,'model["contoury2"]',model.contoury2,nx);
+	writejsfield(fid,'model["contourz2"]',model.contourz2,nx);
+
+
+	results=model.results;
+	fprintf(fid,'results={};\n');
+
+	for i=1:length(results),
+		fprintf(fid,'result={};\n');
+		writejsfield(fid,'result["data"]',results(i).data,nods);
+		fprintf(fid,'<!--{{{-->\n');
+		fprintf(fid,'result["caxis"]=[%g,%g];\n',results(i).caxis(1),results(i).caxis(2));
+		fprintf(fid,'result["label"]="%s";\n',results(i).label);
+		fprintf(fid,'result["shortlabel"]="%s";\n',results(i).shortlabel);
+		fprintf(fid,'result["unit"]="%s";\n',results(i).unit);
+		if size(results(i).data,2)>1,
+			fprintf(fid,'result["time_range"]=[%g,%g];\n',results(i).time_range(1),results(i).time_range(2));
+		end
+		fprintf(fid,'results["%i"]=result;\n',i);
+		fprintf(fid,'<!--}}}-->\n');
+	end
+	fprintf(fid,'model.results=results;\n');
+	fprintf(fid,'models["%s"]=model;\n',keyname);
+
+	fclose(fid);
Index: ../trunk-jpl/src/m/plot/writejsfield.m
===================================================================
--- ../trunk-jpl/src/m/plot/writejsfield.m	(revision 0)
+++ ../trunk-jpl/src/m/plot/writejsfield.m	(revision 19013)
@@ -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,'%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,'%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
Index: ../trunk-jpl/src/m/plot/export_gl.m
===================================================================
--- ../trunk-jpl/src/m/plot/export_gl.m	(revision 0)
+++ ../trunk-jpl/src/m/plot/export_gl.m	(revision 19013)
@@ -0,0 +1,117 @@
+function export_gl(md,varargin)
+
+	templist=plotoptions(varargin{:}); 
+	optionslist=templist.list;
+	options=optionslist{1};
+	options=checkplotoptions(md,options);
+
+	%Setup unique directory in present dir: 
+	directory=getfieldvalue(options,'directory','./');
+	databasename=getfieldvalue(options,'database','webgl');
+
+	%scaling factor: 
+	scaling_factor=getfieldvalue(options,'scaling_factor',50);
+
+	%Deal with title: 
+	if exist(options,'title')
+		title=getfieldvalue(options,'title');
+	else
+		title='';
+	end
+
+	%initialize model: 
+	model.title=title;
+	model.initialZoomFactor=getfieldvalue(options,'zoom',-.25);
+
+	%Deal with contour {{{
+
+	contour_lat1=md.mesh.lat(md.mesh.segments(:,1));
+	contour_lat2=md.mesh.lat(md.mesh.segments(:,2));
+	contour_long1=md.mesh.long(md.mesh.segments(:,1));
+	contour_long2=md.mesh.long(md.mesh.segments(:,2));
+	contour_surface1=md.geometry.surface(md.mesh.segments(:,1));
+	contour_surface2=md.geometry.surface(md.mesh.segments(:,2));
+
+	R1=6371000*ones(length(contour_surface1),1)+scaling_factor*contour_surface1;
+	R2=6371000*ones(length(contour_surface2),1)+scaling_factor*contour_surface2;
+
+	contourx1 = R1 .* cosd(contour_lat1) .* cosd(contour_long1);
+	contoury1 = R1 .* cosd(contour_lat1) .* sind(contour_long1);
+	contourz1 = R1 .* sind(contour_lat1);
+	
+	contourx2 = R2 .* cosd(contour_lat2) .* cosd(contour_long2);
+	contoury2 = R2 .* cosd(contour_lat2) .* sind(contour_long2);
+	contourz2 = R2 .* sind(contour_lat2);
+
+
+	model.contourx1=contourx1;
+	model.contoury1=contoury1;
+	model.contourz1=contourz1;
+	model.contourx2=contourx2;
+	model.contoury2=contoury2;
+	model.contourz2=contourz2;
+
+
+	%}}}
+%Deal with mesh and results {{{
+	
+	
+	lat=md.mesh.lat;
+	long=md.mesh.long;
+	surface=md.geometry.surface;
+	numberofelements=md.mesh.numberofelements;
+	numberofvertices=md.mesh.numberofvertices;
+
+	R=6371000*ones(numberofvertices,1)+scaling_factor*surface;
+
+	x = R .* cosd(lat) .* cosd(long);
+	y = R .* cosd(lat) .* sind(long);
+	z = R .* sind(lat);
+
+
+	%Deal with triangulation: 
+	model.index=md.mesh.elements;
+	model.x=x;
+	model.y=y;
+	model.z=z;
+	model.surface=surface;
+	
+	%Deal with data: 
+	results=struct([]);
+	for i=1:length(optionslist),
+		options=optionslist{i}; options=checkplotoptions(md,options);
+		data=getfieldvalue(options,'data');
+		results(i).data=data;
+		results(i).caxis=getfieldvalue(options,'caxis',[min(data(:)) max(data(:))]);
+
+		label=getfieldvalue(options,'label','');
+		if strcmpi(label,''),
+			%create generic label: 
+			label=['data' num2str(i)];
+		end
+		results(i).label=label;
+
+		shortlabel=getfieldvalue(options,'shortlabel','');
+		if strcmpi(shortlabel,''),
+			%create generic short label: 
+			shortlabel=['data' num2str(i)];
+		end
+		results(i).shortlabel=shortlabel;
+		
+		if size(data,2)>1,
+			time_range=getfieldvalue(options,'time_range',[0 100]);
+			results(i).time_range=time_range;
+		end
+
+		unit=getfieldvalue(options,'unit','');
+		if strcmpi(unit,''),
+			%create generic unit: 
+			unit='SI';
+		end
+		results(i).unit=unit;
+	end
+	model.results=results;
+	
+	%Write model to javascript database file: 
+	writejsfile([directory databasename '.js'],model,databasename);
+%}}}
