Index: ../trunk-jpl/src/m/plot/writejsfile.py
===================================================================
--- ../trunk-jpl/src/m/plot/writejsfile.py	(revision 19043)
+++ ../trunk-jpl/src/m/plot/writejsfile.py	(revision 19044)
@@ -1,3 +1,4 @@
+from writejsfield import writejsfield
 def writejsfile(filename,model,keyname):
 #WRITEJSFILE - write model file to javascript database
 #
@@ -6,23 +7,22 @@
 #
 
 	nods=len(model.x)
-	nel=len(model.index[1])
+	nel=len(model.index)
 	nx=len(model.contourx1)
-	
-	fid=open(filename,'w')
+	print(filename)	
+	fid=open(filename,'w', 0)
 
 	fid.write('model = {};\n')
 	fid.write('model["title"]="{0}";\n'.format(model.title))
 	fid.write('model["initialZoomFactor"]={0};\n'.format(model.initialZoomFactor))
-	
 	#write index:
 	fid.write('<!-- model["index"]{{{-->\n')
 	fid.write('model["index"]=[')
-	for i in xrange(1,nel-1):
-		fid.write('[{0}, {1}, {2}],'.format(model.index[i][1],model.index[i][2],model.index[i][3]))
-	fid.write('[{0}, {1}, {2}]];\n'.format(model.index[-1][1],model.index[-1][2],model.index[-1][3]))
+	for i in xrange(1, nel-1):
+		fid.write('[{0}, {1}, {2}],'.format(model.index[i][0],model.index[i][1],model.index[i][2]))
+	fid.write('[{0}, {1}, {2}]];\n'.format(model.index[-1][0],model.index[-1][1],model.index[-1][2]))
 	fid.write('<!--}}}-->\n')
-	
+	print('writing model coordinates')
 	writejsfield(fid,'model["x"]',model.x,nods)
 	writejsfield(fid,'model["y"]',model.y,nods)
 	writejsfield(fid,'model["z"]',model.z,nods)
@@ -34,7 +34,7 @@
 	writejsfield(fid,'model["contoury2"]',model.contoury2,nx)
 	writejsfield(fid,'model["contourz2"]',model.contourz2,nx)
 
-
+	print('writing results')
 	results=model.results
 	fid.write('results={};\n')
 
@@ -42,12 +42,12 @@
 		fid.write('result={};\n')
 		writejsfield(fid,'result["data"]',results[i].data,nods)
 		fid.write('<!--{{{-->\n')
-		fid.write('result["caxis"]=[{0},{1}];\n'.format(results[i].caxis[1],results[i].caxis[2]))
+		fid.write('result["caxis"]=[{0},{1}];\n'.format(results[i].caxis[0],results[i].caxis[1]))
 		fid.write('result["label"]="{0}";\n'.format(results[i].label))
 		fid.write('result["shortlabel"]="{0}";\n'.format(results[i].shortlabel))
 		fid.write('result["unit"]="{0}";\n'.format(results[i].unit))
 		if len(results[i].data[2])>1:
-			fid.write('result["time_range"]=[{0},{1}];\n'.format(results[i].time_range[1],results[i].time_range[2]))
+			fid.write('result["time_range"]=[{0},{1}];\n'.format(results[i].time_range[0],results[i].time_range[1]))
 		fid.write('results["{0}"]=result;\n'.format(i))
 		fid.write('<!--}}}-->\n')
 	fid.write('model.results=results;\n')
Index: ../trunk-jpl/src/m/plot/writejsfield.py
===================================================================
--- ../trunk-jpl/src/m/plot/writejsfield.py	(revision 19043)
+++ ../trunk-jpl/src/m/plot/writejsfield.py	(revision 19044)
@@ -5,20 +5,21 @@
 #      writejsfield(fid,name,variable)
 #
 	#write array:
-	if len(variable[2])==1:
-		fid.write('<!-- {0}{{{-->\n'.format(name))
+	#if not isinstance(variable, list):
+	if True:
+		fid.write('<!-- {0}{{{{{{-->\n'.format(name))
 		fid.write('{0}=['.format(name))
 		for i in xrange(1, nods-1):
-			fid.write('{0},',variable[i])
-		fid.write('{0}];\n',variable[-1])
-		fid.write('<!--}}}-->\n')
+			fid.write('{0},'.format(variable[i]))
+		fid.write('{0}];\n'.format(variable[-1]))
+		fid.write('<!--}}}}}}-->\n')
 	else:
 		#multi-sized array: 
-		fid.write('<!-- {0}{{{-->\n'.format(name))
+		fid.write('<!-- {0}{{{{{{-->\n'.format(name))
 		fid.write('{0}=[]\n'.format(name))
 		for i in xrange(1, len(variable[2])):
 			fid.write('{0}["{1}"]=['.format(name,i))
 			for j in xrange(1, nods-1):
-				fid.write('{0},'.format(variable[j,i]))
-			fid.write('{0}];\n'.format(variable[-1,i]))
-		fid.write('<!--}}}-->\n')
+				fid.write('{0},'.format(variable[j][i]))
+			fid.write('{0}];\n'.format(variable[-1][i]))
+		fid.write('<!--}}}}}}-->\n')
Index: ../trunk-jpl/src/m/plot/export_gl.py
===================================================================
--- ../trunk-jpl/src/m/plot/export_gl.py	(revision 19043)
+++ ../trunk-jpl/src/m/plot/export_gl.py	(revision 19044)
@@ -1,47 +1,61 @@
-def export_gl(md,varargin):
-	return;
-	templist=plotoptions(varargin[:]); 
+from plotoptions import plotoptions
+from checkplotoptions import checkplotoptions
+from model import model
+import numpy as np
+import math
+from writejsfile import writejsfile
+
+def export_gl(md,*varargin):
+	class ResultObj(object):
+	    def __getattr__(self, attr):
+		return self.__dict__.get(attr)
+	print ('getting options')
+	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');
-
+	print ('setting directory')
+	directory=options.getfieldvalue('directory','./');
+	databasename=options.getfieldvalue('database','Pig');
+	print(directory +databasename)	
 	#scaling factor: 
