Index: /issm/trunk-jpl/src/c/bamg/Geometry.cpp
===================================================================
--- /issm/trunk-jpl/src/c/bamg/Geometry.cpp	(revision 22895)
+++ /issm/trunk-jpl/src/c/bamg/Geometry.cpp	(revision 22896)
@@ -41,5 +41,6 @@
 	Geometry::~Geometry() {/*{{{*/
 		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/~Geometry)*/
-		if(NbRef>0){   _printf_("Trying to delete geometry and NbRef>0, probably due to an error"); return;}
+        
+		if(NbRef>0){   _printf_("Trying to delete geometry and NbRef>0, probably due to an error. NbRef:" << NbRef); return;}
 		if(vertices)   delete [] vertices;  vertices=0;
 		if(edges)      delete [] edges;     edges=0;
@@ -551,4 +552,5 @@
 				delete [] head_v;
 				delete [] eangle;
+                _printf_("Length of edge " << i << " is 0\n");
 				_error_("Length of edge " << i << " is 0");
 			}
Index: /issm/trunk-jpl/src/m/array/arrayoperations.js
===================================================================
--- /issm/trunk-jpl/src/m/array/arrayoperations.js	(revision 22895)
+++ /issm/trunk-jpl/src/m/array/arrayoperations.js	(revision 22896)
@@ -325,5 +325,5 @@
 function ArrayRange(lower, upper) { //{{{
 
-    var range = upper - lower;
+    var range = upper - lower + 1;
     return Array.apply(null, Array(range)).map(function (val, ind) {return ind + lower;});
 
Index: /issm/trunk-jpl/src/m/mesh/bamg.js
===================================================================
--- /issm/trunk-jpl/src/m/mesh/bamg.js	(revision 22895)
+++ /issm/trunk-jpl/src/m/mesh/bamg.js	(revision 22896)
@@ -452,5 +452,5 @@
     bamg_options.coeff=options.getfieldvalue('coeff',1.);
     bamg_options.cutoff=options.getfieldvalue('cutoff',Math.pow(10,-5));
-    bamg_options.err=options.getfieldvalue('err',0.01);
+    bamg_options.err=options.getfieldvalue('err',[[0.01]]);
     bamg_options.errg=options.getfieldvalue('errg',0.1);
     bamg_options.field=options.getfieldvalue('field',[]);
@@ -472,5 +472,5 @@
     bamg_options.power=options.getfieldvalue('power',1.);
     bamg_options.splitcorners=options.getfieldvalue('splitcorners',1);
-    bamg_options.verbose=options.getfieldvalue('verbose',1);
+    bamg_options.verbose=options.getfieldvalue('verbose',6);
     //}}}
 
Index: /issm/trunk-jpl/src/m/solve/solve.js
===================================================================
--- /issm/trunk-jpl/src/m/solve/solve.js	(revision 22895)
+++ /issm/trunk-jpl/src/m/solve/solve.js	(revision 22896)
@@ -233,2 +233,3 @@
 	}//}}}
 }//}}}
+
Index: /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h	(revision 22895)
+++ /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h	(revision 22896)
@@ -47,12 +47,12 @@
 #ifdef _HAVE_JAVASCRIPT_MODULES_
 /* serial input macros: */
-#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
+#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, hminVerticesSize, hminVertices, hmaxVerticesSize, hmaxVertices, hVerticesSize, hVertices, metricSize, metric, fieldSize, field, errSize, err
 /* serial output macros: */
-#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 BAMGMESHOUT VerticesSize_mesh_out, Vertices_mesh_out, EdgesSize_mesh_out, Edges_mesh_out, TrianglesSize_mesh_out, Triangles_mesh_out, IssmEdgesSize_mesh_out, IssmEdges_mesh_out, IssmSegmentsSize_mesh_out, IssmSegments_mesh_out, VerticesOnGeomVertexSize_mesh_out, VerticesOnGeomVertex_mesh_out, VerticesOnGeomEdgeSize_mesh_out, VerticesOnGeomEdge_mesh_out, EdgesOnGeomEdgeSize_mesh_out, EdgesOnGeomEdge_mesh_out, SubDomainsSize_mesh_out, SubDomains_mesh_out, SubDomainsFromGeomSize_mesh_out, SubDomainsFromGeom_mesh_out, ElementConnectivitySize_mesh_out, ElementConnectivity_mesh_out, NodalConnectivitySize_mesh_out, NodalConnectivity_mesh_out, NodalElementConnectivitySize_mesh_out, NodalElementConnectivity_mesh_out, CrackedVerticesSize_mesh_out, CrackedVertices_mesh_out, CrackedEdgesSize_mesh_out, CrackedEdges_mesh_out, PreviousNumberingSize_mesh_out, PreviousNumbering_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!
+#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** IssmEdgesSize_mesh_out, double** IssmEdges_mesh_out, int** IssmSegmentsSize_mesh_out, double** IssmSegments_mesh_out, int** VerticesOnGeomVertexSize_mesh_out, double** VerticesOnGeomVertex_mesh_out, int** VerticesOnGeomEdgeSize_mesh_out, double** VerticesOnGeomEdge_mesh_out, int** EdgesOnGeomEdgeSize_mesh_out, double** EdgesOnGeomEdge_mesh_out, int** SubDomainsSize_mesh_out, double** SubDomains_mesh_out, int** SubDomainsFromGeomSize_mesh_out, double** SubDomainsFromGeom_mesh_out, int** ElementConnectivitySize_mesh_out, double** ElementConnectivity_mesh_out, int** NodalConnectivitySize_mesh_out, double** NodalConnectivity_mesh_out, int** NodalElementConnectivitySize_mesh_out, double** NodalElementConnectivity_mesh_out, int** CrackedVerticesSize_mesh_out, double** CrackedVertices_mesh_out, int** CrackedEdgesSize_mesh_out, double** CrackedEdges_mesh_out, int** PreviousNumberingSize_mesh_out, double** PreviousNumbering_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)
+
 #endif
 
Index: /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.js
===================================================================
--- /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.js	(revision 22895)
+++ /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.js	(revision 22896)
@@ -24,5 +24,5 @@
 	return Module.HEAPU32.slice(ptr / 4, ptr / 4 + nods);
 }
