Index: /issm/trunk-jpl/src/m/array/ArrayOperations.js
===================================================================
--- /issm/trunk-jpl/src/m/array/ArrayOperations.js	(revision 19711)
+++ /issm/trunk-jpl/src/m/array/ArrayOperations.js	(revision 19711)
@@ -0,0 +1,56 @@
+function ArrayMax(array){ //{{{
+	return Math.max.apply(null,array);
+} //}}}
+function ArrayMax2D(array){ //{{{
+	
+	var max=0;
+
+	for (i=0;i<array.length;i++){
+		var subarray=array[i];
+		max=Math.max(max,ArrayMax(subarray));
+	}
+
+	return max;
+} //}}}
+function ArrayMin(array){ //{{{
+	return Math.min.apply(null,array);
+} //}}}
+function ArrayMin2D(array){ //{{{
+	
+	var min=ArrayMax2D(array);
+
+	for (i=0;i<array.length;i++){
+		var subarray=array[i];
+		min=Math.min(min,ArrayMin(subarray));
+	}
+
+	return min;
+} //}}}
+function ListToMatrix(list, elementsPerSubArray) { //{{{
+	var matrix = [], i, k;
+
+	for (i = 0, k = -1; i < list.length; i++) {
+		if (i % elementsPerSubArray === 0) {
+			k++;
+			matrix[k] = [];
+		}
+
+		matrix[k].push(list[i]);
+	}
+
+	return matrix;
+} //}}}
+function MatrixToList(matrix) { //{{{
+	
+	var width = matrix[0].length;
+	var length = matrix.length;
+	var list= new Array(width*length);
+
+	for (i=0;i<length;i++){
+		for(j=0;j<width;j++){
+			list[i*width+j]=matrix[i][j];
+		}
+	}
+		
+	return list;
+} //}}}
Index: /issm/trunk-jpl/src/m/mesh/triangle.js
===================================================================
--- /issm/trunk-jpl/src/m/mesh/triangle.js	(revision 19710)
+++ /issm/trunk-jpl/src/m/mesh/triangle.js	(revision 19711)
@@ -1,3 +1,3 @@
-function triangle(md,domain, rifts, resolution){
+function triangle(md){
 //TRIANGLE - create model mesh using the triangle package
 //
@@ -15,15 +15,44 @@
 //      triangle(md,domain, rifts, 1500);
 
+	if (!(arguments.length==3 | arguments.length==4)){
+		console.log('triangle usage error.');
+	}
+	
+	var md=arguments[0];
+	var domain=arguments[1];
+
+	if (arguments.length==3){
+		var resolution=arguments[2];
+		var rifts=[];
+	}
+	if (arguments.length==4){
+		var rifts=arguments[2];
+		var resolution=arguments[3];
+	}
+
+	//Figure out a characteristic area. Resolution is a node oriented concept (ex a 1000m  resolution node would 
+	//be made of 1000*1000 area squares). 
 	var area=Math.pow(resolution,2);
 
 	//Call mesher: 
-	var array = TriMesh(md, domain, rifts, area); 
+	var return_array=TriMesh(md, domain, rifts, area); 
 
+	//Plug into md:
+	md.mesh.elements=return_array[0];
+	md.mesh.x=return_array[1];
+	md.mesh.y=return_array[2];
+	md.mesh.segments=return_array[3];
+	md.mesh.segmentmarkers=return_array[4];
+	
 	//Fill in rest of fields:
-	//md.mesh.vertexonboundary=zeros(md.mesh.numberofvertices,1); md.mesh.vertexonboundary(md.mesh.segments(:,1:2))=1;
+	md.mesh.numberofelements=md.mesh.elements.length;
+	md.mesh.numberofvertices=md.mesh.x.length;
+	md.mesh.vertexonboundary=new Float64Array(md.mesh.numberofvertices); 
+
+	for (i=0;i<md.mesh.segments.length;i++) for(j=0;j<2;j++) md.mesh.vertexonboundary[md.mesh.segments[i][j]-1]=1;
 
 	//Now, build the connectivity tables for this mesh.
-	//md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices);
-	//md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity);
+	md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices);
+	//md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity);	
 
 }
