Index: /issm/trunk-jpl/src/m/array/arrayoperations.js
===================================================================
--- /issm/trunk-jpl/src/m/array/arrayoperations.js	(revision 22877)
+++ /issm/trunk-jpl/src/m/array/arrayoperations.js	(revision 22878)
@@ -317,4 +317,10 @@
 
 } //}}}
+function ArrayRange(lower, upper) { //{{{
+
+    var range = upper - lower;
+    return Array.apply(null, Array(range)).map(function (val, ind) {return ind + lower;});
+
+} //}}}
 function ArrayAny(array) { //{{{
     //Emulates Matlab 'any' function
Index: /issm/trunk-jpl/src/m/mesh/bamg.js
===================================================================
--- /issm/trunk-jpl/src/m/mesh/bamg.js	(revision 22877)
+++ /issm/trunk-jpl/src/m/mesh/bamg.js	(revision 22878)
@@ -60,12 +60,9 @@
     //initialize the structures required as input of Bamg
     var bamg_options = {}
-    var bamg_geometry = bamggeom();
-    var bamg_mesh = bamgmesh();
+    var bamg_geometry = new bamggeom();
+    var bamg_mesh = new bamgmesh();
 
     var subdomain_ref = 1;
     var hole_ref = 1;
-    var vertices = [];
-    var edges = [];
-    var subdomains = [];
     // Bamg Geometry parameters {{{
     if (options.exist('domain')) {
@@ -134,18 +131,17 @@
             //Add all points to bamg_geometry
             for (var j = 0; j < nods; j++) {
-                vertices.push(domain[i].x[j]);
-                vertices.push(domain[i].y[j]);
-                vertices.push(1);
-            }
+                bamg_geometry.Vertices.push([domain[i].x[j], domain[i].y[j], 1]);
+            }
+            var edges1 = ArrayRange(count + 1, count + nods);
+            var edges2 = ArrayConcat(ArrayRange(count + 2, count + nods), [count + 1]);
             for (var j = 0; j < nods; j++) {
-                edges.push(ArrayRange(count + 1, count + nods));
-                edges.push(ArrayConcat(ArrayRange(count + 2, count + nods), [count + 1]));
-                edges.push(1);
-            }
-            subdomains.push([2, count + 1, 1, -subdomain_ref]);
-            subdomain_ref = subdomain_ref + 1;
-            bamg_geometry.Vertices = vertices;
-            bamg_geometry.Edges = edges;
-            bamg_geometry.SubDomains = subdomains;
+                bamg_geometry.Edges.push([edges1[j], edges2[j], 1]);
+            }
+            if (i > 1) {
+                bamg_geometry.SubDomains.push([2, count + 1, 1, -subdomain_ref]);
+                subdomain_ref = subdomain_ref + 1;
+            } else {
+                bamg_geometry.SubDomains.push([2, count + 1, 1, 0]);
+            }
 
             //update counter
@@ -183,18 +179,13 @@
             //Add all points to bamg_geometry
             for (var j = 0; j < nods; j++) {
-                vertices.push(holes[i].x[j]);
-                vertices.push(holes[i].y[j]);
-                vertices.push(1);
-            }
+                bamg_geometry.Vertices.push([holes[i].x[j], holes[i].y[j], 1]);
+            }
+            var edges1 = ArrayRange(count + 1, count + nods);
+            var edges2 = ArrayConcat(ArrayRange(count + 2, count + nods), [count + 1]);
             for (var j = 0; j < nods; j++) {
-                edges.push(ArrayRange(count + 1, count + nods));
-                edges.push(ArrayConcat(ArrayRange(count + 2, count + nods), [count + 1]));
-                edges.push(1);
-            }
-            subdomains.push([2, count + 1, 1, -hole_ref]);
+                bamg_geometry.Edges.push([edges1[j], edges2[j], 1]);
+            }
+            bamg_geometry.SubDomains.push([2, count + 1, 1, -hole_ref]);
             hole_ref = hole_ref + 1;
-            bamg_geometry.Vertices = vertices;
-            bamg_geometry.Edges = edges;
-            bamg_geometry.SubDomains = subdomains;
 
             //update counter
@@ -227,18 +218,13 @@
             //Add all points to bamg_geometry
             for (var j = 0; j < nods; j++) {
-                vertices.push(subdomains[i].x[j]);
-                vertices.push(subdomains[i].y[j]);
-                vertices.push(1);
-            }
+                bamg_geometry.Vertices.push([subdomains[i].x[j], subdomains[i].y[j], 1]);
+            }
+            var edges1 = ArrayRange(count + 1, count + nods);
+            var edges2 = ArrayConcat(ArrayRange(count + 2, count + nods), [count + 1]);
             for (var j = 0; j < nods; j++) {
-                edges.push(ArrayRange(count + 1, count + nods));
-                edges.push(ArrayConcat(ArrayRange(count + 2, count + nods), [count + 1]));
-                edges.push(1);
-            }
-            subdomains.push([2, count + 1, 1, subdomain_ref]);
+                bamg_geometry.Edges.push([edges1[j], edges2[j], 1]);
+            }
+            bamg_geometry.SubDomains.push([2, count + 1, 1, subdomain_ref]);
             subdomain_ref = subdomain_ref + 1;
-            bamg_geometry.Vertices = vertices;
-            bamg_geometry.Edges = edges;
-            bamg_geometry.SubDomains = subdomains;
 
             //update counter
Index: /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h	(revision 22877)
+++ /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h	(revision 22878)
@@ -47,11 +47,11 @@
 #ifdef _HAVE_JAVASCRIPT_MODULES_
 /* serial input macros: */
