Index: /issm/trunk-jpl/src/m/modules/MeshPartition.m
===================================================================
--- /issm/trunk-jpl/src/m/modules/MeshPartition.m	(revision 22673)
+++ /issm/trunk-jpl/src/m/modules/MeshPartition.m	(revision 22674)
@@ -3,5 +3,5 @@
 %
 %	   Usage:
-%			[element_partitioning,node_partitioning]=MeshPartition(md.mesh,numpartitions)");
+%			[element_partitioning,node_partitioning]=MeshPartition(md,numpartitions)");
 %
 %	   element_partitioning: Vector of partitioning area numbers, for every element.
@@ -14,4 +14,24 @@
 end
 
+%Get mesh info from md.mesh
+numberofvertices = md.mesh.numberofvertices;
+numberofelements = md.mesh.numberofelements;
+elements         = md.mesh.elements;
+numberofelements2d = 0;
+numberofvertices2d = 0;
+numberoflayers     = 1;
+elements2d         = [];
+if isa(md.mesh,'mesh3dprisms')
+	elementtype = 'Penta';
+	numberofelements2d = md.mesh.numberofelements2d;
+	numberofvertices2d = md.mesh.numberofvertices2d;
+	numberoflayers     = md.mesh.numberoflayers;
+	elements2d         = md.mesh.elements2d;
+elseif isa(md.mesh,'mesh2d')
+	elementtype = 'Tria';
+elseif isa(md.mesh,'mesh2dvertical')
+	elementtype = 'Tria';
+end
+
 % Call mex module
-[element_partitioning, node_partitioning] = MeshPartition_matlab(md.mesh,numpartitions);
+[element_partitioning, node_partitioning] = MeshPartition_matlab(numberofvertices,elements,numberofvertices2d,elements2d,numberoflayers,meshelementtype,numpartitions);
Index: /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.cpp	(revision 22673)
+++ /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.cpp	(revision 22674)
@@ -15,18 +15,12 @@
 WRAPPER(MeshPartition_python){
 
-	/*Indexing: */
-	int i,j;
-
 	/* required input: */
-	int  meshelementtype;
 	int  numberofelements;
 	int  numberofvertices;
-	int *elements         = NULL;
+	int *elements = NULL;
 	int  elements_width;
-
 	int numberofelements2d=0;
 	int numberofvertices2d=0;
 	int* elements2d=NULL;
-
 	int numberoflayers;
 	int numareas=1;
@@ -42,30 +36,19 @@
 
 	/*checks on arguments on the matlab side: */
-	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&MeshPartitionUsage);
+	CHECKARGUMENTS(NLHS,NRHS,&MeshPartitionUsage);
 
 	/*Fetch data: */
-	FetchData(&numberofelements,mxGetAssignedField(MESH,0,"numberofelements"));
-	FetchData(&numberofvertices,mxGetAssignedField(MESH,0,"numberofvertices"));
-	FetchData(&elements,NULL,&elements_width,mxGetAssignedField(MESH,0,"elements"));
+	FetchData(&numberofvertices,NUMBEROFVERTICES);
+	FetchData(&elements,&numberofelements,&elements_width,ELEMENTS);
+	FetchData(&numberofvertices2d,NUMBEROFVERTICES2D);
+	FetchData(&elements2d,&numberofelements2d,NULL,ELEMENTS2D);
+	FetchData(&numberoflayers,NUMBEROFLAYERS);
+	FetchData(&numareas,NUMAREAS);
 