Index: /issm/trunk-jpl/src/m/mesh/triangle.m
===================================================================
--- /issm/trunk-jpl/src/m/mesh/triangle.m	(revision 19710)
+++ /issm/trunk-jpl/src/m/mesh/triangle.m	(revision 19711)
@@ -1,3 +1,3 @@
-function md=triangle(md,domainname,varargin)
+function md=triangle(md)
 %TRIANGLE - create model mesh using the triangle package
 %
Index: /issm/trunk-jpl/src/m/parameterization/setmask.js
===================================================================
--- /issm/trunk-jpl/src/m/parameterization/setmask.js	(revision 19711)
+++ /issm/trunk-jpl/src/m/parameterization/setmask.js	(revision 19711)
@@ -0,0 +1,70 @@
+function md=setmask(md,floatingicename,groundedicename,varargin)
+%SETMASK - establish boundaries between grounded and floating ice.
+%
+%   By default, ice is considered grounded. The contour floatingicename defines nodes 
+%   for which ice is floating. The contour groundedicename defines nodes inside an floatingice, 
+%   that are grounded (ie: ice rises, islands, etc ...)
+%   All input files are in the Argus format (extension .exp).
+%
+%   Usage:
+%      md=setmask(md,floatingicename,groundedicename)
+%
+%   Examples:
+%      md=setmask(md,'all','');
+%      md=setmask(md,'Iceshelves.exp','Islands.exp');
+
+%some checks on list of arguments
+if ((mod(nargin,2)==0) | (nargout~=1)),
+	help mask
+	error('mask error message');
+end
+
+if(nargin>3)
+	if(varargin(1)=='icedomain'),
+		icedomainname=varargin(2);	
+	else
+		error('mask error message: wrong field specified. Only icedomain allowed for now.');
+	end
+	if ~exist(icedomainname),
+        error(['setmask error message: file ' icedomainname ' not found!']);
+	end
+end
+
+%Get assigned fields
+x=md.mesh.x;
+y=md.mesh.y;
+elements=md.mesh.elements;
+
+%Assign elementonfloatingice, elementongroundedice, vertexongroundedice and vertexonfloatingice. Only change at your own peril! This is synchronized heavily with the GroundingLineMigration module. {{{
+elementonfloatingice=FlagElements(md,floatingicename);
+elementongroundedice=FlagElements(md,groundedicename);
+
+%Because groundedice nodes and elements can be included into an floatingice, we need to update. Remember, all the previous 
+%arrays come from domain outlines that can intersect one another: 
+elementonfloatingice=double((elementonfloatingice & ~elementongroundedice));
+elementongroundedice=double(~elementonfloatingice);
+
+%the order here is important. we choose vertexongroundedice as default on the grounding line.
+vertexonfloatingice=zeros(md.mesh.numberofvertices,1);
+vertexongroundedice=zeros(md.mesh.numberofvertices,1);
+vertexongroundedice(md.mesh.elements(find(elementongroundedice),:))=1;
+vertexonfloatingice(find(~vertexongroundedice))=1;
+%}}}
+
+%level sets
+md.mask.groundedice_levelset=vertexongroundedice;
+md.mask.groundedice_levelset(find(vertexongroundedice==0.))=-1.;
+
+if(nargin>3)
+	if(varargin(1)=='icedomain')
+		md.mask.ice_levelset = 1.*ones(md.mesh.numberofvertices,1);
+		%use contourtomesh to set ice values inside ice domain
+		[vertexinsideicedomain,elementinsideicedomain]=ContourToMesh(elements,x,y,icedomainname,'node',1);
+		pos=find(vertexinsideicedomain==1.);
+		md.mask.ice_levelset(pos) = -1.;
+	end
+else
+	md.mask.ice_levelset = -1.*ones(md.mesh.numberofvertices,1);
+end
+
+
Index: /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.cpp	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.cpp	(revision 19711)
@@ -10,5 +10,5 @@
 	_printf0_("\n");
 }/*}}}*/