-function BamgMesher(md, bamgmesh, bamggeom, bamgopts) {
+function BamgMesher(bamgmesh_in, bamggeom_in, bamgopts) {
 /*
 	   usage: var array = Triangle(domain,rifts,area);
@@ -39,36 +39,37 @@
 	//Dynamic allocations: {{{
 	//Retrieve domain arrays, and allocate on Module heap: 
+    //For each property, calculate the size and fill with 0 if the 2nd dimension is undefined, then use the int size array to init the double array.
 	//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 pEdgesSize_mesh_in                  = intsToHeap([bamgmesh.Edges.length, bamgmesh.Edges[0].length]);
-    var pEdges_mesh_in                      = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.Edges));
-    var pTrianglesSize_mesh_in              = intsToHeap([bamgmesh.Triangle.length, bamgmesh.Triangle[0].length]);
-    var pTriangles_mesh_in                  = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.Triangle));
-    var pCrackedEdgesSize_mesh_in           = intsToHeap([bamgmesh.CrackedEdges.length, bamgmesh.CrackedEdges[0].length]);
-    var pCrackedEdges_mesh_in               = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.CrackedEdges));
-    var pVerticesOnGeomEdgeSize_mesh_in     = intsToHeap([bamgmesh.VerticesOnGeomEdge.length, bamgmesh.VerticesOnGeomEdge[0].length]);
-    var pVerticesOnGeomEdge_mesh_in         = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.VerticesOnGeomEdge));
-    var pVerticesOnGeomVertexSize_mesh_in   = intsToHeap([bamgmesh.VerticesOnGeomVertex.length, bamgmesh.VerticesOnGeomVertex[0].length]);
-    var pVerticesOnGeomVertex_mesh_in       = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.VerticesOnGeomVertex));
-    var pEdgesOnGeomEdgeSize_mesh_in        = intsToHeap([bamgmesh.EdgesOnGeomEdge.length, bamgmesh.EdgesOnGeomEdge[0].length]);
-    var pEdgesOnGeomEdge_mesh_in            = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.EdgesOnGeomEdge));
-    var pIssmSegmentsSize_mesh_in           = intsToHeap([bamgmesh.IssmSegments.length, bamgmesh.IssmSegments[0].length]);
-    var pIssmSegments_mesh_in               = doublesToHeap(Array.prototype.concat.apply([], bamgmesh.IssmSegments));
-
-    var pVerticesSize_geom_in               = intsToHeap([bamggeom.Vertices.length, bamggeom.Vertices[0].length]);
-    var pVertices_geom_in                   = doublesToHeap(Array.prototype.concat.apply([], bamggeom.Vertices));
-    var pEdgesSize_geom_in                  = intsToHeap([bamggeom.Edges.length, bamggeom.Edges[0].length]);
-    var pEdges_geom_in                      = doublesToHeap(Array.prototype.concat.apply([], bamggeom.Edges));
-    var pCornersSize_geom_in                = intsToHeap([bamggeom.Corners.length, bamggeom.Corners[0].length]);
-    var pCorners_geom_in                    = doublesToHeap(Array.prototype.concat.apply([], bamggeom.Corners));
-    var pRequiredVerticesSize_geom_in       = intsToHeap([bamggeom.RequiredVertices.length, bamggeom.RequiredVertices[0].length]);
-    var pRequiredVertices_geom_in           = doublesToHeap(Array.prototype.concat.apply([], bamggeom.RequiredVertices));
-    var pRequiredCrackedEdgesSize_geom_in   = intsToHeap([bamggeom.RequiredCrackedEdges.length, bamggeom.RequiredCrackedEdges[0].length]);
-    var pRequiredCrackedEdges_geom_in       = doublesToHeap(Array.prototype.concat.apply([], bamggeom.RequiredCrackedEdges));
-    var pCrackedEdgesSize_geom_in           = intsToHeap([bamggeom.CrackedEdges.length, bamggeom.CrackedEdges[0].length]);
-    var pCrackedEdges_geom_in               = doublesToHeap(Array.prototype.concat.apply([], bamggeom.CrackedEdges));
-    var pSubDomainsSize_geom_in             = intsToHeap([bamggeom.SubDomains.length, bamggeom.SubDomains[0].length]);
-    var pSubDomains_geom_in                 = doublesToHeap(Array.prototype.concat.apply([], bamggeom.SubDomains));
+    var pVerticesSize_mesh_in               = intsToHeap([bamgmesh_in.Vertices.length, bamgmesh_in.Vertices[0] != undefined ? bamgmesh_in.Vertices[0].length : 1]);
+    var pVertices_mesh_in                   = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.Vertices));
+    var pEdgesSize_mesh_in                  = intsToHeap([bamgmesh_in.Edges.length, bamgmesh_in.Edges[0] != undefined ? bamgmesh_in.Edges[0].length : 1]);
+    var pEdges_mesh_in                      = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.Edges));
+    var pTrianglesSize_mesh_in              = intsToHeap([bamgmesh_in.Triangles.length, bamgmesh_in.Triangles[0] != undefined ? bamgmesh_in.Triangles[0].length : 1]);
+    var pTriangles_mesh_in                  = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.Triangles));
+    var pCrackedEdgesSize_mesh_in           = intsToHeap([bamgmesh_in.CrackedEdges.length, bamgmesh_in.CrackedEdges[0] != undefined ? bamgmesh_in.CrackedEdges[0].length : 1]);
+    var pCrackedEdges_mesh_in               = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.CrackedEdges));
+    var pVerticesOnGeomEdgeSize_mesh_in     = intsToHeap([bamgmesh_in.VerticesOnGeomEdge.length, bamgmesh_in.VerticesOnGeomEdge[0] != undefined ? bamgmesh_in.VerticesOnGeomEdge[0].length : 1]);
+    var pVerticesOnGeomEdge_mesh_in         = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.VerticesOnGeomEdge));
+    var pVerticesOnGeomVertexSize_mesh_in   = intsToHeap([bamgmesh_in.VerticesOnGeomVertex.length, bamgmesh_in.VerticesOnGeomVertex[0] != undefined ? bamgmesh_in.VerticesOnGeomVertex[0].length : 1]);
+    var pVerticesOnGeomVertex_mesh_in       = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.VerticesOnGeomVertex));
+    var pEdgesOnGeomEdgeSize_mesh_in        = intsToHeap([bamgmesh_in.EdgesOnGeomEdge.length, bamgmesh_in.EdgesOnGeomEdge[0] != undefined ? bamgmesh_in.EdgesOnGeomEdge[0].length : 1]);
+    var pEdgesOnGeomEdge_mesh_in            = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.EdgesOnGeomEdge));
+    var pIssmSegmentsSize_mesh_in           = intsToHeap([bamgmesh_in.IssmSegments.length, bamgmesh_in.IssmSegments[0] != undefined ? bamgmesh_in.IssmSegments[0].length : 1]);
+    var pIssmSegments_mesh_in               = doublesToHeap(Array.prototype.concat.apply([], bamgmesh_in.IssmSegments));
+
+    var pVerticesSize_geom_in               = intsToHeap([bamggeom_in.Vertices.length, bamggeom_in.Vertices[0] != undefined ? bamggeom_in.Vertices[0].length : 1]);
+    var pVertices_geom_in                   = doublesToHeap(Array.prototype.concat.apply([], bamggeom_in.Vertices));
+    var pEdgesSize_geom_in                  = intsToHeap([bamggeom_in.Edges.length, bamggeom_in.Edges[0] != undefined ? bamggeom_in.Edges[0].length : 1]);
+    var pEdges_geom_in                      = doublesToHeap(Array.prototype.concat.apply([], bamggeom_in.Edges));
+    var pCornersSize_geom_in                = intsToHeap([bamggeom_in.Corners.length, bamggeom_in.Corners[0] != undefined ? bamggeom_in.Corners[0].length : 1]);
+    var pCorners_geom_in                    = doublesToHeap(Array.prototype.concat.apply([], bamggeom_in.Corners));
+    var pRequiredVerticesSize_geom_in       = intsToHeap([bamggeom_in.RequiredVertices.length, bamggeom_in.RequiredVertices[0] != undefined ? bamggeom_in.RequiredVertices[0].length : 1]);
+    var pRequiredVertices_geom_in           = doublesToHeap(Array.prototype.concat.apply([], bamggeom_in.RequiredVertices));
+    var pRequiredEdgesSize_geom_in          = intsToHeap([bamggeom_in.RequiredEdges.length, bamggeom_in.RequiredEdges[0] != undefined ? bamggeom_in.RequiredEdges[0].length : 1]);
+    var pRequiredEdges_geom_in              = doublesToHeap(Array.prototype.concat.apply([], bamggeom_in.RequiredEdges));
+    var pCrackedEdgesSize_geom_in           = intsToHeap([bamggeom_in.CrackedEdges.length, bamggeom_in.CrackedEdges[0] != undefined ? bamggeom_in.CrackedEdges[0].length : 1]);
+    var pCrackedEdges_geom_in               = doublesToHeap(Array.prototype.concat.apply([], bamggeom_in.CrackedEdges));
+    var pSubDomainsSize_geom_in             = intsToHeap([bamggeom_in.SubDomains.length, bamggeom_in.SubDomains[0] != undefined ? bamggeom_in.SubDomains[0].length : 1]);
+    var pSubDomains_geom_in                 = doublesToHeap(Array.prototype.concat.apply([], bamggeom_in.SubDomains));
 
     var anisomax                            = bamgopts.anisomax;
@@ -91,103 +92,136 @@
     var hmin                                = bamgopts.hmin;
     var hmax                                = bamgopts.hmax;
-    var phminVerticesSize                   = intsToHeap([bamgopts.hminVertices.length, bamgopts.hminVertices[0].length]);
+    var phminVerticesSize                   = intsToHeap([bamgopts.hminVertices.length, bamgopts.hminVertices[0] != undefined ? bamgopts.hminVertices[0].length : 1]);
     var phminVertices                       = doublesToHeap(Array.prototype.concat.apply([], bamgopts.hminVertices));
-    var phmaxVerticesSize                   = intsToHeap([bamgopts.hmaxVertices.length, bamgopts.hmaxVertices[0].length]);
+    var phmaxVerticesSize                   = intsToHeap([bamgopts.hmaxVertices.length, bamgopts.hmaxVertices[0] != undefined ? bamgopts.hmaxVertices[0].length : 1]);
     var phmaxVertices                       = doublesToHeap(Array.prototype.concat.apply([], bamgopts.hmaxVertices));
-    var phVerticesSize                      = intsToHeap([bamgopts.hVertices.length, bamgopts.hVertices[0].length]);
+    var phVerticesSize                      = intsToHeap([bamgopts.hVertices.length, bamgopts.hVertices[0] != undefined ? bamgopts.hVertices[0].length : 1]);
     var phVertices                          = doublesToHeap(Array.prototype.concat.apply([], bamgopts.hVertices));
-    var pmetricSize                         = intsToHeap([bamgopts.metric.length, bamgopts.metric[0].length]);
+    var pmetricSize                         = intsToHeap([bamgopts.metric.length, bamgopts.metric[0] != undefined ? bamgopts.metric[0].length : 1]);
     var pmetric                             = doublesToHeap(Array.prototype.concat.apply([], bamgopts.metric));
-    var pfieldSize                          = intsToHeap([bamgopts.field.length, bamgopts.field[0].length]);
+    var pfieldSize                          = intsToHeap([bamgopts.field.length, bamgopts.field[0] != undefined ? bamgopts.field[0].length : 1]);
     var pfield                              = doublesToHeap(Array.prototype.concat.apply([], bamgopts.field));
-    var perrSize                            = intsToHeap([bamgopts.err.length, bamgopts.err[0].length]);
+    var perrSize                            = intsToHeap([bamgopts.err.length, bamgopts.err[0] != undefined ? bamgopts.err[0].length : 1]);
     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 pEdgesSize_geom_out                 = Module._malloc(4); 
-    var pEdges_geom_out                     = Module._malloc(4); 
-    var pCornersSize_geom_out               = Module._malloc(4); 
-    var pCorners_geom_out                   = Module._malloc(4); 
-    var pRequiredVerticesSize_geom_out      = Module._malloc(4); 
-    var pRequiredVertices_geom_out          = Module._malloc(4); 
-    var pRequiredCrackedEdgesSize_geom_out  = Module._malloc(4); 
-    var pRequiredCrackedEdges_geom_out      = Module._malloc(4); 
-    var pCrackedEdgesSize_geom_out          = Module._malloc(4); 
-    var pCrackedEdges_geom_out              = Module._malloc(4); 
-    var pSubDomainsSize_geom_out            = Module._malloc(4); 
-    var pSubDomains_geom_out                = Module._malloc(4); 
-
-    var pVerticesSize_mesh_out              = Module._malloc(4); 
-    var pVertices_mesh_out                  = Module._malloc(4); 
-    var pEdgesSize_mesh_out                 = Module._malloc(4); 
-    var pEdges_mesh_out                     = Module._malloc(4); 
-    var pTrianglesSize_mesh_out             = Module._malloc(4); 
-    var pTriangles_mesh_out                 = Module._malloc(4); 
-    var pCrackedEdgesSize_mesh_out          = Module._malloc(4); 
-    var pCrackedEdges_mesh_out              = Module._malloc(4); 
-    var pVerticesOnGeomEdgeSize_mesh_out    = Module._malloc(4); 
-    var pVerticesOnGeomEdge_mesh_out        = Module._malloc(4); 
-    var pVerticesOnGeomVertexSize_mesh_out  = Module._malloc(4); 
-    var pVerticesOnGeomVertex_mesh_out      = Module._malloc(4); 
-    var pEdgesOnGeomEdgeSize_mesh_out       = Module._malloc(4); 
-    var pEdgesOnGeomEdge_mesh_out           = Module._malloc(4); 
-    var pIssmSegmentsSize_mesh_out          = Module._malloc(4); 
-    var pIssmSegments_mesh_out              = Module._malloc(4); 
+    var pVerticesSize_mesh_out                  = Module._malloc(4); 
+    var pVertices_mesh_out                      = Module._malloc(4); 
+    var pEdgesSize_mesh_out                     = Module._malloc(4); 
+    var pEdges_mesh_out                         = Module._malloc(4); 
+    var pTrianglesSize_mesh_out                 = Module._malloc(4); 
+    var pTriangles_mesh_out                     = Module._malloc(4); 
+    var pIssmEdgesSize_mesh_out                 = Module._malloc(4); 
+    var pIssmEdges_mesh_out                     = Module._malloc(4); 
+    var pIssmSegmentsSize_mesh_out              = Module._malloc(4); 
+    var pIssmSegments_mesh_out                  = Module._malloc(4); 
+    var pVerticesOnGeomVertexSize_mesh_out      = Module._malloc(4); 
+    var pVerticesOnGeomVertex_mesh_out          = Module._malloc(4); 
+    var pVerticesOnGeomEdgeSize_mesh_out        = Module._malloc(4); 
+    var pVerticesOnGeomEdge_mesh_out            = Module._malloc(4); 
+    var pEdgesOnGeomEdgeSize_mesh_out           = Module._malloc(4); 
+    var pEdgesOnGeomEdge_mesh_out               = Module._malloc(4); 
+    var pSubDomainsSize_mesh_out                = Module._malloc(4); 
+    var pSubDomains_mesh_out                    = Module._malloc(4); 
+    var pSubDomainsFromGeomSize_mesh_out        = Module._malloc(4); 
+    var pSubDomainsFromGeom_mesh_out            = Module._malloc(4); 
+    var pElementConnectivitySize_mesh_out       = Module._malloc(4); 
+    var pElementConnectivity_mesh_out           = Module._malloc(4); 
+    var pNodalConnectivitySize_mesh_out         = Module._malloc(4); 
+    var pNodalConnectivity_mesh_out             = Module._malloc(4); 
+    var pNodalElementConnectivitySize_mesh_out  = Module._malloc(4); 
+    var pNodalElementConnectivity_mesh_out      = Module._malloc(4); 
+    var pCrackedVerticesSize_mesh_out           = Module._malloc(4); 
+    var pCrackedVertices_mesh_out               = Module._malloc(4); 
+    var pCrackedEdgesSize_mesh_out              = Module._malloc(4); 
+    var pCrackedEdges_mesh_out                  = Module._malloc(4); 
+    var pPreviousNumberingSize_mesh_out         = Module._malloc(4); 
+    var pPreviousNumbering_mesh_out             = Module._malloc(4); 
+
+    var pVerticesSize_geom_out                  = Module._malloc(4); 
+    var pVertices_geom_out                      = Module._malloc(4);
+    var pEdgesSize_geom_out                     = Module._malloc(4); 
+    var pEdges_geom_out                         = Module._malloc(4); 
+    var pCornersSize_geom_out                   = Module._malloc(4); 
+    var pCorners_geom_out                       = Module._malloc(4); 
+    var pRequiredVerticesSize_geom_out          = Module._malloc(4); 
+    var pRequiredVertices_geom_out              = Module._malloc(4); 
+    var pRequiredEdgesSize_geom_out             = Module._malloc(4); 
+    var pRequiredEdges_geom_out                 = Module._malloc(4); 
+    var pCrackedEdgesSize_geom_out              = Module._malloc(4); 
+    var pCrackedEdges_geom_out                  = Module._malloc(4); 
+    var pSubDomainsSize_geom_out                = Module._malloc(4); 
+    var pSubDomains_geom_out                    = Module._malloc(4); 
 	//}}}
 
 	//Declare BamgMesher module: 
 	BamgMesherModule = Module.cwrap('BamgMesherModule', 'number',[
-        'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 
+        'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number',
         'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 
         'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 
         'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 
-        'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']);
+        'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']);
 	
 	//Call BamgMesher module: 
+
 	BamgMesherModule(
-        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_out, pVertices_mesh_out, pEdgesSize_mesh_out, pEdges_mesh_out, pTrianglesSize_mesh_out, pTriangles_mesh_out, pIssmEdgesSize_mesh_out, pIssmEdges_mesh_out, pIssmSegmentsSize_mesh_out, pIssmSegments_mesh_out, pVerticesOnGeomVertexSize_mesh_out, pVerticesOnGeomVertex_mesh_out, pVerticesOnGeomEdgeSize_mesh_out, pVerticesOnGeomEdge_mesh_out, pEdgesOnGeomEdgeSize_mesh_out, pEdgesOnGeomEdge_mesh_out, pSubDomainsSize_mesh_out, pSubDomains_mesh_out, pSubDomainsFromGeomSize_mesh_out, pSubDomainsFromGeom_mesh_out, pElementConnectivitySize_mesh_out, pElementConnectivity_mesh_out, pNodalConnectivitySize_mesh_out, pNodalConnectivity_mesh_out, pNodalElementConnectivitySize_mesh_out, pNodalElementConnectivity_mesh_out, pCrackedVerticesSize_mesh_out, pCrackedVertices_mesh_out, pCrackedEdgesSize_mesh_out, pCrackedEdges_mesh_out, pPreviousNumberingSize_mesh_out, pPreviousNumbering_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, pRequiredEdgesSize_geom_out, pRequiredEdges_geom_out, pCrackedEdgesSize_geom_out, pCrackedEdges_geom_out, pSubDomainsSize_geom_out, pSubDomains_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, 
+        pVerticesSize_geom_in, pVertices_geom_in, pEdgesSize_geom_in, pEdges_geom_in, pCornersSize_geom_in, pCorners_geom_in, pRequiredVerticesSize_geom_in, pRequiredVertices_geom_in, pRequiredEdgesSize_geom_in, pRequiredEdges_geom_in, pCrackedEdgesSize_geom_in, pCrackedEdges_geom_in, pSubDomainsSize_geom_in, pSubDomains_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: {{{*/
 	//recover mesh: 
-    var bamgmeshout = bamgmesh();
-    var bamggeomout = bamggeom();
-
-    bamgmeshout.VerticesSize                = heapToint(pVerticesSize_mesh_out, 2);
-    bamgmeshout.Vertices                    = heapToDoubles(heapToDoubles(pVertices_mesh_out), bamgmeshout.VerticesSize);
-    bamgmeshout.EdgesSize                   = heapToint(pEdgesSize_mesh_out, 2);
-    bamgmeshout.Edges                       = heapToDoubles(heapToDoubles(pEdges_mesh_out), bamgmeshout.EdgesSize);
-    bamgmeshout.TrianglesSize               = heapToint(pTrianglesSize_mesh_out, 2);
-    bamgmeshout.Triangles                   = heapToDoubles(heapToDoubles(pTriangles_mesh_out), bamgmeshout.TrianglesSize);
-    bamgmeshout.CrackedEdgesSize            = heapToint(pCrackedEdgesSize_mesh_out, 2);
-    bamgmeshout.CrackedEdges                = heapToDoubles(heapToDoubles(pCrackedEdges_mesh_out), bamgmeshout.CrackedEdgesSize);
-    bamgmeshout.VerticesOnGeomEdgeSize      = heapToint(pVerticesOnGeomEdgeSize_mesh_out, 2);
-    bamgmeshout.VerticesOnGeomEdge          = heapToDoubles(heapToDoubles(pVerticesOnGeomEdge_mesh_out), bamgmeshout.VerticesOnGeomEdgeSize);
-    bamgmeshout.VerticesOnGeomVertexSize    = heapToint(pVerticesOnGeomVertexSize_mesh_out, 2);
-    bamgmeshout.VerticesOnGeomVertex        = heapToDoubles(heapToDoubles(pVerticesOnGeomVertex_mesh_out), bamgmeshout.VerticesOnGeomVertexSize);
-    bamgmeshout.EdgesOnGeomEdgeSize         = heapToint(pEdgesOnGeomEdgeSize_mesh_out, 2);
-    bamgmeshout.EdgesOnGeomEdge             = heapToDoubles(heapToDoubles(pEdgesOnGeomEdge_mesh_out), bamgmeshout.EdgesOnGeomEdgeSize);
-    bamgmeshout.IssmSegmentsSize            = heapToint(pIssmSegmentsSize_mesh_out, 2);
-    bamgmeshout.IssmSegments                = heapToDoubles(heapToDoubles(pIssmSegments_mesh_out), bamgmeshout.IssmSegmentsSize);
-
-    bamggeomout.VerticesSize                = heapToint(pVerticesSize_mesh_out, 2);
-    bamggeomout.Vertices                    = heapToDoubles(heapToDoubles(pVertices_mesh_out), bamggeomout.VerticesSize);
-    bamggeomout.EdgesSize                   = heapToint(pEdgesSize_mesh_out, 2);
-    bamggeomout.Edges                       = heapToDoubles(heapToDoubles(pEdges_mesh_out), bamggeomout.EdgesSize);
-    bamggeomout.CornersSize                 = heapToint(pCornersSize_mesh_out, 2);
-    bamggeomout.Corners                     = heapToDoubles(heapToDoubles(pCorners_mesh_out), bamggeomout.CornersSize);
-    bamggeomout.RequiredVerticesSize        = heapToint(pRequiredVerticesSize_mesh_out, 2);
-    bamggeomout.RequiredVertices            = heapToDoubles(heapToDoubles(pRequiredVertices_mesh_out), bamggeomout.RequiredVerticesSize);
-    bamggeomout.RequiredCrackedEdgesSize    = heapToint(pRequiredCrackedEdgesSize_mesh_out, 2);
-    bamggeomout.RequiredCrackedEdges        = heapToDoubles(heapToDoubles(pRequiredCrackedEdges_mesh_out), bamggeomout.RequiredCrackedEdgesSize);
-    bamggeomout.CrackedEdgesSize            = heapToint(pCrackedEdgesSize_mesh_out, 2);
-    bamggeomout.CrackedEdges                = heapToDoubles(heapToDoubles(pCrackedEdges_mesh_out), bamggeomout.CrackedEdgesSize);
-    bamggeomout.SubDomainSize               = heapToint(pSubDomainsSize_mesh_out, 2);
-    bamggeomout.SubDomains                  = heapToDoubles(heapToDoubles(pSubDomains_mesh_out), bamggeomout.SubDomainsSize);
+    var bamgmeshout = new bamgmesh();
+    var bamggeomout = new bamggeom();
+
+	bamgmeshout.VerticesSize                   = heapToInts(pVerticesSize_mesh_out, 2);
+    bamgmeshout.Vertices                       = heapToDoubles(pVertices_mesh_out, bamgmeshout.VerticesSize);
+	bamgmeshout.EdgesSize                      = heapToInts(pEdgesSize_mesh_out, 2);
+    bamgmeshout.Edges                          = heapToDoubles(pEdges_mesh_out, bamgmeshout.EdgesSize);
+	bamgmeshout.TrianglesSize                  = heapToInts(pTrianglesSize_mesh_out, 2);
+    bamgmeshout.Triangles                      = heapToDoubles(pTriangles_mesh_out, bamgmeshout.TrianglesSize);
+	bamgmeshout.IssmEdgesSize                  = heapToInts(pIssmEdgesSize_mesh_out, 2);
+    bamgmeshout.IssmEdges                      = heapToDoubles(pIssmEdges_mesh_out, bamgmeshout.IssmEdgesSize);
+	bamgmeshout.IssmSegmentsSize               = heapToInts(pIssmSegmentsSize_mesh_out, 2);
+    bamgmeshout.IssmSegments                   = heapToDoubles(pIssmSegments_mesh_out, bamgmeshout.IssmSegmentsSize);
+	bamgmeshout.VerticesOnGeomVertexSize       = heapToInts(pVerticesOnGeomVertexSize_mesh_out, 2);
+    bamgmeshout.VerticesOnGeomVertex           = heapToDoubles(pVerticesOnGeomVertex_mesh_out, bamgmeshout.VerticesOnGeomVertexSize);
+	bamgmeshout.VerticesOnGeomEdgeSize         = heapToInts(pVerticesOnGeomEdgeSize_mesh_out, 2);
+    bamgmeshout.VerticesOnGeomEdge             = heapToDoubles(pVerticesOnGeomEdge_mesh_out, bamgmeshout.VerticesOnGeomEdgeSize);
+	bamgmeshout.EdgesOnGeomEdgeSize            = heapToInts(pEdgesOnGeomEdgeSize_mesh_out, 2);
+    bamgmeshout.EdgesOnGeomEdge                = heapToDoubles(pEdgesOnGeomEdge_mesh_out, bamgmeshout.EdgesOnGeomEdgeSize);
+	bamgmeshout.SubDomainsSize                 = heapToInts(pSubDomainsSize_mesh_out, 2);
+    bamgmeshout.SubDomains                     = heapToDoubles(pSubDomains_mesh_out, bamgmeshout.SubDomainsSize);
+	bamgmeshout.SubDomainsFromGeomSize         = heapToInts(pSubDomainsFromGeomSize_mesh_out, 2);
+    bamgmeshout.SubDomainsFromGeom             = heapToDoubles(pSubDomainsFromGeom_mesh_out, bamgmeshout.SubDomainsFromGeomSize);
+	bamgmeshout.ElementConnectivitySize        = heapToInts(pElementConnectivitySize_mesh_out, 2);
+    bamgmeshout.ElementConnectivity            = heapToDoubles(pElementConnectivity_mesh_out, bamgmeshout.ElementConnectivitySize);
+	bamgmeshout.NodalConnectivitySize          = heapToInts(pNodalConnectivitySize_mesh_out, 2);
+    bamgmeshout.NodalConnectivity              = heapToDoubles(pNodalConnectivity_mesh_out, bamgmeshout.NodalConnectivitySize);
+	bamgmeshout.NodalElementConnectivitySize   = heapToInts(pNodalElementConnectivitySize_mesh_out, 2);
+    bamgmeshout.NodalElementConnectivity       = heapToDoubles(pNodalElementConnectivity_mesh_out, bamgmeshout.NodalElementConnectivitySize);
+	bamgmeshout.CrackedVerticesSize            = heapToInts(pCrackedVerticesSize_mesh_out, 2);
+    bamgmeshout.CrackedVertices                = heapToDoubles(pCrackedVertices_mesh_out, bamgmeshout.CrackedVerticesSize);
+	bamgmeshout.CrackedEdgesSize               = heapToInts(pCrackedEdgesSize_mesh_out, 2);
+    bamgmeshout.CrackedEdges                   = heapToDoubles(pCrackedEdges_mesh_out, bamgmeshout.CrackedEdgesSize);
+    bamgmeshout.PreviousNumberingSize          = heapToInts(pPreviousNumberingSize_mesh_out, 2);
+    bamgmeshout.PreviousNumbering              = heapToDoubles(pPreviousNumbering_mesh_out, bamgmeshout.PreviousNumberingSize);
+
+    bamggeomout.VerticesSize                   = heapToInts(pVerticesSize_geom_out, 2);
+    bamggeomout.Vertices                       = heapToDoubles(pVertices_geom_out, bamggeomout.VerticesSize);
+    bamggeomout.EdgesSize                      = heapToInts(pEdgesSize_geom_out, 2);
+    bamggeomout.Edges                          = heapToDoubles(pEdges_geom_out, bamggeomout.EdgesSize);
+    bamggeomout.CornersSize                    = heapToInts(pCornersSize_geom_out, 2);
+    bamggeomout.Corners                        = heapToDoubles(pCorners_geom_out, bamggeomout.CornersSize);
+    bamggeomout.RequiredVerticesSize           = heapToInts(pRequiredVerticesSize_geom_out, 2);
+    bamggeomout.RequiredVertices               = heapToDoubles(pRequiredVertices_geom_out, bamggeomout.RequiredVerticesSize);
+    bamggeomout.RequiredEdgesSize              = heapToInts(pRequiredEdgesSize_geom_out, 2);
+    bamggeomout.RequiredEdges                  = heapToDoubles(pRequiredEdges_geom_out, bamggeomout.RequiredEdgesSize);
+    bamggeomout.CrackedEdgesSize               = heapToInts(pCrackedEdgesSize_geom_out, 2);
+    bamggeomout.CrackedEdges                   = heapToDoubles(pCrackedEdges_geom_out, bamggeomout.CrackedEdgesSize);
+    bamggeomout.SubDomainsSize                 = heapToInts(pSubDomainsSize_geom_out, 2);
+    bamggeomout.SubDomains                     = heapToDoubles(pSubDomains_geom_out, bamggeomout.SubDomainsSize);
 	/*}}}*/
 
@@ -195,4 +229,52 @@
 
 	/*Free ressources: */
+    Module._free(pVerticesSize_mesh_out); 
+    Module._free(pVertices_mesh_out); 
+    Module._free(pEdgesSize_mesh_out); 
+    Module._free(pEdges_mesh_out); 
+    Module._free(pTrianglesSize_mesh_out); 
+    Module._free(pTriangles_mesh_out); 
+    Module._free(pIssmEdgesSize_mesh_out); 
+    Module._free(pIssmEdges_mesh_out); 
+    Module._free(pIssmSegmentsSize_mesh_out); 
+    Module._free(pIssmSegments_mesh_out); 
+    Module._free(pVerticesOnGeomVertexSize_mesh_out); 
+    Module._free(pVerticesOnGeomVertex_mesh_out); 
+    Module._free(pVerticesOnGeomEdgeSize_mesh_out); 
+    Module._free(pVerticesOnGeomEdge_mesh_out); 
+    Module._free(pEdgesOnGeomEdgeSize_mesh_out); 
+    Module._free(pEdgesOnGeomEdge_mesh_out); 
+    Module._free(pSubDomainsSize_mesh_out); 
+    Module._free(pSubDomains_mesh_out); 
+    Module._free(pSubDomainsFromGeomSize_mesh_out); 
+    Module._free(pSubDomainsFromGeom_mesh_out); 
+    Module._free(pElementConnectivitySize_mesh_out); 
+    Module._free(pElementConnectivity_mesh_out); 
+    Module._free(pNodalConnectivitySize_mesh_out); 
+    Module._free(pNodalConnectivity_mesh_out); 
+    Module._free(pNodalElementConnectivitySize_mesh_out); 
+    Module._free(pNodalElementConnectivity_mesh_out); 
+    Module._free(pCrackedVerticesSize_mesh_out); 
+    Module._free(pCrackedVertices_mesh_out); 
+    Module._free(pCrackedEdgesSize_mesh_out); 
+    Module._free(pCrackedEdges_mesh_out); 
+    Module._free(pPreviousNumberingSize_mesh_out); 
+    Module._free(pPreviousNumbering_mesh_out); 
+
+    Module._free(pVerticesSize_geom_out);
+    Module._free(pVertices_geom_out);
+    Module._free(pEdgesSize_geom_out);
+    Module._free(pEdges_geom_out);
+    Module._free(pCornersSize_geom_out);
+    Module._free(pCorners_geom_out);
+    Module._free(pRequiredVerticesSize_geom_out);
+    Module._free(pRequiredVertices_geom_out);
+    Module._free(pRequiredEdgesSize_geom_out);
+    Module._free(pRequiredEdges_geom_out);
+    Module._free(pCrackedEdgesSize_geom_out);
+    Module._free(pCrackedEdges_geom_out);
+    Module._free(pSubDomainsSize_geom_out);
+    Module._free(pSubDomains_geom_out);
+
     Module._free(pVerticesSize_mesh_in);
     Module._free(pVertices_mesh_in);
@@ -220,42 +302,10 @@
     Module._free(pRequiredVerticesSize_geom_in);
     Module._free(pRequiredVertices_geom_in);
-    Module._free(pRequiredCrackedEdgesSize_geom_in);
-    Module._free(pRequiredCrackedEdges_geom_in);
+    Module._free(pRequiredEdgesSize_geom_in);
+    Module._free(pRequiredEdges_geom_in);
     Module._free(pCrackedEdgesSize_geom_in);
     Module._free(pCrackedEdges_geom_in);
     Module._free(pSubDomainsSize_geom_in);
     Module._free(pSubDomains_geom_in);
-
-    Module._free(pVerticesSize_geom_out);
-    Module._free(pVertices_geom_out);
-    Module._free(pEdgesSize_geom_out);
-    Module._free(pEdges_geom_out);
-    Module._free(pCornersSize_geom_out);
-    Module._free(pCorners_geom_out);
-    Module._free(pRequiredVerticesSize_geom_out);
-    Module._free(pRequiredVertices_geom_out);
-    Module._free(pRequiredCrackedEdgesSize_geom_out);
-    Module._free(pRequiredCrackedEdges_geom_out);
-    Module._free(pCrackedEdgesSize_geom_out);
-    Module._free(pCrackedEdges_geom_out);
-    Module._free(pSubDomainsSize_geom_out);
-    Module._free(pSubDomains_geom_out);
-
-    Module._free(pVerticesSize_mesh_out);
-    Module._free(pVertices_mesh_out);
-    Module._free(pEdgesSize_mesh_out);
-    Module._free(pEdges_mesh_out);
-    Module._free(pTrianglesSize_mesh_out);
-    Module._free(pTriangles_mesh_out);
-    Module._free(pCrackedEdgesSize_mesh_out);
-    Module._free(pCrackedEdges_mesh_out);
-    Module._free(pVerticesOnGeomEdgeSize_mesh_out);
-    Module._free(pVerticesOnGeomEdge_mesh_out);
-    Module._free(pVerticesOnGeomVertexSize_mesh_out);
-    Module._free(pVerticesOnGeomVertex_mesh_out);
-    Module._free(pEdgesOnGeomEdgeSize_mesh_out);
-    Module._free(pEdgesOnGeomEdge_mesh_out);
-    Module._free(pIssmSegmentsSize_mesh_out);
-    Module._free(pIssmSegments_mesh_out);
 
     Module._free(phminVerticesSize);
Index: /issm/trunk-jpl/src/wrappers/javascript/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 22895)
+++ /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 22896)
@@ -83,5 +83,6 @@
 endif
 