-	if(strcmp(mxGetClassName(MESH),"mesh3dprisms")==0){
-		meshelementtype = PentaEnum;
-		FetchData(&numberofelements2d,mxGetAssignedField(MESH,0,"numberofelements2d"));
-		FetchData(&numberofvertices2d,mxGetAssignedField(MESH,0,"numberofvertices2d"));
-		FetchData(&elements2d,NULL,NULL,mxGetAssignedField(MESH,0,"elements2d"));
-		FetchData(&numberoflayers,mxGetAssignedField(MESH,0,"numberoflayers"));
-	}
-	else if(strcmp(mxGetClassName(MESH),"mesh2d")==0){
-		meshelementtype = TriaEnum;
-		numberoflayers=1;
-	}
-	else if(strcmp(mxGetClassName(MESH),"mesh2dvertical")==0){
-		meshelementtype = TriaEnum;
-		numberoflayers=1;
-	}
-	else{
-		_error_("Mesh type "<<mxGetClassName(MESH)<<" not supported yet");
-	}
-	FetchData(&numareas,NUMAREAS);
+	/*Get mesh element type and convert to Enum*/
+	char* meshtype_str = NULL;
+	FetchData(&meshtype_str,MESHELEMENTTYPE);
+	int meshelementtype = StringToEnumx(meshtype_str); 
+	xDelete<char>(meshtype_str);
 
 	/*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
@@ -75,10 +58,10 @@
 	/*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
 	element_partitioning=xNew<double>(numberofelements);
-	for (i=0;i<numberofelements;i++){
+	for(int i=0;i<numberofelements;i++){
 		element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
 	}
 
 	node_partitioning=xNew<double>(numberofvertices);
-	for (i=0;i<numberofvertices;i++){
+	for(int i=0;i<numberofvertices;i++){
 		node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
 	}
@@ -90,5 +73,5 @@
 	/*Free ressources:*/
 	xDelete<int>(elements);
-	xDelete<int>( elements2d);
+	xDelete<int>(elements2d);
 	xDelete<int>(int_element_partitioning);
 	xDelete<int>(int_node_partitioning);
Index: /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h	(revision 22673)
+++ /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h	(revision 22674)
@@ -27,6 +27,11 @@
 #ifdef _HAVE_MATLAB_MODULES_
 /* serial input macros: */
-#define MESH    prhs[0]
-#define NUMAREAS prhs[1]
+#define NUMBEROFVERTICES   prhs[0]
+#define ELEMENTS           prhs[1]
+#define NUMBEROFVERTICES2D prhs[2]
+#define ELEMENTS2D         prhs[3]
+#define NUMBEROFLAYERS     prhs[4]
+#define MESHELEMENTTYPE    prhs[5]
+#define NUMAREAS           prhs[6]
 /* serial output macros: */
 #define ELEMENTPARTITIONING (mxArray**)&plhs[0]
@@ -36,6 +41,11 @@
 #ifdef _HAVE_PYTHON_MODULES_
 /* serial input macros: */
-#define MESH     PyTuple_GetItem(args,0)
-#define NUMAREAS PyTuple_GetItem(args,1)
+#define NUMBEROFVERTICES   PyTuple_GetItem(args,0)
+#define ELEMENTS           PyTuple_GetItem(args,1)
+#define NUMBEROFVERTICES2D PyTuple_GetItem(args,2)
+#define ELEMENTS2D         PyTuple_GetItem(args,3)
+#define NUMBEROFLAYERS     PyTuple_GetItem(args,4)
+#define MESHELEMENTTYPE    PyTuple_GetItem(args,5)
+#define NUMAREAS           PyTuple_GetItem(args,6)
 /* serial output macros: */
 #define ELEMENTPARTITIONING output,0
@@ -47,5 +57,5 @@
 #define NLHS  2
 #undef NRHS
-#define NRHS  2
+#define NRHS  7
 
 #endif  /* _MESHPARTITION_H */
Index: /issm/trunk-jpl/src/wrappers/python/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/Makefile.am	(revision 22673)
+++ /issm/trunk-jpl/src/wrappers/python/Makefile.am	(revision 22674)
@@ -39,8 +39,13 @@
 						InterpFromMeshToGrid_python.la\
 						IssmConfig_python.la\
+						MeshPartition_python.la\
 						MeshProfileIntersection_python.la\
 						NodeConnectivity_python.la\
 						Triangle_python.la\
 						ProcessRifts_python.la
+
+if CHACO
+lib_LTLIBRARIES += Chaco_python.la
+endif
 endif 
 #}}}
@@ -101,4 +106,10 @@
 BamgTriangulate_python_la_LIBADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB) $(PROJ4LIB)
 
