Index: /issm/trunk-jpl/src/wrappers/Chaco/Chaco.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/Chaco/Chaco.cpp	(revision 22670)
+++ /issm/trunk-jpl/src/wrappers/Chaco/Chaco.cpp	(revision 22671)
@@ -23,25 +23,15 @@
 	/*Inputs: */
 	int     nvtxs;               /* number of vertices in graph           */
-	int    *start;               /* start of edge list for each vertex    */
-	int    *adjacency;           /* edge list data                        */
+	int    *start = NULL;        /* start of edge list for each vertex    */
+	int    *adjacency = NULL;    /* edge list data                        */
 	int    *vwgts       = NULL;  /* weights for all vertices              */
-	int     nedges;
 	float  *ewgts       = NULL;  /* weights for all edges                 */
 	float  *x           = NULL;
 	float  *y           = NULL;
 	float  *z           = NULL;  /* coordinates for inertial method       */
-	double  options[10] = {1,1,0,0,1,1,50,0,.001,7654321}; /* architecture and partitioning options */
+	double  options[10] = {1,1,0,0,1,1,50,0,0.001,7654321}; /* architecture and partitioning options */
 	double *in_options  = NULL;
-	int    *nparts      = NULL;   /* number of parts options               */
 	int     npart;
 	double *goal        = NULL;   /* desired set sizes                     */
-
-	/*intermediary pointers: */
-	mwIndex *mwstart, *mwadjacency;
-	double  *doublepointer;
-
-	/*output: */
-   short  *assignment       = NULL; /* set number of each vtx (length nvtxs+1)                */
-   double *doubleassignment = NULL; /*holds assignment, in double format, to return to matlab */
 
 	#ifndef _HAVE_CHACO_ //only works if dakota library has been compiled in.
@@ -53,25 +43,8 @@
 
 	/*checks on arguments on the matlab side: */
-	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ChacoUsage);
+	CHECKARGUMENTS(NLHS,NRHS,&ChacoUsage);
 
-	/*Fetch adjacency matrix: */
-	nvtxs = mxGetN(A_IN);
-	mwstart = mxGetJc(A_IN);
-	start=xNew<int>((nvtxs+1));
-	for (i=0; i<nvtxs+1;i++)start[i]=(int)mwstart[i];
-
-	mwadjacency = mxGetIr(A_IN);
-	adjacency = xNew<int>(mxGetNzmax(A_IN));
-	for (i=0; i<mxGetNzmax(A_IN); i++) adjacency[i]= (int)mwadjacency[i];
-
-	nedges = start[nvtxs];
-	if(!mxIsEmpty(EWGTS_IN)){
-		ewgts = xNewZeroInit<float>(nedges);
-		doublepointer=mxGetPr(A_IN);
-		for (i = 0; i < nedges; i++)ewgts[i] = (float)doublepointer[i];
-	}
-	else ewgts=NULL;
-
-	/*Fetch rest of data: */
+	/*Fetch Data*/
+	FetchChacoData(&nvtxs,&adjacency,&start,&ewgts,A_IN,EWGTS_IN);
 	FetchData(&vwgts,&nterms,VWGTS_IN); 
 	FetchData(&x,&nterms,X_IN); 
@@ -81,45 +54,20 @@
 	for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options
 	FetchData(&npart,NPARTS_IN); 
-	nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
+	//int * nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
 	FetchData(&goal,&nterms,GOAL_IN); 
 
-	/*Some debugging print: {{{*/
-	#ifdef _DEBUG_
-	_printf_("nvtxs: " << nvtxs << "\n");
-	_printf_("options: [");
-	for(i=0;i<10;i++)_printf_(options[i] << "|");
-	_printf_("]\n");
-	_printf_("start: \n");
-	for (i=0; i<nvtxs+1;i++)_printf_(start[i] << " ");
-	_printf_("\n");
-	_printf_("adjacency: \n");
-	for (i=0; i<mxGetNzmax(A_IN);i++)_printf_("" <<adjacency[i]<< " ");i++)
-	_printf_("\n");
-	_printf_("nedges: " << nedges << " " << ewgts << "\n");
-	if(ewgts) for (i = 0; i < nedges; i++)_printf_(ewgts[i] << " ");
-	_printf_("\n");
-	_printf_("vwgts:\n");
-	for (i = 0; i < nvtxs; i++)_printf_(vwgts[i] << " ");
-	_printf_("\n");
-	_printf_("nparts: " << nparts[0] << "\n");
-	_printf_("goal: " << goal << "\n");
-	#endif
-	/*}}}*/
-
 	/*Allocate output: */