-IssmModule_SOURCES = ../Triangle/Triangle.cpp \
+IssmModule_SOURCES = ../BamgMesher/BamgMesher.cpp \
+                     ../Triangle/Triangle.cpp \
 					 ../NodeConnectivity/NodeConnectivity.cpp\
 					 ../ContourToMesh/ContourToMesh.cpp\
@@ -92,5 +93,5 @@
 					 ../Issm/issm.cpp
 
-IssmModule_CXXFLAGS= -fPIC -D_DO_NOT_LOAD_GLOBALS_  --memory-init-file 0 $(AM_CXXFLAGS) $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) -s EXPORTED_FUNCTIONS="['_TriangleModule','_NodeConnectivityModule','_ContourToMeshModule','_ElementConnectivityModule','_InterpFromGridToMeshModule','_InterpFromMeshToMesh2dModule','_IssmConfigModule','_IssmModule']"  -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 -s INVOKE_RUN=0
+IssmModule_CXXFLAGS= -fPIC -D_DO_NOT_LOAD_GLOBALS_  --memory-init-file 0 $(AM_CXXFLAGS) $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) -s EXPORTED_FUNCTIONS="['_BamgMesherModule','_TriangleModule','_NodeConnectivityModule','_ContourToMeshModule','_ElementConnectivityModule','_InterpFromGridToMeshModule','_InterpFromMeshToMesh2dModule','_IssmConfigModule','_IssmModule']"  -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 -s INVOKE_RUN=0
 IssmModule_LDADD = ${deps} $(TRIANGLELIB)  $(GSLLIB)
 #}}}
