Index: /issm/trunk-jpl/src/c/shared/Alloc/alloc.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Alloc/alloc.cpp	(revision 12435)
+++ /issm/trunk-jpl/src/c/shared/Alloc/alloc.cpp	(revision 12436)
@@ -84,5 +84,4 @@
 }
 
-
 void* xrealloc( void* pv, int size){
 	
Index: /issm/trunk-jpl/src/c/shared/Numerics/GaussPoints.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Numerics/GaussPoints.cpp	(revision 12435)
+++ /issm/trunk-jpl/src/c/shared/Numerics/GaussPoints.cpp	(revision 12436)
@@ -52,6 +52,6 @@
 
 	//	_printf_(true,"Gauss-Legendre recurrence coefficients ngaus=%d\n",ngaus);
-	*pxgaus = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
-	*pxwgt  = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
+	*pxgaus =xNew<IssmPDouble>(ngaus);
+	*pxwgt  =xNew<IssmPDouble>(ngaus);
 
 	/*  check to see if Gauss points need to be calculated  */
@@ -70,6 +70,6 @@
 
 		/*  calculate the Gauss points using recurrence relations  */
-		alpha=(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
-		beta =(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
+		alpha=xNew<IssmPDouble>(ngaus);
+		beta =xNew<IssmPDouble>(ngaus);
 
 		/*  calculate the Legendre recurrence coefficients  */
@@ -84,6 +84,6 @@
 		/*  calculate the Gauss points  */
 		GaussRecur(*pxgaus, *pxwgt, ngaus, alpha, beta );
-		xfree((void **)&beta );
-		xfree((void **)&alpha);
+		xDelete<IssmPDouble>(beta);
+		xDelete<IssmPDouble>(alpha);
 	}
 }/*}}}*/
@@ -1150,8 +1150,8 @@
 		*pngaus=np[iord-1];
 
-		*pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
+		*pl1  =xNew<IssmPDouble>(*pngaus);
+		*pl2  =xNew<IssmPDouble>(*pngaus);
+		*pl3  =xNew<IssmPDouble>(*pngaus);
+		*pwgt =xNew<IssmPDouble>(*pngaus);
 
 		for (i=0; i<*pngaus; i++) {
@@ -1168,8 +1168,8 @@
 		*pngaus=nigaus*nigaus;
 
-		*pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
+		*pl1  =xNew<IssmPDouble>(*pngaus);
+		*pl2  =xNew<IssmPDouble>(*pngaus);
+		*pl3  =xNew<IssmPDouble>(*pngaus);
+		*pwgt =xNew<IssmPDouble>(*pngaus);
 
 		/*  get the gauss points in each direction  */
@@ -1195,6 +1195,6 @@
 			}
 		}
-		xfree((void **)&xwgt );
-		xfree((void **)&xgaus);
+		xDelete<IssmPDouble>(xwgt );
+		xDelete<IssmPDouble>(xgaus);
 	}
 
@@ -1410,9 +1410,9 @@
 		*pngaus=np[iord-1];
 
-		*pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl4  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
+		*pl1  =xNew<IssmPDouble>(*pngaus);
+		*pl2  =xNew<IssmPDouble>(*pngaus);
+		*pl3  =xNew<IssmPDouble>(*pngaus);
+		*pl4  =xNew<IssmPDouble>(*pngaus);
+		*pwgt =xNew<IssmPDouble>(*pngaus);
 
 		for (i=0; i<*pngaus; i++) {
@@ -1430,9 +1430,9 @@
 		*pngaus=nigaus*nigaus*nigaus;
 
-		*pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pl4  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
-		*pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
+		*pl1  =xNew<IssmPDouble>(*pngaus);
+		*pl2  =xNew<IssmPDouble>(*pngaus);
+		*pl3  =xNew<IssmPDouble>(*pngaus);
+		*pl4  =xNew<IssmPDouble>(*pngaus);
+		*pwgt =xNew<IssmPDouble>(*pngaus);
 
 		/*  get the gauss points in each direction  */
@@ -1467,6 +1467,6 @@
 			}
 		}
-		xfree((void **)&xwgt );
-		xfree((void **)&xgaus);
+		xDelete<IssmPDouble>(xwgt );
+		xDelete<IssmPDouble>(xgaus);
 	}
 }/*}}}*/
@@ -1522,6 +1522,6 @@
 
 	//	_printf_(true,"Gauss-Lobatto recurrence coefficients ngaus=%d\n",ngaus);