-#define BAMGMESHIN Vertices_mesh_in,VerticesSize_mesh_in,Edges_mesh_in,EdgesSize_mesh_in,Triangles_mesh_in,TrianglesSize_mesh_in,CrackedEdges_mesh_in,CrackedEdgesSize_mesh_in,VerticesOnGeomEdge_mesh_in,VerticesOnGeomEdgeSize_mesh_in,VerticesOnGeomVertex_mesh_in,VerticesOnGeomVertexSize_mesh_in,EdgesOnGeomEdge_mesh_in,EdgesOnGeomEdgeSize_mesh_in,IssmSegments_mesh_in,IssmSegmentsSize_mesh_in
-#define BAMGGEOMIN Vertices_geom_in,VerticesSize_geom_in,Edges_geom_in,EdgesSize_geom_in,Corners_geom_in,CornersSize_geom_in,RequiredVertices_geom_in,RequiredVerticesSize_geom_in,RequiredCrackedEdges_geom_in,RequiredCrackedEdgesSize_geom_in,CrackedEdges_geom_in,CrackedEdgesSize_geom_in,SubDomains_geom_in,SubDomainsSize_geom_in
-#define BAMGOPTIONS pbamgopts,anisomax,cutoff,coeff,errg,gradation,Hessiantype,maxnbv,maxsubdiv,Metrictype,nbjacobi,nbsmooth,omega,power,verbose,Crack,KeepVertices,splitcorners,hmin,hmax,hminVertices,hmaxVertices,hVertices,metric,field,err
+#define BAMGMESHIN VerticesSize_mesh_in, Vertices_mesh_in, EdgesSize_mesh_in, Edges_mesh_in, TrianglesSize_mesh_in, Triangles_mesh_in, CrackedEdgesSize_mesh_in, CrackedEdges_mesh_in, VerticesOnGeomEdgeSize_mesh_in, VerticesOnGeomEdge_mesh_in, VerticesOnGeomVertexSize_mesh_in, VerticesOnGeomVertex_mesh_in, EdgesOnGeomEdgeSize_mesh_in, EdgesOnGeomEdge_mesh_in, IssmSegmentsSize_mesh_in, IssmSegments_mesh_in,
+#define BAMGGEOMIN VerticesSize_geom_in, Vertices_geom_in, EdgesSize_geom_in, Edges_geom_in, CornersSize_geom_in, Corners_geom_in, RequiredVerticesSize_geom_in, RequiredVertices_geom_in, RequiredEdgesSize_geom_in, RequiredEdges_geom_in, CrackedEdgesSize_geom_in, CrackedEdges_geom_in, SubDomainsSize_geom_in, SubDomains_geom_in,
+#define BAMGOPTIONS anisomax, cutoff, coeff, errg, gradation, Hessiantype, maxnbv, maxsubdiv, Metrictype, nbjacobi, nbsmooth, omega, power, verbose, Crack, KeepVertices, splitcorners, hmin, hmax, hminVertices, hmaxVertices, hVertices, metric, field, err
 /* serial output macros: */
-#define BAMGMESHOUT Vertices_mesh_out,VerticesSize_mesh_out,Edges_mesh_out,EdgesSize_mesh_out,Triangles_mesh_out,TrianglesSize_mesh_out,CrackedEdges_mesh_out,CrackedEdgesSize_mesh_out,VerticesOnGeomEdge_mesh_out,VerticesOnGeomEdgeSize_mesh_out,VerticesOnGeomVertex_mesh_out,VerticesOnGeomVertexSize_mesh_out,EdgesOnGeomEdge_mesh_out,EdgesOnGeomEdgeSize_mesh_out,IssmSegments_mesh_out,IssmSegmentsSize_mesh_out
-#define BAMGGEOMOUT Vertices_geom_out,VerticesSize_geom_out,Edges_geom_out,EdgesSize_geom_out,Corners_geom_out,CornersSize_geom_out,RequiredVertices_geom_out,RequiredVerticesSize_geom_out,RequiredCrackedEdges_geom_out,RequiredCrackedEdgesSize_geom_out,CrackedEdges_geom_out,CrackedEdgesSize_geom_out,SubDomains_geom_out,SubDomainsSize_geom_out
-#define WRAPPER(modulename) extern "C" { int  BamgMesherModule(double* Vertices_mesh_out, int* VerticesSize_mesh_out, double* Edges_mesh_out, int* EdgesSize_mesh_out, double* Triangles_mesh_out, int* TrianglesSize_mesh_out, double* CrackedEdges_mesh_out, int* CrackedEdgesSize_mesh_out, double* VerticesOnGeomEdge_mesh_out, int* VerticesOnGeomEdgeSize_mesh_out, double* VerticesOnGeomVertex_mesh_out, int* VerticesOnGeomVertexSize_mesh_out, double* EdgesOnGeomEdge_mesh_out, int* EdgesOnGeomEdgeSize_mesh_out, double* IssmSegments_mesh_out, int* IssmSegmentsSize_mesh_out, double* Vertices_geom_out, int* VerticesSize_geom_out, double* Edges_geom_out, int* EdgesSize_geom_out, double* Corners_geom_out, int* CornersSize_geom_out, double* RequiredVertices_geom_out, int* RequiredVerticesSize_geom_out, double* RequiredCrackedEdges_geom_out, int* RequiredCrackedEdgesSize_geom_out, double* CrackedEdges_geom_out, int* CrackedEdgesSize_geom_out, double* SubDomains_geom_out, int* SubDomainsSize_geom_out, double* Vertices_mesh_in, int* VerticesSize_mesh_in, double* Edges_mesh_in, int* EdgesSize_mesh_in, double* Triangles_mesh_in, int* TrianglesSize_mesh_in, double* CrackedEdges_mesh_in, int* CrackedEdgesSize_mesh_in, double* VerticesOnGeomEdge_mesh_in, int* VerticesOnGeomEdgeSize_mesh_in, double* VerticesOnGeomVertex_mesh_in, int* VerticesOnGeomVertexSize_mesh_in, double* EdgesOnGeomEdge_mesh_in, int* EdgesOnGeomEdgeSize_mesh_in, double* IssmSegments_mesh_in, int* IssmSegmentsSize_mesh_in, double* Vertices_geom_in, int* VerticesSize_geom_in, double* Edges_geom_in, int* EdgesSize_geom_in, double* Corners_geom_in, int* CornersSize_geom_in, double* RequiredVertices_geom_in, int* RequiredVerticesSize_geom_in, double* RequiredCrackedEdges_geom_in, int* RequiredCrackedEdgesSize_geom_in, double* CrackedEdges_geom_in, int* CrackedEdgesSize_geom_in, double* SubDomains_geom_in, int* SubDomainsSize_geom_in, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, double* hminVertices, double* hmaxVertices, double* hVertices, double* metric, double* field, double err)
+#define BAMGMESHOUT VerticesSize_mesh_out, Vertices_mesh_out, EdgesSize_mesh_out, Edges_mesh_out, TrianglesSize_mesh_out, Triangles_mesh_out, CrackedEdgesSize_mesh_out, CrackedEdges_mesh_out, VerticesOnGeomEdgeSize_mesh_out, VerticesOnGeomEdge_mesh_out, VerticesOnGeomVertexSize_mesh_out, VerticesOnGeomVertex_mesh_out, EdgesOnGeomEdgeSize_mesh_out, EdgesOnGeomEdge_mesh_out, IssmSegmentsSize_mesh_out, IssmSegments_mesh_out
+#define BAMGGEOMOUT VerticesSize_geom_out, Vertices_geom_out, EdgesSize_geom_out, Edges_geom_out, CornersSize_geom_out, Corners_geom_out, RequiredVerticesSize_geom_out, RequiredVertices_geom_out, RequiredEdgesSize_geom_out, RequiredEdges_geom_out, CrackedEdgesSize_geom_out, CrackedEdges_geom_out, SubDomainsSize_geom_out, SubDomains_geom_out
+#define WRAPPER(modulename) extern "C" { int  BamgMesherModule(int* VerticesSize_mesh_out, double* Vertices_mesh_out, int* EdgesSize_mesh_out, double* Edges_mesh_out, int* TrianglesSize_mesh_out, double* Triangles_mesh_out, int* CrackedEdgesSize_mesh_out, double* CrackedEdges_mesh_out, int* VerticesOnGeomEdgeSize_mesh_out, double* VerticesOnGeomEdge_mesh_out, int* VerticesOnGeomVertexSize_mesh_out, double* VerticesOnGeomVertex_mesh_out, int* EdgesOnGeomEdgeSize_mesh_out, double* EdgesOnGeomEdge_mesh_out, int* IssmSegmentsSize_mesh_out, double* IssmSegments_mesh_out, int* VerticesSize_geom_out, double* Vertices_geom_out, int* EdgesSize_geom_out, double* Edges_geom_out, int* CornersSize_geom_out, double* Corners_geom_out, int* RequiredVerticesSize_geom_out, double* RequiredVertices_geom_out, int* RequiredEdgesSize_geom_out, double* RequiredEdges_geom_out, int* CrackedEdgesSize_geom_out, double* CrackedEdges_geom_out, int* SubDomainsSize_geom_out, double* SubDomains_geom_out, int* VerticesSize_mesh_in, double* Vertices_mesh_in, int* EdgesSize_mesh_in, double* Edges_mesh_in, int* TrianglesSize_mesh_in, double* Triangles_mesh_in, int* CrackedEdgesSize_mesh_in, double* CrackedEdges_mesh_in, int* VerticesOnGeomEdgeSize_mesh_in, double* VerticesOnGeomEdge_mesh_in, int* VerticesOnGeomVertexSize_mesh_in, double* VerticesOnGeomVertex_mesh_in, int* EdgesOnGeomEdgeSize_mesh_in, double* EdgesOnGeomEdge_mesh_in, int* IssmSegmentsSize_mesh_in, double* IssmSegments_mesh_in, int* VerticesSize_geom_in, double* Vertices_geom_in, int* EdgesSize_geom_in, double* Edges_geom_in, int* CornersSize_geom_in, double* Corners_geom_in, int* RequiredVerticesSize_geom_in, double* RequiredVertices_geom_in, int* RequiredEdgesSize_geom_in, double* RequiredEdges_geom_in, int* CrackedEdgesSize_geom_in, double* CrackedEdges_geom_in, int* SubDomainsSize_geom_in, double* SubDomains_geom_in, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int* hVerticesSize, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err)
 #define _DO_NOT_LOAD_GLOBALS_//we only load globals for TriangleModule.js, not other modules!
 #endif
