Index: /issm/trunk-jpl/configs/config-macosx64-larour-nopetsc.sh
===================================================================
--- /issm/trunk-jpl/configs/config-macosx64-larour-nopetsc.sh	(revision 12111)
+++ /issm/trunk-jpl/configs/config-macosx64-larour-nopetsc.sh	(revision 12112)
@@ -1,5 +1,5 @@
 #!/bin/sh
 
-pythonversion=2.7
+pythonversion=3.2
 
 ./configure \
Index: /issm/trunk-jpl/src/c/python/io/FetchPythonData.cpp
===================================================================
--- /issm/trunk-jpl/src/c/python/io/FetchPythonData.cpp	(revision 12111)
+++ /issm/trunk-jpl/src/c/python/io/FetchPythonData.cpp	(revision 12112)
@@ -57,4 +57,28 @@
 }
 /*}}}*/
+/*FUNCTION FetchData(double** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{1*/
+void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_matrix){
+
+	/*output: */
+	double* matrix=NULL;
+	int M,N;
+	int ndim;
+	npy_intp*  dims=NULL;
+
+	/*retrive dimensions: */
+	ndim=PyArray_NDIM((const PyArrayObject*)py_matrix);
+	if(ndim!=2)_error_("expecting an MxN matrix in input!");
+	dims=PyArray_DIMS((PyArrayObject*)py_matrix);
+	M=dims[0]; N=dims[1];
+	
+	/*retrieve internal value: */
+	matrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);
+
+	/*output: */
+	if(pM)*pM=M;
+	if(pN)*pN=N;
+	if(pmatrix)*pmatrix=matrix;
+}
+/*}}}*/
 
 /*Python version dependent: */
Index: /issm/trunk-jpl/src/c/python/io/WritePythonData.cpp
===================================================================
--- /issm/trunk-jpl/src/c/python/io/WritePythonData.cpp	(revision 12111)
+++ /issm/trunk-jpl/src/c/python/io/WritePythonData.cpp	(revision 12112)
@@ -64,2 +64,15 @@
 }
 /*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index, double* matrix, int M, int N){{{1*/
+void WriteData(PyObject* tuple, int index, double* matrix, int M,int N){
+	
+	npy_intp dims[2]={0,0};
+	PyObject* array=NULL;
+	
+	dims[0]=(npy_intp)M;
+	dims[1]=(npy_intp)N;
+	array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix);
+	
+	PyTuple_SetItem(tuple, index, array);
+
+}
Index: /issm/trunk-jpl/src/c/python/io/pythonio.h
===================================================================
--- /issm/trunk-jpl/src/c/python/io/pythonio.h	(revision 12111)
+++ /issm/trunk-jpl/src/c/python/io/pythonio.h	(revision 12112)
@@ -21,5 +21,4 @@
 
 //void WriteData(PyObject* py_tuple,DataSet* dataset);
-//void WriteData(PyObject* py_tuple,double* matrix, int M,int N);
 //void WriteData(PyObject* py_tuple,int*    matrix, int M,int N);
 //void WriteData(PyObject* py_tuple,double* vector, int M);
@@ -28,4 +27,5 @@
 //void WriteData(PyObject* py_tuple,double scalar);
 //void WriteData(DataHandle* py_tuple,Parameters* parameters);
+void WriteData(PyObject* py_tuple, int index, double* matrix, int M,int N);
 void WriteData(PyObject* py_tuple, int index, char* string);
 void WriteData(PyObject* py_tuple, int index, Matrix* matrix);
@@ -34,5 +34,4 @@
 
 //void FetchData(DataSet** pdataset,PyObject* py_ref);
-//void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_ref);
 //void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,PyObject* py_ref);
 //void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_ref);
@@ -47,4 +46,5 @@
 //void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,PyObject* py_ref);
 //void FetchData(Parameters** pparameters, DataHandle py_ref);
+void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array);
 void FetchData(char** pstring,PyObject* py_unicode);
 void FetchData(double* pscalar,PyObject* py_float);
Index: /issm/trunk-jpl/src/m/model/mesh/triangle.py
===================================================================
--- /issm/trunk-jpl/src/m/model/mesh/triangle.py	(revision 12111)
+++ /issm/trunk-jpl/src/m/model/mesh/triangle.py	(revision 12112)
@@ -1,4 +1,6 @@
-from TriMesh import *
 from numpy import *
+import TriMesh as tm
+import NodeConnectivity as nc
+import ElementConnectivity as ec
 
 def triangle(md, domainname, resolution,riftname=''):