-	*pxgaus = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
-	*pxwgt  = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
+	*pxgaus =xNew<IssmPDouble>(ngaus);
+	*pxwgt  =xNew<IssmPDouble>(ngaus);
 
 	/*  check to see if Gauss points need to be calculated  */
@@ -1539,6 +1539,6 @@
 
 		/*  calculate the Gauss points using recurrence relations  */
-		alpha=(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
-		beta =(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
+		alpha=xNew<IssmPDouble>(ngaus);
+		beta =xNew<IssmPDouble>(ngaus);
 
 		/*  calculate the Legendre recurrence coefficients  */
@@ -1575,6 +1575,6 @@
 		/*  calculate the Gauss points  */
 		GaussRecur(*pxgaus, *pxwgt, ngaus, alpha, beta );
-		xfree((void **)&beta );
-		xfree((void **)&alpha);
+		xDelete<IssmPDouble>(beta );
+		xDelete<IssmPDouble>(alpha);
 	}
 
@@ -1598,5 +1598,5 @@
 	}
 
-	work=(IssmPDouble*)xmalloc(n*sizeof(IssmPDouble));
+	work=xNew<IssmPDouble>(n);
 
 	zero[0]  =alpha[0];
@@ -1669,5 +1669,5 @@
 		} while (iter < MAX_GAUS_ITER);
 		if (iter >= MAX_GAUS_ITER) {
-			xfree((void **)&work);
+			xDelete<IssmPDouble>(work);
 			_error_("%s%i"," Max iterations exceeded for l=",MAX_GAUS_ITER);
 		}
@@ -1698,5 +1698,5 @@
 
 	/*Cleanup*/
-	xfree((void **)&work);
+	xDelete<IssmPDouble>(work);
 
 }/*}}}*/
Index: /issm/trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp	(revision 12435)
+++ /issm/trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp	(revision 12436)
@@ -7,4 +7,5 @@
 #include "./trimesh.h"
 #include "../Exceptions/exceptions.h"
+#include "../Alloc/xNewDelete.h"
 #include "../Alloc/alloc.h"
 #include "../../include/include.h"
@@ -53,5 +54,5 @@
 	current_size=max_number_elements;
 	NumGridElements=0;