Index: /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.js
===================================================================
--- /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.js	(revision 22877)
+++ /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.js	(revision 22878)
@@ -40,35 +40,35 @@
 	//Retrieve domain arrays, and allocate on Module heap: 
 	//input
+    var pVerticesSize_mesh_in               = intsToHeap([bamgmesh.Vertices.length, bamgmesh.Vertices[0].length]);
     var pVertices_mesh_in                   = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.Vertices));
-    var pVerticesSize_mesh_in               = intsToHeap([bamgmesh.Vertices.length, bamgmesh.Vertices[0].length]);
+    var pEdgesSize_mesh_in                  = intsToHeap([bamgmesh.Edges.length, bamgmesh.Edges[0].length]);
     var pEdges_mesh_in                      = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.Edges));
-    var pEdgesSize_mesh_in                  = intsToHeap([bamgmesh.Edges.length, bamgmesh.Edges[0].length]);
+    var pTrianglesSize_mesh_in              = intsToHeap([bamgmesh.Triangle.length, bamgmesh.Triangle[0].length]);
     var pTriangles_mesh_in                  = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.Triangle));
-    var pTrianglesSize_mesh_in              = intsToHeap([bamgmesh.Triangle.length, bamgmesh.Triangle[0].length]);
+    var pCrackedEdgesSize_mesh_in           = intsToHeap([bamgmesh.CrackedEdges.length, bamgmesh.CrackedEdges[0].length]);
     var pCrackedEdges_mesh_in               = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.CrackedEdges));
-    var pCrackedEdgesSize_mesh_in           = intsToHeap([bamgmesh.CrackedEdges.length, bamgmesh.CrackedEdges[0].length]);
+    var pVerticesOnGeomEdgeSize_mesh_in     = intsToHeap([bamgmesh.VerticesOnGeomEdge.length, bamgmesh.VerticesOnGeomEdge[0].length]);
     var pVerticesOnGeomEdge_mesh_in         = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.VerticesOnGeomEdge));
-    var pVerticesOnGeomEdgeSize_mesh_in     = intsToHeap([bamgmesh.VerticesOnGeomEdge.length, bamgmesh.VerticesOnGeomEdge[0].length]);
+    var pVerticesOnGeomVertexSize_mesh_in   = intsToHeap([bamgmesh.VerticesOnGeomVertex.length, bamgmesh.VerticesOnGeomVertex[0].length]);
     var pVerticesOnGeomVertex_mesh_in       = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.VerticesOnGeomVertex));
-    var pVerticesOnGeomVertexSize_mesh_in   = intsToHeap([bamgmesh.VerticesOnGeomVertex.length, bamgmesh.VerticesOnGeomVertex[0].length]);
+    var pEdgesOnGeomEdgeSize_mesh_in        = intsToHeap([bamgmesh.EdgesOnGeomEdge.length, bamgmesh.EdgesOnGeomEdge[0].length]);
     var pEdgesOnGeomEdge_mesh_in            = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.EdgesOnGeomEdge));
-    var pEdgesOnGeomEdgeSize_mesh_in        = intsToHeap([bamgmesh.EdgesOnGeomEdge.length, bamgmesh.EdgesOnGeomEdge[0].length]);
+    var pIssmSegmentsSize_mesh_in           = intsToHeap([bamgmesh.IssmSegments.length, bamgmesh.IssmSegments[0].length]);
     var pIssmSegments_mesh_in               = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.IssmSegments));