-	scaling_factor=getfieldvalue(options,'scaling_factor',50);
+	print ('setting scaling factor')
+	scaling_factor=options.getfieldvalue('scaling_factor',50);
 
 	#Deal with title: 
-	if options['title']:
-		title=getfieldvalue(options,'title');
+	print ('setting title')
+	if options.exist('title'):
+		title=options.getfieldvalue('title');
 	else:
 		title='';
 
 	#initialize model: 
+	print ('initializing model')
 	model.title=title;
-	model.initialZoomFactor=getfieldvalue(options,'zoom',-.25);
+	model.initialZoomFactor=options.getfieldvalue('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]);
+	print ('getting contour')
+	contour_lat1=md.mesh.lat.take(md.mesh.segments[:,0])
+	contour_lat2=md.mesh.lat.take(md.mesh.segments[:,1]);
+	contour_long1=md.mesh.long.take(md.mesh.segments[:,0]);
+	contour_long2=md.mesh.long.take(md.mesh.segments[:,1]);
+	contour_surface1=md.geometry.surface.take(md.mesh.segments[:,0]);
+	contour_surface2=md.geometry.surface.take(md.mesh.segments[:,1]);
 
-	R1=6371000*ones(len(contour_surface1),1)+scaling_factor*contour_surface1;
-	R2=6371000*ones(len(contour_surface2),1)+scaling_factor*contour_surface2;
+	R1=6371000*np.ones(len(contour_surface1))+scaling_factor*contour_surface1;
+	R2=6371000*np.ones(len(contour_surface2))+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);
+	contourx1 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.cos(math.radians(long)), R1, contour_lat1, contour_long1);
+	contoury1 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.sin(math.radians(long)), R1, contour_lat1, contour_long1);
+	contourz1 = map(lambda r, lat: r * math.sin(math.radians(lat)), R1, contour_lat1);
 	
-	contourx2 = R2 * cosd(contour_lat2) * cosd(contour_long2);
-	contoury2 = R2 * cosd(contour_lat2) * sind(contour_long2);
-	contourz2 = R2 * sind(contour_lat2);
+	contourx2 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.cos(math.radians(long)), R2, contour_lat2, contour_long2);
+	contoury2 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.sin(math.radians(long)), R2, contour_lat2, contour_long2);
+	contourz2 = map(lambda r, lat: r * math.sin(math.radians(lat)), R2, contour_lat2);
 
-
 	model.contourx1=contourx1;
 	model.contoury1=contoury1;
 	model.contourz1=contourz1;
@@ -51,61 +65,61 @@
 
 
 	#}}}
-#Deal with mesh and results {{{
-	
-	
-	lat=md.mesh.lat;
-	long=md.mesh.long;
+	#Deal with mesh and results {{{
+	print ('getting mesh')
 	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);
-
-
+	R=6371000*np.ones(len(md.mesh.lat))+scaling_factor*surface.flatten();
+	
+	x = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.cos(math.radians(long)), R, md.mesh.lat,md.mesh.long);
+	y = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.sin(math.radians(long)), R, md.mesh.lat,md.mesh.long);
+	z = map(lambda r, lat: r * math.sin(math.radians(lat)), R, md.mesh.lat);
+	
 	#Deal with triangulation: 
+	print('getting triangulation')
 	model.index=md.mesh.elements;
 	model.x=x;
 	model.y=y;
 	model.z=z;
 	model.surface=surface;
 	
+	results = [""]
+	
 	#Deal with data: 
-	results=struct([]);
+	print('getting data')
 	for i in xrange(1,len(optionslist)):
 		options=optionslist[i]; 
 		options=checkplotoptions(md,options);
-		data=getfieldvalue(options,'data');
+		data=options.getfieldvalue('data');
+		results.append(ResultObj())
 		results[i].data=data;
-		results[i].caxis=getfieldvalue(options,'caxis',[min(data), max(data)]);
+		results[i].caxis=options.getfieldvalue('caxis',[min(data), max(data)]);
 
-		label=getfieldvalue(options,'label','');
-		if strcmpi(label,''):
+		label=options.getfieldvalue('label','');
+		if label=='':
 			#create generic label: 
-			label=['data', num2str(i)];
+			label=['data', str(i)];
 		results[i].label=label;
 
-		shortlabel=getfieldvalue(options,'shortlabel','');
-		if strcmpi(shortlabel,''):
+		shortlabel=options.getfieldvalue('shortlabel','');
+		if shortlabel=='':
 			#create generic short label: 
-			shortlabel=['data', num2str(i)];
+			shortlabel=['data', str(i)];
 		results[i].shortlabel=shortlabel;
-		
+
 		if len(data[2])>1:
-			time_range=getfieldvalue(options,'time_range',[0, 100]);
+			time_range=options.getfieldvalue('time_range',[0, 100]);
 			results[i].time_range=time_range;
 
-		unit=getfieldvalue(options,'unit','');
-		if strcmpi(unit,''):
+		unit=options.getfieldvalue('unit','');
+		if unit=='':
 			#create generic unit: 
 			unit='SI';
 		results[i].unit=unit;
 	model.results=results;
 	
 	#Write model to javascript database file: 
+	print('writing to file')
 	writejsfile(directory + databasename + '.js',model,databasename);
 #}}}