-	GridElements=(int*)xmalloc(max_number_elements*sizeof(int));
+	GridElements=xNew<int>(max_number_elements);
 
 	for (i=0;i<nel;i++){
@@ -81,5 +82,5 @@
 	cleanup_and_return:
 	if(!noerr){
-		xfree((void**)&GridElements);
+		xDelete<int>(GridElements);
 	}
 	/*Allocate return pointers: */
@@ -165,5 +166,5 @@
 
 	/*Compress riftsegments_uncompressed:*/
-	riftsegments=(int*)xmalloc(nriftsegs*4*sizeof(int));
+	riftsegments=xNew<int>(nriftsegs*4);
 	counter=0;
 	for (i=0;i<nsegs;i++){
@@ -177,5 +178,5 @@
 	}
 
-	xfree((void**)&riftsegments_uncompressed);
+	xDelete<int>(riftsegments_uncompressed);
 	
 	/*Assign output pointers: */
@@ -202,5 +203,5 @@
 	/*Figure out the list of elements  that are on the same side of the rift. To do so, we start from one 
 	 * side of the rift and keep rotating in the same direction:*/
-	GridElementListOnOneSideOfRift=(int*)xmalloc(NumGridElements*sizeof(int));
+	GridElementListOnOneSideOfRift=xNew<int>(NumGridElements);
 	//bootstrap the GridElementListOnOneSideOfRift by filling elements from riftsegments: */
 	GridElementListOnOneSideOfRift[0]=*(riftsegments+4*segmentnumber+0); /*this one does not belong to the same side, but is just there 
@@ -241,5 +242,5 @@
 
 	/*Free ressources: */
-	xfree((void**)&GridElements);
+	xDelete<int>(GridElements);
 	/*Assign output pointers: */
 	*pNumGridElementListOnOneSideOfRift=NumGridElementListOnOneSideOfRift;
@@ -380,14 +381,14 @@
 
 	/*input: */
-	double* segments=NULL;
-	double* segmentmarkerlist=NULL;
+	double *segments          = NULL;
+	double *segmentmarkerlist = NULL;
 	int numsegs;
 	
 	/*output: */
-	int* riftsnumsegs=NULL;
-	double** riftssegments=NULL;
-	int new_numsegs;
-	double* new_segments=NULL;
-	double* new_segmentmarkers=NULL;
+	int      new_numsegs;
+	int     *riftsnumsegs       = NULL;
+	double **riftssegments      = NULL;
+	double  *new_segments       = NULL;
+	double  *new_segmentmarkers = NULL;
 
 	/*intermediary: */
@@ -406,6 +407,6 @@
 	/*Allocate new segments: */
 	new_numsegs=counter;
-	new_segments=(double*)xmalloc(new_numsegs*3*sizeof(double));
-	new_segmentmarkers=(double*)xmalloc(new_numsegs*sizeof(double));
+	new_segments=xNew<double>(new_numsegs*3);
+	new_segmentmarkers=xNew<double>(new_numsegs);
 
 	/*Copy new segments info : */
@@ -422,6 +423,6 @@
 
 	/*Now deal with rift segments: */
-	riftsnumsegs=(int*)xmalloc(numrifts*sizeof(int));
-	riftssegments=(double**)xmalloc(numrifts*sizeof(double*));
+	riftsnumsegs=xNew<int>(numrifts);
+	riftssegments=xNew<double*>(numrifts);
 	for (i=0;i<numrifts;i++){
 		/*Figure out how many segments for rift i: */
@@ -431,5 +432,5 @@
 		}
 		riftsnumsegs[i]=counter;
-		riftsegment=(double*)xmalloc(counter*3*sizeof(double));
+		riftsegment=xNew<double>(counter*3);
 		/*Copy new segments info :*/
 		counter=0;
@@ -446,5 +447,5 @@
 
 	/*Free ressources: */
-	xfree((void**)&segments);
+	xDelete<double>(segments);
 
 	/*Assign output pointers: */
@@ -465,6 +466,6 @@
 
 	/*output: */
-	int* riftsnumpairs=NULL;
-	double** riftspairs=NULL;
+	int     *riftsnumpairs = NULL;
+	double **riftspairs    = NULL;
 
 	/*intermediary :*/
@@ -474,11 +475,11 @@
 	int     node1,node2,node3,node4;
 
-	riftsnumpairs=(int*)xmalloc(numrifts*sizeof(int));
-	riftspairs=(double**)xmalloc(numrifts*sizeof(double*));
+	riftsnumpairs=xNew<int>(numrifts);
+	riftspairs=xNew<double*>(numrifts);
 	for (i=0;i<numrifts;i++){
 		segments=riftssegments[i];
 		numsegs=riftsnumsegments[i];
 		riftsnumpairs[i]=numsegs;
-		pairs=(double*)xmalloc(2*numsegs*sizeof(double));
+		pairs=xNew<double>(2*numsegs);
 		for (j=0;j<numsegs;j++){
 			*(pairs+2*j+0)=*(segments+3*j+2); //retrieve element to which this segment belongs.
@@ -500,9 +501,7 @@
 	}
 
-
 	/*Assign output pointers: */
 	*priftsnumpairs=riftsnumpairs;
 	*priftspairs=riftspairs;
-
 	return noerr;
 }/*}}}*/
@@ -522,17 +521,16 @@
 
 	/*intermediary: */
-	double* riftsegments=NULL;
-	double* riftpairs=NULL;
+	double *riftsegments = NULL;
+	double *riftpairs    = NULL;
 	int     node1,node2,node3,node4,temp_node;
 	double  el2;
 	int     newnods; //temporary # node counter.
 	double  xmin,ymin;
-	double* xreal=NULL;
-	double* yreal=NULL;
-	int* nodes=NULL;
-	int* mergingnodes=NULL;
+	double *xreal        = NULL;
+	double *yreal        = NULL;
+	int    *nodes        = NULL;
+	int    *mergingnodes = NULL;
 	int     max_size;
 	int     redundant;
-
 
 	/*Recover input: */
@@ -562,6 +560,6 @@
 		max_size+=rifts1numsegs[i];
 	}
-	nodes=(int*)xmalloc(max_size*sizeof(int));
-	mergingnodes=(int*)xmalloc(max_size*sizeof(int));
+	nodes=xNew<int>(max_size);
+	mergingnodes=xNew<int>(max_size);
 
 	/*Go through the rifts segments, and identify which node we are going to merge with its counterpart on the other side 
@@ -678,6 +676,6 @@
 		}
 	}
-	xfree((void**)&x); x=xreal;
-	xfree((void**)&y); y=yreal;
+	xDelete<double>(x); x=xreal;
+	xDelete<double>(y); y=yreal;
 
 	/*Assign output pointers:*/