-    var pIssmSegmentsSize_mesh_in           = intsToHeap([bamgmesh.IssmSegments.length, bamgmesh.IssmSegments[0].length]);
-
+
+    var pVerticesSize_geom_in               = intsToHeap([bamggeom.Vertices.length, bamggeom.Vertices[0].length]);
     var pVertices_geom_in                   = doublesToHeap(Array.prototype.concat.apply([], bamggeom.Vertices));
-    var pVerticesSize_geom_in               = intsToHeap([bamggeom.Vertices.length, bamggeom.Vertices[0].length]);
+    var pEdgesSize_geom_in                  = intsToHeap([bamggeom.Edges.length, bamggeom.Edges[0].length]);
     var pEdges_geom_in                      = doublesToHeap(Array.prototype.concat.apply([], bamggeom.Edges));
-    var pEdgesSize_geom_in                  = intsToHeap([bamggeom.Edges.length, bamggeom.Edges[0].length]);
+    var pCornersSize_geom_in                = intsToHeap([bamggeom.Corners.length, bamggeom.Corners[0].length]);
     var pCorners_geom_in                    = doublesToHeap(Array.prototype.concat.apply([], bamggeom.Corners));
-    var pCornersSize_geom_in                = intsToHeap([bamggeom.Corners.length, bamggeom.Corners[0].length]);
+    var pRequiredVerticesSize_geom_in       = intsToHeap([bamggeom.RequiredVertices.length, bamggeom.RequiredVertices[0].length]);
     var pRequiredVertices_geom_in           = doublesToHeap(Array.prototype.concat.apply([], bamggeom.RequiredVertices));
-    var pRequiredVerticesSize_geom_in       = intsToHeap([bamggeom.RequiredVertices.length, bamggeom.RequiredVertices[0].length]);
+    var pRequiredCrackedEdgesSize_geom_in   = intsToHeap([bamggeom.RequiredCrackedEdges.length, bamggeom.RequiredCrackedEdges[0].length]);
     var pRequiredCrackedEdges_geom_in       = doublesToHeap(Array.prototype.concat.apply([], bamggeom.RequiredCrackedEdges));
-    var pRequiredCrackedEdgesSize_geom_in   = intsToHeap([bamggeom.RequiredCrackedEdges.length, bamggeom.RequiredCrackedEdges[0].length]);
+    var pCrackedEdgesSize_geom_in           = intsToHeap([bamggeom.CrackedEdges.length, bamggeom.CrackedEdges[0].length]);
     var pCrackedEdges_geom_in               = doublesToHeap(Array.prototype.concat.apply([], bamggeom.CrackedEdges));
-    var pCrackedEdgesSize_geom_in           = intsToHeap([bamggeom.CrackedEdges.length, bamggeom.CrackedEdges[0].length]);
+    var pSubDomainsSize_geom_in             = intsToHeap([bamggeom.SubDomains.length, bamggeom.SubDomains[0].length]);
     var pSubDomains_geom_in                 = doublesToHeap(Array.prototype.concat.apply([], bamggeom.SubDomains));
-    var pSubDomainsSize_geom_in             = intsToHeap([bamggeom.SubDomains.length, bamggeom.SubDomains[0].length]);
 
     var anisomax                            = bamgopts.anisomax;
@@ -91,48 +91,49 @@
     var hmin                                = bamgopts.hmin;
     var hmax                                = bamgopts.hmax;
+    var phminVerticesSize                   = intsToHeap([bamgopts.hminVertices.length, bamgopts.hminVertices[0].length]);
     var phminVertices                       = doublesToHeap(Array.prototype.concat.apply([], bamgopts.hminVertices));
-    var phminVerticesSize                   = intsToHeap([bamgopts.hminVertices.length, bamgopts.hminVertices[0].length]);
+    var phmaxVerticesSize                   = intsToHeap([bamgopts.hmaxVertices.length, bamgopts.hmaxVertices[0].length]);
     var phmaxVertices                       = doublesToHeap(Array.prototype.concat.apply([], bamgopts.hmaxVertices));
-    var phmaxVerticesSize                   = intsToHeap([bamgopts.hmaxVertices.length, bamgopts.hmaxVertices[0].length]);
+    var phVerticesSize                      = intsToHeap([bamgopts.hVertices.length, bamgopts.hVertices[0].length]);
     var phVertices                          = doublesToHeap(Array.prototype.concat.apply([], bamgopts.hVertices));
-    var phVerticesSize                      = intsToHeap([bamgopts.hVertices.length, bamgopts.hVertices[0].length]);
+    var pmetricSize                         = intsToHeap([bamgopts.metric.length, bamgopts.metric[0].length]);
     var pmetric                             = doublesToHeap(Array.prototype.concat.apply([], bamgopts.metric));
-    var pmetricSize                         = intsToHeap([bamgopts.metric.length, bamgopts.metric[0].length]);
+    var pfieldSize                          = intsToHeap([bamgopts.field.length, bamgopts.field[0].length]);
     var pfield                              = doublesToHeap(Array.prototype.concat.apply([], bamgopts.field));
-    var pfieldSize                          = intsToHeap([bamgopts.field.length, bamgopts.field[0].length]);
-    var err                                 = bamgopts.err;
+    var perrSize                            = intsToHeap([bamgopts.err.length, bamgopts.err[0].length]);
+    var perr                                = doublesToHeap(Array.prototype.concat.apply([], bamgopts.err));
 	
 	//output
+    var pVerticesSize_geom_out              = Module._malloc(4); 
     var pVertices_geom_out                  = Module._malloc(4);
-    var pVerticesSize_geom_out              = Module._malloc(4); 
+    var pEdgesSize_geom_out                 = Module._malloc(4); 
     var pEdges_geom_out                     = Module._malloc(4); 
-    var pEdgesSize_geom_out                 = Module._malloc(4); 
+    var pCornersSize_geom_out               = Module._malloc(4); 
     var pCorners_geom_out                   = Module._malloc(4); 
-    var pCornersSize_geom_out               = Module._malloc(4); 
+    var pRequiredVerticesSize_geom_out      = Module._malloc(4); 
     var pRequiredVertices_geom_out          = Module._malloc(4); 
-    var pRequiredVerticesSize_geom_out      = Module._malloc(4); 
+    var pRequiredCrackedEdgesSize_geom_out  = Module._malloc(4); 
     var pRequiredCrackedEdges_geom_out      = Module._malloc(4); 
