Index: /issm/trunk-jpl/configure.ac
===================================================================
--- /issm/trunk-jpl/configure.ac	(revision 19701)
+++ /issm/trunk-jpl/configure.ac	(revision 19702)
@@ -37,4 +37,5 @@
 					  src/wrappers/python/Makefile
 					  src/wrappers/matlab/Makefile
+					  src/wrappers/javascript/Makefile
 					  src/mobile/Makefile
 					  src/mobile/native/Makefile
Index: /issm/trunk-jpl/m4/issm_options.m4
===================================================================
--- /issm/trunk-jpl/m4/issm_options.m4	(revision 19701)
+++ /issm/trunk-jpl/m4/issm_options.m4	(revision 19702)
@@ -304,5 +304,5 @@
 		   *)
            MEXLINK=$($MATLAB_ROOT/bin/mex -v 2>&1 < /dev/null | grep LDFLAGS     | sed -e "s/         LDFLAGS            = //g")
-           MEXLIB=$( $MATLAB_ROOT/bin/mex -v 2>&1 < /dev/null | grep CXXLIBS     | sed -e "s/         CXXLIBS            = //g")
+           MEXLIB="-L$MATLAB_ROOT/bin/maci64  -Wl,$MATLAB_ROOT/bin/maci64/libmx.dylib -lmex -lmat -lstdc++"
 		     MEXEXT=$( $MATLAB_ROOT/bin/mex -v 2>&1 < /dev/null | grep LDEXTENSION | sed -e "s/         LDEXTENSION        = //g")
 				dnl version 2014 and up
@@ -551,4 +551,23 @@
 	AM_CONDITIONAL([ISSM_DAKOTA],[test x$DAKOTA_MAJOR = x6])
 	dnl }}}