+if CHACO
+Chaco_python_la_SOURCES = ../Chaco/Chaco.cpp
+Chaco_python_la_CXXFLAGS = ${AM_CXXFLAGS}
+Chaco_python_la_LIBADD = ${deps} $(MPILIB)  $(CHACOLIB) $(PETSCLIB) $(GSLLIB) $(PROJ4LIB)
+endif
+
 ContourToMesh_python_la_SOURCES = ../ContourToMesh/ContourToMesh.cpp
 ContourToMesh_python_la_CXXFLAGS = ${AM_CXXFLAGS}
@@ -133,4 +144,8 @@
 IssmConfig_python_la_LIBADD = ${deps} $(MPILIB) $(PETSCLIB)
 
+MeshPartition_python_la_SOURCES = ../MeshPartition/MeshPartition.cpp
+MeshPartition_python_la_CXXFLAGS = ${AM_CXXFLAGS}
+MeshPartition_python_la_LIBADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB) $(PROJ4LIB)
+
 MeshProfileIntersection_python_la_SOURCES = ../MeshProfileIntersection/MeshProfileIntersection.cpp
 MeshProfileIntersection_python_la_CXXFLAGS = ${AM_CXXFLAGS}
Index: /issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp	(revision 22673)
+++ /issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp	(revision 22674)
@@ -44,4 +44,34 @@
 	/*output: */
 	*pscalar=dscalar;
+}
+/*}}}*/
+/*FUNCTION FetchData(float* pscalar,PyObject* py_float){{{*/
+void FetchData(float* pscalar,PyObject* py_float){
+
+	float fscalar;
+
+	/*return internal value: */
+	if  (PyFloat_Check(py_float))
+	 fscalar=PyFloat_AsDouble(py_float);
+	else if (PyLong_Check(py_float)){
+		#if _PYTHON_MAJOR_ == 3
+		fscalar=(float)PyLong_AsLong(py_float);
+		#else
+		fscalar=(float)PyLong_AsDouble(py_float);
+		#endif
+	}
+	else if (PyInt_Check(py_float))
+	 fscalar=(float)PyInt_AsLong(py_float);
+	else if (PyBool_Check(py_float))
+	 fscalar=(float)PyLong_AsLong(py_float);
+	else if (PyTuple_Check(py_float) && (int)PyTuple_Size(py_float)==1)
+	 FetchData(&fscalar,PyTuple_GetItem(py_float,(Py_ssize_t)0));
+	else if (PyList_Check(py_float) && (int)PyList_Size(py_float)==1)
+	 FetchData(&fscalar,PyList_GetItem(py_float,(Py_ssize_t)0));
+	else
+	 _error_("unrecognized float type in input!");
+
+	/*output: */
+	*pscalar=fscalar;
 }
 /*}}}*/
@@ -464,4 +494,89 @@
 }
 /*}}}*/