-    var pRequiredCrackedEdgesSize_geom_out  = Module._malloc(4); 
+    var pCrackedEdgesSize_geom_out          = Module._malloc(4); 
     var pCrackedEdges_geom_out              = Module._malloc(4); 
-    var pCrackedEdgesSize_geom_out          = Module._malloc(4); 
+    var pSubDomainsSize_geom_out            = Module._malloc(4); 
     var pSubDomains_geom_out                = Module._malloc(4); 
-    var pSubDomainsSize_geom_out            = Module._malloc(4); 
-
+
+    var pVerticesSize_mesh_out              = Module._malloc(4); 
     var pVertices_mesh_out                  = Module._malloc(4); 
-    var pVerticesSize_mesh_out              = Module._malloc(4); 
+    var pEdgesSize_mesh_out                 = Module._malloc(4); 
     var pEdges_mesh_out                     = Module._malloc(4); 
-    var pEdgesSize_mesh_out                 = Module._malloc(4); 
+    var pTrianglesSize_mesh_out             = Module._malloc(4); 
     var pTriangles_mesh_out                 = Module._malloc(4); 
-    var pTrianglesSize_mesh_out             = Module._malloc(4); 
+    var pCrackedEdgesSize_mesh_out          = Module._malloc(4); 
     var pCrackedEdges_mesh_out              = Module._malloc(4); 
-    var pCrackedEdgesSize_mesh_out          = Module._malloc(4); 
+    var pVerticesOnGeomEdgeSize_mesh_out    = Module._malloc(4); 
     var pVerticesOnGeomEdge_mesh_out        = Module._malloc(4); 
-    var pVerticesOnGeomEdgeSize_mesh_out    = Module._malloc(4); 
+    var pVerticesOnGeomVertexSize_mesh_out  = Module._malloc(4); 
     var pVerticesOnGeomVertex_mesh_out      = Module._malloc(4); 
-    var pVerticesOnGeomVertexSize_mesh_out  = Module._malloc(4); 
+    var pEdgesOnGeomEdgeSize_mesh_out       = Module._malloc(4); 
     var pEdgesOnGeomEdge_mesh_out           = Module._malloc(4); 
-    var pEdgesOnGeomEdgeSize_mesh_out       = Module._malloc(4); 
+    var pIssmSegmentsSize_mesh_out          = Module._malloc(4); 
     var pIssmSegments_mesh_out              = Module._malloc(4); 
-    var pIssmSegmentsSize_mesh_out          = Module._malloc(4); 
 	//}}}
 
@@ -147,9 +148,9 @@
 	//Call BamgMesher module: 
 	BamgMesherModule(
-        pVertices_mesh_out, pVerticesSize_mesh_out, pEdges_mesh_out, pEdgesSize_mesh_out, pTriangles_mesh_out, pTrianglesSize_mesh_out, pCrackedEdges_mesh_out, pCrackedEdgesSize_mesh_out, pVerticesOnGeomEdge_mesh_out, pVerticesOnGeomEdgeSize_mesh_out, pVerticesOnGeomVertex_mesh_out, pVerticesOnGeomVertexSize_mesh_out, pEdgesOnGeomEdge_mesh_out, pEdgesOnGeomEdgeSize_mesh_out, pIssmSegments_mesh_out, pIssmSegmentsSize_mesh_out, 
-        pVertices_geom_out, pVerticesSize_geom_out, pEdges_geom_out, pEdgesSize_geom_out, pCorners_geom_out, pCornersSize_geom_out, pRequiredVertices_geom_out, pRequiredVerticesSize_geom_out, pRequiredCrackedEdges_geom_out, pRequiredCrackedEdgesSize_geom_out, pCrackedEdges_geom_out, pCrackedEdgesSize_geom_out, pSubDomaouts_geom_out, pSubDomaoutsSize_geom_out, 
-        pVertices_mesh_in, pVerticesSize_mesh_in, pEdges_mesh_in, pEdgesSize_mesh_in, pTriangles_mesh_in, pTrianglesSize_mesh_in, pCrackedEdges_mesh_in, pCrackedEdgesSize_mesh_in, pVerticesOnGeomEdge_mesh_in, pVerticesOnGeomEdgeSize_mesh_in, pVerticesOnGeomVertex_mesh_in, pVerticesOnGeomVertexSize_mesh_in, pEdgesOnGeomEdge_mesh_in, pEdgesOnGeomEdgeSize_mesh_in, pIssmSegments_mesh_in, pIssmSegmentsSize_mesh_in, 
-        pVertices_geom_in, pVerticesSize_geom_in, pEdges_geom_in, pEdgesSize_geom_in, pCorners_geom_in, pCornersSize_geom_in, pRequiredVertices_geom_in, pRequiredVerticesSize_geom_in, pRequiredCrackedEdges_geom_in, pRequiredCrackedEdgesSize_geom_in, pCrackedEdges_geom_in, pCrackedEdgesSize_geom_in, pSubDomains_geom_in, pSubDomainsSize_geom_in, 
-        anisomax, cutoff, coeff, errg, gradation, Hessiantype, maxnbv, maxsubdiv, Metrictype, nbjacobi, nbsmooth, omega, power, verbose, Crack, KeepVertices, splitcorners, hmin, hmax, phminVertices, phminVerticesSize, phmaxVertices, phmaxVerticesSize, phVertices, phVerticesSize, pmetric, pmetricSize, pfield, pfieldSize, err);
+        pVerticesSize_mesh_out, pVertices_mesh_out, pEdgesSize_mesh_out, pEdges_mesh_out, pTrianglesSize_mesh_out, pTriangles_mesh_out, pCrackedEdgesSize_mesh_out, pCrackedEdges_mesh_out, pVerticesOnGeomEdgeSize_mesh_out, pVerticesOnGeomEdge_mesh_out, pVerticesOnGeomVertexSize_mesh_out, pVerticesOnGeomVertex_mesh_out, pEdgesOnGeomEdgeSize_mesh_out, pEdgesOnGeomEdge_mesh_out, pIssmSegmentsSize_mesh_out, pIssmSegments_mesh_out, 
+        pVerticesSize_geom_out, pVertices_geom_out, pEdgesSize_geom_out, pEdges_geom_out, pCornersSize_geom_out, pCorners_geom_out, pRequiredVerticesSize_geom_out, pRequiredVertices_geom_out, pRequiredCrackedEdgesSize_geom_out, pRequiredCrackedEdges_geom_out, pCrackedEdgesSize_geom_out, pCrackedEdges_geom_out, pSubDomaoutsSize_geom_out, pSubDomaouts_geom_out, 
+        pVerticesSize_mesh_in, pVertices_mesh_in, pEdgesSize_mesh_in, pEdges_mesh_in, pTrianglesSize_mesh_in, pTriangles_mesh_in, pCrackedEdgesSize_mesh_in, pCrackedEdges_mesh_in, pVerticesOnGeomEdgeSize_mesh_in, pVerticesOnGeomEdge_mesh_in, pVerticesOnGeomVertexSize_mesh_in, pVerticesOnGeomVertex_mesh_in, pEdgesOnGeomEdgeSize_mesh_in, pEdgesOnGeomEdge_mesh_in, pIssmSegmentsSize_mesh_in, pIssmSegments_mesh_in, 
+        pVerticesSize_geom_in, pVertices_geom_in, pEdgesSize_geom_in, pEdges_geom_in, pCornersSize_geom_in, pCorners_geom_in, pRequiredVerticesSize_geom_in, pRequiredVertices_geom_in, pRequiredCrackedEdgesSize_geom_in, pRequiredCrackedEdges_geom_in, pCrackedEdgesSize_geom_in, pCrackedEdges_geom_in, pSubDomaoutsSize_geom_in, pSubDomaouts_geom_in, 
+        anisomax, cutoff, coeff, errg, gradation, Hessiantype, maxnbv, maxsubdiv, Metrictype, nbjacobi, nbsmooth, omega, power, verbose, Crack, KeepVertices, splitcorners, hmin, hmax, phminVerticesSize, phminVertices, phmaxVerticesSize, phmaxVertices, phVerticesSize, phVertices, pmetricSize, pmetric, pfieldSize, pfield, perrSize, perr);
 	
 	/*Dynamic copying from heap: {{{*/