+	dnl javascript{{{
+	AC_ARG_WITH([javascript],
+	  AS_HELP_STRING([--with-javascript], [compile javascript wrappers? default is no.]),
+	  [JAVASCRIPT=$withval],[JAVASCRIPT="no"]) 
+
+	dnl Check whether javascript wrappers are desired
+	AC_MSG_CHECKING([for javascript])
+	if test "x$JAVASCRIPT" = "xno" ; then
+		HAVE_JAVASCRIPT=no
+	else
+		HAVE_JAVASCRIPT=yes
+		AC_DEFINE([_HAVE_JAVASCRIPT_],[1],[with javascript])
+	fi
+	AC_MSG_RESULT($HAVE_JAVASCRIPT)
+	AM_CONDITIONAL([JAVASCRIPT],[test x$HAVE_JAVASCRIPT = xyes])
+	JAVASCRIPTWRAPPEREXT=.js
+	AC_SUBST([JAVASCRIPTWRAPPEREXT])
+
+	dnl }}}
 	dnl python{{{
 	AC_ARG_WITH([python-dir],
Index: /issm/trunk-jpl/src/c/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/c/Makefile.am	(revision 19701)
+++ /issm/trunk-jpl/src/c/Makefile.am	(revision 19702)
@@ -636,5 +636,9 @@
 endif
 else
+if JAVASCRIPT
+bin_PROGRAMS =
+else
 bin_PROGRAMS = issm 
+endif
 endif
 
Index: /issm/trunk-jpl/src/m/array/listToMatrix.js
===================================================================
--- /issm/trunk-jpl/src/m/array/listToMatrix.js	(revision 19702)
+++ /issm/trunk-jpl/src/m/array/listToMatrix.js	(revision 19702)
@@ -0,0 +1,14 @@
+function listToMatrix(list, elementsPerSubArray) {
+	var matrix = [], i, k;
+
+	for (i = 0, k = -1; i < list.length; i++) {
+		if (i % elementsPerSubArray === 0) {
+			k++;
+			matrix[k] = [];
+		}
+
+		matrix[k].push(list[i]);
+	}
+
+	return matrix;
+}
Index: /issm/trunk-jpl/src/m/classes/mesh2d.js
===================================================================
--- /issm/trunk-jpl/src/m/classes/mesh2d.js	(revision 19702)
+++ /issm/trunk-jpl/src/m/classes/mesh2d.js	(revision 19702)
@@ -0,0 +1,72 @@
+//MESH2D class definition
+//
+//   Usage:
+//      mesh2d= new mesh2d();
+
+function mesh2d () {
+	//properties 
+	// {{{
+		this.x                           = NaN;
+		this.y                           = NaN;
+		this.elements                    = NaN;
+		this.numberofelements            = 0;
+		this.numberofvertices            = 0;
+		this.numberofedges               = 0;
+
+		this.lat                         = NaN;
+		this.long                        = NaN;
+		this.epsg                        = 0;
+
+		this.vertexonboundary            = NaN;
+
+		this.edges                       = NaN;
+		this.segments                    = NaN;
+		this.segmentmarkers              = NaN;
+		this.vertexconnectivity          = NaN;
+		this.elementconnectivity         = NaN;
+		this.average_vertex_connectivity = 0;
+
+		this.extractedvertices           = NaN;
+		this.extractedelements           = NaN;
+		//}}}
+	//methods 
+		this.setdefaultparameters = function () //{{{
+
+			//the connectivity is the averaged number of nodes linked to a
+			//given node through an edge. This connectivity is used to initially
+			//allocate memory to the stiffness matrix. A value of 16 seems to
+			//give a good memory/time ration. This value can be checked in
+			//trunk/test/Miscellaneous/runme.m
+			this.average_vertex_connectivity=25;
+		// }}}
+		this.disp = function () { //{{{
+			console.log(sprintf("   2D tria Mesh (horizontal):")); 
+
+			console.log(sprintf("\n      Elements and vertices:"));
+			fielddisplay(this,"numberofelements","number of elements");
+			fielddisplay(this,"numberofvertices","number of vertices");
+			fielddisplay(this,"elements","vertex indices of the mesh elements");
+			fielddisplay(this,"x","vertices x coordinate [m]");
+			fielddisplay(this,"y","vertices y coordinate [m]");
+			fielddisplay(this,"edges","edges of the 2d mesh (vertex1 vertex2 element1 element2)");
+			fielddisplay(this,"numberofedges","number of edges of the 2d mesh");
+
+			console.log(sprintf("\n      Properties:"));
+			fielddisplay(this,"vertexonboundary","vertices on the boundary of the domain flag list");
+			fielddisplay(this,"segments","edges on domain boundary (vertex1 vertex2 element)");
+			fielddisplay(this,"segmentmarkers","number associated to each segment");
+			fielddisplay(this,"vertexconnectivity","list of vertices connected to vertex_i");
+			fielddisplay(this,"elementconnectivity","list of vertices connected to element_i");
+			fielddisplay(this,"average_vertex_connectivity","average number of vertices connected to one vertex");
+
+			console.log(sprintf("\n      Extracted model:"));
+			fielddisplay(this,"extractedvertices","vertices extracted from the model");
+			fielddisplay(this,"extractedelements","elements extracted from the model");
+
+			console.log(sprintf("\n      Projection:"));
+			fielddisplay(this,"lat","vertices latitude [degrees]");
+			fielddisplay(this,"long","vertices longitude [degrees]");
+			fielddisplay(this,"epsg","EPSG code (ex: 3413 for UPS Greenland, 3031 for UPS Antarctica)");
+		} //}}}
+
+}
Index: /issm/trunk-jpl/src/m/classes/model.js
===================================================================
--- /issm/trunk-jpl/src/m/classes/model.js	(revision 19702)
+++ /issm/trunk-jpl/src/m/classes/model.js	(revision 19702)
@@ -0,0 +1,138 @@
+//MODEL class definition
+//
+//   Usage:
+//      md = new model()
+
+function model () {
+	//methods
+		this.disp = function() { //{{{
+			console.log(sprintf("class model echo: "));
+			console.log(sprintf("%19s: %-22s -- %s","mesh"            ,"[1x1 " + typeof(this.mesh) + "]","mesh properties"));
+			console.log(sprintf("%19s: %-22s -- %s","mask"            ,"[1x1 " + typeof(this.mask) + "]","defines grounded and floating elements"));
+			console.log(sprintf("%19s: %-22s -- %s","geometry"        ,"[1x1 " + typeof(this.geometry) + "]","surface elevation, bedrock topography, ice thickness,..."));
+			console.log(sprintf("%19s: %-22s -- %s","constants"       ,"[1x1 " + typeof(this.constants) + "]","physical constants"));
+			console.log(sprintf("%19s: %-22s -- %s","smb"             ,"[1x1 " + typeof(this.smb) + "]","surface mass balance"));
+			console.log(sprintf("%19s: %-22s -- %s","basalforcings"   ,"[1x1 " + typeof(this.basalforcings) + "]","bed forcings"));
+			console.log(sprintf("%19s: %-22s -- %s","materials"       ,"[1x1 " + typeof(this.materials) + "]","material properties"));
+			console.log(sprintf("%19s: %-22s -- %s","damage"          ,"[1x1 " + typeof(this.damage) + "]","parameters for damage evolution solution"));
+			console.log(sprintf("%19s: %-22s -- %s","friction"        ,"[1x1 " + typeof(this.friction) + "]","basal friction/drag properties"));
+			console.log(sprintf("%19s: %-22s -- %s","flowequation"    ,"[1x1 " + typeof(this.flowequation) + "]","flow equations"));
+			console.log(sprintf("%19s: %-22s -- %s","timestepping"    ,"[1x1 " + typeof(this.timestepping) + "]","time stepping for transient models"));
+			console.log(sprintf("%19s: %-22s -- %s","initialization"  ,"[1x1 " + typeof(this.initialization) + "]","initial guess/state"));
+			console.log(sprintf("%19s: %-22s -- %s","rifts"           ,"[1x1 " + typeof(this.rifts) + "]","rifts properties"));
+			console.log(sprintf("%19s: %-22s -- %s","debug"           ,"[1x1 " + typeof(this.debug) + "]","debugging tools (valgrind, gprof)"));
+			console.log(sprintf("%19s: %-22s -- %s","verbose"         ,"[1x1 " + typeof(this.verbose) + "]","verbosity level in solve"));
+			console.log(sprintf("%19s: %-22s -- %s","settings"        ,"[1x1 " + typeof(this.settings) + "]","settings properties"));
+			console.log(sprintf("%19s: %-22s -- %s","toolkits"        ,"[1x1 " + typeof(this.toolkits) + "]","PETSc options for each solution"));
+			console.log(sprintf("%19s: %-22s -- %s","cluster"         ,"[1x1 " + typeof(this.cluster) + "]","cluster parameters (number of cpus...)"));
+			console.log(sprintf("%19s: %-22s -- %s","balancethickness","[1x1 " + typeof(this.balancethickness) + "]","parameters for balancethickness solution"));
+			console.log(sprintf("%19s: %-22s -- %s","stressbalance"   ,"[1x1 " + typeof(this.stressbalance) + "]","parameters for stressbalance solution"));
+			console.log(sprintf("%19s: %-22s -- %s","groundingline"   ,"[1x1 " + typeof(this.groundingline) + "]","parameters for groundingline solution"));
+			console.log(sprintf("%19s: %-22s -- %s","hydrology"       ,"[1x1 " + typeof(this.hydrology) + "]","parameters for hydrology solution"));
+			console.log(sprintf("%19s: %-22s -- %s","masstransport"   ,"[1x1 " + typeof(this.masstransport) + "]","parameters for masstransport solution"));
+			console.log(sprintf("%19s: %-22s -- %s","thermal"         ,"[1x1 " + typeof(this.thermal) + "]","parameters for thermal solution"));
+			console.log(sprintf("%19s: %-22s -- %s","steadystate"     ,"[1x1 " + typeof(this.steadystate) + "]","parameters for steadystate solution"));
+			console.log(sprintf("%19s: %-22s -- %s","transient"       ,"[1x1 " + typeof(this.transient) + "]","parameters for transient solution"));
+			console.log(sprintf("%19s: %-22s -- %s","calving"         ,"[1x1 " + typeof(this.calving) + "]","parameters for calving"));
+			console.log(sprintf("%19s: %-22s -- %s","gia"             ,"[1x1 " + typeof(this.gia) + "]","parameters for gia solution"));
+			console.log(sprintf("%19s: %-22s -- %s","autodiff"        ,"[1x1 " + typeof(this.autodiff) + "]","automatic differentiation parameters"));
+			console.log(sprintf("%19s: %-22s -- %s","flaim"           ,"[1x1 " + typeof(this.flaim) + "]","flaim parameters"));
+			console.log(sprintf("%19s: %-22s -- %s","inversion"       ,"[1x1 " + typeof(this.inversion) + "]","parameters for inverse methods"));
+			console.log(sprintf("%19s: %-22s -- %s","qmu"             ,"[1x1 " + typeof(this.qmu) + "]","dakota properties"));
+			console.log(sprintf("%19s: %-22s -- %s","outputdefinition","[1x1 " + typeof(this.outputdefinition) + "]","output definition"));
+			console.log(sprintf("%19s: %-22s -- %s","results"         ,"[1x1 " + typeof(this.results) + "]","model results"));
+			console.log(sprintf("%19s: %-22s -- %s","radaroverlay"    ,"[1x1 " + typeof(this.radaroverlay) + "]","radar image for plot overlay"));
+			console.log(sprintf("%19s: %-22s -- %s","miscellaneous"   ,"[1x1 " + typeof(this.miscellaneous) + "]","miscellaneous fields"));
+		} //}}}
+		this.setdefaultparameters = function () { // {{{
+
+			//initialize subclasses
+			this.mesh             = new mesh2d();
+//			this.mask             = mask();
+//			this.constants        = constants();
+//			this.geometry         = geometry();
+//			this.initialization   = initialization();
+//			this.smb              = SMBforcing();
+//			this.basalforcings    = basalforcings();
+//			this.friction         = friction();
+//			this.rifts            = rifts();
+//			this.timestepping     = timestepping();
+//			this.groundingline    = groundingline();
+//			this.materials        = matice();
+//			this.damage           = damage();
+//			this.flowequation     = flowequation();
+//			this.debug            = debug();
+//			this.verbose          = verbose();
+//			this.settings         = settings();
+//			this.toolkits         = toolkits();
+//			this.cluster          = generic();
+//			this.balancethickness = balancethickness();
+//			this.stressbalance    = stressbalance();
+//			this.hydrology        = hydrologyshreve();
+//			this.masstransport    = masstransport();
+//			this.thermal          = thermal();
+//			this.steadystate      = steadystate();
+//			this.transient        = transient();
+//			this.calving          = calving();
+//			this.gia              = gia();
+//			this.autodiff         = autodiff();
+//			this.flaim            = flaim();
+//			this.inversion        = inversion();
+//			this.qmu              = qmu();
+//			this.radaroverlay     = radaroverlay();
+//			this.results          = struct();
+//			this.outputdefinition = outputdefinition();
+//			this.miscellaneous    = miscellaneous();
+//			this.private          = private();
+		} //}}}
+	//properties
+	// {{{
+		//Careful here: no other class should be used as default value this is a bug of matlab
+		this.mesh             = 0;
+		this.mask             = 0;
+
+		this.geometry         = 0;
+		this.constants        = 0;
+		this.smb              = 0;
+		this.basalforcings    = 0;
+		this.materials        = 0;
+		this.damage           = 0;
+		this.friction         = 0;
+		this.flowequation     = 0;
+		this.timestepping     = 0;
+		this.initialization   = 0;
+		this.rifts            = 0;
+
+		this.debug            = 0;
+		this.verbose          = 0;
+		this.settings         = 0;
+		this.toolkits         = 0;
+		this.cluster          = 0;
+
+		this.balancethickness = 0;
+		this.stressbalance    = 0;
+		this.groundingline    = 0;
+		this.hydrology        = 0;
+		this.masstransport    = 0;
+		this.thermal          = 0;
+		this.steadystate      = 0;
+		this.transient        = 0;
+		this.calving          = 0;
+		this.gia              = 0;
+
+		this.autodiff         = 0;
+		this.flaim            = 0;
+		this.inversion        = 0;
+		this.qmu              = 0;
+
+		this.results          = 0;
+		this.outputdefinition = 0;
+		this.radaroverlay     = 0;
+		this.miscellaneous    = 0;
+		this.private          = 0;
+
+		//set default values for fields
+		this.setdefaultparameters();
+
+		//}}}
+}
Index: /issm/trunk-jpl/src/m/mesh/triangle.js
===================================================================
--- /issm/trunk-jpl/src/m/mesh/triangle.js	(revision 19702)
+++ /issm/trunk-jpl/src/m/mesh/triangle.js	(revision 19702)
@@ -0,0 +1,29 @@
+function triangle(md,domain, rifts, resolution){
+//TRIANGLE - create model mesh using the triangle package
+//
+//   This routine creates a model mesh using TriMesh and a domain outline, to within a certain resolution
+//   where md is a @model object, domainname is the name of an Argus domain outline file, 
+//   and resolution is a characteristic length for the mesh (same unit as the domain outline
+//   unit). Riftname is an optional argument (Argus domain outline) describing rifts.
+//
+//   Usage:
+//      triangle(md,domain,resolution)
+//   or triangle(md,domain,riftname, resolution)
+//
+//   Examples:
+//      triangle(md,domain,1000);
+//      triangle(md,domain, rifts, 1500);
+
+	var area=Math.pow(resolution,2);
+
+	//Call mesher: 
+	var array = TriMesh(md, domain, rifts, area); 
+
+	//Fill in rest of fields:
+	//md.mesh.vertexonboundary=zeros(md.mesh.numberofvertices,1); md.mesh.vertexonboundary(md.mesh.segments(:,1:2))=1;
+
+	//Now, build the connectivity tables for this mesh.
+	//md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices);
+	//md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity);
+
+}
Index: /issm/trunk-jpl/src/m/miscellaneous/fielddisplay.js
===================================================================
--- /issm/trunk-jpl/src/m/miscellaneous/fielddisplay.js	(revision 19702)
+++ /issm/trunk-jpl/src/m/miscellaneous/fielddisplay.js	(revision 19702)
@@ -0,0 +1,85 @@
+function fielddisplay(md,name,comment){
+//FIELDDISPLAY - display model field
+//
+//   Usage:
+//      fielddisplay(md,name,comment)
+
+	//get field
+	field=md[name];
+
+	//disp corresponding line as a function of field type (offset set as 9 spaces)
+	parsedisplay('         ',name,field,comment);
+}
+
+function parsedisplay(offset,name,field,comment) { //{{{
+
+	//string
+	if (typeof(field) == "string"){
+
+		if (field.length > 30){
+			displayunit(offset,name,"not displayed",comment);
+		}
+		else{
+			console.log(offset)
+			console.log(name)
+			console.log(field)
+			//displayunit(offset,name,"""" + field """",comment),
+		}
+	}
+	//numeric
+	else if (typeof(field) == "number"){
+		
+		displayunit(offset,name,sprintf("%g",field),comment);
+
+	}
+	//logical
+	else if (typeof(field) == "boolean") {
+
+		if (field){
+			displayunit(offset,name,"true",comment);
+		}
+		else{
+			displayunit(offset,name,"false",comment);
+		}
+
+	}
+	//object
+	else if (typeof(field) == "object"){
+			
+		displayunit(offset,name,sprintf("(%i)",field.length),comment);
+
+	}
+	else{
+		displayunit(offset,name,"not displayed",comment);
+	}
+} //}}}
+
+function displayunit(offset,name,characterization,comment){ // {{{
+
+	//take care of name
+	if (name.length>23){
+		name=name.slice(0,21) + "...";
+	}
+
+	//take care of characterization
+	if ( characterization == "\" \"" || characterization == "NaN" ){
+	
+		characterization="N/A";
+	}
+	if (characterization.length>15){
+		characterization=characterization.slice(0,13) + "...";
+	}
+
+	//print
+	if (comment.length==0){
+		console.log(sprintf("%s%-23s: %-15s",offset,name,characterization));
+	}
+	else{
+		if (typeof(comment) == "string"){
+			console.log(sprintf("%s%-23s: %-15s -- %s",offset,name,characterization,comment));
+		}
+		else{
+			console.error("fielddisplay error message: format for comment not supported yet");
+		}
+	}
+} //}}}
Index: /issm/trunk-jpl/src/wrappers/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/Makefile.am	(revision 19701)
+++ /issm/trunk-jpl/src/wrappers/Makefile.am	(revision 19702)
@@ -6,4 +6,8 @@
 endif
 
+if JAVASCRIPT
+SUBDIRS += javascript
+endif
+
 if PYTHON
 SUBDIRS += python
Index: /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.cpp	(revision 19701)
+++ /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.cpp	(revision 19702)
@@ -14,5 +14,6 @@
 	_printf_("\n");
 }/*}}}*/
-WRAPPER(TriMesh){
+WRAPPER(TriMesh,double** pindex, double** px, double** py, int* pnel, int* pnods, double* domainx, double* domainy, int domainnods, double areain){
+	
 
 	/*intermediary: */
@@ -27,5 +28,5 @@
 	int    *segments          = NULL;
 	int    *segmentmarkerlist = NULL;
-	int     nels,nods,nsegs;
+	int     nel,nods,nsegs;
 
 	/*Boot module: */
@@ -41,8 +42,8 @@
 
 	/*call x core: */
-	TriMeshx(&index,&x,&y,&segments,&segmentmarkerlist,&nels,&nods,&nsegs,domain,rifts,area);
+	TriMeshx(&index,&x,&y,&segments,&segmentmarkerlist,&nel,&nods,&nsegs,domain,rifts,area);
 
 	/*write outputs: */
-	WriteData(INDEX,index,nels,3);
+	WriteData(INDEX,index,nel,3);
 	WriteData(X,x,nods);
 	WriteData(Y,y,nods);
Index: /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h	(revision 19701)
+++ /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h	(revision 19702)
@@ -55,4 +55,18 @@
 #endif
 
+#ifdef _HAVE_JAVASCRIPT_MODULES_
+/* serial input macros: */
+#define DOMAINOUTLINE domainx,domainy,domainnods
+#define RIFTSOUTLINE  NULL,NULL,0
+#define AREA          areain
+/* serial output macros: */
+#define INDEX             pindex,pnel
+#define X                 px,pnods
+#define Y                 py,pnods
+#define SEGMENTS          NULL,NULL
+#define SEGMENTMARKERLIST NULL,NULL
+#endif
+
+
 /* serial arg counts: */
 #undef NLHS
Index: /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.js
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.js	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.js	(revision 19702)
@@ -0,0 +1,76 @@
+function TriMesh(md,domain,rifts, area){
+/*TriMesh 
+	   usage: var array = TriMesh(domain,rifts,area);
+	      where: array is made of [index,x,y,segments,segmentmarkers]
+		  and index,x,y defines a triangulation, segments is an array made 
+	      of exterior segments to the mesh domain outline, segmentmarkers is an array 
+		  flagging each segment, domain a js array defining the domain outline  (sames for 
+		  rifts) and area is the maximum area desired for any element of the resulting mesh.
+
+		  Ok, for now, we are not dealing with rifts. Also, the domain is made of only one 
+		  profile, this to avoid passing a double** pointer to js. 
+*/
+
+	//Dynamic allocations: {{{
+	//Retrieve domain arrays, and allocate on Module heap: 
+	
+	//input
+	var dx=new Float64Array(domain['x']); var nx=dx.length * dx.BYTES_PER_ELEMENT;
+	var dxPtr= Module._malloc(nx); var domainxHeap = new Uint8Array(Module.HEAPU8.buffer,dxPtr,nx);
+	domainxHeap.set(new Uint8Array(dx.buffer)); var domainx=domainxHeap.byteOffset;
+
+	var dy=new Float64Array(domain['y']); var ny=dy.length * dy.BYTES_PER_ELEMENT;
+	var dyPtr = Module._malloc(ny); var domainyHeap = new Uint8Array(Module.HEAPU8.buffer,dyPtr,ny);
+	domainyHeap.set(new Uint8Array(dy.buffer)); var domainy=domainyHeap.byteOffset;
+	
+	//output
+	var nel,indexlinear,index,nods,x,y;
+	var pnel= Module._malloc(4); 
+	var pindex= Module._malloc(4); 
+	var pnods= Module._malloc(4); 
+	var px= Module._malloc(4); 
+	var py= Module._malloc(4); 
+	//}}}
+
+	//Declare TriMesh module: 
+	TriMeshModule = Module.cwrap('TriMeshModule','number',['number','number','number','number','number','number','number','number','number']);
+	
+	//Call TriMesh module: 
+	TriMeshModule(pindex,px,py,pnel,pnods,domainx,domainy,dx.length,area);
+	
+	/*Dynamic copying from heap: {{{*/
+	//recover mesh: 
+	nel = Module.getValue(pnel, 'i32');
+	var indexptr = Module.getValue(pindex,'i32');
+	indexlinear = Module.HEAPF64.slice(indexptr /8, indexptr/8 + nel*3);
+	index = listToMatrix(indexlinear,3);
+
+	nods = Module.getValue(pnods, 'i32');
+	var xptr = Module.getValue(px,'i32');
+	var yptr = Module.getValue(py,'i32');
+	x = Module.HEAPF64.slice(xptr /8, xptr/8 + nods);
+	y = Module.HEAPF64.slice(yptr /8, yptr/8 + nods);
+	/*}}}*/
+
+	/*Assign output: */
+	md.mesh=new mesh2d();
+
+	md.mesh.elements=index;
+	md.mesh.numberofelements=nel;
+	md.mesh.numberofvertices=nods;
+	md.mesh.x=x;
+	md.mesh.y=y;
+	md.mesh.segments=[];
+	md.mesh.segmentmarkers=[];
+
+	/*Free ressources: */
+	Module._free(pindex); 
+	Module._free(indexlinear); 
+	Module._free(px); 
+	Module._free(x); 
+	Module._free(py); 
+	Module._free(y); 
+	Module._free(pnel); 
+	Module._free(pnods); 
+
+}
Index: /issm/trunk-jpl/src/wrappers/bindings.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/bindings.h	(revision 19701)
+++ /issm/trunk-jpl/src/wrappers/bindings.h	(revision 19702)
@@ -20,3 +20,10 @@
 #endif
 
+#ifdef  _HAVE_JAVASCRIPT_MODULES_
+#include "./javascript/include/javascriptincludes.h"
+#include "./javascript/include/wrapper_macros.h"
+#include "./javascript/io/javascriptio.h"
 #endif
+
+
+#endif
Index: /issm/trunk-jpl/src/wrappers/javascript/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 19702)
@@ -0,0 +1,76 @@
+AM_CPPFLAGS = @DAKOTAINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @AMPIINCL@
+AUTOMAKE_OPTIONS = subdir-objects
+
+EXEEXT=$(JAVASCRIPTWRAPPEREXT)
+
+#define prefix (from http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Defining-Directories.html)
+AM_CPPFLAGS+=  -DISSM_PREFIX='"$(prefix)"'
+
+bin_SCRIPTS = 
+bin_SCRIPTS += ../TriMesh/TriMesh.js 
+	
+#javascript io{{{
+if !WINDOWS
+lib_LTLIBRARIES = libISSMJavascript.la
+else
+noinst_LTLIBRARIES = libISSMJavascript.la
+lib_LTLIBRARIES = 
+endif
+
+io_sources=   ./io/WriteJavascriptData.cpp\
+				./io/FetchJavascriptData.cpp
+
+ALLCXXFLAGS= -fPIC -D_WRAPPERS_ $(CXXFLAGS) $(CXXOPTFLAGS) 
+
+libISSMJavascript_la_SOURCES = $(io_sources)
+libISSMJavascript_la_CXXFLAGS= $(ALLCXXFLAGS)
+#}}}
+#api io{{{
+if !WINDOWS
+lib_LTLIBRARIES += libISSMApi.la
+else
+noinst_LTLIBRARIES += libISSMApi.la
+endif
+
+api_sources= ./io/ApiPrintf.cpp
+
+libISSMApi_la_SOURCES = $(api_sources)
+libISSMApi_la_CXXFLAGS= $(ALLCXXFLAGS)
+#}}}
+#Wrappers {{{
+bin_PROGRAMS = 		 TriMeshModule
+#}}}
+
+# Dependencies {{{
+
+#Triangle library
+AM_CXXFLAGS =  -DTRILIBRARY -DANSI_DECLARATORS -DNO_TIMER -D_WRAPPERS_
+AM_CXXFLAGS +=  -D_HAVE_JAVASCRIPT_MODULES_ -fPIC
+
+deps = ./libISSMJavascript.la ../../c/libISSMModules.la ../../c/libISSMCore.la ./libISSMApi.la
+
+#Optimization flags:
+AM_CXXFLAGS += $(CXXOPTFLAGS) 
+#}}}
+# Module sources and dependencies {{{
+if !WINDOWS
+libISSMJavascript_la_LIBADD = ./../../c/libISSMCore.la ./../../c/libISSMModules.la $(MPILIB) $(PETSCLIB) $(MKLLIB) $(GSLLIB) $(PROJ4LIB) $(MATHLIB) 
+endif
+
+if STANDALONE_LIBRARIES
+libISSMJavascript_la_LDFLAGS = -static 
+deps += $(PETSCLIB) $(TAOLIB) $(M1QN3LIB) $(PLAPACKLIB) $(MUMPSLIB) $(SUPERLULIB) $(SPOOLESLIB) $(TRIANGLELIB) $(SCALAPACKLIB) $(BLACSLIB) $(HYPRELIB) $(SPAILIB) $(PROMETHEUSLIB) $(PASTIXLIB) $(MLLIB) $(DAKOTALIB) $(METISLIB) $(CHACOLIB) $(SCOTCHLIB) $(BLASLAPACKLIB) $(MKLLIB) $(MPILIB) $(MATHLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB) $(OSLIBS) $(GSLLIB)   $(ADOLCLIB) $(AMPILIB) $(METEOIOLIB) $(SNOWPACKLIB)
+endif
+
+if !WINDOWS
+libISSMApi_la_LIBADD = $(MPILIB) $(PETSCLIB) $(GSLLIB) $(PROJ4LIB) $(MATHLIB) $(MEXLIB)
+endif
+
+if STANDALONE_LIBRARIES
+libISSMApi_la_LDFLAGS = -static 
+endif
+
+TriMeshModule_SOURCES = ../TriMesh/TriMesh.cpp
+TriMeshModule_CXXFLAGS= -fPIC --memory-init-file 0 $(AM_CXXFLAGS) $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) -s EXPORTED_FUNCTIONS="['_TriMeshModule']"  -s DISABLE_EXCEPTION_CATCHING=0
+TriMeshModule_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(TRIANGLELIB) $(GSLLIB) $(PROJ4LIB)
+#}}}
Index: /issm/trunk-jpl/src/wrappers/javascript/include/javascriptincludes.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/include/javascriptincludes.h	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/javascript/include/javascriptincludes.h	(revision 19702)
@@ -0,0 +1,15 @@
+
+#ifndef _JAVASCRIPT_INCLUDES_H_
+#define _JAVASCRIPT_INCLUDES_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#ifdef _HAVE_JAVASCRIPT_
+//nothing for now
+#endif
+
+#endif /*_JAVASCRIPT_INCLUDES_H_*/
Index: /issm/trunk-jpl/src/wrappers/javascript/include/wrapper_macros.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/include/wrapper_macros.h	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/javascript/include/wrapper_macros.h	(revision 19702)
@@ -0,0 +1,44 @@
+/* \file javascript macros.h
+ * \brief: macros used for the javascript bindings
+ */
+
+#ifndef _JAVASCRIPT_MACROS_H_
+#define _JAVASCRIPT_MACROS_H_
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#ifdef _HAVE_JAVASCRIPT_
+/* MODULEBOOT/MODULEEND {{{*/
+
+/*The following macros hide the error exception handling in a javascript module. Just put 
+ * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions 
+ * will be trapped*/
+#define MODULEBOOT(); try{ \
+	IssmComm::SetComm();
+
+#define MODULEEND(); }\
+	catch(ErrorException &exception){\
+		printf(exception.WrapperReport()); \
+	}\
+	catch (exception &e){\
+		printf(e.what());\
+	}\
+	catch(...){\
+		printf("An unexpected error occurred");\
+	}\
+	return 0;\
+	}
+/*}}}*/
+/* WRAPPER {{{*/
+#define WRAPPER(modulename,...) extern "C" { int  modulename##Module(__VA_ARGS__) 
+/*}}}*/
+/* CHECKARGUMENTS {{{*/
+#define CHECKARGUMENTS(NLHS,NRHS,functionpointer)  //do nothing, we are not creating a dynamic library here!
+/*}}}*/
+#endif
+
+#endif
Index: /issm/trunk-jpl/src/wrappers/javascript/io/ApiPrintf.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/ApiPrintf.cpp	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/ApiPrintf.cpp	(revision 19702)
@@ -0,0 +1,19 @@
+/* \file ApiPrintf.c:
+ * \brief: API specific symbols from libISSMCore that we need to resolve here
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./javascriptio.h"
+
+/*Javascript printf i/o: */
+void ApiPrintf(const char* string){
+
+	/*use mexPrintf in matlab: */
+	printf(string);
+	return;
+}
Index: /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 19702)
@@ -0,0 +1,46 @@
+/*\file FetchData.cpp:
+ * \brief: general I/O interface to fetch data in javascript
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./javascriptio.h"
+#include <cstring> 
+
+/*Primitive data types*/
+/*FUNCTION FetchData(double* pscalar,double scalar){{{*/
+void FetchData(double* pscalar,double scalar){
+	
+	*pscalar = scalar;
+}
+/*}}}*/
+
+/*ISSM objects*/
+/*FUNCTION FetchData(Contours** pcontours,double* x, double* y, int nods){{{*/
+void FetchData(Contours** pcontours,double* x, double* y, int nods){
+
+	int             numcontours,index,test1,test2;
+	char            *contourname = NULL;
+	Contours        *contours    = NULL;
+	Contour<double> *contouri    = NULL;
+
+	/*only 1 contour for now: */
+	contours=new Contours();
+
+	if (nods){
+			
+		contouri=new Contour<double>();
+		contouri->nods=nods;
+		contouri->x=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(contouri->x,x,nods);
+		contouri->y=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(contouri->y,y,nods);
+
+		contours->AddObject(contouri);
+	}
+	
+	*pcontours=contours;
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp	(revision 19702)
@@ -0,0 +1,55 @@
+/* \file WriteData.c:
+ * \brief: general interface for writing data
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./javascriptio.h"
+#include "./../../../c/datastructures/datastructures.h"
+
+/*Primitive data types*/
+/*FUNCTION WriteData(IssmPDouble** pmatrix, int* pnel, int* matrix, int M,int N){{{*/
+void WriteData(IssmPDouble** pmatrix,int* pnel, int* matrix, int M,int N){
+
+	if(pmatrix && matrix){
+
+		/*Copy matrix: */
+		IssmPDouble* dmatrix = xNew<IssmPDouble>(M*N); 
+		for (int i=0;i<M*N;i++)dmatrix[i]=(IssmPDouble)matrix[i];
+		*pmatrix=dmatrix;
+		*pnel=M;
+	}
+}
+/*}}}*/
+/*FUNCTION WriteData(IssmPDouble** px, int* pnods, double* vector, int M){{{*/
+void WriteData(IssmPDouble** px, int* pnods, double* vector, int M){
+
+	if(px && vector){
+
+		IssmPDouble* dx=xNew<IssmPDouble>(M); 
+		for(int i=0;i<M;i++)dx[i]=vector[i];
+		*px=dx;
+		*pnods=M;
+	}
+}
+/*}}}*/
+/*FUNCTION WriteData(IssmPDouble** px, int* pnods, int* vector, int M){{{*/
+void WriteData(IssmPDouble** px, int* pnods, int* vector, int M){
+
+	if(px && vector){
+
+		IssmPDouble* dx=xNew<IssmPDouble>(M); 
+		for(int i=0;i<M;i++)dx[i]=(IssmPDouble)vector[i];
+		*px=dx;
+		*pnods=M;
+	}
+}
+/*}}}*/
+
+/*ISSM objects*/
+
+/*Toolkit*/
Index: /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 19702)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 19702)
@@ -0,0 +1,29 @@
+/*\file matlabio.h
+ *\brief: I/O for ISSM in matlab mode
+ */
+
+#ifndef _JAVASCRIPT_IO_H_
+#define _JAVASCRIPT_IO_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif 
+
+#include "../include/javascriptincludes.h"
+#include "../../../c/bamg/bamgobjects.h"
+#include "../../../c/classes/classes.h"
+#include "../../../c/toolkits/toolkits.h"
+#include "../../../c/shared/shared.h"
+
+void WriteData(IssmPDouble** pmatrix,int* pnel, int* matrix, int M,int N);
+void WriteData(IssmPDouble** px, int* pnods, int* vector, int M);
+void WriteData(IssmPDouble** px, int* pnods, double* vector, int M);
+
+void FetchData(double* pscalar,double scalar);
+void FetchData(Contours** pcontours,double* x, double* y, int nods);
+
+/*Print*/
+void ApiPrintf(const char* string);
+#endif	/* _IO_H_ */
Index: /issm/trunk-jpl/test/Exp/Square.js
===================================================================
--- /issm/trunk-jpl/test/Exp/Square.js	(revision 19702)
+++ /issm/trunk-jpl/test/Exp/Square.js	(revision 19702)
@@ -0,0 +1,8 @@
+// Name:domainoutline
+// Icon:0
+// Points Count  Value
+var square={}
+square["nods"]=5;
+// X pos Y pos
+square["x"]=[0,1000000,1000000,0,0];
+square["y"]=[0, 0, 1000000,  1000000, 0];
Index: /issm/trunk-jpl/test/NightlyRun/test101.html
===================================================================
--- /issm/trunk-jpl/test/NightlyRun/test101.html	(revision 19702)
+++ /issm/trunk-jpl/test/NightlyRun/test101.html	(revision 19702)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head><!--{{{-->
+<title>ISSM Web APP &mdash; Beta</title>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+<!-- Includes {{{-->
+<script type="text/javascript" src="../Exp/Square.js"></script>
+<script type="text/javascript" src="../../src/m/miscellaneous/fielddisplay.js"></script>
+<script type="text/javascript" src="../../src/m/classes/model.js"></script>
+<script type="text/javascript" src="../../src/m/mesh/triangle.js"></script>
+<script type="text/javascript" src="../../src/m/array/listToMatrix.js"></script>
+<script type="text/javascript" src="../../src/m/classes/mesh2d.js"></script>
+<script type="text/javascript" src="../../src/wrappers/TriMesh/TriMesh.js"></script>
+<script type="text/javascript" src="../../build-js/src/wrappers/javascript/TriMeshModule.js"></script>
+<script type="text/javascript" src="../../externalpackages/javascript/src/sprintf.js"></script>
+<!-- Includes }}}-->
+</head><!--}}}-->
+<body> <!--{{{-->
+
+	<script type="text/javascript" async>
+	var md = new model();
+	triangle(md,square,[],5000); 
+	setmask(md,'all','');
+
+	</script>
+
+</body><!--}}}-->
+</html>