Index: /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 22895)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 22896)
@@ -124,5 +124,5 @@
 }
 /*}}}*/
-/*FUNCTION FetchData(BamgGeom** pbamggeom, double* vertices, int nods){{{*/
+/*FUNCTION 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(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){
 
@@ -143,5 +143,5 @@
 }
 /*}}}*/
-/*FUNCTION FetchData(BamgMesh** pbamgmesh, double* vertices, int nods){{{*/
+/*FUNCTION 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(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){
 
@@ -163,6 +163,6 @@
 }
 /*}}}*/
-/*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, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int* hVerticesSize, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){
+/*FUNCTION 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(BamgOpts** pbamgopts, double anisomax, double coeff, double cutoff, 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();
Index: /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp	(revision 22895)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp	(revision 22896)
@@ -14,5 +14,5 @@
 /*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){
+void WriteData(IssmPDouble** pmatrix, int* pnel, int* matrix, int M,int N){
 
 	if(pmatrix && matrix){
@@ -27,11 +27,11 @@
 /*}}}*/
 /*FUNCTION WriteData(IssmPDouble** pmatrix, int* pM, int* pN, , int* matrix, int M,int N){{{*/
-void WriteData(IssmPDouble** pmatrix,int* pM, int* pN, int* matrix, int M, int N){
+void WriteData(IssmPDouble** pmatrix, int* pM, int* pN, 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];
+	    IssmPDouble* dmatrix = xNew<IssmPDouble>(M*N); 
+		for (int i=0;i<M*N;i++) dmatrix[i]=(IssmPDouble)matrix[i];
 		*pmatrix=dmatrix;
 		*pM=M;
@@ -41,5 +41,5 @@
 /*}}}*/
 /*FUNCTION WriteData(IssmPDouble** pmatrix, int* pM, IssmPDouble* pN, , int* matrix, int M,int N){{{*/
-void WriteData(IssmPDouble** pmatrix,int* pM, int* pN, IssmPDouble* matrix, int M, int N){
+void WriteData(IssmPDouble** pmatrix, int* pM, int* pN, IssmPDouble* matrix, int M, int N){
 
 	if(pmatrix && matrix){
@@ -47,9 +47,24 @@
 		/*Copy matrix: */
 		IssmPDouble* dmatrix = xNew<IssmPDouble>(M*N); 
-		for (int i=0;i<M*N;i++)dmatrix[i]=matrix[i];
+		for (int i=0;i<M*N;i++) dmatrix[i]=matrix[i];
 		*pmatrix=dmatrix;
-		if(pM)*pM=M;
-		if(pN)*pN=N;
+		*pM=M;
+		*pN=N;
 	}
+}
+/*}}}*/
+/*FUNCTION WriteData(IssmPDouble** pmatrix, int** pSize, IssmPDouble* matrix, int* size){{{*/
+void WriteData(IssmPDouble** pmatrix, int** pSize, IssmPDouble* matrix, int* size){
+
+    int M = size[0];
+    int N = size[1];
+    int* imatrix = xNew<int>(2);
+    IssmPDouble* dmatrix = xNew<IssmPDouble>(M*N); 
+
+    /*Copy matrix: */
+    for (int i=0;i<2;i++) imatrix[i]=size[i];
+    for (int i=0;i<M*N;i++) dmatrix[i]=matrix[i];
+    *pmatrix=dmatrix;
+    *pSize=imatrix;
 }
 /*}}}*/
@@ -120,2 +135,39 @@
 }
 /*}}}*/
+
+/*ISSM objects*/
+/*FUNCTION WriteData(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, BamgGeom* bamggeom){{{*/
+void WriteData(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, BamgGeom* bamggeom){
+
+	/*Assign each field to output*/
+    WriteData(Vertices, VerticesSize, bamggeom->Vertices, bamggeom->VerticesSize);
+    WriteData(Edges, EdgesSize, bamggeom->Edges, bamggeom->EdgesSize);
+    WriteData(Corners, CornersSize, bamggeom->Corners, bamggeom->CornersSize);
+    WriteData(RequiredVertices, RequiredVerticesSize, bamggeom->RequiredVertices, bamggeom->RequiredVerticesSize);
+    WriteData(RequiredEdges, RequiredEdgesSize, bamggeom->RequiredEdges, bamggeom->RequiredEdgesSize);
+    WriteData(CrackedEdges, CrackedEdgesSize, bamggeom->CrackedEdges, bamggeom->CrackedEdgesSize);
+    WriteData(SubDomains, SubDomainsSize, bamggeom->SubDomains, bamggeom->SubDomainsSize);
+}
+/*}}}*/
+/*FUNCTION WriteData(int** VerticesSize, double** Vertices, int** EdgesSize, double** Edges, int** TrianglesSize, double** Triangles, int** IssmEdgesSize, double** IssmEdges, int** IssmSegmentsSize, double** IssmSegments, int** VerticesOnGeomVertexSize, double** VerticesOnGeomVertex, int** VerticesOnGeomEdgeSize, double** VerticesOnGeomEdge, int** EdgesOnGeomEdgeSize, double** EdgesOnGeomEdge, int** SubDomainsSize, double** SubDomains, int** SubDomainsFromGeomSize, double** SubDomainsFromGeom, int** ElementConnectivitySize, double** ElementConnectivity, int** NodalConnectivitySize, double** NodalConnectivity, int** NodalElementConnectivitySize, double** NodalElementConnectivity, int** CrackedVerticesSize, double** CrackedVertices, int** CrackedEdgesSize, double** CrackedEdges, int** PreviousNumberingSize, double** PreviousNumbering, BamgMesh* bamgmesh){{{*/
+void WriteData(int** VerticesSize, double** Vertices, int** EdgesSize, double** Edges, int** TrianglesSize, double** Triangles, int** IssmEdgesSize, double** IssmEdges, int** IssmSegmentsSize, double** IssmSegments, int** VerticesOnGeomVertexSize, double** VerticesOnGeomVertex, int** VerticesOnGeomEdgeSize, double** VerticesOnGeomEdge, int** EdgesOnGeomEdgeSize, double** EdgesOnGeomEdge, int** SubDomainsSize, double** SubDomains, int** SubDomainsFromGeomSize, double** SubDomainsFromGeom, int** ElementConnectivitySize, double** ElementConnectivity, int** NodalConnectivitySize, double** NodalConnectivity, int** NodalElementConnectivitySize, double** NodalElementConnectivity, int** CrackedVerticesSize, double** CrackedVertices, int** CrackedEdgesSize, double** CrackedEdges, int** PreviousNumberingSize, double** PreviousNumbering, BamgMesh* bamgmesh){
+
+	/*Assign each field to output*/
+    WriteData(Vertices, VerticesSize, bamgmesh->Vertices, bamgmesh->VerticesSize);
+    WriteData(Edges, EdgesSize, bamgmesh->Edges, bamgmesh->EdgesSize);
+    WriteData(Triangles, TrianglesSize, bamgmesh->Triangles, bamgmesh->TrianglesSize);
+    WriteData(IssmEdges, IssmEdgesSize, bamgmesh->IssmEdges, bamgmesh->IssmEdgesSize);
+    WriteData(IssmSegments, IssmSegmentsSize, bamgmesh->IssmSegments, bamgmesh->IssmSegmentsSize);
+    WriteData(VerticesOnGeomVertex, VerticesOnGeomVertexSize, bamgmesh->VerticesOnGeomVertex, bamgmesh->VerticesOnGeomVertexSize);
+    WriteData(VerticesOnGeomEdge, VerticesOnGeomEdgeSize, bamgmesh->VerticesOnGeomEdge, bamgmesh->VerticesOnGeomEdgeSize);
+    WriteData(EdgesOnGeomEdge, EdgesOnGeomEdgeSize, bamgmesh->EdgesOnGeomEdge, bamgmesh->EdgesOnGeomEdgeSize);
+    WriteData(SubDomains, SubDomainsSize, bamgmesh->SubDomains, bamgmesh->SubDomainsSize);
+    WriteData(SubDomainsFromGeom, SubDomainsFromGeomSize, bamgmesh->SubDomainsFromGeom, bamgmesh->SubDomainsFromGeomSize);
+    WriteData(ElementConnectivity, ElementConnectivitySize, bamgmesh->ElementConnectivity, bamgmesh->ElementConnectivitySize);
+    WriteData(NodalConnectivity, NodalConnectivitySize, bamgmesh->NodalConnectivity, bamgmesh->NodalConnectivitySize);
+    WriteData(NodalElementConnectivity, NodalElementConnectivitySize, bamgmesh->NodalElementConnectivity, bamgmesh->NodalElementConnectivitySize);
+    WriteData(CrackedVertices, CrackedVerticesSize, bamgmesh->CrackedVertices, bamgmesh->CrackedVerticesSize);
+    WriteData(CrackedEdges, CrackedEdgesSize, bamgmesh->CrackedEdges, bamgmesh->CrackedEdgesSize);
+    WriteData(PreviousNumbering, PreviousNumberingSize, bamgmesh->PreviousNumbering, bamgmesh->VerticesSize); //PreviousNumbering just resuses Vertices' Size
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 22895)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 22896)
@@ -18,7 +18,8 @@
 #include "../../../c/shared/shared.h"
 