-WRAPPER(NodeConnectivity){
+WRAPPER(NodeConnectivity, double** pconnectivity, int* pnods, int *pwidth, int* elementsin, int nelsin, int nodsin){
 
 	/*inputs: */
Index: /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h	(revision 19711)
@@ -22,5 +22,7 @@
 /*Header files: */
 #include "../bindings.h"
+#ifndef _HAVE_JAVASCRIPT_MODULES_
 #include "../../c/main/globals.h"
+#endif
 #include "../../c/toolkits/toolkits.h"
 #include "../../c/modules/modules.h"
@@ -45,4 +47,12 @@
 #endif
 
+#ifdef _HAVE_JAVASCRIPT_MODULES_
+/* serial input macros: */
+#define ELEMENTS elementsin, nelsin,3
+#define NUMNODES nodsin
+/* serial output macros: */
+#define CONNECTIVITY pconnectivity,pnods,pwidth
+#endif
+
 /* serial arg counts: */
 #undef NLHS
Index: /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.js
===================================================================
--- /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.js	(revision 19711)
+++ /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.js	(revision 19711)
@@ -0,0 +1,43 @@
+function NodeConnectivity(elementsin,nods){
+/*NodeConnectivity 
+	   usage: var md.mesh.vertexconnectivity = NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices);
+*/
+
+	//Dynamic allocations: {{{
+	//Retrieve elements and allocate on Module heap: 
+	
+	//input
+	var delements=new Int32Array(MatrixToList(elementsin)); var nelements=delements.length * delements.BYTES_PER_ELEMENT;
+	var delementsPtr= Module._malloc(nelements); var elementsHeap = new Uint8Array(Module.HEAPU8.buffer,delementsPtr,nelements);
+	elementsHeap.set(new Uint8Array(delements.buffer)); var elements=elementsHeap.byteOffset;
+
+	//output
+	var width,connectivitylinear,connectivity;
+	var pwidth= Module._malloc(4); 
+	var pnods= Module._malloc(4); 
+	var pconnectivity= Module._malloc(4); 
+	var nels=elementsin.length;
+	//}}}
+
+	//Declare NodeConnectivity module: 
+	NodeConnectivityModule = Module.cwrap('NodeConnectivityModule','number',['number','number','number','number']);
+	
+	//Call NodeConnectivity module: 
+	NodeConnectivityModule(pconnectivity,pnods,pwidth,elements,nels,nods);
+	
+	/*Dynamic copying from heap: {{{*/
+	//recover mesh: 
+	width = Module.getValue(pwidth, 'i32');
+	var connectivityptr = Module.getValue(pconnectivity,'i32');
+	connectivitylinear = Module.HEAPF64.slice(connectivityptr /8, connectivityptr/8 + nods*width);
+	connectivity = ListToMatrix(connectivitylinear,width);
+	/*}}}*/
+
+	/*Free ressources: */
+	Module._free(pconnectivity); 
+	Module._free(connectivitylinear); 
+	Module._free(pwidth); 
+	Module._free(pnods); 
+
+	return connectivity;
+}
Index: /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.cpp	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.cpp	(revision 19711)
@@ -14,5 +14,5 @@
 	_printf_("\n");
 }/*}}}*/
-WRAPPER(TriMesh,double** pindex, double** px, double** py, int* pnel, int* pnods, double* domainx, double* domainy, int domainnods, double areain){
+WRAPPER(TriMesh,double** pindex, double** px, double** py, int* pnel, int* pnods, double** psegments, double** psegmentmarkers, int* pnsegs, double* domainx, double* domainy, int domainnods, double areain){
 	
 
Index: /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h	(revision 19711)
@@ -64,6 +64,6 @@
 #define X                 px,pnods
 #define Y                 py,pnods
-#define SEGMENTS          NULL,NULL
-#define SEGMENTMARKERLIST NULL,NULL
+#define SEGMENTS          psegments,pnsegs
+#define SEGMENTMARKERLIST psegmentmarkers,pnsegs
 #endif
 
Index: /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.js
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.js	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.js	(revision 19711)
@@ -31,11 +31,14 @@
 	var px= Module._malloc(4); 
 	var py= Module._malloc(4); 
+	var psegments= Module._malloc(4); 
+	var psegmentmarkers= Module._malloc(4); 
+	var pnsegs= Module._malloc(4); 
 	//}}}
 
 	//Declare TriMesh module: 
-	TriMeshModule = Module.cwrap('TriMeshModule','number',['number','number','number','number','number','number','number','number','number']);
+	TriMeshModule = Module.cwrap('TriMeshModule','number',['number','number','number','number','number','number','number','number','number','number','number','number']);
 	
 	//Call TriMesh module: 
-	TriMeshModule(pindex,px,py,pnel,pnods,domainx,domainy,dx.length,area);
+	TriMeshModule(pindex,px,py,pnel,pnods,psegments,psegmentmarkers,pnsegs, domainx,domainy,dx.length,area);
 	
 	/*Dynamic copying from heap: {{{*/
@@ -44,5 +47,5 @@
 	var indexptr = Module.getValue(pindex,'i32');
 	indexlinear = Module.HEAPF64.slice(indexptr /8, indexptr/8 + nel*3);
-	index = listToMatrix(indexlinear,3);
+	index = ListToMatrix(indexlinear,3);
 
 	nods = Module.getValue(pnods, 'i32');
@@ -51,16 +54,15 @@
 	x = Module.HEAPF64.slice(xptr /8, xptr/8 + nods);
 	y = Module.HEAPF64.slice(yptr /8, yptr/8 + nods);
+	
+	nsegs = Module.getValue(pnsegs, 'i32');
+	var segmentsptr = Module.getValue(psegments,'i32');
+	segmentslinear = Module.HEAPF64.slice(segmentsptr /8, segmentsptr/8 + nsegs*3);
+	segments = ListToMatrix(segmentslinear,3);
+	
+	var segmentmarkersptr = Module.getValue(psegmentmarkers,'i32');
+	segmentmarkers = Module.HEAPF64.slice(segmentmarkersptr /8, segmentmarkersptr/8 + nsegs);
 	/*}}}*/
 
-	/*Assign output: */
-	md.mesh=new mesh2d();
-
-	md.mesh.elements=index;
-	md.mesh.numberofelements=nel;
-	md.mesh.numberofvertices=nods;
-	md.mesh.x=x;
-	md.mesh.y=y;
-	md.mesh.segments=[];
-	md.mesh.segmentmarkers=[];
+	var return_array=[index,x,y,segments,segmentmarkers];
 
 	/*Free ressources: */
@@ -73,4 +75,8 @@
 	Module._free(pnel); 
 	Module._free(pnods); 
+	Module._free(psegments); 
+	Module._free(psegmentmarkers); 
+	Module._free(pnsegs); 
 
+	return return_array;
 }
Index: /issm/trunk-jpl/src/wrappers/javascript/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/javascript/Makefile.am	(revision 19711)
@@ -8,5 +8,6 @@
 
 bin_SCRIPTS = 
-bin_SCRIPTS += ../TriMesh/TriMesh.js 
+bin_SCRIPTS += ../TriMesh/TriMesh.js  \
+			   ../NodeConnectivity/NodeConnectivity.js
 	
 #javascript io{{{
@@ -39,5 +40,5 @@
 #}}}
 #Wrappers {{{
-bin_PROGRAMS = 		 TriMeshModule
+bin_PROGRAMS = 		 IssmModule
 #}}}
 
@@ -71,6 +72,7 @@
 endif
 
-TriMeshModule_SOURCES = ../TriMesh/TriMesh.cpp
-TriMeshModule_CXXFLAGS= -fPIC --memory-init-file 0 $(AM_CXXFLAGS) $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) -s EXPORTED_FUNCTIONS="['_TriMeshModule']"  -s DISABLE_EXCEPTION_CATCHING=0
-TriMeshModule_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(TRIANGLELIB) $(GSLLIB) $(PROJ4LIB)
+IssmModule_SOURCES = ../TriMesh/TriMesh.cpp \
+					 ../NodeConnectivity/NodeConnectivity.cpp
+IssmModule_CXXFLAGS= -fPIC --memory-init-file 0 $(AM_CXXFLAGS) $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) -s EXPORTED_FUNCTIONS="['_TriMeshModule','_NodeConnectivityModule']"  -s DISABLE_EXCEPTION_CATCHING=0
+IssmModule_LDADD = ${deps} $(TRIANGLELIB) 
 #}}}