@@ -194,78 +195,80 @@
 
 	/*Free ressources: */
+    Module._free(pVerticesSize_mesh_in);
     Module._free(pVertices_mesh_in);
-    Module._free(pVerticesSize_mesh_in);
+    Module._free(pEdgesSize_mesh_in);
     Module._free(pEdges_mesh_in);
-    Module._free(pEdgesSize_mesh_in);
+    Module._free(pTrianglesSize_mesh_in);
     Module._free(pTriangles_mesh_in);
-    Module._free(pTrianglesSize_mesh_in);
+    Module._free(pCrackedEdgesSize_mesh_in);
     Module._free(pCrackedEdges_mesh_in);
-    Module._free(pCrackedEdgesSize_mesh_in);
+    Module._free(pVerticesOnGeomEdgeSize_mesh_in);
     Module._free(pVerticesOnGeomEdge_mesh_in);
-    Module._free(pVerticesOnGeomEdgeSize_mesh_in);
+    Module._free(pVerticesOnGeomVertexSize_mesh_in);
     Module._free(pVerticesOnGeomVertex_mesh_in);
-    Module._free(pVerticesOnGeomVertexSize_mesh_in);
+    Module._free(pEdgesOnGeomEdgeSize_mesh_in);
     Module._free(pEdgesOnGeomEdge_mesh_in);
-    Module._free(pEdgesOnGeomEdgeSize_mesh_in);
+    Module._free(pIssmSegmentsSize_mesh_in);
     Module._free(pIssmSegments_mesh_in);
-    Module._free(pIssmSegmentsSize_mesh_in);
-
+
+    Module._free(pVerticesSize_geom_in);
     Module._free(pVertices_geom_in);
-    Module._free(pVerticesSize_geom_in);
+    Module._free(pEdgesSize_geom_in);
     Module._free(pEdges_geom_in);
-    Module._free(pEdgesSize_geom_in);
+    Module._free(pCornersSize_geom_in);
     Module._free(pCorners_geom_in);
-    Module._free(pCornersSize_geom_in);
+    Module._free(pRequiredVerticesSize_geom_in);
     Module._free(pRequiredVertices_geom_in);
-    Module._free(pRequiredVerticesSize_geom_in);
+    Module._free(pRequiredCrackedEdgesSize_geom_in);
     Module._free(pRequiredCrackedEdges_geom_in);
-    Module._free(pRequiredCrackedEdgesSize_geom_in);
+    Module._free(pCrackedEdgesSize_geom_in);
     Module._free(pCrackedEdges_geom_in);
-    Module._free(pCrackedEdgesSize_geom_in);
+    Module._free(pSubDomainsSize_geom_in);
     Module._free(pSubDomains_geom_in);
-    Module._free(pSubDomainsSize_geom_in);
-
+
+    Module._free(pVerticesSize_geom_out);
     Module._free(pVertices_geom_out);
-    Module._free(pVerticesSize_geom_out);
+    Module._free(pEdgesSize_geom_out);
     Module._free(pEdges_geom_out);
-    Module._free(pEdgesSize_geom_out);
+    Module._free(pCornersSize_geom_out);
     Module._free(pCorners_geom_out);
-    Module._free(pCornersSize_geom_out);
+    Module._free(pRequiredVerticesSize_geom_out);
     Module._free(pRequiredVertices_geom_out);
-    Module._free(pRequiredVerticesSize_geom_out);
+    Module._free(pRequiredCrackedEdgesSize_geom_out);
     Module._free(pRequiredCrackedEdges_geom_out);
-    Module._free(pRequiredCrackedEdgesSize_geom_out);
+    Module._free(pCrackedEdgesSize_geom_out);
     Module._free(pCrackedEdges_geom_out);
-    Module._free(pCrackedEdgesSize_geom_out);
+    Module._free(pSubDomainsSize_geom_out);
     Module._free(pSubDomains_geom_out);
-    Module._free(pSubDomainsSize_geom_out);
-
+
+    Module._free(pVerticesSize_mesh_out);
     Module._free(pVertices_mesh_out);
-    Module._free(pVerticesSize_mesh_out);
+    Module._free(pEdgesSize_mesh_out);
     Module._free(pEdges_mesh_out);
-    Module._free(pEdgesSize_mesh_out);
+    Module._free(pTrianglesSize_mesh_out);
     Module._free(pTriangles_mesh_out);
-    Module._free(pTrianglesSize_mesh_out);
+    Module._free(pCrackedEdgesSize_mesh_out);
     Module._free(pCrackedEdges_mesh_out);
-    Module._free(pCrackedEdgesSize_mesh_out);
+    Module._free(pVerticesOnGeomEdgeSize_mesh_out);
     Module._free(pVerticesOnGeomEdge_mesh_out);
-    Module._free(pVerticesOnGeomEdgeSize_mesh_out);
+    Module._free(pVerticesOnGeomVertexSize_mesh_out);
     Module._free(pVerticesOnGeomVertex_mesh_out);