@@ -32,5 +34,5 @@
 
 	#Mesh using TriMesh
-	[md.mesh.elements,md.mesh.x,md.mesh.y,md.mesh.segments,md.mesh.segmentmarkers]=TriMesh(domainname,riftname,area)
+	[md.mesh.elements,md.mesh.x,md.mesh.y,md.mesh.segments,md.mesh.segmentmarkers]=tm.TriMesh(domainname,riftname,area)
 
 	#Fill in rest of fields:
@@ -46,8 +48,6 @@
 
 	#Now, build the connectivity tables for this mesh.
-	print "Node: NodeConnectivity not implemented yet!"
-	#md.mesh.vertexconnectivity = NodeConnectivity((md.mesh.elements), (md.mesh.numberofvertices))
-	print "Node: ElementConnectivity not implemented yet!"
-	#md.mesh.elementconnectivity = ElementConnectivity((md.mesh.elements), (md.mesh.vertexconnectivity))
+	[md.mesh.vertexconnectivity]= nc.NodeConnectivity(md.mesh.elements, md.mesh.numberofvertices)
+	[md.mesh.elementconnectivity] = ec.ElementConnectivity(md.mesh.elements, md.mesh.vertexconnectivity)
 
 	#type of model
Index: /issm/trunk-jpl/src/m/model/setmask.py
===================================================================
--- /issm/trunk-jpl/src/m/model/setmask.py	(revision 12112)
+++ /issm/trunk-jpl/src/m/model/setmask.py	(revision 12112)
@@ -0,0 +1,55 @@
+from numpy import *
+import FlagElements as fe
+
+def setmask(md, floatingicename, groundedicename):
+	#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');
+
+	#%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. {{{1
+	elementonfloatingice = fe.FlagElements(md, floatingicename)
+	elementongroundedice = fe.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 = logical_and(elementonfloatingice,~elementongroundedice)
+	elementongroundedice = ~elementonfloatingice
+
+	#the order here is important. we choose vertexongroundedice as default on the grounding line.
+	vertexonfloatingice = zeros(md.mesh.numberofvertices,'bool')
+	vertexongroundedice = zeros(md.mesh.numberofvertices,'bool')
+
+	pos=argwhere(elementongroundedice==1)
+	pos=md.mesh.elements[pos,:]-1
+	if pos.size:
+		vertexongroundedice[pos]=True
+
+	pos=argwhere(~vertexongroundedice)
+	if pos.size:
+		vertexonfloatingice[pos]=True;
+	#%}}}
+
+	#Return: 
+	md.mask.elementonfloatingice = double(elementonfloatingice)
+	md.mask.vertexonfloatingice = double(vertexonfloatingice)
+	md.mask.elementongroundedice = double(elementongroundedice)
+	md.mask.vertexongroundedice = double(vertexongroundedice)
+	md.mask.vertexonwater = zeros(md.mesh.numberofvertices)
+	md.mask.elementonwater = zeros(md.mesh.numberofelements)
+	return md
Index: /issm/trunk-jpl/src/m/utils/Geometry/FlagElements.py
===================================================================
--- /issm/trunk-jpl/src/m/utils/Geometry/FlagElements.py	(revision 12112)
+++ /issm/trunk-jpl/src/m/utils/Geometry/FlagElements.py	(revision 12112)
@@ -0,0 +1,54 @@
+from numpy import * 
+def FlagElements(md,region):
+#FLAGELEMENTS - flag the elements in an region
+#
+#   The region can be given with an exp file, a list of elements.
+#
+#   Usage: 
+#      flag=FlagElements(md,region);
+#
+#   Example:
+#      flag=FlagElements(md,'all');
+#      flag=FlagElements(md,'');
+#      flag=FlagElements(md,'Domain.exp');
+#      flag=FlagElements(md,'~Domain.exp');
+#      flag=FlagElements(md,md.mask.elementongroundedice);
+
+	if isinstance(region,basestring):
+		if not(region):
+			flag=zeros(md.mesh.numberofelements,'bool')
+			invert=0;
+		elif region=='all':
+			flag=ones(md.mesh.numberofelements,'bool')
+			invert=0;
+		else:
+			#make sure that we actually don't want the elements outside the domain outline!
+			if region[0]=='~':
+				region=region[1:]
+				invert=1;
+			else:
+				invert=0;
+			
+			#does the region domain outline exist or do we have to look for xlim,ylim in basinzoom?
+			if not os.path.isfile(region):
+				[xlim,ylim]=basinzoom('basin',region);
+				flag_nodes=double(md.mesh.x<xlim(2) & md.mesh.x>xlim(1) &  md.mesh.y<ylim(2) & md.mesh.y>ylim(1));
+				flag=prod(flag_nodes(md.mesh.elements),2);
+			else:
+				#ok, flag elements
+				flag=ContourToMesh(md.mesh.elements[:,0:3],md.mesh.x,md.mesh.y,region,'element',1);
+		
+		if invert:
+			flag=~flag;
+	
+	elif isinstance(region,nparray):
+		if len(region)!=md.mesh.numberofelements:
+			print FlagElements.__doc__
+			print 'Flaglist for region must be of same size as number of elements in model'
+			return []
+		flag=region;
+	else:
+		print 'Invalid region option'
+		return []
+
+	return flag;
Index: /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.cpp	(revision 12111)
+++ /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.cpp	(revision 12112)
@@ -5,5 +5,5 @@
 #include "./ElementConnectivity.h"
 