Index: /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp	(revision 19711)
@@ -19,5 +19,49 @@
 }
 /*}}}*/
+/*FUNCTION FetchData(double* pscalar,double scalar){{{*/
+void FetchData(int* pinteger,int integer){
+	
+	*pinteger = integer;
+}
+/*}}}*/
+/*FUNCTION FetchData(double **pvector, double* vectorin, int nods){{{*/
+void FetchData(double** pvector, double* vectorin, int nods){
 
+	double* vector=NULL;
+	
+	vector=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(vector,vectorin,nods);
+	
+	*pvector=vector;
+}
+/*}}}*/
+/*FUNCTION FetchData(double **pmatrix, int* pM, int* pN, int* matrix, int M, int N){{{*/
+void FetchData(double **pmatrix, int* pM, int* pN, int* matrixin, int M, int N){
+
+	double* matrix=NULL;
+	
+	if(pmatrix && matrixin){ 
+
+		matrix=xNew<IssmPDouble>(M*N); 
+		for(int i=0;i<M*N;i++)matrix[i]=(IssmPDouble)matrixin[i];
+		if (pM)*pM=M;
+		if (pN)*pN=N;
+		*pmatrix=matrix;
+	}
+}
+/*}}}*/
+/*FUNCTION FetchData(int **pmatrix, int* pM, int* pN, int* matrix, int M, int N){{{*/
+void FetchData(int **pmatrix, int* pM, int* pN, int* matrixin, int M, int N){
+
+	int* matrix=NULL;
+	
+	if(pmatrix && matrixin){ 
+
+		matrix=xNew<int>(M*N);xMemCpy<int>(matrix,matrixin,M*N); 
+		if (pM)*pM=M;
+		if (pN)*pN=N;
+		*pmatrix=matrix;
+	}
+}
+/*}}}*/
 /*ISSM objects*/
 /*FUNCTION FetchData(Contours** pcontours,double* x, double* y, int nods){{{*/