-    Module._free(pVerticesOnGeomVertexSize_mesh_out);
+    Module._free(pEdgesOnGeomEdgeSize_mesh_out);
     Module._free(pEdgesOnGeomEdge_mesh_out);
-    Module._free(pEdgesOnGeomEdgeSize_mesh_out);
+    Module._free(pIssmSegmentsSize_mesh_out);
     Module._free(pIssmSegments_mesh_out);
-    Module._free(pIssmSegmentsSize_mesh_out);
-
+
+    Module._free(phminVerticesSize);
     Module._free(phminVertices);
-    Module._free(phminVerticesSize);
+    Module._free(phmaxVerticesSize);
     Module._free(phmaxVertices);
-    Module._free(phmaxVerticesSize);
+    Module._free(phVerticesSize);
     Module._free(phVertices);
-    Module._free(phVerticesSize);
+    Module._free(pmetricSize);
     Module._free(pmetric);
-    Module._free(pmetricSize);
+    Module._free(pfieldSize);
     Module._free(pfield);
-    Module._free(pfieldSize);
+    Module._free(perrSize);
+    Module._free(perr);
 
 	return return_array;
Index: /issm/trunk-jpl/src/wrappers/javascript/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 22877)
+++ /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 22878)
@@ -7,5 +7,6 @@
 AM_CPPFLAGS+=  -DISSM_PREFIX='"$(prefix)"'
 
-js_scripts = ${ISSM_DIR}/src/wrappers/Triangle/Triangle.js  \
+js_scripts = ${ISSM_DIR}/src/wrappers/BamgMesher/BamgMesher.js \
+             ${ISSM_DIR}/src/wrappers/Triangle/Triangle.js  \
 			 ${ISSM_DIR}/src/wrappers/NodeConnectivity/NodeConnectivity.js\
 			 ${ISSM_DIR}/src/wrappers/ContourToMesh/ContourToMesh.js\
Index: /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 22877)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 22878)
@@ -125,5 +125,5 @@
 /*}}}*/
 /*FUNCTION FetchData(BamgGeom** pbamggeom, double* vertices, int nods){{{*/
-void FetchData(BamgGeom** pbamggeom, double* Vertices, int* VerticesSize, double* Edges, int* EdgesSize, double* Corners, int* CornersSize, double* RequiredVertices, int* RequiredVerticesSize, double* RequiredCrackedEdges, int* RequiredCrackedEdgesSize, double* CrackedEdges, int* CrackedEdgesSize, double* SubDomains, int* SubDomainsSize){
+void FetchData(BamgGeom** pbamggeom, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* CornersSize, double* Corners, int* RequiredVerticesSize, double* RequiredVertices, int* RequiredEdgesSize, double* RequiredEdges, int* CrackedEdgesSize, double* CrackedEdges, int* SubDomainsSize, double* SubDomains){
 
 	/*Initialize output*/
@@ -144,5 +144,5 @@
 /*}}}*/
 /*FUNCTION FetchData(BamgMesh** pbamgmesh, double* vertices, int nods){{{*/
-void FetchData(BamgMesh** pbamgmesh, double* Vertices, int* VerticesSize, double* Edges, int* EdgesSize, double* Triangles, int* TrianglesSize, double* CrackedEdges, int* CrackedEdgesSize, double* VerticesOnGeomEdge, int* VerticesOnGeomEdgeSize, double* VerticesOnGeomVertex, int* VerticesOnGeomVertexSize, double* EdgesOnGeomEdge, int* EdgesOnGeomEdgeSize, double* IssmSegments, int* IssmSegmentsSize){
+void FetchData(BamgMesh** pbamgmesh, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* TrianglesSize, double* Triangles, int* CrackedEdgesSize, double* CrackedEdges, int* VerticesOnGeomEdgeSize, double* VerticesOnGeomEdge, int* VerticesOnGeomVertexSize, double* VerticesOnGeomVertex, int* EdgesOnGeomEdgeSize, double* EdgesOnGeomEdge, int* IssmSegmentsSize, double* IssmSegments){
 
 	/*Initialize output*/
@@ -150,12 +150,12 @@
 
 	/*Fetch all fields*/
-	FetchData(&bamggeom->Vertices, &bamggeom->VerticesSize[0], &bamggeom->VerticesSize[1], Vertices, VerticesSize[0], VerticesSize[1]);
-	FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], Edges, EdgesSize[0], EdgesSize[1]);
-	FetchData(&bamggeom->Triangles, &bamggeom->TrianglesSize[0], &bamggeom->TrianglesSize[1], Triangles, TrianglesSize[0], TrianglesSize[1]);
-	FetchData(&bamggeom->CrackedEdges, &bamggeom->CrackedEdgesSize[0], &bamggeom->CrackedEdgesSize[1], CrackedEdges, CrackedEdgesSize[0], CrackedEdgesSize[1]);
-	FetchData(&bamggeom->VerticesOnGeomEdge, &bamggeom->VerticesOnGeomEdgeSize[0], &bamggeom->VerticesOnGeomEdgeSize[1], VerticesOnGeomEdge, VerticesOnGeomEdgeSize[0], VerticesOnGeomEdgeSize[1]);
-	FetchData(&bamggeom->VerticesOnGeomVertex, &bamggeom->VerticesOnGeomVertexSize[0], &bamggeom->VerticesOnGeomVertexSize[1], VerticesOnGeomVertex, VerticesOnGeomVertexSize[0], VerticesOnGeomVertexSize[1]);
-	FetchData(&bamggeom->EdgesOnGeomEdge, &bamggeom->EdgesOnGeomEdgeSize[0], &bamggeom->EdgesOnGeomEdgeSize[1], EdgesOnGeomEdge, EdgesOnGeomEdgeSize[0], EdgesOnGeomEdgeSize[1]);
-	FetchData(&bamggeom->IssmSegments, &bamggeom->IssmSegmentsSize[0], &bamggeom->IssmSegmentsSize[1], IssmSegments, IssmSegmentsSize[0], IssmSegmentsSize[1]);
+	FetchData(&bamgmesh->Vertices, &bamgmesh->VerticesSize[0], &bamgmesh->VerticesSize[1], Vertices, VerticesSize[0], VerticesSize[1]);
+	FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], Edges, EdgesSize[0], EdgesSize[1]);
+	FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], Triangles, TrianglesSize[0], TrianglesSize[1]);
+	FetchData(&bamgmesh->CrackedEdges, &bamgmesh->CrackedEdgesSize[0], &bamgmesh->CrackedEdgesSize[1], CrackedEdges, CrackedEdgesSize[0], CrackedEdgesSize[1]);
+	FetchData(&bamgmesh->VerticesOnGeomEdge, &bamgmesh->VerticesOnGeomEdgeSize[0], &bamgmesh->VerticesOnGeomEdgeSize[1], VerticesOnGeomEdge, VerticesOnGeomEdgeSize[0], VerticesOnGeomEdgeSize[1]);
+	FetchData(&bamgmesh->VerticesOnGeomVertex, &bamgmesh->VerticesOnGeomVertexSize[0], &bamgmesh->VerticesOnGeomVertexSize[1], VerticesOnGeomVertex, VerticesOnGeomVertexSize[0], VerticesOnGeomVertexSize[1]);
+	FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], EdgesOnGeomEdge, EdgesOnGeomEdgeSize[0], EdgesOnGeomEdgeSize[1]);
+	FetchData(&bamgmesh->IssmSegments, &bamgmesh->IssmSegmentsSize[0], &bamgmesh->IssmSegmentsSize[1], IssmSegments, IssmSegmentsSize[0], IssmSegmentsSize[1]);
 
 	/*Assign output pointers:*/