-void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+WRAPPER(ElementConnectivity){
 
 	/*inputs: */
@@ -19,6 +19,6 @@
 	MODULEBOOT();
 
-	/*checks on arguments on the matlab side: */
-	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ElementConnectivityUsage);
+	/*checks on arguments: */
+	CHECKARGUMENTS(NLHS,NRHS,&ElementConnectivityUsage);
         
 	/*Input datasets: */
@@ -32,8 +32,4 @@
 	WriteData(ELEMENTCONNECTIVITY,elementconnectivity,nel,3);
 
-	/*Free ressources: */
-	xfree((void**)&elements);
-	xfree((void**)&nodeconnectivity);
-
 	/*end module: */
 	MODULEEND();
Index: /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.h	(revision 12111)
+++ /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.h	(revision 12112)
@@ -6,22 +6,46 @@
 #define _ELEMENTCONNECTIVITY_H
 
-/* local prototypes: */
-void ElementConnectivityUsage(void);
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
 
+/*Very important definition in case we are compiling a python module!: needs to come before header files inclusion*/
+#ifdef _HAVE_PYTHON_
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#endif
+
+/*Header files: */
 #include "../../c/include/globals.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/include/include.h"
 #include "../../c/modules/modules.h"
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
 #include "../../c/issm-binding.h"
+#include "../../c/io/io.h"
+#include "../../c/EnumDefinitions/EnumDefinitions.h"
+
+#ifdef _HAVE_MATLAB_MODULES_
+/* serial input macros: */
+/* serial input macros: */
+#define ELEMENTS (mxArray*)prhs[0]
+#define NODECONNECTIVITY (mxArray*)prhs[1]
+/* serial output macros: */
+#define ELEMENTCONNECTIVITY (mxArray**)&plhs[0]
+#endif
+
+#ifdef _HAVE_PYTHON_MODULES_
+/* serial input macros: */
+/* serial input macros: */
+#define ELEMENTS PyTuple_GetItem(args,0)
+#define NODECONNECTIVITY PyTuple_GetItem(args,1)
+/* serial output macros: */
+#define ELEMENTCONNECTIVITY output,0
+#endif
 
 #undef __FUNCT__ 
 #define __FUNCT__  "ElementConnectivity"
-
-/* serial input macros: */
-#define ELEMENTS (mxArray*)prhs[0]
-#define NODECONNECTIVITY (mxArray*)prhs[1]
-
-/* serial output macros: */
-#define ELEMENTCONNECTIVITY (mxArray**)&plhs[0]
 
 /* serial arg counts: */
@@ -31,3 +55,6 @@
 #define NRHS  2
 
+/* local prototypes: */
+void ElementConnectivityUsage(void);
+
 #endif  /* _ELEMENTCONNECTIVITY_H */
Index: /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.cpp	(revision 12111)
+++ /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.cpp	(revision 12112)
@@ -5,9 +5,10 @@
 #include "./NodeConnectivity.h"
 
-void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+WRAPPER(NodeConnectivity){
 
 	/*inputs: */
 	double* elements=NULL;
-	int     nel,nods;
+	int     nel;
+	int     nods;
 
 	/*outputs: */
@@ -18,6 +19,6 @@
 	MODULEBOOT();
 
-	/*checks on arguments on the matlab side: */
-	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&NodeConnectivityUsage);
+	/*checks on arguments: */
+	CHECKARGUMENTS(NLHS,NRHS,&NodeConnectivityUsage);
         
 	/*Input datasets: */