Index: /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/WriteJavascriptData.cpp	(revision 19711)
@@ -23,4 +23,18 @@
 		*pmatrix=dmatrix;
 		*pnel=M;
+	}
+}
+/*}}}*/
+/*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){
+
+	if(pmatrix && matrix){
+
+		/*Copy matrix: */
+		IssmPDouble* dmatrix = xNew<IssmPDouble>(M*N); 
+		for (int i=0;i<M*N;i++)dmatrix[i]=(IssmPDouble)matrix[i];
+		*pmatrix=dmatrix;
+		*pM=M;
+		*pN=N;
 	}
 }
Index: /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 19710)
+++ /issm/trunk-jpl/src/wrappers/javascript/io/javascriptio.h	(revision 19711)
@@ -19,8 +19,13 @@
 
 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** px, int* pnods, int* vector, int M);
 void WriteData(IssmPDouble** px, int* pnods, double* vector, int M);
 
 void FetchData(double* pscalar,double scalar);
+void FetchData(int* pinteger,int integer);
+void FetchData(double** pvector, double* vectorin, int nods);
+void FetchData(double **pmatrix, int* pM, int* pN, int* matrixin, int M, int N);
+void FetchData(int **pmatrix, int* pM, int* pN, int* matrixin, int M, int N);
 void FetchData(Contours** pcontours,double* x, double* y, int nods);
 
Index: /issm/trunk-jpl/test/NightlyRun/test101.html
===================================================================
--- /issm/trunk-jpl/test/NightlyRun/test101.html	(revision 19710)
+++ /issm/trunk-jpl/test/NightlyRun/test101.html	(revision 19711)
@@ -9,8 +9,10 @@
 <script type="text/javascript" src="../../src/m/classes/model.js"></script>
 <script type="text/javascript" src="../../src/m/mesh/triangle.js"></script>
-<script type="text/javascript" src="../../src/m/array/listToMatrix.js"></script>
+<script type="text/javascript" src="../../src/m/array/ArrayOperations.js"></script>
 <script type="text/javascript" src="../../src/m/classes/mesh2d.js"></script>
 <script type="text/javascript" src="../../src/wrappers/TriMesh/TriMesh.js"></script>
 <script type="text/javascript" src="../../build-js/src/wrappers/javascript/TriMeshModule.js"></script>
+<script type="text/javascript" src="../../src/wrappers/NodeConnectivity/NodeConnectivity.js"></script>
+<script type="text/javascript" src="../../build-js/src/wrappers/javascript/IssmModule.js"></script>
 <script type="text/javascript" src="../../externalpackages/javascript/src/sprintf.js"></script>
 <!-- Includes }}}-->
@@ -20,6 +22,7 @@
 	<script type="text/javascript" async>
 	var md = new model();
-	triangle(md,square,[],5000); 
-	setmask(md,'all','');
+	triangle(md,square,50000); 
+	md.mesh.disp();
+
 
 	</script>