@@ -164,5 +164,5 @@
 /*}}}*/
 /*FUNCTION FetchData(BamgMesh** pbamgopts, double* vertices, int nods){{{*/
-void FetchData(BamgOpts** pbamgopts, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, double* hminVertices, double* hmaxVertices, double* hVertices, double* metric, double* field, double err){
+void FetchData(BamgOpts** pbamgopts, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int* hVerticesSize, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){
 
 	BamgOpts *bamgopts      = new BamgOpts();
@@ -192,11 +192,15 @@
     bamgopts->hmin	        = hmin;
     bamgopts->hmax       	= hmax;
-    bamgopts->hminVertices	= xNew<IssmPDouble>(hminVerticesNods);  xMemCpy<IssmPDouble>(bamgopts->hminVertices, hminVertices, hminVerticesNods);
-    bamgopts->hmaxVertices  = xNew<IssmPDouble>(hmaxVerticesNods);  xMemCpy<IssmPDouble>(bamgopts->hmaxVertices, hmaxVertices, hmaxVerticesNods);
-    bamgopts->hVertices     = xNew<IssmPDouble>(hVerticesNods);     xMemCpy<IssmPDouble>(bamgopts->hVertices, hVertices, hVerticesNods);
-    bamgopts->field	        = xNew<IssmPDouble>(fieldNods);         xMemCpy<IssmPDouble>(bamgopts->field, field, fieldNods);
-    bamgopts->metric	    = xNew<IssmPDouble>(metricNods);        xMemCpy<IssmPDouble>(bamgopts->metric, metric, metricNods);
-    bamgopts->err	        = err;
-
+	FetchData(&bamgopts->hminVertices, &bamgopts->hminVerticesSize[0], &bamgopts->hminVerticesSize[1], hminVertices, hminVerticesSize[0], hminVerticesSize[1]);
+	FetchData(&bamgopts->hmaxVertices, &bamgopts->hmaxVerticesSize[0], &bamgopts->hmaxVerticesSize[1], hmaxVertices, hmaxVerticesSize[0], hmaxVerticesSize[1]);
+	FetchData(&bamgopts->hVertices, &bamgopts->hVerticesSize[0], &bamgopts->hVerticesSize[1], hVertices, hVerticesSize[0], hVerticesSize[1]);
+	FetchData(&bamgopts->field, &bamgopts->fieldSize[0], &bamgopts->fieldSize[1], field, fieldSize[0], fieldSize[1]);
+	FetchData(&bamgopts->metric, &bamgopts->metricSize[0], &bamgopts->metricSize[1], metric, metricSize[0], metricSize[1]);
+	FetchData(&bamgopts->err, &bamgopts->errSize[0], &bamgopts->errSize[1], err, errSize[0], errSize[1]);
+    
+	/*Additional checks*/
+	bamgopts->Check();
+
+	/*Assign output pointers:*/
 	*pbamgopts              = bamgopts;
 }
Index: /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 22877)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 22878)
@@ -37,7 +37,7 @@
 void FetchData(int **pmatrix, int* pM, int* pN, int* matrixin, int M, int N);
 void FetchData(Contours** pcontours,double* x, double* y, int nods);
-void FetchData(BamgGeom** pbamggeom, double* Vertices, int* VerticesSize, double* Edges, int* EdgesSize, double* Corners, int* CornersSize, double* RequiredVertices, int* RequiredVerticesSize, double* RequiredCrackedEdges, int* RequiredCrackedEdgesSize, double* CrackedEdges, int* CrackedEdgesSize, double* SubDomains, int* SubDomainsSize);
-void FetchData(BamgMesh** pbamgmesh, double* Vertices, int* VerticesSize, double* Edges, int* EdgesSize, double* Triangles, int* TrianglesSize, double* CrackedEdges, int* CrackedEdgesSize, double* VerticesOnGeomEdge, int* VerticesOnGeomEdgeSize, double* VerticesOnGeomVertex, int* VerticesOnGeomVertexSize, double* EdgesOnGeomEdge, int* EdgesOnGeomEdgeSize, double* IssmSegments, int* IssmSegmentsSize);
-void FetchData(BamgOpts** pbamgopts, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, double* hminVertices, double* hmaxVertices, double* hVertices, double* metric, double* field, double err);
+void FetchData(BamgGeom** pbamggeom, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* CornersSize, double* Corners, int* RequiredVerticesSize, double* RequiredVertices, int* RequiredEdgesSize, double* RequiredEdges, int* CrackedEdgesSize, double* CrackedEdges, int* SubDomainsSize, double* SubDomains);
+void FetchData(BamgMesh** pbamgmesh, int* VerticesSize, double* Vertices, int* EdgesSize, double* Edges, int* TrianglesSize, double* Triangles, int* CrackedEdgesSize, double* CrackedEdges, int* VerticesOnGeomEdgeSize, double* VerticesOnGeomEdge, int* VerticesOnGeomVertexSize, double* VerticesOnGeomVertex, int* EdgesOnGeomEdgeSize, double* EdgesOnGeomEdge, int* IssmSegmentsSize, double* IssmSegments);
+void FetchData(BamgOpts** pbamgopts, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int* hVerticesSize, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err);
 void FetchData(Options** poptions,int NRHS, int nrhs, const char* optionname, double optionvalue);
 void FetchData(int* pinteger,int integer);