@@ -31,7 +32,4 @@
 	WriteData(CONNECTIVITY,connectivity,nods,width);
 
-	/*Free ressources: */
-	xfree((void**)&elements);
-
 	/*end module: */
 	MODULEEND();
Index: /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.h	(revision 12111)
+++ /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.h	(revision 12112)
@@ -6,22 +6,44 @@
 #define _NODECONNECTIVITY_H
 
-/* local prototypes: */
-void NodeConnectivityUsage(void);
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
 
+/*Very important definition in case we are compiling a python module!: needs to come before header files inclusion*/
+#ifdef _HAVE_PYTHON_
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#endif
+
+/*Header files: */
 #include "../../c/include/globals.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/include/include.h"
 #include "../../c/modules/modules.h"
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
 #include "../../c/issm-binding.h"
+#include "../../c/io/io.h"
+#include "../../c/EnumDefinitions/EnumDefinitions.h"
+
+#ifdef _HAVE_MATLAB_MODULES_
+/* serial input macros: */
+#define ELEMENTS (mxArray*)prhs[0]
+#define NUMNODES (mxArray*)prhs[1]
+/* serial output macros: */
+#define CONNECTIVITY (mxArray**)&plhs[0]
+#endif
+
+#ifdef _HAVE_PYTHON_MODULES_
+/* serial input macros: */
+#define ELEMENTS PyTuple_GetItem(args,0)
+#define NUMNODES PyTuple_GetItem(args,1)
+/* serial output macros: */
+#define CONNECTIVITY output,0
+#endif
 
 #undef __FUNCT__ 
 #define __FUNCT__  "NodeConnectivity"
-
-/* serial input macros: */
-#define ELEMENTS (mxArray*)prhs[0]
-#define NUMNODES (mxArray*)prhs[1]
-
-/* serial output macros: */
-#define CONNECTIVITY (mxArray**)&plhs[0]
 
 /* serial arg counts: */
@@ -31,3 +53,6 @@
 #define NRHS  2
 
+/* local prototypes: */
+void NodeConnectivityUsage(void);
+
 #endif  /* _NODECONNECTIVITY_H */
Index: /issm/trunk-jpl/src/modules/TriMesh/TriMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriMesh/TriMesh.cpp	(revision 12111)
+++ /issm/trunk-jpl/src/modules/TriMesh/TriMesh.cpp	(revision 12112)
@@ -26,5 +26,5 @@
 	MODULEBOOT();
 
-	/*checks on arguments on the matlab side: */
+	/*checks on arguments: */
 	CHECKARGUMENTS(NLHS,NRHS,&TriMeshUsage);
 	
Index: /issm/trunk-jpl/src/modules/python/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/modules/python/Makefile.am	(revision 12111)
+++ /issm/trunk-jpl/src/modules/python/Makefile.am	(revision 12112)
@@ -3,5 +3,7 @@
 #Bin programs {{{1
 if MODULES
-bin_PROGRAMS = TriMesh
+bin_PROGRAMS = TriMesh \
+			   NodeConnectivity \
+			   ElementConnectivity
 endif 
 #}}}
@@ -26,4 +28,10 @@
 #}}}
 #Bin sources {{{1
+ElementConnectivity_SOURCES = ../ElementConnectivity/ElementConnectivity.cpp\
+			  ../ElementConnectivity/ElementConnectivity.h
+
+NodeConnectivity_SOURCES = ../NodeConnectivity/NodeConnectivity.cpp\
+										../NodeConnectivity/NodeConnectivity.h
+
 TriMesh_SOURCES = ../TriMesh/TriMesh.cpp\
 			  ../TriMesh/TriMesh.h
Index: /issm/trunk-jpl/startup.py
===================================================================
--- /issm/trunk-jpl/startup.py	(revision 12111)
+++ /issm/trunk-jpl/startup.py	(revision 12112)
@@ -83,4 +83,5 @@
 from private import *
 from triangle import *
+from setmask import *
 
 #}}}
Index: /issm/trunk-jpl/test/NightlyRun/test102.py
===================================================================
--- /issm/trunk-jpl/test/NightlyRun/test102.py	(revision 12111)
+++ /issm/trunk-jpl/test/NightlyRun/test102.py	(revision 12112)
@@ -1,5 +1,7 @@
 from model import *
 from triangle import *
+from setmask import *
 
 md=model();
 md=triangle(md,'../Exp/Square.exp',150000);
+md=setmask(md,'all','');