@@ -688,5 +686,4 @@
 	*psegments=segments;
 	*pnumsegs=numsegs;
-
 	return noerr;
 }/*}}}*/
@@ -716,5 +713,4 @@
 	*priftflag=riftflag;
 	*pnumrifts=numrifts;
-
 	return noerr;
 }/*}}}*/
@@ -726,12 +722,12 @@
 
 	/*intermediary: */
-	double* riftsegments=NULL;
-	double* riftpairs=NULL;
+	double *riftsegments = NULL;
+	double *riftpairs    = NULL;
 	int numsegs;
 
 	/*ordering and copy: */
-	int*    order=NULL;
-	double* riftsegments_copy=NULL;
-	double* riftpairs_copy=NULL;
+	int    *order             = NULL;
+	double *riftsegments_copy = NULL;
+	double *riftpairs_copy    = NULL;
 
 	/*node and element manipulation: */
@@ -744,5 +740,5 @@
 
 	/*Allocate byproduct of this routine, riftstips: */
-	riftstips=(double*)xmalloc(numrifts*2*sizeof(double));
+	riftstips=xNew<double>(numrifts*2);
 
 	/*Go through all rifts: */
@@ -754,7 +750,7 @@
 		/*Allocate copy of riftsegments and riftpairs, 
 		 *as well as ordering vector: */
-		riftsegments_copy=(double*)xmalloc(numsegs*3*sizeof(double));
-		riftpairs_copy=(double*)xmalloc(numsegs*2*sizeof(double));
-		order=(int*)xmalloc(numsegs*sizeof(int));
+		riftsegments_copy=xNew<double>(numsegs*3);
+		riftpairs_copy=xNew<double>(numsegs*2);
+		order=xNew<int>(numsegs);
 
 		/*First find the tips, using the pairs. If a pair of elements has one node in common, this node is a rift tip: */
@@ -814,5 +810,4 @@
 		*(riftstips+2*i+0)=(double)tip1;
 		*(riftstips+2*i+1)=(double)tip2;
-
 
 		/*We have the two tips for this rift.  Go from tip1 to tip2, and figure out the order in which segments are sequential. 
@@ -865,7 +860,7 @@
 		}
 
-		xfree((void**)&order);
-		xfree((void**)&riftsegments_copy);
-		xfree((void**)&riftpairs_copy);
+		xDelete<int>(order);
+		xDelete<double>(riftsegments_copy);
+		xDelete<double>(riftpairs_copy);
 
 	}
@@ -887,7 +882,7 @@
 
 	/*output: */
-	double** riftspenaltypairs=NULL;
-	double*  riftpenaltypairs=NULL;
-	int*     riftsnumpenaltypairs=NULL;
+	double **riftspenaltypairs    = NULL;
+	double  *riftpenaltypairs     = NULL;
+	int     *riftsnumpenaltypairs = NULL;
 
 	/*intermediary: */
@@ -901,6 +896,6 @@
 
 	/*Allocate: */
-	riftspenaltypairs=(double**)xmalloc(numrifts*sizeof(double*));
-	riftsnumpenaltypairs=(int*)xmalloc(numrifts*sizeof(int));
+	riftspenaltypairs=xNew<double*>(numrifts);
+	riftsnumpenaltypairs=xNew<int>(numrifts);
 
 	for(i=0;i<numrifts;i++){
@@ -910,5 +905,5 @@
 
 		/*allocate riftpenaltypairs, and riftnumpenaltypairs: */
-		if((numsegs/2-1)!=0)riftpenaltypairs=(double*)xcalloc((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH,sizeof(double));
+		if((numsegs/2-1)!=0)riftpenaltypairs=xNewInit<double>((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH,0.0);
 		
 		/*Go through only one flank of the rifts, not counting the tips: */
@@ -1006,11 +1001,8 @@
 		riftsnumpenaltypairs[i]=(numsegs/2-1);
 	}
-			
-
 
 	/*Assign output pointers: */
 	*priftspenaltypairs=riftspenaltypairs;
 	*priftsnumpenaltypairs=riftsnumpenaltypairs;
-
 	return noerr;
 }
@@ -1143,5 +1135,4 @@
 	*py=y;
 	*pnods=nods;
-
 	return noerr;
 }