-void WriteData(IssmPDouble** pmatrix,int* pnel, int* matrix, int M,int N);
-void WriteData(IssmPDouble** pmatrix,int* pM, int* pN, int* matrix, int M, int N);
-void WriteData(IssmPDouble** pmatrix,int* pM, int* pN, IssmPDouble* matrix, int M, int N);
+void WriteData(IssmPDouble** pmatrix, int* pnel, int* matrix, int M,int N);
+void WriteData(IssmPDouble** pmatrix, int* pM, int* pN, int* matrix, int M, int N);
+void WriteData(IssmPDouble** pmatrix, int* pM, int* pN, IssmPDouble* matrix, int M, int N);
+void WriteData(IssmPDouble** pmatrix, int** pSize, IssmPDouble* matrix, int* size);
 void WriteData(IssmPDouble** px, int* pnods, int* vector, int M);
 void WriteData(IssmPDouble** px, int* pnods, double* vector, int M);
@@ -27,4 +28,6 @@
 void WriteData(IssmPDouble** pdataref, IssmSeqVec<double>* vector);
 void WriteData(IssmPDouble** pdouble, void*);
+void WriteData(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, BamgGeom* bamggeom);
+void WriteData(int** VerticesSize, double** Vertices, int** EdgesSize, double** Edges, int** TrianglesSize, double** Triangles, int** IssmEdgesSize, double** IssmEdges, int** IssmSegmentsSize, double** IssmSegments, int** VerticesOnGeomVertexSize, double** VerticesOnGeomVertex, int** VerticesOnGeomEdgeSize, double** VerticesOnGeomEdge, int** EdgesOnGeomEdgeSize, double** EdgesOnGeomEdge, int** SubDomainsSize, double** SubDomains, int** SubDomainsFromGeomSize, double** SubDomainsFromGeom, int** ElementConnectivitySize, double** ElementConnectivity, int** NodalConnectivitySize, double** NodalConnectivity, int** NodalElementConnectivitySize, double** NodalElementConnectivity, int** CrackedVerticesSize, double** CrackedVertices, int** CrackedEdgesSize, double** CrackedEdges, int** PreviousNumberingSize, double** PreviousNumbering, BamgMesh* bamgmesh);
 
 void FetchData(char** pstring, char* stringin);