-	assignment = xNewZeroInit<short>(nvtxs);
+	short* assignment = xNewZeroInit<short>(nvtxs);
 
     /*Call core: */
-	Chacox(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, assignment, options, nparts, goal);
+	Chacox(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, assignment, options,&npart, goal);
 
     /*Output data: */
-	doubleassignment=xNew<double>(nvtxs);
-	for(i=0;i<nvtxs;i++) doubleassignment[i]=(double)assignment[i];
-	WriteData(ASSGN_OUT,doubleassignment,nvtxs);
+	WriteData(ASSGN_OUT,assignment,nvtxs);
 
 	/*Free ressources:*/
 	xDelete<short>(assignment); 
 	xDelete<double>(goal);
-	xDelete<int>(nparts);
+	//xDelete<int>(nparts);
 	xDelete<float>(z);
 	xDelete<float>(y);
@@ -129,5 +77,4 @@
 	xDelete<int>(adjacency);
 	xDelete<int>(start);
-	xDelete<double>(doubleassignment);
 
 	/*end module: */
Index: /issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp	(revision 22670)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp	(revision 22671)
@@ -642,4 +642,34 @@
 }
 /*}}}*/
+void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,const mxArray* A_IN, const mxArray* EWGTS_IN){/*{{{*/
+
+	/*Fetch adjacency matrix: */
+	int      nvtxs       = mxGetN(A_IN);
+	mwIndex* mwstart     = mxGetJc(A_IN);
+	mwIndex* mwadjacency = mxGetIr(A_IN);
+	int      nzmax       = mxGetNzmax(A_IN);
+
+	int* start = xNew<int>(nvtxs+1);
+	for(int i=0;i<nvtxs+1;i++) start[i]=(int)mwstart[i];
+
+	int* adjacency = xNew<int>(nzmax);
+	for(int i=0; i<nzmax; i++) adjacency[i]= (int)mwadjacency[i];
+
+	/*Get edges weights*/
+	int nedges = start[nvtxs];
+	float* ewgts = NULL;
+	if(!mxIsEmpty(EWGTS_IN)){
+		ewgts = xNewZeroInit<float>(nedges);
+		double* doublepointer = mxGetPr(A_IN);
+		for(int i = 0; i<nedges;i++) ewgts[i] = (float)doublepointer[i];
+	}
+
+	/*Assign output pointers*/
+	*pnvtxs     = nvtxs;
+	*padjacency = adjacency;
+	*pstart     = start;
+	*pewgts     = ewgts;
+}
+/*}}}*/
 
 /*Toolkit*/
Index: /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp	(revision 22670)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp	(revision 22671)
@@ -88,4 +88,27 @@
 /*FUNCTION WriteData(mxArray** pdataref,int* vector, int M){{{*/
 void WriteData(mxArray** pdataref,int* vector, int M){
+
+	mxArray* dataref       = NULL;
+	double*  vector_matlab = NULL;
+
+	if(vector){
+
+		/*create the matlab vector with Matlab's memory manager */
+		vector_matlab=(double*)mxMalloc(M*sizeof(double));
+		for(int i=0;i<M;i++) vector_matlab[i]=double(vector[i]);
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+		mxSetM(dataref,(mwSize)M);
+		mxSetN(dataref,(mwSize)1);
+		mxSetPr(dataref,vector_matlab);
+	}
+	else{
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+	}
+
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,short* vector, int M){{{*/
+void WriteData(mxArray** pdataref,short* vector, int M){
 
 	mxArray* dataref       = NULL;
Index: /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 22670)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 22671)
@@ -23,4 +23,5 @@
 void WriteData(mxArray** pdataref,IssmSeqVec<double>* vector);
 void WriteData(mxArray** pdataref,double* vector, int M);
+void WriteData(mxArray** pdataref,short* vector, int M);
 void WriteData(mxArray** pdataref,int* vector, int M);
 void WriteData(mxArray** pdataref,int integer);
@@ -53,4 +54,5 @@
 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref);
 void FetchData(Contours** pcontours,const mxArray* dataref);
+void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,const mxArray* A_IN, const mxArray* EWGTS_IN);
 
 Option* OptionParse(char* name, const mxArray* prhs[]);