+/*FUNCTION FetchData(float** pvector,int* pM, PyObject* py_vector){{{*/
+void FetchData(float** pvector,int* pM,PyObject* py_vector){
+
+	/*output: */
+	float* vector=NULL;
+	int M;
+	int ndim;
+	npy_intp*  dims=NULL;
+
+	/*intermediary:*/
+	long*   lvector=NULL;
+	bool*   bvector=NULL;
+	double* dvector=NULL;
+	int i;
+	PyObject* py_vector2=NULL;
+
+	if     (PyArray_Check((PyArrayObject*)py_vector)) {
+		/*retrieve dimensions: */
+		ndim=PyArray_NDIM((const PyArrayObject*)py_vector);
+		if      (ndim==1) {
+			dims=PyArray_DIMS((PyArrayObject*)py_vector);
+			M=dims[0]; 
+		}
+		else if (ndim==2) {
+			dims=PyArray_DIMS((PyArrayObject*)py_vector);
+			if (dims[1]==1)
+			 M=dims[0]; 
+			else
+			 _error_("expecting an Mx1 matrix or M vector in input!");
+		}
+		else
+		 _error_("expecting an Mx1 matrix or M vector in input!");
+
+		if (M) {
+			if (!PyArray_ISCONTIGUOUS((PyArrayObject*)py_vector)) {
+				py_vector2=PyArray_ContiguousFromAny(py_vector,NPY_LONG,ndim,ndim);
+				py_vector=py_vector2;
+			}
+
+			if      (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_DOUBLE) {
+				/*retrieve internal value: */
+				dvector=(double*)PyArray_DATA((PyArrayObject*)py_vector);
+
+				/*transform into int vector: */
+				vector=xNew<float>(M);
+				for(i=0;i<M;i++)vector[i]=(float)lvector[i];
+			}
+
+			else if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_LONG) {
+				/*retrieve internal value: */
+				lvector=(long*)PyArray_DATA((PyArrayObject*)py_vector);
+
+				/*transform into int vector: */
+				vector=xNew<float>(M);
+				for(i=0;i<M;i++)vector[i]=(float)lvector[i];
+			}
+
+			else if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_BOOL) {
+				/*retrieve internal value: */
+				bvector=(bool*)PyArray_DATA((PyArrayObject*)py_vector);
+
+				/*transform into int vector: */
+				vector=xNew<float>(M);
+				for(i=0;i<M;i++)vector[i]=(float)bvector[i];
+			}
+
+			else
+			 _error_("unrecognized int pyarray type in input!");
+
+			if(py_vector2) delete(py_vector2);
+		}
+		else
+		 vector=NULL;
+	}
+	else{
+		M=1;
+		vector=xNew<float>(M);
+		FetchData(&(vector[0]),py_vector);
+	}
+
+	/*output: */
+	if(pM)*pM=M;
+	if(pvector)*pvector=vector;
+}
+/*}}}*/
 /*FUNCTION FetchData(int** pvector,int* pM, PyObject* py_vector){{{*/
 void FetchData(int** pvector,int* pM,PyObject* py_vector){
@@ -809,4 +924,7 @@
 }
 /*}}}*/
+void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,PyObject* A_IN,PyObject* EWGTS_IN){
+	_error_("Nathan... I need your help here");
+}
 
 /*Python version dependent: */
Index: /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp	(revision 22673)
+++ /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp	(revision 22674)
@@ -93,4 +93,21 @@
 	dim=(npy_intp)M;
 	array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,vector_python);
+
+	PyTuple_SetItem(py_tuple, index, array);
+
+}/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index, short* vector, int M){{{*/
+void WriteData(PyObject* py_tuple, int index,short* vector, int M){
+
+	long* lvector=NULL;
+	npy_intp dim=10;
+	PyObject* array=NULL;
+
+	/*transform into long matrix: */
+	lvector=xNew<long>(M);
+	for(int i=0;i<M;i++)lvector[i]=(long)vector[i];
+
+	dim=(npy_intp)M;
+	array=PyArray_SimpleNewFromData(1,&dim,NPY_INT64,lvector);
 
 	PyTuple_SetItem(py_tuple, index, array);
Index: /issm/trunk-jpl/src/wrappers/python/io/pythonio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/pythonio.h	(revision 22673)
+++ /issm/trunk-jpl/src/wrappers/python/io/pythonio.h	(revision 22674)
@@ -22,4 +22,5 @@
 void WriteData(PyObject* py_tuple,int index, int integer);
 void WriteData(PyObject* py_tuple,int index, double* vector, int M);
+void WriteData(PyObject* py_tuple,int index, short* vector, int M);
 void WriteData(PyObject* py_tuple,int index, int* vector, int M);
 void WriteData(PyObject* py_tuple,int index, char* string);
@@ -35,8 +36,10 @@
 void FetchData(bool** pmatrix,int* pM,int *pN,PyObject* py_matrix);
 void FetchData(double** pvector,int* pM,PyObject* py_ref);
+void FetchData(float** pvector,int* pM,PyObject* dataref);
 void FetchData(int** pvector,int* pM,PyObject* py_ref);
 void FetchData(bool** pvector,int* pM,PyObject* py_ref);
 void FetchData(char** pstring,PyObject* py_unicode);
 void FetchData(double* pscalar,PyObject* py_float);
+void FetchData(short* pscalar,PyObject* py_float);
 void FetchData(int* pscalar,PyObject* py_long);
 void FetchData(bool* pbool,PyObject* py_boolean);
@@ -46,4 +49,5 @@
 void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple);
 void FetchData(Contours** pcontours,PyObject* py_list);
+void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,PyObject* A_IN,PyObject* EWGTS_IN);
 
 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void ));
